.viz-root {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #242422; --line: #33332f; --grid: #2c2c29;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86; --accent: #ffd84d;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --good: #3fae6b; --critical: #e66767; --warning: #c98500;
  margin: 0; background: var(--surface-0); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
.hidden { display: none !important; }
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; padding: 12px 20px; background: var(--surface-1); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; margin-right: auto; }
.brand b { display: block; font-size: 15px; } .brand small { color: var(--text-muted); }
.logo { color: var(--accent); font-size: 22px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters label, label.inline { display: grid; gap: 3px; font-size: 12px; color: var(--text-secondary); }
label.inline { display: inline-grid; margin-bottom: 8px; }
select, input { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; min-width: 0; }
input { width: 150px; }
.btn { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--accent); color: #1a1a19; border-color: var(--accent); font-weight: 600; }
.export { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 12px 30px #0008; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; color: var(--text-primary); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--surface-1); outline: none; }
.menu small { display: block; color: var(--text-muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 0 20px; background: var(--surface-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--text-secondary); padding: 11px 14px; font: inherit; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); }
main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.status { color: var(--text-muted); margin: 0 0 14px; min-height: 1.4em; }
.status.err { color: var(--critical); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi span { display: block; color: var(--text-secondary); font-size: 12px; }
.kpi b { display: block; font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--text-muted); font-size: 11px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; margin-bottom: 16px; }
.grid .card { margin-bottom: 0; }
.card.wide { grid-column: span 2; }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } .card.wide { grid-column: auto; } .brand { margin-right: 0; width: 100%; } }
.card h2 { margin: 0; font-size: 15px; }
.sub { margin: 2px 0 10px; color: var(--text-muted); font-size: 12px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 6px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.empty { color: var(--text-muted); padding: 18px 0; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 200px; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
.scroll { overflow: auto; max-height: 520px; }
/* Wide tables scroll inside their card instead of widening the page on phones. */
.card > div:has(> table) { overflow-x: auto; }
.scroll.tall { max-height: 70vh; }
.bars { display: grid; gap: 7px; }
.bar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.bar .fill { height: 10px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar .val { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.split { display: flex; height: 10px; gap: 2px; min-width: 60px; }
.split span { height: 10px; border-radius: 2px; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; background: var(--surface-2); color: var(--text-secondary); }
.pill.defeat { background: #e6676722; color: #f1a3a3; } .pill.open { background: #3987e522; color: #9cc3f2; } .pill.won_continuing { background: #3fae6b22; color: #95d6ad; }
canvas#heatmap { width: 100%; height: auto; background: #20301f; border-radius: 10px; display: block; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 12px; box-shadow: 0 8px 20px #0007; max-width: 280px; }
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .row { display: flex; gap: 8px; align-items: center; color: var(--text-secondary); }
.tooltip .row i { width: 8px; height: 8px; border-radius: 50%; }
.event-row td { vertical-align: top; }
.event-row pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 11px; color: var(--text-secondary); max-height: 0; overflow: hidden; }
.event-row.open pre { max-height: none; }
.event-row code { font-size: 12px; color: var(--text-secondary); }
.detail-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; flex-wrap: wrap; }
.slim { margin: 10px 0; }
.login { max-width: 460px; margin: 60px auto; text-align: center; }
.login a { color: var(--accent); }

/* Token login */
body.locked .filters, body.locked .export, body.locked #logout, body.locked .tabs { display: none; }
.login { max-width: 440px; margin: 64px auto; display: grid; gap: 14px; text-align: left; }
.login h2 { margin: 0; }
.login .field { display: grid; gap: 6px; color: var(--text-secondary); }
.login input { width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 16px; }
.login code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.login .error { margin: 0; min-height: 1.2em; color: #f08a6c; }
.btn.ghost { background: transparent; }
