/* Polyscalp dashboard (base from polyweather) — 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
