:root {
  color-scheme: dark;
  --bg: #0f0f0e;
  --sidebar: #141413;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2b2b29;
  --border: #2a2a27;
  --border-strong: #3d3d38;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c84;
  --grid: #282825;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, .14);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --div-pos: #3987e5; --div-neg: #e66767; --div-mid: #383835;
  --seq-0: #0d366b; --seq-1: #1c5cab; --seq-2: #3987e5; --seq-3: #86b6ef; --seq-4: #cde2fb;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --r: 10px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f1ef; --sidebar: #f8f8f6; --surface-1: #fcfcfb; --surface-2: #f3f3f1; --surface-3: #e9e9e6;
  --border: #e3e2dd; --border-strong: #cfcec7; --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #77766f;
  --grid: #ecebe7; --accent: #2a78d6; --accent-soft: rgba(42, 120, 214, .1);
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --div-pos: #2a78d6; --div-neg: #e34948; --div-mid: #f0efec;
  --seq-0: #cde2fb; --seq-1: #86b6ef; --seq-2: #3987e5; --seq-3: #1c5cab; --seq-4: #0d366b;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); font: 13px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ------------------------------------------------------------ shell */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--sidebar); border-right: 1px solid var(--border); padding: 14px 10px 20px; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 14px; font-weight: 650; font-size: 14px; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font: 600 10.5px var(--mono); }
.brand small { display: block; font-weight: 400; color: var(--text-muted); font-size: 11px; }
.nav-group { margin-top: 12px; }
.nav-group > span { display: block; padding: 0 10px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); }
.nav-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 6px 10px; border: 0; background: none; border-radius: 7px; color: var(--text-secondary); cursor: pointer; text-align: left; font-size: 13px; }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.on { background: var(--accent-soft); color: var(--text-primary); font-weight: 550; }
.nav-item .ic { width: 16px; text-align: center; opacity: .8; font-size: 12px; }
.side-foot { margin-top: 18px; padding: 10px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); line-height: 1.5; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar .title h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.1px; }
.topbar .title p { margin: 1px 0 0; font-size: 11.5px; color: var(--text-muted); max-width: 640px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis { display: flex; gap: 16px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.kpi { display: flex; flex-direction: column; min-width: max-content; }
.kpi .k { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .v { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; align-items: center; }
.modes { display: flex; gap: 8px; align-items: center; flex: none; }
.mseg { display: inline-flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; gap: 2px; }
.mseg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; font: 600 12px var(--sans); color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.mseg button:hover { color: var(--text-primary); }
.mseg button.on { background: var(--accent); color: #fff; }
#scope-seg button.on[data-scope="0dte"] { background: var(--warning); color: #111; }
.refs-card .refs-g { margin: 4px 0 8px; font-size: 12px; color: var(--text-secondary); }
.refs-card .refs-g b { color: var(--text-primary); font-weight: 600; }
.refs-card ol { margin: 4px 0 0; padding-left: 20px; line-height: 1.5; }
.ref { border-bottom: 1px dotted var(--text-muted); cursor: help; }
.tag.warn { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--text-primary); }
table.drivers td.txt { min-width: 150px; font-size: 11.5px; }
.scope-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--warning); color: #111; font: 600 10px var(--sans); vertical-align: 2px; }
.flow-tables { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; }
.flow-tables .tbl { max-height: 360px; }
td.buy { color: var(--good); } td.sell { color: var(--div-neg); } td.unk { color: var(--text-muted); }
tr.spot-row td { background: var(--accent-soft); }
@media (max-width: 1500px) { .topbar { flex-wrap: wrap; row-gap: 6px; } .topbar .title { flex: 1 1 200px; min-width: 0; } .kpis { order: 3; width: 100%; margin-left: 0; } }
@media (max-width: 1000px) { .flow-tables { grid-template-columns: 1fr; } .modes { order: -1; width: 100%; } }
.asof { font: 11px var(--mono); color: var(--text-muted); white-space: nowrap; }

.page { display: none; padding: 16px 20px 48px; }
.page.on { display: block; }
.stack { display: grid; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.section-title { margin: 10px 2px -2px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); font-weight: 600; }

/* ------------------------------------------------------------ toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; padding: 10px 12px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); }
.ctl { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ctl > label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.ctl input[type=number], .ctl input[type=text], .ctl input[type=date], .ctl select {
  height: 30px; padding: 0 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; outline: none; font: 12.5px var(--mono);
}
.ctl input[type=number] { width: 84px; }
.ctl input:focus, .ctl select:focus { border-color: var(--accent); }
.ctl.check { flex-direction: row; align-items: center; gap: 6px; height: 30px; font-size: 12px; color: var(--text-secondary); }
.toolbar .grow { flex: 1; }
.btn { height: 30px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); cursor: pointer; font-weight: 550; font-size: 12.5px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: none; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn[disabled] { opacity: .6; cursor: progress; }

.seg { display: inline-flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; gap: 2px; }
.seg button { border: 0; background: none; padding: 3px 9px; border-radius: 5px; font-size: 11.5px; color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text-primary); }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border-strong); }

/* ------------------------------------------------------------ cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px 10px; min-width: 0; position: relative; }
.card-h { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.card-h .t { flex: 1; min-width: 0; }
.card-h h2 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-h p { margin: 2px 0 0; font-size: 11.5px; color: var(--text-muted); }
.card-h .tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.info { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border-strong); background: none; color: var(--text-muted); cursor: pointer; font: 600 11px var(--sans); }
.info:hover { color: var(--text-primary); border-color: var(--accent); }
.pop { position: absolute; right: 12px; top: 40px; z-index: 40; width: min(440px, 92%); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px 12px; font-size: 11.5px; color: var(--text-secondary); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.pop b { color: var(--text-primary); }
.pop ol { margin: 6px 0 0; padding-left: 18px; }
.pop li { margin: 3px 0; }
.plot { width: 100%; height: 340px; }
.plot.s { height: 250px; } .plot.m { height: 400px; } .plot.l { height: 480px; } .plot.xl { height: 600px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.tile .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v { font: 500 16px var(--mono); font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.tile .d { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* tables */
.tbl { overflow: auto; max-height: 440px; }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th, table.data td { padding: 5px 9px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-muted); font-weight: 550; font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px; z-index: 1; }
table.data td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.txt { font-family: var(--sans); white-space: normal; text-align: left; color: var(--text-secondary); }
table.data tr:hover td { background: var(--surface-2); }
.pos { color: var(--good); } .neg { color: var(--div-neg); } .muted { color: var(--text-muted); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font: 10.5px var(--sans); border: 1px solid var(--border-strong); color: var(--text-secondary); }
.tag.ok { border-color: var(--good); color: var(--good); }
.tag.bad::before { content: "! "; color: var(--critical); }
.sig { display: inline-flex; align-items: center; gap: 5px; font: 11px var(--sans); }
.sig::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.sig.up::before { background: var(--good); } .sig.down::before { background: var(--critical); }

/* positions */
.positions { display: flex; flex-wrap: wrap; gap: 6px; }
.position { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; font: 11.5px var(--mono); }
.position button { background: none; border: 0; color: var(--text-muted); cursor: pointer; }
.position button:hover { color: var(--critical); }

/* notes, states */
.note { font-size: 11.5px; color: var(--text-muted); line-height: 1.55; }
.note b { color: var(--text-secondary); }
.callout { padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text-secondary); font-size: 12px; }
.empty { display: grid; place-items: center; min-height: 120px; color: var(--text-muted); font-size: 12px; text-align: center; padding: 20px; }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: 460px; z-index: 60; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--critical); background: var(--surface-2); font-size: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.toast::before { content: "ERR  "; color: var(--critical); font-weight: 600; }
.card.loading::after { content: ""; position: absolute; inset: 0; border-radius: var(--r); background: color-mix(in srgb, var(--surface-1) 55%, transparent); z-index: 5; }
.card.loading::before { content: "Computing…"; position: absolute; top: 12px; right: 14px; z-index: 6; font-size: 11px; color: var(--text-secondary); padding: 2px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border-strong); }
.spin { display: inline-block; width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* network */
.net { width: 100%; overflow-x: auto; }
.net svg { display: block; min-width: 980px; }
.net .node rect { fill: var(--surface-2); stroke: var(--border-strong); rx: 8; }
.net .node:hover rect, .net .node.hl rect { stroke: var(--accent); stroke-width: 1.5; }
.net .node { cursor: pointer; }
.net .node .lbl { fill: var(--text-secondary); font: 11px var(--sans); }
.net .node .val { fill: var(--text-primary); font: 500 13px var(--mono); }
.net .edge { fill: none; stroke: var(--border-strong); stroke-width: 1.2; }
.net .edge.hl { stroke: var(--accent); stroke-width: 2; }
.net .layer { fill: var(--text-muted); font: 600 10.5px var(--sans); text-transform: uppercase; letter-spacing: .6px; }
.refs { columns: 2; column-gap: 28px; font-size: 11.5px; color: var(--text-secondary); }
.refs p { margin: 0 0 6px; break-inside: avoid; }
.refs code { color: var(--accent); font: 10.5px var(--mono); }

@media (max-width: 1200px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; z-index: 40; height: auto; display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--border); scrollbar-width: none; }
  .brand { padding: 0 8px 0 0; flex: none; } .brand small { display: none; }
  .sidebar nav { display: flex; flex-wrap: nowrap; }
  .nav-group { display: flex; margin: 0; gap: 2px; padding-left: 6px; border-left: 1px solid var(--border); }
  .nav-group > span, .side-foot { display: none; }
  .nav-item { width: auto; white-space: nowrap; padding: 6px 9px; }
  .nav-item .ic { display: none; }
  .topbar { position: relative; top: 0; flex-wrap: wrap; padding: 8px 16px; }
  .kpis { order: 3; width: 100%; margin: 0; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .page { padding: 12px 16px 40px; }
  .refs { columns: 1; }
}

