/* SPX VRP dashboard. Brand tokens follow roymeshulam.com: navy #1F4E79, slate ink, Inter + Georgia headings. */

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --primary: #1f4e79;
  --primary-ink: #1f4e79;
  --primary-wash: rgba(31, 78, 121, 0.06);
  --line: rgba(31, 78, 121, 0.12);
  --line-strong: rgba(31, 78, 121, 0.22);
  --grid: #e2e8f0;
  --axis: #cbd5e1;
  /* Chart series: validated for colour-blind separation on this surface (dataviz validator, all pairs). */
  --s-real: #2563eb;
  --s-all: #eb6834;
  --s-skip: #1baf7a;
  --gain: #2563eb;
  --loss: #e34948;
  --neutral: #cbd5e1;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --bad: #d03b3b;
  --bad-ink: #b42323;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, "Inter Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #172234;
    --ink: #f1f5f9;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --primary: #1f4e79;
    --primary-ink: #93c5fd;
    --primary-wash: rgba(147, 197, 253, 0.08);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --grid: #2b3a52;
    --axis: #475569;
    --s-real: #3b82f6;
    --s-all: #d95926;
    --s-skip: #199e70;
    --gain: #3b82f6;
    --loss: #e66767;
    --neutral: #475569;
    --good-ink: #34c434;
    --bad-ink: #f08080;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #172234;
  --ink: #f1f5f9;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --primary: #1f4e79;
  --primary-ink: #93c5fd;
  --primary-wash: rgba(147, 197, 253, 0.08);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --grid: #2b3a52;
  --axis: #475569;
  --s-real: #3b82f6;
  --s-all: #d95926;
  --s-skip: #199e70;
  --gain: #3b82f6;
  --loss: #e66767;
  --neutral: #475569;
  --good-ink: #34c434;
  --bad-ink: #f08080;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary); color: #fff; }

h1, h2 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; line-height: 1.3; }
p { margin: 0; }
button, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary-ink); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.visually-hidden, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip:focus { position: fixed; top: 12px; left: 12px; z-index: 200; background: var(--surface); padding: 10px 14px; }

/* Top bar: sticky and blurred, as on the brand site. */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 20px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand img { border-radius: 7px; display: block; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; text-transform: uppercase; color: var(--primary-ink); }
.modes { display: flex; gap: 4px; }
.modes button, .seg button {
  border: 1px solid transparent; background: none; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; font-size: 0.875rem; font-weight: 500; color: var(--ink-2);
}
.modes button:hover, .seg button:hover { color: var(--primary-ink); background: var(--primary-wash); }
.modes button[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--primary); color: #fff; font-weight: 600;
}
.modes .count { opacity: 0.7; font-weight: 500; margin-left: 4px; }
.actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.asof { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.asof.stale { color: var(--bad-ink); }
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; font-weight: 700; font-size: 0.875rem;
  transition: box-shadow 0.15s ease;
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(31, 78, 121, 0.3); }
.btn-primary:disabled { opacity: 0.7; cursor: progress; }
.btn-primary svg, .icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary.busy svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-flex; padding: 8px; border-radius: 999px; border: 0; background: none; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--primary-wash); color: var(--primary-ink); }

.toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-size: 0.875rem; font-weight: 500; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2); max-width: calc(100vw - 32px);
}

main.wrap { padding-top: 40px; padding-bottom: 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }

/* Hero: the question the bot exists to answer, then the numbers behind the answer. */
.hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 40px; align-items: start; padding-bottom: 8px; }
.kicker { font-size: 0.8125rem; font-weight: 600; color: var(--primary-ink); margin-bottom: 12px; }
.hero h1 { font-size: clamp(2.2rem, 4.2vw, 3.4rem); line-height: 1.08; }
.verdict-text { font-size: 1.125rem; line-height: 1.6; color: var(--ink-2); margin-top: 18px; max-width: 62ch; }
.verdict-text strong { color: var(--ink); font-weight: 600; }
.evidence { margin-top: 24px; max-width: 520px; }
.tscale { position: relative; height: 8px; border-radius: 999px; background: var(--grid); margin: 10px 0 6px; }
.tscale .zone { position: absolute; top: 0; bottom: 0; background: var(--primary-wash); border-left: 1px dashed var(--line-strong); }
.tscale .mark {
  position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%;
  transform: translate(-50%, -50%); background: var(--s-real); box-shadow: 0 0 0 3px var(--surface);
}
.tscale-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.evidence-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.875rem; font-weight: 600; }
.evidence-head span:last-child { color: var(--ink-2); font-weight: 500; }

