/* Polyweather dashboard — dark surface only.
 *
 * Colors come from the validated data-viz palette: chart surface #1a1a19 on a
 * #0d0d0d page plane, series blue #3987e5, status good/critical #0ca30c/#d03b3b.
 *
 * The red/green pair fails CVD separation on its own (ΔE 4.1 under deuteranopia),
 * so every P&L figure carries an explicit +/− sign and gains/losses are never
 * distinguished by hue alone. Color reinforces the sign; it never replaces it.
 */

:root {
  color-scheme: dark;

  --plane: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #211f1f;
  --border: #2c2c2a;
  --baseline: #383835;

  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;

  --series-1: #3987e5;
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;

  --radius: 12px;
  /* Gaps between components are deliberately tight — 8px on both axes. Each
   * card already carries a border and its own internal padding, so that is the
   * separation doing the work; whitespace between them only needs to keep the
   * borders from reading as one line. The names are kept split by axis so the
   * two can be tuned independently later.
   *
   *   --gap          horizontal, between items in a group (the stat tiles)
   *   --gap-row      vertical,   between items in a group
   *   --gap-section  vertical,   between the major blocks (hero, chart, table)
   */
  --gap: 8px;
  --gap-row: 8px;
  --gap-section: 8px;
  --pad-card: 16px;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Anything toggled with `el.hidden` must actually disappear.
 *
 * The UA stylesheet's `[hidden] { display: none }` is a plain rule, so ANY rule
 * that sets an explicit `display` beats it — and most components here do
 * (grid, flex). That silently leaves "hidden" elements on screen: an empty red
 * error bar under the login form, the app shell showing behind its own empty
 * state. One !important covers the whole class of bug rather than patching each
 * component as it turns up. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; letter-spacing: -0.01em; }
h2 { font-size: 14px; letter-spacing: -0.005em; }
p { margin: 0; }

.muted { color: var(--ink-muted); }
.num { text-align: right; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 12px 16px;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-sub { font-size: 11px; color: var(--ink-muted); }

.mode-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.is-active { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--baseline); }

.mode-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); }
.mode-dot.is-running { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18); }
.mode-dot.is-stopped { background: var(--warning); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill.is-running { color: var(--good); border-color: rgba(12, 163, 12, 0.45); }
.pill.is-stopped { color: var(--warning); border-color: rgba(250, 178, 25, 0.4); }

.signout {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.signout:hover { color: var(--ink); border-color: var(--baseline); }

.conn { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-muted); }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.conn.is-live i { background: var(--good); }
.conn.is-down i { background: var(--critical); }

/* ------------------------------------------------------------------- layout */

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  row-gap: var(--gap-section);
}

/* Every section actually lives inside #content, not directly under <main>, so
 * <main>'s row-gap only ever separated the empty state from the content wrapper
 * — the sections themselves sat flush against each other with 0px between them,
 * separated only by their own borders. The wrapper has to be the grid. */
#content {
  display: grid;
  row-gap: var(--gap-section);
}

/* A grid item's default `min-width: auto` refuses to shrink below its content,
 * so a wide table pushes its card past the viewport and the whole page scrolls
 * sideways — instead of the table scrolling inside its own container. Every
 * grid child opts out, #content's children included now that it is a grid. */
main > *,
#content > *,
.hero-row > *,
.tile-grid > *,
.grid-2 > * { min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-card);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-sub { font-size: 11px; color: var(--ink-muted); margin-top: 4px; max-width: 62ch; line-height: 1.5; }

.hero-row {
  display: grid;
  grid-template-columns: minmax(250px, 310px) 1fr;
  column-gap: var(--gap);
  row-gap: var(--gap-row);
}
.tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: var(--gap); row-gap: var(--gap-row); }
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; column-gap: var(--gap); row-gap: var(--gap-row); }

/* -------------------------------------------------------------- stat tiles */

