/* Minimal styling - functional dashboard, not a design system. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1f26;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #3468e0;
  --danger: #d1293d;
  --ok: #12805c;
  --warn: #b25e09;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topnav .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.topnav a { color: var(--text); text-decoration: none; }
.topnav a:hover { color: var(--accent); }

/* Log out is a POST form (2026-08-03, unsafe-GET fix) but must still read as
   the nav link it replaced - the button carries no button chrome. */
.nav-logout { display: inline; margin: 0; }
.linklike {
  background: none; border: none; padding: 0; font: inherit; cursor: pointer;
  color: var(--text);
}
.linklike:hover { color: var(--accent); }
/* A .linklike button that has to sit in the SAME table column as real anchors
   and be indistinguishable from them (the symbol and hold-time cells in trade
   history, where a same-arm row is a plain link and a cross-arm row is a
   switch form). Without this the identical cell renders blue-underlined on one
   row and plain black on the next. `LinkText` is the browser's own link
   colour, so the two match in light and dark alike - this stylesheet sets no
   `a` rule of its own, which is exactly why hardcoding a blue would drift. */
/* --- Overview status cards (operator ask, 2026-08-26) ---------------------
   Three cards answering "what is this, is it working, and is the experiment
   still intact". They wrap to one column on a narrow screen rather than
   shrinking, because the text inside is prose, not figures. */
