:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f2f1ed;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,0.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s7: #4a3aa7;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b; --good-text: #006300;
  --band-green: rgba(12,163,12,0.16); --band-green-2: rgba(12,163,12,0.30); --band-red: rgba(208,59,59,0.14); --band-red-2: rgba(208,59,59,0.28);
  --overlay: #9a9891;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s7: #9085e9;
  --band-green: rgba(12,163,12,0.18); --band-green-2: rgba(12,163,12,0.32); --band-red: rgba(230,103,103,0.16); --band-red-2: rgba(230,103,103,0.30);
  --overlay: #7d7b74;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.4; }
a { color: var(--s1); }
button { font-family: inherit; }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--ring); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.logo { width: 14px; height: 14px; border-radius: 50%; background: var(--s1); display: inline-block; }
.phase { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.tabs button { background: transparent; border: 0; color: var(--ink-2); padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.tabs button:hover { background: var(--surface-2); }
.tabs button.active { background: var(--surface-2); color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--s1); }
.tools { display: flex; align-items: center; gap: 10px; }
.asof { font-size: 12px; color: var(--muted); }
.ghost { background: transparent; border: 1px solid var(--ring); color: var(--ink-2); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 14px; }

main { padding: 16px; max-width: 1600px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.placeholder { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--ring); border-radius: 12px; }
.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--page); z-index: 50; color: var(--muted); }
.loading.hidden { display: none; }

/* grid + cards */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 10px 12px 8px; min-width: 0; display: flex; flex-direction: column; }
.card.c4 { grid-column: span 4; } .card.c6 { grid-column: span 6; } .card.c8 { grid-column: span 8; } .card.c12 { grid-column: span 12; } .card.c3 { grid-column: span 3; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.card-t { font-weight: 600; font-size: 13.5px; }
.card-sub { color: var(--muted); font-size: 12px; }
.card-r { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chart { width: 100%; height: 230px; }
.chart.tall { height: 300px; } .chart.short { height: 150px; }
.card-f { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.formula { display: none; font-size: 11.5px; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.card.show-formula .formula { display: block; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--ring); color: var(--ink-2); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.FRESH .dot { background: var(--good); } .badge.LATE .dot { background: var(--warn); } .badge.STALE .dot, .badge.MISSING .dot { background: var(--critical); }
.seg { display: inline-flex; border: 1px solid var(--ring); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--ink-2); padding: 3px 8px; cursor: pointer; font-size: 11.5px; }
.seg button.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.ibtn { background: transparent; border: 1px solid var(--ring); color: var(--muted); border-radius: 50%; width: 20px; height: 20px; font-size: 11px; cursor: pointer; line-height: 1; }
.big { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.zone { font-size: 11px; padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.zone.hi { background: var(--band-red-2); color: var(--ink); } .zone.lo { background: var(--band-green-2); color: var(--ink); } .zone.mid { background: var(--surface-2); color: var(--ink-2); }

/* regime banner */
.banner { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.banner .card { padding: 12px 14px; }
.regime { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.regime .pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; color: #0b0b0b; }
.pill.RISK-ON { background: var(--good); } .pill.MIXED { background: var(--warn); } .pill.RISK-OFF { background: var(--critical); color: #fff; }
.cond { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12.5px; margin-top: 6px; }
.cond div { display: flex; gap: 6px; align-items: center; color: var(--ink-2); }
.tick { width: 16px; height: 16px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.tick.on { background: var(--good); } .tick.off { background: var(--critical); } .tick.na { background: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; }
.kv b { color: var(--ink); } .kv span { color: var(--ink-2); }
.override { font-weight: 700; } .override.yes { color: var(--critical); } .override.no { color: var(--good-text); }
:root[data-theme="dark"] .override.no { color: var(--good); }

/* dumbbell */
.dumb { display: flex; flex-direction: column; gap: 2px; }
.dumb-row { display: grid; grid-template-columns: 110px 1fr 84px; align-items: center; gap: 8px; font-size: 12px; height: 22px; }
.dumb-row .lbl { text-align: right; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dumb-row .val { color: var(--muted); font-size: 11px; white-space: nowrap; }
.track { position: relative; height: 18px; }
.track .rail { position: absolute; left: 0; right: 0; top: 8px; height: 2px; background: var(--grid); }
.track .g { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--axis); }
.track .g.lo { border-color: var(--good); } .track .g.hi { border-color: var(--critical); }
.track .seg-line { position: absolute; top: 8px; height: 2px; background: var(--axis); }
.track .pt { position: absolute; top: 4px; width: 10px; height: 10px; border-radius: 50%; margin-left: -5px; border: 2px solid var(--surface); }
.pt.sent { background: var(--s2); } .pt.pos { background: var(--s1); }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--ink-2); margin: 6px 0 2px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.crowd { font-size: 11.5px; color: var(--ink-2); margin-top: 6px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill-s { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; color: #0b0b0b; }
.pill-s.FRESH { background: var(--good); color: #fff; } .pill-s.LATE { background: var(--warn); } .pill-s.STALE { background: var(--critical); color: #fff; } .pill-s.MISSING { background: var(--muted); color: #fff; } .pill-s.UNKNOWN { background: var(--muted); color: #fff; }
.ws { list-style: none; padding: 0; margin: 0; }
.ws li { display: grid; grid-template-columns: 36px 200px 1fr; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--grid); }
.ws li .n { color: var(--muted); } .ws li .l { font-weight: 600; } .ws li .v { color: var(--ink-2); }
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.subtabs button { background: var(--surface); border: 1px solid var(--ring); border-radius: 999px; padding: 5px 12px; color: var(--ink-2); cursor: pointer; font-size: 12.5px; }
.subtabs button.active { background: var(--s1); color: #fff; border-color: var(--s1); }
.sub { display: none; } .sub.active { display: block; }
.note { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.tl { width: 100%; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; background: var(--surface-2); padding: 10px; border-radius: 8px; }

@media (max-width: 1100px) {
  .card.c4 { grid-column: span 6; } .card.c3 { grid-column: span 6; }
  .banner { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  main { padding: 10px; }
  .card.c4, .card.c6, .card.c8, .card.c3 { grid-column: span 12; }
  .dumb-row { grid-template-columns: 90px 1fr 70px; }
  .ws li { grid-template-columns: 30px 1fr; } .ws li .v { grid-column: 2; }
  .tabs button { padding: 6px 8px; font-size: 12px; }
}