.tile-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.hero-card { display: flex; flex-direction: column; justify-content: center; }
/* Exactly one hero figure per view; proportional figures, not tabular. */
.hero-figure { font-size: 44px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.1; margin: 8px 0 5px; }
.hero-sub { font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-sep { color: var(--baseline); }

.tile { display: flex; flex-direction: column; gap: 4px; }
.tile-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.tile-foot { font-size: 11px; color: var(--ink-muted); }

/* Sign is the primary cue; color reinforces it. Never color alone. */
.pos { color: var(--good); }
.neg { color: var(--critical); }
.delta { font-weight: 600; }

/* ------------------------------------------------------------------- chart */

.chart-card { padding-bottom: 10px; }
.range-row { display: flex; gap: 2px; padding: 3px; background: var(--plane); border: 1px solid var(--border); border-radius: 8px; }
.range-btn {
  padding: 4px 11px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-muted); font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
.range-btn:hover { color: var(--ink-2); }
.range-btn.is-active { background: var(--surface-2); color: var(--ink); }

.chart-wrap { position: relative; height: 280px; }
#equityChart { width: 100%; height: 100%; display: block; overflow: visible; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  min-width: 150px;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  font-size: 12px;
}
.chart-tooltip .tt-time { color: var(--ink-muted); font-size: 11px; margin-bottom: 5px; }
.chart-tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.chart-tooltip .tt-row span:first-child { color: var(--ink-2); }
.chart-tooltip .tt-row span:last-child { font-variant-numeric: tabular-nums; }

.chart-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--ink-muted); font-size: 12px; text-align: center; padding: 0 24px;
}

/* ------------------------------------------------------------------ params */

.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px 24px; margin: 0; }
.params > div { display: grid; gap: 3px; }
.params dt { font-size: 11px; color: var(--ink-muted); }
.params dd { margin: 0; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }

.rule-chip {
  padding: 4px 10px; border-radius: 6px; background: var(--plane);
  border: 1px solid var(--border); font-family: var(--mono); font-size: 11px; color: var(--ink-2);
}

.exit-mix { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.exit-tag {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 6px;
  background: var(--plane); border: 1px solid var(--border);
  font-size: 11px; color: var(--ink-2);
}
.exit-tag b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ tables */

.table-scroll { overflow-x: auto; min-width: 0; }

/* Both data tables scroll inside their own card instead of growing the page.
 *
 * Open positions was previously uncapped, which was fine at five positions and
 * not at twenty: 20 rows is roughly 1,100px of table pushing the chart, trades
 * and performance panels off the bottom of the screen. Recent trades had the
 * opposite problem — a fixed 340px cap showed 5 of 11 rows regardless of how
 * much room the screen actually had.
 *
 * The cap is viewport-relative so a tall display shows more rows, with an
 * absolute ceiling so it never becomes an unwieldy pane. Column headers are
 * already sticky, so they stay visible while scrolling. */
.table-pane { max-height: min(56vh, 580px); overflow-y: auto; }

/* Recent trades shares its row with Performance, so grid already gives the two
 * cards a common height. Making the card a flex column and letting the pane
 * grow means the trades table fills that height rather than stopping short and
 * leaving dead space under it. min-height:0 is what allows a flex child to
 * shrink below its content and actually scroll. */
/* Trades beside Performance: the log has nine columns and a filter bar, the
 * stats a short list, so the split is 2:1 rather than the grid's default. */
.grid-trades { grid-template-columns: 2.5fr 1fr; }
/* Nine columns in one card: tighter cells so PNL and Reason stay in view. */
#tradesTable th, #tradesTable td { padding-left: 8px; padding-right: 8px; }
#tradesTable td { font-size: 12.5px; }
/* Long strategy labels ellipsize here (the full name is in the tooltip). */
#tradesTable .strat-cell { max-width: 132px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; }
#tradesTable .strat-cell .bt-strat-swatch { vertical-align: middle; }
.grid-2 > .card { display: flex; flex-direction: column; }
.grid-2 > .card > .table-pane { flex: 1 1 auto; min-height: 0; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  text-align: left; white-space: nowrap;
}
thead th.num { text-align: right; }
tbody td { padding: 9px 12px; border-bottom: 1px solid rgba(44, 44, 42, 0.6); white-space: nowrap; line-height: 1.4; }
tbody tr:last-child td { border-bottom: 0; }
thead th:first-child, tbody td:first-child { padding-left: 0; }
thead th:last-child, tbody td:last-child { padding-right: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Open positions stacks city over date — the date matters there, because rows
 * from different days sit in the same table. */
.market-cell { display: grid; gap: 2px; }
.market-cell b { font-weight: 600; text-transform: capitalize; }
.market-cell span { font-size: 10.5px; color: var(--ink-muted); line-height: 1.3; }

/* The city name links to Polymarket. It keeps the row's ink so the table does
 * not turn into a column of blue links; the underline and arrow appear on hover
 * so it is still discoverable. */
.market-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--ink-muted); }
.market-link:hover { color: var(--series-1); border-bottom-color: var(--series-1); }
.market-link:hover::after { content: ' ↗'; font-size: 10px; color: var(--series-1); }
.market-link:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 2px; }