/* ---------------------------------------------------------------- annotation overlay */
.ann-svg { position: absolute; left: 0; top: 0; z-index: 25; pointer-events: none; overflow: visible; touch-action: none; }
.ann-svg.on { pointer-events: auto; cursor: crosshair; }
.ann-svg.on[data-tool="text"] { cursor: text; }
.ann-notes { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 25; pointer-events: none; }
.ann-note { position: absolute; white-space: pre-wrap; width: max-content; max-width: 360px; font: 600 14px var(--sans); line-height: 1.35;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .55); pointer-events: none; }
.ann-edit { z-index: 26; min-width: 40px; padding: 2px 4px; outline: 1px dashed currentColor; border-radius: 3px; pointer-events: auto; cursor: text;
  background: color-mix(in srgb, var(--bg) 60%, transparent); }
.ann-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 12px; background: var(--surface-1); border: 1px solid var(--border-strong);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .35); }
.ann-bar button { display: inline-grid; place-items: center; width: 34px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--text-secondary); cursor: pointer; }
.ann-bar button:hover { background: var(--surface-2); color: var(--text-primary); }
.ann-bar button.on { background: var(--accent-soft); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--accent); }
.ann-bar .ann-split { position: relative; display: inline-flex; align-items: center; }
.ann-bar .ann-chev { width: 18px; margin-left: -4px; }
.ann-bar .ann-sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; }
.ann-bar .ann-color span { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 3px var(--border-strong); }
.ann-menu { position: absolute; bottom: 42px; left: -6px; display: flex; flex-direction: column; gap: 2px; padding: 5px; border-radius: 10px;
  background: var(--surface-1); border: 1px solid var(--border-strong); box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.ann-menu[hidden] { display: none; }
.ann-menu button { width: auto; justify-content: start; display: flex; gap: 8px; padding: 0 10px; font: 12px var(--sans); white-space: nowrap; }
.main { padding-bottom: 64px; }

/* ---------------------------------------------------------------- market structure */
.hu-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 14px; align-items: stretch; }
.hu-grid.wide { grid-template-columns: minmax(0, 1fr) 260px; }
.hu-side { border-left: 1px solid var(--border); padding: 4px 4px 4px 14px; font-size: 12px; }
.hu-grid:not(.wide) .hu-side { border-left: 0; border-right: 1px solid var(--border); padding: 4px 14px 4px 4px; }
.hu-quad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hs-k { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.hs-status { font: 700 18px var(--mono); margin: 4px 0 10px; letter-spacing: .5px; }
.hs-status.warn-t, td.warn-t { color: var(--warning); }
.hs-tbl { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.hs-tbl td { padding: 5px 0; border-bottom: 1px solid var(--border); }
.hs-tbl td:last-child { text-align: right; }
.hs-note { margin-top: 12px; font-size: 11.5px; line-height: 1.5; color: var(--text-secondary); }
@media (max-width: 1000px) { .hu-grid, .hu-grid.wide { grid-template-columns: 1fr; } .hu-side { border: 0 !important; padding: 0 !important; } .hu-quad { grid-template-columns: 1fr; } }
.hu-last { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.hl-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.hl-k { font-size: 11px; color: var(--text-secondary); }
.hl-v { font: 600 20px var(--mono); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.hl-u { font: 400 11px var(--sans); color: var(--text-muted); }
.hl-d { font-size: 11.5px; color: var(--text-secondary); line-height: 1.45; }
@media (max-width: 1200px) { .hu-last { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .hu-last { grid-template-columns: 1fr; } }
.ctl-inline { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); margin-right: 8px; }
.ctl-inline input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary); border-radius: 6px; padding: 3px 6px; font: 12px var(--mono); }

.data-g ul { margin: 4px 0 6px; padding-left: 18px; line-height: 1.6; }
.data-g .tag { margin-right: 4px; }

/* ================================================================ theme: dark, light-cyan accent, rounded */
:root {
  color-scheme: dark;
  --bg: #000000; --sidebar: #0b0b0d; --surface-1: #161618; --surface-2: #222225; --surface-3: #2e2e32;
  --border: rgba(255, 255, 255, .07); --border-strong: rgba(255, 255, 255, .13);
  --text-primary: #f5f5f7; --text-secondary: #c7c7cc; --text-muted: #8e8e93;
  --grid: rgba(255, 255, 255, .06); --accent: #8fe3f5; --accent-ink: #062a33; --accent-soft: rgba(143, 227, 245, .13); --hdr: #f5f5f7;
  --series-1: #8fe3f5; --series-2: #f5f5f7; --series-3: #5e9bff; --series-4: #8e8e93; --series-5: #18afad; --series-6: #a90f8d; --series-7: #c7c7cc; --series-8: #4fb3c8;
  --div-pos: #18afad; --div-neg: #a90f8d; --div-mid: #161618;
  --seq-0: #161618; --seq-1: #173a44; --seq-2: #2f7f93; --seq-3: #8fe3f5; --seq-4: #e6fbff;
  --good: #18afad; --warning: #ffd60a; --critical: #a90f8d;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --r: 14px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .28);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7; --sidebar: #ececef; --surface-1: #ffffff; --surface-2: #f2f2f5; --surface-3: #e5e5ea;
  --border: rgba(0, 0, 0, .07); --border-strong: rgba(0, 0, 0, .13);
  --text-primary: #1d1d1f; --text-secondary: #424245; --text-muted: #86868b;
  --grid: rgba(0, 0, 0, .06); --accent: #0e9fbf; --accent-ink: #ffffff; --accent-soft: rgba(14, 159, 191, .1); --hdr: #1d1d1f;
  --series-1: #0e9fbf; --series-2: #1d1d1f; --series-3: #0a6ad6; --series-4: #86868b; --series-5: #18afad; --series-6: #a90f8d; --series-7: #6e6e73; --series-8: #5bc2d8;
  --div-pos: #18afad; --div-neg: #a90f8d; --div-mid: #ffffff;
  --seq-0: #ffffff; --seq-1: #d6f4fa; --seq-2: #7fd3e6; --seq-3: #0e9fbf; --seq-4: #064e5e;
  --good: #18afad; --critical: #a90f8d; --warning: #b98900;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
}
html, body { font: 13px/1.45 var(--sans); letter-spacing: -.005em; font-variant-numeric: tabular-nums; }
.app { grid-template-columns: 224px minmax(0, 1fr); }

/* sidebar */
.sidebar { padding: 16px 10px 40px; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; justify-content: space-between; padding: 2px 10px 14px; }
.brand-name { font: 650 15px var(--sans); letter-spacing: -.01em; color: var(--text-primary); }
.brand-sym { font: 600 11.5px var(--sans); color: var(--accent-ink); background: var(--accent); padding: 2px 9px; border-radius: 999px; }
.nav-group { margin-top: 14px; }
.nav-group > span { padding: 0 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-muted); }
.nav-item { border-radius: 8px; padding: 6px 10px; gap: 10px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
.nav-item .code { display: inline-block; flex: none; width: 34px; color: var(--text-muted); font: 500 10.5px var(--mono); }
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.on { background: var(--accent-soft); color: var(--text-primary); font-weight: 600; }
.nav-item.on .code { color: var(--accent); }
.side-foot { font-size: 11px; padding: 12px 10px; border-top: 1px solid var(--border); }

/* top bar */
.topbar { gap: 12px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border); }
.topbar .title h1 { font: 650 17px var(--sans); letter-spacing: -.015em; display: flex; align-items: center; gap: 8px; }
.pcode { color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; font: 600 10.5px var(--mono); letter-spacing: 0; }
.topbar .title p { font-size: 12px; }
.cmd { display: flex; align-items: center; gap: 8px; flex: 0 1 340px; min-width: 200px; background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; padding: 0 12px; height: 32px; transition: border-color .15s, box-shadow .15s; }
.cmd:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cmd-p { color: var(--text-muted); font-weight: 500; }
.cmd input { flex: 1; min-width: 0; background: none; border: 0; outline: none; font: 13px var(--sans); color: var(--text-primary); }
.cmd input::placeholder { color: var(--text-muted); }
.mseg { padding: 2px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 0; }
.mseg button { border-radius: 8px; padding: 5px 12px; font: 600 12px var(--sans); color: var(--text-secondary); transition: background .15s, color .15s; }
.mseg button.on { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
#scope-seg button.on[data-scope="0dte"] { background: var(--warning); color: #1d1d1f; }
.kpis { gap: 18px; }
.kpi { padding: 0; border: 0; }
.kpi .k { font-size: 10.5px; letter-spacing: 0; text-transform: none; color: var(--text-muted); }
.kpi .v { font: 600 13.5px var(--sans); color: var(--text-primary); }
.asof { font: 11.5px var(--sans); }

/* controls */
.btn { border-radius: 9px; height: 30px; padding: 0 13px; font: 600 12.5px var(--sans); letter-spacing: 0; text-transform: none; background: var(--surface-2); border: 1px solid transparent; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 11px; font-size: 12px; }
.page { padding: 18px 22px 72px; }
.stack, .grid2, .grid3 { gap: 16px; }
.toolbar { border-radius: var(--r); padding: 12px 14px; gap: 10px 14px; background: var(--surface-1); border: 1px solid var(--border); box-shadow: var(--shadow); }
.ctl > label { font-size: 11px; letter-spacing: 0; text-transform: none; color: var(--text-muted); font-weight: 500; }
.ctl input[type=number], .ctl input[type=text], .ctl input[type=date], .ctl select { height: 30px; border-radius: 8px; font: 13px var(--sans); background: var(--surface-2); border: 1px solid transparent; transition: border-color .15s, box-shadow .15s; }
.ctl input:focus, .ctl select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.seg { border-radius: 9px; padding: 2px; gap: 2px; background: var(--surface-2); border: 0; }
.seg button { border-radius: 7px; padding: 4px 10px; font: 500 12px var(--sans); }
.seg button.on { background: var(--surface-3); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
:root[data-theme="light"] .seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.section-title { font-size: 13px; text-transform: none; letter-spacing: -.01em; color: var(--text-primary); font-weight: 650; margin: 14px 2px 0; }

/* cards */
.card { border-radius: var(--r); padding: 14px 16px 12px; border: 1px solid var(--border); background: var(--surface-1); box-shadow: var(--shadow); }
.card-h { margin: 0 0 8px; padding: 0; border: 0; background: none; align-items: flex-start; }
.card-h h2 { font: 650 14px var(--sans); letter-spacing: -.01em; text-transform: none; color: var(--text-primary); }
.card-h p { font-size: 12px; margin-top: 2px; color: var(--text-muted); }
.info { border-radius: 50%; width: 22px; height: 22px; font: 600 11px var(--sans); border: 0; background: var(--surface-2); }
.pop { border-radius: 12px; font: 12px/1.5 var(--sans); padding: 12px 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .35); }
.tiles { gap: 8px; background: none; border: 0; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { border-radius: 11px; background: var(--surface-2); padding: 9px 12px; }
.tile .k { font-size: 11px; letter-spacing: 0; text-transform: none; }
.tile .v { font: 600 17px var(--sans); letter-spacing: -.01em; }
.tile .d { font-size: 11px; }
table.data { font-size: 12.5px; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-1); font: 600 11px var(--sans); letter-spacing: 0; text-transform: none; color: var(--text-muted); }
table.data td { font-family: var(--sans); }
table.data td.txt { font-family: var(--sans); font-size: 12px; }
table.data tr:nth-child(even) td { background: none; }
table.data tr:hover td { background: var(--surface-2); }
.tag { border-radius: 999px; font: 500 11px var(--sans); padding: 1px 8px; border: 0; background: var(--surface-2); }
.tag.ok { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.callout { border-radius: 11px; border: 0; background: var(--accent-soft); font-size: 12.5px; padding: 10px 14px; }
.toast { border-radius: 12px; font: 12.5px var(--sans); bottom: 40px; }
.card.loading::before { content: "Loading…"; border-radius: 999px; font: 500 11px var(--sans); letter-spacing: 0; color: var(--text-secondary); }
.empty { font-size: 12.5px; }
.sq { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; vertical-align: 0; background: currentColor; }
.hl-card { border-radius: 12px; }
.position { border-radius: 999px; }
.hl-v { font: 650 20px var(--sans); }
.hs-status { font: 700 17px var(--sans); }
.hs-tbl { font-family: var(--sans); }

/* status bar */
.statusbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; display: flex; gap: 0; height: 26px; align-items: center;
  padding: 0 8px env(safe-area-inset-bottom, 0px); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border); font: 11px var(--sans); color: var(--text-muted); overflow: hidden; white-space: nowrap; }
.statusbar > span { padding: 0 10px; border-right: 1px solid var(--border); }
.statusbar > span:last-child { border-right: 0; }
.statusbar b { color: var(--text-primary); font-weight: 600; }
.ann-bar { bottom: calc(36px + env(safe-area-inset-bottom, 0px)); left: auto; right: 16px; transform: none; padding: 4px; gap: 2px; border-radius: 14px;
  background: color-mix(in srgb, var(--surface-1) 85%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.ann-bar button { width: 30px; height: 28px; border-radius: 9px; }
.ann-menu { border-radius: 12px; }
.main { padding-bottom: 34px; }

/* calculators */
.cform { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin: 4px 0 10px; }
.cf { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 500; color: var(--text-muted); }
.cf input, .cf select { height: 30px; padding: 0 9px; background: var(--surface-2); border: 1px solid transparent; border-radius: 8px; color: var(--text-primary); font: 13px var(--sans); outline: none; }
.cf input:focus, .cf select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid2.tight { gap: 16px; align-items: start; }
table.data.kv td:first-child { color: var(--text-secondary); }
table.data.kv td:last-child { color: var(--text-primary); font-weight: 500; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
@media (max-width: 1000px) { .app { grid-template-columns: minmax(0, 1fr); } .nav-item .code { display: none; } .cmd { order: -2; flex: 1 1 100%; } .statusbar > span:nth-child(n+5) { display: none; } }

/* login (hosted mode) */
.login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.login-card { display: flex; flex-direction: column; gap: 10px; width: min(340px, 100%); padding: 26px 24px 22px; border-radius: 18px;
  background: var(--surface-1); border: 1px solid var(--border); box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.login-card h2 { margin: 0; font: 650 20px var(--sans); letter-spacing: -.02em; }
.login-card p { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; }
.login-card input { height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid transparent; background: var(--surface-2); color: var(--text-primary); font: 14px var(--sans); outline: none; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { height: 38px; font-size: 14px; }
.login-err { min-height: 16px; font-size: 12px; color: var(--critical); }

/* ---------------------------------------------------------------- dashboard */
:root { --dash-pos: #18afad; --dash-neg: #a90f8d; }
:root[data-theme="light"] { --dash-pos: #18afad; --dash-neg: #a90f8d; }
#page-dash { padding: 10px 12px 40px; }
.dash { display: flex; flex-direction: column; gap: 8px; }
.dash-bar { display: flex; align-items: center; gap: 12px; }
.dash-sym { font: 650 15px var(--sans); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: 560px 440px; gap: 8px;
  grid-template-areas: "heat bars fwd" "heat ts smile"; }
.dash-heat { grid-area: heat; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 8px; min-height: 0; }
.d-bars { grid-area: bars; } .d-fwd { grid-area: fwd; } .d-ts { grid-area: ts; } .d-smile { grid-area: smile; }
.d-raw { grid-column: 2 / 4; }
.dpanel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.dpanel > header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 11.5px; color: var(--text-secondary); }
.dpanel > header.sub { border-top: 1px solid var(--border); }
.dpanel > header b { font-weight: 600; color: var(--text-primary); margin-right: 2px; }
.dpanel .grow { flex: 1; }
.dsel { display: inline-flex; align-items: center; gap: 4px; }
.dsel span { color: var(--text-muted); font-size: 11px; }
.dsel select { height: 24px; padding: 0 6px; border-radius: 7px; border: 1px solid transparent; background: var(--surface-2); color: var(--text-primary); font: 500 11.5px var(--sans); outline: none; }
.dsel select:focus { border-color: var(--accent); }
.dbtn { height: 24px; padding: 0 9px; border: 0; border-radius: 7px; background: var(--surface-2); color: var(--text-secondary); font: 500 11px var(--sans); cursor: pointer; margin-left: auto; }
.dbtn:hover { color: var(--text-primary); background: var(--surface-3); }
.dstat { font-size: 11px; color: var(--text-muted); display: inline-flex; gap: 10px; }
.dpos { color: var(--dash-pos); } .dneg { color: var(--dash-neg); }
.dplot { flex: 1; min-height: 0; width: 100%; }
.dheat { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; }
table.dhm { width: 100%; border-collapse: separate; border-spacing: 2px; font-size: 11px; table-layout: fixed; }
table.dhm th { width: 34px; padding: 0 4px 0 2px; text-align: right; font-weight: 500; color: var(--text-muted); position: sticky; left: 0; background: var(--surface-1); }
table.dhm td { height: 21px; padding: 0 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; color: var(--text-secondary); background: var(--surface-2); }
table.dhm td.hi { color: #fff; font-weight: 500; }
:root[data-theme="light"] table.dhm td.hi { color: #fff; }
table.dhm tr.atm td { box-shadow: inset 0 0 0 1.5px var(--warning); }
table.dhm tr.atm th { color: var(--warning); font-weight: 650; }
table.dhm tfoot td { position: sticky; bottom: 0; background: var(--surface-1); color: var(--text-muted); font-size: 10.5px; height: 22px; }
table.dhm tfoot small { color: var(--text-muted); }
.dtbl { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; }
table.dt { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.dt th { position: sticky; top: 0; background: var(--surface-1); text-align: left; font-weight: 500; color: var(--text-muted); padding: 4px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.dt td { padding: 3px 8px; white-space: nowrap; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
table.dt tr:hover td { background: var(--surface-2); }
.d-raw { height: 360px; }
@media (max-width: 1400px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: 620px 440px 420px; grid-template-areas: "heat heat" "bars fwd" "ts smile"; }
  .d-raw { grid-column: 1 / 3; }
}
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "heat" "bars" "fwd" "ts" "smile"; }
  .dash-heat { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(4, 420px); }
  .d-bars, .d-fwd, .d-smile { height: 380px; } .d-ts { height: 480px; } .d-raw { grid-column: auto; }
}
