:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --zone-1: #86b6ef;
  --zone-2: #5598e7;
  --zone-3: #2a78d6;
  --zone-4: #1c5cab;
  --zone-5: #104281;
  --wash: rgba(42, 120, 214, 0.08);
  --critical: #d03b3b;
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c7: #4a3aa7;
  --neg: #e34948;
  --nonwear: #c3c2b7;
  --gate: rgba(27, 175, 122, 0.22);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --zone-1: #184f95;
    --zone-2: #256abf;
    --zone-3: #3987e5;
    --zone-4: #6da7ec;
    --zone-5: #b7d3f6;
    --wash: rgba(57, 135, 229, 0.14);
    --c1: #3987e5;
    --c2: #d95926;
    --c3: #199e70;
    --c7: #9085e9;
    --neg: #e66767;
    --nonwear: #52514e;
    --gate: rgba(25, 158, 112, 0.30);
  }
}
:root[data-theme="dark"] {
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --c7: #9085e9;
  --neg: #e66767;
  --nonwear: #52514e;
  --gate: rgba(25, 158, 112, 0.30);

  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --series-1: #3987e5;
  --zone-1: #184f95;
  --zone-2: #256abf;
  --zone-3: #3987e5;
  --zone-4: #6da7ec;
  --zone-5: #b7d3f6;
  --wash: rgba(57, 135, 229, 0.14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .2rem; }
h2 { font-size: 1rem; margin: 0 0 .8rem; color: var(--ink); }
code { font-size: .9em; background: var(--wash); padding: .1em .35em; border-radius: 4px; word-break: break-all; }
.muted { color: var(--ink-2); margin: 0; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1120px; margin: 0 auto; padding: 10px 16px 6px;
}
.actions { display: flex; gap: 8px; align-items: center; }
.tabs {
  display: flex; gap: 2px; max-width: 1120px; margin: 0 auto; padding: 0 12px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 8px 10px 10px; color: var(--ink-2); text-decoration: none; font-size: .92rem;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.brand { font-weight: 650; color: var(--ink); text-decoration: none; }
.inline { display: inline; margin: 0; }

.btn {
  display: inline-block; border: 0; border-radius: 8px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 550;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--border); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.flash {
  background: var(--wash); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 20px;
}
.back { color: var(--ink-2); text-decoration: none; }

.pagehead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.chips { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.chips button {
  border: 0; background: none; color: var(--ink-2); font: inherit; font-size: .9rem;
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.chips button:hover { background: var(--wash); }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .label { display: block; color: var(--ink-2); font-size: .85rem; }
.kpi .value { display: block; font-size: 1.5rem; font-weight: 650; line-height: 1.3; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.welcome { max-width: 560px; margin: 40px auto; }

.chart { position: relative; height: 220px; }
.chart.tall { height: 280px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty { color: var(--muted); display: grid; place-items: center; height: 100%; font-size: .9rem; }
.tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.bar { fill: var(--series-1); }
.bar.dim { opacity: .45; }
.line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: var(--axis); stroke-width: 1; }

.tip {
  position: absolute; pointer-events: none; z-index: 5; white-space: nowrap;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: .85rem; line-height: 1.35;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12); opacity: 0; transition: opacity .1s;
}
.tip.on { opacity: 1; }
.tip b { font-weight: 650; }
.tip span { color: var(--ink-2); }

.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: .9rem; }
.hbar .name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 14px; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 4.5em; text-align: right; }

.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th { text-align: left; font-weight: 550; color: var(--ink-2); border-bottom: 1px solid var(--axis); padding: 8px 10px; white-space: nowrap; }
.list td { border-bottom: 1px solid var(--grid); padding: 9px 10px; white-space: nowrap; }
.list .num { text-align: right; font-variant-numeric: tabular-nums; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--wash); }
.list a { color: var(--ink); text-decoration: none; font-weight: 550; }

.login { max-width: 340px; margin: 12vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login h1 { margin-bottom: 1rem; }
.login label { display: block; font-size: .9rem; color: var(--ink-2); margin-bottom: 4px; }
.login input {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--axis);
  background: var(--page); color: var(--ink); font: inherit; margin-bottom: 14px;
}
.login .btn { width: 100%; }
.error { color: var(--critical); margin: -6px 0 12px; font-size: .9rem; }

#map { height: 380px; border-radius: 8px; z-index: 0; }

/* v2 */
h2 a { color: inherit; text-decoration: none; }
h2 a:hover { color: var(--accent); }
h2.section { font-size: .95rem; color: var(--ink-2); font-weight: 550; margin: 0 0 10px; }
.kpi .sub { display: block; color: var(--ink-2); font-size: .82rem; margin-top: 2px; }
a.kpi.link { color: inherit; text-decoration: none; }
a.kpi.link:hover { border-color: var(--accent); }
.kpi .value { overflow-wrap: anywhere; }

.bar.neg { fill: var(--neg); }
.dim { opacity: .45; }
.refline { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 3; }
.gate { fill: var(--gate); }
.seg:hover { opacity: .8; }
.tick.lane { font-size: 12px; fill: var(--ink-2); }
.chart.lanes4 { height: 170px; }
.chart.lanes6 { height: 220px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -4px 0 10px; font-size: .85rem; color: var(--ink-2); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.lg i.band { height: 12px; width: 18px; border-radius: 2px; }

.item {
  display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none;
  border: 1px solid var(--border); margin-bottom: 8px;
}
.item b { color: var(--ink); margin-right: 6px; }
.item:hover { border-color: var(--accent); background: var(--wash); }
.daynav { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.ghost:hover { color: var(--ink); filter: none; background: var(--wash); }
.ecg { margin-bottom: 22px; }
.ecg-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
.ecg-head .muted { font-size: .88rem; }
[hidden] { display: none !important; }
@media (max-width: 520px) {
  .chips button { padding: 5px 7px; }
  h1 { font-size: 1.35rem; }
}