/* Recent trades keeps city and bucket on one line: both are short, the row is
 * already identified by its timestamp, and a single line halves the row height
 * so more of the trade log fits in the same pane. */
/* ---- clickable rows → market chart dialog */
tr.row-open { cursor: pointer; }
tr.row-open:hover td { background: rgba(57, 135, 229, 0.06); }
.mc-dialog {
  width: min(960px, 94vw); max-width: none; padding: 18px 20px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.mc-dialog:focus { outline: none; }
.mc-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.mc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.mc-titles { min-width: 0; }
.mc-titles h2 { font-size: 15px; margin: 0 0 3px; }
.mc-actions { display: flex; gap: 6px; flex: none; }
.mc-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
.mc-key { display: inline-flex; align-items: center; gap: 6px; }
.mc-key i, .mc-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.mc-dot { margin-right: 6px; }
.mc-key b { color: var(--ink); font-weight: 600; }
.mc-key.is-held { padding: 1px 7px; margin: -1px -7px; border: 1px solid var(--baseline); border-radius: 999px; }
.mc-wrap { position: relative; height: min(360px, 52vh); }
.mc-wrap svg { width: 100%; height: 100%; display: block; }
.mc-foot { margin: 8px 0 0; font-size: 11px; color: var(--ink-muted); }
.mc-dialog { max-height: 94vh; overflow-y: auto; }
.mc-h4 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); }
.mc-trades-wrap { max-height: 240px; overflow-y: auto; }
#mcTrades { width: 100%; font-size: 12.5px; }
#mcTrades th, #mcTrades td { padding: 7px 8px; white-space: nowrap; }
#mcTrades td:last-child { white-space: normal; }
.mc-tip-trade { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--border); color: var(--ink); font-size: 11.5px; }
.side-tag.side-settle { color: #8fbcf2; border-color: rgba(57, 135, 229, 0.55); background: rgba(57, 135, 229, 0.1); }
@media (max-width: 600px) { .mc-dialog { padding: 14px 12px 10px; } .mc-wrap { height: 44vh; } }
.trade-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.trade-filters select, .trade-filters input[type="search"] {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--plane); color: var(--ink); font: inherit; font-size: 12px; min-width: 0;
}
.trade-filters select { max-width: 160px; }
.trade-filters input[type="search"] { flex: 1 1 160px; }
.trade-filters select.is-set, .trade-filters input.is-set { border-color: rgba(57, 135, 229, 0.6); }
.trade-filters select:focus-visible, .trade-filters input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.market-inline { display: inline-flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.market-inline b { font-weight: 600; text-transform: capitalize; }
.market-inline span { font-family: var(--mono); font-size: 11px; color: var(--ink-muted); }

.bucket-tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  background: rgba(57, 135, 229, 0.14); border: 1px solid rgba(57, 135, 229, 0.35);
  color: #9ec5f4; font-family: var(--mono); font-size: 11px;
}