.system-description {
  max-width: 70ch; line-height: 1.55; color: var(--text);
  border-left: 3px solid var(--border); padding-left: 12px; margin: 16px 0 20px;
}
.status-grid {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.status-card {
  background: var(--panel); border: 1px solid var(--border);
  border-left-width: 3px; border-radius: 6px; padding: 12px 14px;
}
.status-card h3 {
  margin: 0 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.status-card p { margin: 0; font-size: 14px; line-height: 1.65; }
/* Colour carries the state on the left edge only. A whole card tinted red
   reads as an emergency; a red edge reads as "look here". */
.status-card.status-ok { border-left-color: var(--ok); }
.status-card.status-bad { border-left-color: var(--danger); }
.status-card.status-live { border-left-color: var(--warn); }
.ok-text { color: var(--ok); }
.bad-text { color: var(--danger); }

/* The Held badge is two targets in one pill (operator ask, 2026-08-26): the
   word opens the selected arm's own position, the count opens the cross-arm
   day panel. They need to look like one badge but read as two links, so the
   count carries a divider rather than sitting flush against the word. */
.held-badge a { color: inherit; text-decoration: none; }
.held-badge a:hover { text-decoration: underline; }
.held-badge .held-count {
  margin-left: 5px; padding-left: 5px;
  border-left: 1px solid currentColor; opacity: 0.75;
}
.held-badge .held-count:hover { opacity: 1; }
.linklike.as-link { color: LinkText; text-decoration: underline; }
.linklike.as-link:hover { color: var(--accent); }
.topnav .spacer { flex: 1; }
.topnav .render-time { color: var(--muted); }
.topnav .user { color: var(--muted); }
.topnav .instance-switcher { display: inline-flex; }

/* --- Responsive nav (2026-07-27) -------------------------------------------
   The nav is 11 links plus the brand, instance switcher and render time -
   about 1180px of content with a realistic instance label, so it overflowed
   the viewport on every page below roughly that width. These are the app's
   only breakpoints; everything else already reflows, or scrolls inside its
   own container.

   Wrapping rather than a hamburger: this is an operator tool with no JS
   beyond HTMX, and on a page you glance at from a phone, a few short rows of
   always-visible links beat one row plus a tap-to-reveal with hidden state.

   Just `flex-wrap` - no forced break. .spacer already has flex:1, so it
   absorbs the slack on the first line and the account links fall onto the
   next one by themselves. An earlier version made .spacer a full-width
   `flex: 0 0 100%` break to control the split explicitly; measured side by
   side it was strictly worse (113px and four rows at 935px, versus 79px and
   two here) because it spent a whole row on itself and stranded whichever
   link happened to land last in the primary group. */
@media (max-width: 1200px) {
  .topnav { flex-wrap: wrap; row-gap: 8px; }
}

@media (max-width: 620px) {
  .topnav { gap: 12px; padding: 10px 14px; font-size: 14px; }
  /* Nice-to-have, and the first thing worth its space back. The same
     timestamp is in the page heading. */
  .topnav .render-time { display: none; }
  /* Labels run long ("I hold + stop 4.5"); without a cap one instance name
     can push the whole first row wider than the screen on its own. */
  .topnav .instance-switcher select { max-width: 46vw; }
  .topnav .brand { font-size: 15px; }
}
.topnav .instance-switcher select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Small, semi-opaque secondary text next to a heading - the H1 timestamp,
   "View all" links, etc. Opacity specifically (not a muted color swap like
   .empty uses) per the operator's own "50% opacity" wording, 2026-07-22. */
.heading-annotation { opacity: 0.5; font-size: 12px; font-weight: 400; margin-left: 8px; }

.logo-nav { height: 28px; width: auto; display: block; }
.logo-login { display: block; margin: 0 auto 16px; max-width: 220px; width: 100%; height: auto; }

.login-box {
  max-width: 320px;
  margin: 80px auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
}
.login-box h1 { margin-top: 0; }
.login-box .narrow-form { text-align: left; }
.login-legal-links { margin: 20px 0 0; font-size: 12px; color: var(--muted); }
.login-legal-links a { color: var(--muted); }
.login-legal-links a:hover { color: var(--accent); }

/* Privacy Policy / Terms & Conditions (operator ask, 2026-07-25) - plain
   prose, capped line length for readability, reachable without logging in. */
.legal-page { max-width: 720px; }
.legal-page h1 { margin-bottom: 4px; }
.legal-page h2 { margin-top: 28px; font-size: 17px; }
.legal-page p, .legal-page li { line-height: 1.6; }
.legal-page ul { padding-left: 22px; }
.legal-updated { color: var(--muted); font-size: 13px; margin-top: 0; }

/* Narrow-form spacing - applied explicitly (not a blanket `form` selector,
   which would also squash the wide settings-table form). Used by the login
   box, the Etrade verifier form, and the settings-page password form. */
.narrow-form { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.narrow-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.narrow-form button { align-self: flex-start; }
/* A checkbox+text label reads better on one line than narrow-form's default
   stacked layout (label text above the input) - used by filter forms with a
   toggle alongside text/date fields (History, Activity). */
.narrow-form label.checkbox-label { flex-direction: row; align-items: center; gap: 6px; }

input[type="text"], input[type="password"], input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 4px;
  font-size: 14px;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { opacity: 0.9; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }

/* Recent activity (operator ask, 2026-07-23): bounded height with its own
   scrollbar so the widget behaves like a fixed activity feed instead of
   growing the whole dashboard page taller as more rows show. */
.status-log-scroll { max-height: 420px; overflow-y: auto; }
.status-log-scroll table { margin-top: 0; }
.status-log-scroll th { position: sticky; top: 0; background: var(--panel); }

/* Full-page scrollable/infinite-scroll lists (operator ask, 2026-07-26) -
   Trade History and Bar History: the table body fits the visible page
   instead of growing it, and a trailing sentinel row (hx-trigger="revealed")
   loads the next page just as it scrolls into view. viewport-relative (not
   a flat px value like .status-log-scroll's dashboard-widget sizing) so the
   OUTER page never scrolls instead of this inner list - a fixed height
   taller than "nav + heading + filters" leaves would push the sentinel
   below the page fold, where a mouse-wheel scroll moves the whole page
   instead of revealing it. 260px covers the nav bar, h1, and a typical
   filter form; min-height keeps it usable if that estimate runs long.
   Overridden per-page (e.g. .bars-scroll) when more content sits above it. */
.scroll-list { max-height: calc(100vh - 260px); min-height: 240px; overflow-y: auto; }
.scroll-list table { margin-top: 0; }
.scroll-list th { position: sticky; top: 0; background: var(--panel); }

/* Bar History has a lot more above the list than Trade History does - the
   symbol search form, the close-price chart (period picker + SVG + meta
   line), and the universe-metrics paragraph - so the flat 260px subtraction
   above would push the list below the fold on shorter viewports. */
.bars-scroll { max-height: calc(100vh - 480px); min-height: 200px; }

.settings-table td.description { color: var(--muted); font-size: 13px; }

/* Save button + its own inline status (operator ask, 2026-07-26) - the
   settings forms are long, so the flash at the top of the page is off-screen
   at the moment you click Save and the save read as a no-op. */
.save-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.save-row .save-status { padding: 6px 10px; font-size: 13px; }

/* Settings split into Configuration/Notifications/Password pages (operator
   ask, 2026-07-23), with a small sub-nav shared by all three. */
.settings-nav { display: flex; gap: 16px; margin: 12px 0 20px; }
.settings-nav a { color: var(--text); text-decoration: none; font-weight: 600; }
.settings-nav a:hover { color: var(--accent); }
.settings-search {
  width: 100%; max-width: 420px; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text);
}

/* Compare page. The arm matrix grows a column per enabled instance, so it is
   the one table here that can genuinely outrun the viewport - it scrolls
   inside its own box rather than making the whole page scroll sideways. */
.table-scroll { overflow-x: auto; max-width: 100%; }
td.num, th.num { text-align: right; white-space: nowrap; }
.setting-diff { font-size: 13px; white-space: nowrap; }
.setting-diff code { font-size: 12px; color: var(--muted); }

/* SMS opt-in disclosure. Deliberately reads as a bordered callout rather than
   ordinary body copy: it has to be legible as a consent notice in a screenshot
   submitted for A2P 10DLC review, not blend into the surrounding settings. */
.consent-notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 12px 16px;
  margin: 16px 0;
  background: var(--panel);
}
.consent-notice h2 { margin-top: 0; font-size: 16px; }
.consent-notice ul { margin: 8px 0 0; padding-left: 20px; }
.consent-notice li { margin-bottom: 6px; font-size: 14px; }
.consent-notice p { font-size: 14px; }

.pct-up { color: var(--ok); }
.pct-down { color: var(--danger); }

.notify-table td.toggle-cell { text-align: center; }
.notify-table td.toggle-cell input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.notify-table td .na { color: var(--muted); }

.symbol-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  list-style: none; padding: 0; margin: 10px 0 0;
}
.symbol-suggestions li a {
  display: inline-block; padding: 4px 10px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 14px;
}
.symbol-suggestions li a:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.chart-periods { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }
.chart-periods a {
  display: inline-block; padding: 4px 10px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 13px;
}
.chart-periods a:hover { border-color: var(--accent); }
.chart-periods a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.symbol-name { color: var(--muted); font-size: 14px; margin: -8px 0 8px; }
.chart-meta { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.close-chart { width: 100%; height: 160px; margin-top: 4px; }
.chart-grid-line { stroke: var(--border); stroke-width: 1; }
.chart-grid-label { font-size: 10px; fill: var(--muted); }

/* Position-history chart trade markers + entry reference line */
.chart-entry-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-marker-line { stroke-width: 1; stroke-dasharray: 3 3; }
.chart-marker-line-buy { stroke: var(--ok); }
.chart-marker-line-sale { stroke: var(--danger); }
.chart-marker-dot-buy { fill: var(--ok); }
.chart-marker-dot-sale { fill: var(--danger); }
.marker-legend-buy { color: var(--ok); }
.marker-legend-sale { color: var(--danger); }

/* Position-history table: BOUGHT/SOLD event rows + dimmed post-sale tail */
.event-row td { font-weight: 600; }
.event-row-buy td:nth-child(2) { color: var(--ok); }
.event-row-sale td:nth-child(2) { color: var(--danger); }
.after-sale td { opacity: 0.55; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
}
.badge-test { background: rgba(18, 128, 92, 0.12); color: var(--ok); }
.badge-prod { background: rgba(209, 41, 61, 0.12); color: var(--danger); }
.badge-info { background: rgba(102, 112, 133, 0.12); color: var(--muted); }
.badge-warning { background: rgba(178, 94, 9, 0.12); color: var(--warn); }
.badge-error { background: rgba(209, 41, 61, 0.12); color: var(--danger); }
.badge-pass { background: rgba(18, 128, 92, 0.12); color: var(--ok); }
.badge-fail { background: rgba(209, 41, 61, 0.12); color: var(--danger); }

.flash { padding: 8px 12px; border-radius: 4px; font-size: 14px; }
.flash.error { background: rgba(209, 41, 61, 0.12); color: var(--danger); }
.flash.ok { background: rgba(18, 128, 92, 0.12); color: var(--ok); }

.status-banner { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.status-banner-ok { background: rgba(18, 128, 92, 0.10); border-color: rgba(18, 128, 92, 0.35); }
.status-banner-error { background: rgba(209, 41, 61, 0.10); border-color: rgba(209, 41, 61, 0.35); }
.status-banner-label { font-size: 18px; font-weight: 700; }
.status-banner-ok .status-banner-label { color: var(--ok); }
.status-banner-error .status-banner-label { color: var(--danger); }
.status-banner a { margin-left: 10px; font-weight: 600; }
.status-banner-ok a { color: var(--ok); }
.status-banner-error a { color: var(--danger); }
.status-banner-description { margin: 6px 0 0; font-size: 14px; color: var(--text); }

.rule-jump { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 12px 0 20px; font-size: 13px; }
.rule-jump a { color: var(--muted); }
.timeline-list { margin: 0 0 20px; padding-left: 22px; }
.timeline-list li { margin-bottom: 10px; }
.rule-item { margin-bottom: 18px; }
.rule-item h3 { margin: 0 0 4px; font-size: 15px; }
.rule-item p { margin: 0; color: var(--text); }
.rule-id {
  display: inline-block; font-family: ui-monospace, monospace; font-size: 12px; font-weight: 700;
  color: var(--accent); background: rgba(52, 104, 224, 0.10); border-radius: 4px; padding: 1px 6px;
  margin-right: 6px;
}

.empty { color: var(--muted); }

/* --- Sortable column headers (operator ask, 2026-08-25) -------------------
   Multi-level and stable: clicking a new column keeps the previous one as the
   tiebreaker. That makes the rank number load-bearing rather than decorative -
   with three columns in the stack, three headers carry an arrow, and only the
   rank says which one actually decides the order. */
th .sort-link {
  color: inherit; text-decoration: none; display: inline-flex;
  align-items: baseline; gap: 3px; white-space: nowrap;
}
th .sort-link:hover { color: var(--accent); text-decoration: underline; }
th .sort-link.sorted { color: var(--accent); }
.sort-arrow { font-size: 11px; line-height: 1; }
.sort-rank {
  font-size: 9px; font-weight: 700; line-height: 1;
  color: var(--muted); vertical-align: super;
}
/* Right-aligned headers must push their arrow to the right edge too, or the
   number column and its own header stop lining up. */
th.num .sort-link { justify-content: flex-end; }

/* Company name on its own line under the ticker in the position heading
   (operator ask, 2026-08-25). Un-bolded and muted because the name is context,
   not the identifier - the ticker stays the thing you read first. Stored names
   are upper case and rendered that way; title-casing them turns "JPMORGAN"
   into "Jpmorgan", so the weight and colour do the softening instead of a
   lossy transform.

   .has-company-name closes the h1's bottom margin so the two lines read as one
   heading block rather than as a heading and an unrelated paragraph; the class
   is only applied when a name actually follows, so a delisted symbol keeps the
   normal heading spacing. */
h1.has-company-name { margin-bottom: 0; }
.company-name {
  font-size: 15px; font-weight: 400; color: var(--muted);
  letter-spacing: 0.04em; margin: 2px 0 14px;
}

/* --- Current-instance banner (operator ask, 2026-08-06) -------------------
   Shown on every page so switching the nav dropdown visibly changes the page.
   The label alone was not enough: "E stop 4.5" and "T stop 3.75" differ by two
   characters in a dropdown, which is exactly the change a reader misses. The
   "differs from control by" line carries the weight - no two arms can share it
   without being the same arm. */

.instance-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  margin: 0 0 1.25rem;
  padding: 0.6rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  /* Accent stripe down the side: the largest block of colour on the page that
     is tied to instance identity, so a switch registers peripherally even
     before the text is read. */
  border-left: 4px solid var(--accent);
  border-radius: 6px;
}

.instance-banner.is-control { border-left-color: var(--muted); }

.instance-banner-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.instance-banner-id {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}

.instance-banner.is-control .instance-banner-id { color: var(--muted); }

.instance-banner-label {
  font-weight: 600;
  font-size: 1.05rem;
}

.instance-banner-mode {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
}

/* PRODUCTION means real money. It should not look like the TEST chip. */
.instance-banner-mode.mode-test { background: #eef1f6; color: var(--muted); }
.instance-banner-mode.mode-production { background: var(--danger); color: #fff; }

.instance-banner-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.instance-banner-diff {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 1 1 100%;
}

.instance-banner-diff code {
  background: #eef1f6;
  color: var(--text);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.82rem;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .instance-banner-diff code { white-space: normal; }
}

/* --- Daily candlesticks (operator ask, 2026-08-07) ------------------------
   The line chart shows where price closed; candles show what it did getting
   there. Same axis machinery, but scaled to HIGH/LOW so wicks are never
   clipped - the extremes are the whole reason to draw them. */

/* preserveAspectRatio is deliberately NOT "none" here, unlike the line chart:
   stretching a polyline is harmless, but it would squash candle bodies into
   slivers at some widths and fatten them at others. */
.candle-chart { width: 100%; height: auto; }

.candle-wick { stroke-width: 1; }
.candle-body { stroke-width: 1; }

.candle-up .candle-wick,
.candle-up .candle-body { stroke: var(--ok); }
.candle-up .candle-body { fill: var(--ok); }

.candle-down .candle-wick,
.candle-down .candle-body { stroke: var(--danger); }
.candle-down .candle-body { fill: var(--danger); }

.chart-style-switch { margin-left: 0.75rem; padding-left: 0.75rem; border-left: 1px solid var(--border); }