.kpis {
  margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.kpi { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.kpi:nth-child(odd) { border-right: 1px solid var(--line); }
.kpi:nth-last-child(-n + 2) { border-bottom: 0; }
.kpi dt { font-size: 0.8125rem; color: var(--ink-2); font-weight: 500; }
.kpi dd { margin: 4px 0 0; font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.kpi .note { display: block; font-size: 0.8125rem; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.kpi.lead { grid-column: 1 / -1; border-right: 0; }
.kpi.lead dd { font-size: 2.6rem; }
.pos { color: var(--good-ink); }
.neg { color: var(--bad-ink); }

/* Health strip: operational status, quiet unless something is wrong. */
.health {
  display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 14px 20px;
  border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 60%, transparent); font-size: 0.875rem; color: var(--ink-2);
}
.health b { color: var(--ink); font-weight: 600; }
.health .flag::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--good); vertical-align: 1px; }
.health .flag.warn::before { background: var(--warn); }
.health .flag.bad::before { background: var(--bad); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px 20px;
  box-shadow: var(--shadow); min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head > div:first-child { max-width: 70ch; }
.sub { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.8125rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.seg button { padding: 4px 11px; font-size: 0.8125rem; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.select select {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 5px 10px; font-size: 0.8125rem;
}

/* Charts */
.chart { position: relative; width: 100%; height: 240px; }
.chart-tall { height: 320px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { fill: var(--muted); font: 500 11px var(--sans); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .zero { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .label-strong { fill: var(--ink); font-weight: 600; }
.empty {
  display: grid; place-items: center; text-align: center; min-height: 160px; height: 100%;
  color: var(--muted); font-size: 0.9rem; border: 1px dashed var(--line-strong); border-radius: 10px; padding: 16px;
}

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.split div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 0.8125rem; color: var(--ink-2); }
.split b { display: block; font-size: 1.15rem; color: var(--ink); font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* Outcome bars (horizontal) */
.obars { display: grid; gap: 14px; }
.obar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.875rem; }
.obar-head span:first-child { font-weight: 600; }
.obar-head span:last-child { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.obar-track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; margin-top: 6px; }
.obar-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.data th {
  text-align: left; font-weight: 600; color: var(--ink-2); padding: 8px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
.data td { padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data tr:last-child td { border-bottom: 0; }
.data .num { text-align: right; }
.data tr.agg td { font-weight: 600; background: var(--surface-2); }
.data tr.traded td:first-child { font-weight: 600; }
.sortable th button {
  all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center;
}
.sortable th button:focus-visible { outline: 2px solid var(--primary-ink); outline-offset: 2px; }
.sortable th[aria-sort] button::after { content: "▾"; font-size: 0.7rem; }
.sortable th[aria-sort="ascending"] button::after { content: "▴"; }
.history-scroll { max-height: 560px; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--primary-wash); color: var(--primary-ink);
}
.pill.shadow { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.meter { display: inline-block; width: 72px; height: 6px; border-radius: 999px; background: var(--grid); vertical-align: middle; margin-right: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--s-real); border-radius: 999px; }
.more { margin-top: 12px; text-align: center; }
.more button { border: 1px solid var(--line-strong); background: none; border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 0.8125rem; font-weight: 600; color: var(--primary-ink); }

/* Decision timeline */
.cells { display: flex; flex-wrap: wrap; gap: 4px; }
.cell { width: 16px; height: 16px; border-radius: 4px; border: 0; padding: 0; cursor: pointer; }
.cell:hover, .cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.cell-legend { margin-top: 14px; }
.tl-stats { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 0.8125rem; color: var(--ink-2); margin-top: 14px; }
.tl-stats b { color: var(--ink); font-weight: 600; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; max-width: 300px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18); padding: 10px 12px; font-size: 0.8125rem; line-height: 1.45;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row span:first-child { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-note { color: var(--muted); margin-top: 4px; white-space: normal; }

footer.footer { color: var(--muted); font-size: 0.8125rem; padding-top: 8px; padding-bottom: 40px; }

@media (max-width: 980px) {
  .hero, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hero { gap: 28px; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  main.wrap { padding-top: 24px; gap: 16px; }
  .topbar-row { gap: 10px; }
  .actions { margin-left: 0; width: 100%; justify-content: space-between; }
  .modes { order: 3; width: 100%; overflow-x: auto; }
  .panel { padding: 18px 16px; }
  .kpi { padding: 14px; }
  .kpi dd { font-size: 1.3rem; }
  .kpi.lead dd { font-size: 2.1rem; }
  .chart-tall { height: 260px; }
  .split { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Colour roles as classes: the CSP forbids inline style attributes, and var() is unreliable in SVG attributes. */
.f-real { fill: var(--s-real); } .f-all { fill: var(--s-all); } .f-skip { fill: var(--s-skip); }
.f-gain { fill: var(--gain); } .f-loss { fill: var(--loss); } .f-neutral { fill: var(--neutral); }
.st-real { stroke: var(--s-real); } .st-all { stroke: var(--s-all); } .st-skip { stroke: var(--s-skip); }
.bg-real { background: var(--s-real); } .bg-all { background: var(--s-all); } .bg-skip { background: var(--s-skip); }
.bg-gain { background: var(--gain); } .bg-loss { background: var(--loss); } .bg-neutral { background: var(--neutral); }
.bg-warn { background: var(--warn); } .bg-bad { background: var(--bad); }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { opacity: 0.1; }
.ring { stroke: var(--surface); stroke-width: 2; }
.hit { fill: transparent; cursor: crosshair; }
.bar-hit { fill: transparent; }
.threshold { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