/* HIGH / LOW beside the city. With both kinds traded the same city can hold a
 * position in each on the same day, sometimes in the same bucket ("NYC 70-71°F"
 * twice), so the kind is part of the row's identity. Neutral ink on purpose —
 * blue/amber already mean buy/sell and green/red profit/loss in these rows, so
 * the badge stays out of that palette and lets the text carry the meaning. */
.kind-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--baseline);
  color: var(--ink-muted);
  font-style: normal;
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 1px;
}

/* Side badges.
 *
 * Blue for BUY, amber for SELL — deliberately NOT the conventional green/red.
 * The PNL column in this same row already uses green and red for profit and
 * loss, and since a BUY has no P&L, every coloured PNL value sits on a SELL row:
 * a red SELL badge beside a green +$6.90 reads as a contradiction. This pair is
 * validated clear of the P&L colours (ΔE 27.4 under protanopia, 30.7 normal
 * vision), so the two meanings never blur into each other.
 *
 * The ▲/▼ glyph and the word carry the meaning; colour only reinforces it. */
/* A market past its endDate is in its settling window: still trading, but the
 * day's high is being recorded right now, so the price is converging rather
 * than drifting. Worth calling out — the risk profile is different. */
.stage-settling {
  color: #f0b74a;
  font-weight: 600;
  font-size: 11px;
}

.side-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.side-buy {
  color: #9ec5f4;
  background: rgba(57, 135, 229, 0.14);
  border-color: rgba(57, 135, 229, 0.42);
}
.side-sell {
  color: #f0b74a;
  background: rgba(201, 133, 0, 0.16);
  border-color: rgba(201, 133, 0, 0.45);
}

/* A tinted edge on the row's first cell, so a column of trades can be scanned
 * by side without reading each badge. */
.trade-row td:first-child { border-left: 2px solid transparent; padding-left: 10px; }
.trade-row.is-buy  td:first-child { border-left-color: rgba(57, 135, 229, 0.55); }
.trade-row.is-sell td:first-child { border-left-color: rgba(201, 133, 0, 0.6); }

/* Meter: fill carries progress, unfilled track is a lighter step of the same ramp. */
.meter { display: flex; align-items: center; gap: 10px; min-width: 145px; }
.meter-track { position: relative; flex: 1; height: 6px; border-radius: 3px; background: rgba(57, 135, 229, 0.16); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--series-1); }
.meter-val { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

/* Bidirectional meter: entry sits at the center tick; the fill grows right
 * toward take-profit or left (red) toward stop-loss. */
.meter-bidir .meter-track::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 1px; margin-left: -0.5px; background: var(--ink-muted); opacity: 0.6;
}
.meter-bidir .meter-fill { position: absolute; top: 0; left: 50%; border-radius: 0 3px 3px 0; }
.meter-bidir.is-sl .meter-fill { left: auto; right: 50%; border-radius: 3px 0 0 3px; background: var(--critical); }
.meter-bidir .meter-val { min-width: 52px; }
.meter-bidir.is-sl .meter-val { color: var(--critical); }

.table-empty, .empty { color: var(--ink-muted); font-size: 13px; text-align: center; padding: 26px 0; }
.empty h2 { margin-bottom: 6px; font-size: 16px; color: var(--ink); }

.foot { color: var(--ink-muted); font-size: 11px; text-align: center; padding: 4px 0 2px; }

/* ---------------------------------------------------------------- backtest */

/* The page link in the topbar shares the sign-out button's chrome so the two
 * read as one control group; a plain underlined link would be the odd one out. */
.nav-link {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { color: var(--ink); border-color: var(--baseline); }

.run-picker { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-muted); min-width: 0; }
.run-picker select {
  max-width: min(60vw, 520px);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.run-picker select:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: var(--gap); row-gap: var(--gap-row); }
