:root {
  color-scheme: light;
  --bg: #f4f5f3;
  --surface: #fcfcfb;
  --border: #e3e3df;
  --grid: #e8e8e4;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6d6c67;
  --series: #2a78d6;
  --band-target: rgba(12, 163, 12, 0.08);
  --iqr: rgba(42, 120, 214, 0.30);
  --outer: rgba(42, 120, 214, 0.12);
  --accent: #2a78d6;
  /* status palette: fixed, never themed */
  --very-low: #a32020;
  --low: #d03b3b;
  --in-range: #0ca30c;
  --high: #fab219;
  --very-high: #ec835a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121614;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --grid: #2a2a28;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --series: #3987e5;
    --band-target: rgba(12, 163, 12, 0.14);
    --iqr: rgba(57, 135, 229, 0.38);
    --outer: rgba(57, 135, 229, 0.16);
    --accent: #3987e5;
    --very-low: #e05555;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121614; --surface: #1a1a19; --border: #2c2c2a; --grid: #2a2a28;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f; --series: #3987e5;
  --band-target: rgba(12, 163, 12, 0.14); --iqr: rgba(57, 135, 229, 0.38);
  --outer: rgba(57, 135, 229, 0.16); --accent: #3987e5; --very-low: #e05555;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 16px 16px 40px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--low); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; margin: 0; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.top-meta { display: flex; gap: 12px; align-items: baseline; font-size: 13px; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; font: inherit; cursor: pointer; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }

.login form { display: flex; gap: 8px; margin-top: 10px; }
.login input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
.login button, .ranges button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font: inherit; cursor: pointer;
}
.login button { background: var(--accent); border-color: var(--accent); color: #fff; border-radius: 10px; }

.hero { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero-main { display: flex; align-items: baseline; gap: 8px; }
.hero-value { font-size: 56px; font-weight: 650; line-height: 1; letter-spacing: -0.02em; }
.hero-unit { color: var(--text-2); font-size: 15px; }
.hero-arrow { font-size: 34px; color: var(--text-2); line-height: 1; }
.hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 14px; }
.hero.stale .hero-value { color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--text);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--muted)); }

.ranges { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.ranges::-webkit-scrollbar { display: none; }
.ranges button { white-space: nowrap; font-size: 14px; padding: 6px 12px; }
.ranges button[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .threshold { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.chart .band { fill: var(--band-target); }
.chart .series { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .iqr { fill: var(--iqr); }
.chart .outer { fill: var(--outer); }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  white-space: nowrap;
}
.tip b { font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.stat .unit { font-size: 13px; color: var(--text-2); font-weight: 400; margin-left: 4px; }
.stat .note { color: var(--muted); font-size: 12px; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } .hero-value { font-size: 46px; } }

.tir-bar { display: flex; height: 22px; gap: 2px; border-radius: 6px; overflow: hidden; margin: 6px 0 12px; }
.tir-bar span { display: block; height: 100%; min-width: 0; }
.tir-rows { display: grid; gap: 6px; }
.tir-row { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 10px; align-items: center; font-size: 14px; }
.tir-row i { width: 10px; height: 10px; border-radius: 3px; display: block; }
.tir-row .pct { font-weight: 650; min-width: 52px; text-align: right; }
.tir-row .goal { color: var(--muted); font-size: 12px; min-width: 64px; text-align: right; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-top: 6px; }
.sw { display: inline-block; width: 18px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-line { height: 2px; background: var(--series); vertical-align: 3px; }
.sw-iqr { background: var(--iqr); }
.sw-outer { background: var(--outer); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }

.foot { margin-top: 18px; text-align: center; }