.grid-3 > * { min-width: 0; }
.card-head-mid { margin-top: 18px; }
.chart-wrap-short { height: 200px; }
#monthChart { width: 100%; height: 100%; display: block; overflow: visible; }
.month-bar:hover { fill-opacity: 0.75; }
.assumptions { margin-top: 16px; max-width: none; }
.empty-cmd {
  display: inline-block; text-align: left; margin: 14px auto 0;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink-2); font: 12px/1.6 var(--mono);
}
/* Breakdown tables are short and dense; the first column carries text labels. */
.breakdown tbody td:first-child { color: var(--ink-2); }

/* ------------------------------------------------------- parameter editing */

.card-head-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* One button family. `.btn` is the quiet default (same chrome as sign-out and
 * the nav link); `.btn-primary` is the single filled action in a group. */
.btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { color: var(--ink); border-color: var(--baseline); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { color: #fff; border-color: var(--series-1); filter: brightness(1.1); }
.btn-quiet { background: transparent; }
.btn-danger:hover { color: var(--critical); border-color: rgba(208, 59, 59, 0.5); }
.btn:focus-visible, .pform input:focus-visible, .pform select:focus-visible, .run-picker select:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}

/* Applied / pending chip beside Edit. Colour reinforces the words. */
.param-state { font-size: 11px; color: var(--ink-muted); white-space: nowrap; }
.param-state.is-applied { color: var(--good); }
.param-state.is-pending { color: var(--warning); }

.pform { display: grid; gap: 14px; }
.pform-intro { max-width: none; }
.pform-group { margin: 0; padding: 12px 14px 14px; border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.pform-group legend { padding: 0 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }
.pform-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 18px; }
.pform-field { display: grid; gap: 4px; min-width: 0; }
.pform-field label { font-size: 11.5px; color: var(--ink-2); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.pform-field small { font-size: 10.5px; color: var(--ink-muted); line-height: 1.35; }
.pform input[type="number"], .pform input[type="text"], .pform input[type="date"], .pform select {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--plane);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pform-field.is-overridden input, .pform-field.is-overridden select { border-color: rgba(57, 135, 229, 0.6); }
.pform-field.has-error input, .pform-field.has-error select { border-color: var(--critical); }
.pform-env { font-style: normal; font-family: var(--mono); font-size: 10px; color: var(--series-1); }
.pform-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; cursor: pointer; }
.pform-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--series-1); }
.pform-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pform-error { color: var(--critical); font-size: 12.5px; }

.job-log {
  margin: 0; padding: 10px 12px; max-height: 240px; overflow: auto;
  background: var(--plane); border: 1px solid var(--border); border-radius: 8px;
  color: var(--ink-2); font: 11.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.pill.is-failed { color: var(--critical); border-color: rgba(208, 59, 59, 0.45); }
.foot-actions { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }

/* ------------------------------------------------------------ history data */
.hist-stats { margin-top: 4px; }
.hist-stats dd.is-warn { color: var(--warning); }
.hist-fetch {
  display: flex; flex-wrap: wrap; align-items: end; gap: 10px 14px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.hist-fetch .pform-field { width: 150px; }
.hist-fetch .pform-field.hist-dataset { width: 210px; }
.hist-fetch select {
  width: 100%; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--plane); color: var(--ink); font: inherit; font-size: 13px;
}
.hist-day { position: relative; }
.hist-day.has-trades::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 36%; height: 36%;
  transform: translate(-50%, -50%); border-radius: 50%; background: var(--plane);
}
.hist-fetch input[type="date"] {
  width: 100%; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--plane); color: var(--ink); font: inherit; font-size: 13px;
}
.hist-fetch input[type="date"]:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.hist-fetch-note { flex-basis: 100%; font-size: 10.5px; color: var(--ink-muted); line-height: 1.35; }
.hist-job { display: grid; gap: 6px; margin-top: 12px; }
.hist-progress { height: 6px; border-radius: 3px; background: var(--plane); border: 1px solid var(--border); overflow: hidden; }
.hist-progress span { display: block; height: 100%; width: 0; background: var(--series-1); transition: width 0.4s ease; }
.hist-progress.is-indeterminate span { width: 30%; animation: hist-slide 1.4s ease-in-out infinite; }
@keyframes hist-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .hist-progress.is-indeterminate span { animation: none; width: 100%; opacity: 0.4; } }
.hist-log summary, .hist-cal-wrap summary { cursor: pointer; font-size: 12px; color: var(--ink-2); }
.hist-log .job-log { margin-top: 6px; }
.hist-cal-wrap { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.hist-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 8px; font-size: 11px; color: var(--ink-muted); }
.hist-legend span { display: inline-flex; align-items: center; gap: 5px; }
.hist-legend i { display: inline-block; width: 10px; height: 10px; }
.hist-cal { display: grid; gap: 3px; max-width: 720px; }
.hist-month { display: grid; grid-template-columns: 50px repeat(31, minmax(0, 1fr)); gap: 2px; align-items: center; }
.hist-month-label { font-size: 10.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-day { aspect-ratio: 1; border-radius: 2px; background: transparent; min-width: 0; }
.hist-day.has-data { background: rgb(57 135 229 / var(--a, 1)); }
.hist-day.is-grown { box-shadow: inset 0 0 0 1px var(--warning); }
.hist-day.is-missing { box-shadow: inset 0 0 0 1px var(--critical); }
.hist-day.is-pending { box-shadow: inset 0 0 0 1px var(--warning); }
.hist-day.is-unindexed { background: var(--baseline); }
.hist-day.is-blank { background: var(--surface-2); }
.hist-day.is-none { visibility: hidden; }

/* Forecast positions: the model's probability the bucket pays out. */
.fair-tag { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.fair-tag.is-likely { color: var(--good); }
.fair-tag.is-dead { color: var(--critical); }

/* --------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  .hero-row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  :root { --gap: 8px; --gap-row: 8px; --gap-section: 8px; --pad-card: 14px; }
  main { padding: 8px; }
  .topbar { padding: 10px 12px; }
  tbody td { padding: 10px 10px; }
  thead th { padding: 8px 10px; }
  .tile-grid { grid-template-columns: repeat(2, 1fr); }
  .hero-figure { font-size: 38px; }
  .brand-sub { display: none; }
  .run-picker { order: 3; width: 100%; }
  /* Take the space left after the "Run" caption, not 100% of the label beside
   * it — that overflowed by exactly the caption plus the gap. min-width: 0 is
   * what lets a <select> shrink below its longest option at all. */
  .run-picker select { max-width: none; min-width: 0; flex: 1 1 0; }
}
@media (max-width: 460px) {
  .tile-grid { grid-template-columns: 1fr; }
  .hist-fetch .pform-field { width: calc(50% - 7px); }
  .hist-fetch .pform-field.hist-dataset { width: 100%; }
  .hist-month { grid-template-columns: 40px repeat(31, minmax(0, 1fr)); gap: 1px; }
  .hist-month-label { font-size: 9.5px; }
}

/* ---------------------------------------------------------------- strategies */

/* One card per strategy. They sit inside the Strategies card, so they take the
 * page plane as their ground to read as nested rather than floating. */
.strat-grid {
  display: grid;
  /* auto-FIT, not auto-fill: with three strategies on a wide screen auto-fill
   * leaves empty tracks and the row reads as unfinished. Fit collapses them so
   * the cards share the width. */
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--gap);
}

.strat-card {
  display: flex;
  flex-direction: column;
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
/* A defined-but-disabled strategy is present, not prominent. */
.strat-card.is-idle { opacity: 0.72; }

.strat-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.strat-name { display: grid; gap: 1px; min-width: 0; }
.strat-name b { font-size: 13px; font-weight: 600; }
.strat-name span { font-size: 10px; color: var(--ink-muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; }

/* Deliberately below the page's hero figure: Total equity is the one hero, and
 * several competing 46px numbers would flatten that hierarchy. */
.strat-headline { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 12px; line-height: 1.1; }
.strat-headline-label { font-size: 10px; color: var(--ink-muted); letter-spacing: 0.04em; text-transform: uppercase; margin-top: 2px; }

.strat-stats,
.strat-card-foot {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}
.strat-rule { margin: 4px 0 8px; font-size: 11.5px; color: var(--ink-2); line-height: 1.4; }
.strat-stats { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.strat-card-foot { margin-top: auto; padding-top: 12px; }

.strat-stat { display: grid; gap: 1px; min-width: 0; }
.strat-stat-label { font-size: 10px; color: var(--ink-muted); letter-spacing: 0.03em; text-transform: uppercase; }
.strat-stat-value { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* Status is carried by the word, not the colour — the badge reads on its own. */
.strat-badge {
  font-size: 9.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  border-radius: 4px; padding: 1px 5px; border: 1px solid; white-space: nowrap;
}
.strat-badge.is-on { color: #7fd47f; border-color: rgba(12, 163, 12, 0.45); background: rgba(12, 163, 12, 0.12); }
.strat-badge.is-off { color: var(--ink-muted); border-color: var(--border); }
.strat-badge.is-legacy { color: #f0b74a; border-color: rgba(201, 133, 0, 0.45); background: rgba(201, 133, 0, 0.12); }

/* A rolled-up sell row shows how many fills it took to close. */
.fills-tag {
  font-size: 10px; color: var(--ink-muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 5px; margin-left: 6px; white-space: nowrap;
}

@media (max-width: 460px) {
  .strat-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------- backtest: strategies */

/* Identity swatch beside a strategy name — colour reinforces, the name carries. */
.strat-cell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12px; color: var(--ink-2); }
.strat-cell .bt-strat-swatch { flex: none; }
.bt-strat-swatch {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin-right: 7px; vertical-align: baseline; flex: none;
}

/* ---- new-run form */
.bt-strats-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bt-strats-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
.bt-strats { display: grid; gap: var(--gap); }

.bt-strat { border: 1px solid var(--border); border-radius: 8px; background: var(--plane); min-width: 0; }
.bt-strat.has-error { border-color: var(--critical); }
.bt-strat > summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; cursor: pointer; list-style: none;
}
.bt-strat > summary::-webkit-details-marker { display: none; }
.bt-strat > summary::before {
  content: '▸'; color: var(--ink-muted); font-size: 11px; width: 10px; transition: transform 0.15s;
}
.bt-strat[open] > summary::before { transform: rotate(90deg); }
.bt-strat-title { display: inline-flex; align-items: baseline; gap: 8px; min-width: 0; }
.bt-strat-title b { font-size: 13px; font-weight: 600; }
.bt-strat-title code { font-family: var(--mono); font-size: 10.5px; color: var(--ink-muted); }
.bt-strat-line { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; flex: 1 1 220px; min-width: 0; }
.bt-strat-actions { display: inline-flex; gap: 6px; margin-left: auto; }
.bt-strat-body { display: grid; gap: 12px; padding: 4px 12px 12px; }
.btn-sm { padding: 3px 9px; font-size: 11px; }

/* ---- chart legend */
.chart-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -4px 0 10px; font-size: 11.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-line { width: 16px; height: 2px; border-radius: 1px; }
.legend-line.is-total {
  height: 0; border-top: 1.5px dashed #c3c2b7; background: none;
}

/* ---- parameter comparison */
.param-cmp { width: 100%; border-collapse: collapse; font-size: 12px; }
.param-cmp th, .param-cmp td { padding: 7px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.param-cmp thead th { font-size: 10.5px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.param-cmp tbody td:first-child { color: var(--ink-muted); }
.param-cmp tbody td:not(:first-child) { font-variant-numeric: tabular-nums; color: var(--ink-2); }
/* The rows where strategies disagree are what the run is testing. */
.param-cmp tr.is-diff td:not(:first-child) { color: var(--ink); font-weight: 500; }
.param-cmp tr.is-diff td:first-child { color: var(--ink-2); }
.diff-mark { color: #f0b74a; font-weight: 600; margin-left: 4px; }

/* ---- strategy card footer on the backtest page: rules + sizing */
.strat-rules { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; font-size: 11px; }
.strat-rules .rule-chip { white-space: normal; }
