:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --bar: #17294a;
  --bar-ink: #ffffff;
  --accent: #17294a;
  --accent-ink: #ffffff;
  --tip-bg: #17294a;
  --tip-ink: #ffffff;
  --tip-muted: #b9c3d6;
  --warn: #8a5a00;
  --s-spot: #2a78d6;
  --s-imbalance: #eb6834;
  --s-afrr: #1baf7a;
  --s-mfrr: #eda100;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --bar: #13213b;
    --bar-ink: #ffffff;
    --accent: #c8d3ea;
    --accent-ink: #0d0d0d;
    --tip-bg: #2a3a5c;
    --tip-ink: #ffffff;
    --tip-muted: #b9c3d6;
    --warn: #e0a440;
    --s-spot: #3987e5;
    --s-imbalance: #d95926;
    --s-afrr: #199e70;
    --s-mfrr: #c98500;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --bar: #13213b;
  --bar-ink: #ffffff;
  --accent: #c8d3ea;
  --accent-ink: #0d0d0d;
  --tip-bg: #2a3a5c;
  --tip-ink: #ffffff;
  --tip-muted: #b9c3d6;
  --warn: #e0a440;
  --s-spot: #3987e5;
  --s-imbalance: #d95926;
  --s-afrr: #199e70;
  --s-mfrr: #c98500;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--bar); color: var(--bar-ink);
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.brand span { font-weight: 400; opacity: 0.8; }
.who { display: flex; gap: 16px; align-items: center; font-size: 13px; }
.who a { opacity: 0.85; }

.page { max-width: 1500px; margin: 0 auto; padding: 20px 24px 40px; }

.controls {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg button {
  border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-weight: 600; padding: 7px 16px; border-radius: 999px; cursor: pointer;
}
.seg button:hover { background: var(--border); }
.seg button[aria-checked="true"], .seg button[aria-selected="true"] {
  background: var(--accent); color: var(--accent-ink);
}
.seg.small button { padding: 5px 14px; font-size: 13px; }

.datebox {
  display: inline-flex; align-items: center; gap: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.datebox input {
  border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  background: transparent; color: var(--ink); font: inherit; font-weight: 600; padding: 7px 10px;
}
.iconbtn, .textbtn {
  border: 0; background: transparent; color: var(--ink); font: inherit; cursor: pointer;
  padding: 7px 12px; font-size: 16px; line-height: 1;
}
.textbtn { font-size: 13px; font-weight: 600; border-left: 1px solid var(--border); }
.iconbtn:hover, .textbtn:hover { background: var(--border); }
.iconbtn:disabled { opacity: 0.35; cursor: default; background: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--s-spot); outline-offset: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 24px 16px;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 16px; }
.card h1 { font-size: 20px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.sub .warn { color: var(--warn); font-weight: 600; }

.chart-wrap { position: relative; margin-top: 12px; }
#chart { display: block; width: 100%; height: 440px; touch-action: none; }
.chart-wrap.loading #chart { opacity: 0.45; transition: opacity 0.15s; }
.empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ink-2); text-align: center; padding: 24px; pointer-events: none;
}

#chart .grid line { stroke: var(--grid); stroke-width: 1; }
#chart .grid line.zero { stroke: var(--axis); }
#chart .ylab, #chart .xlab { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#chart .unit { fill: var(--muted); font-size: 11px; }
#chart .halo { fill: none; stroke: var(--surface); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; }
#chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#chart .line.down { stroke-dasharray: 6 4; }
#chart .cursor { stroke: var(--ink-2); stroke-width: 1; }
#chart .nowline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
#chart .nowlab { fill: var(--muted); font-size: 11px; }
#chart .badge rect { fill: var(--tip-bg); }
#chart .badge text { fill: var(--tip-ink); font-size: 12px; font-weight: 600; }
#chart .dot { stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--tip-bg); color: var(--tip-ink);
  border-radius: 10px; padding: 10px 14px; min-width: 300px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 13px;
}
.tooltip .t-head { color: var(--tip-muted); font-size: 12px; margin-bottom: 6px; }
.tooltip table { border-collapse: collapse; width: 100%; }
.tooltip td { padding: 3px 0; white-space: nowrap; }
.tooltip td.lbl { color: var(--tip-muted); padding-right: 16px; }
.tooltip td.val { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; padding-left: 14px; }
.tooltip td.val small { font-weight: 400; color: var(--tip-muted); margin-left: 4px; }
.tooltip td.na { color: var(--tip-muted); font-weight: 400; text-align: right; padding-left: 14px; }
.tooltip .key { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 8px; }
.tooltip .key.down { border-top-style: dashed; }
.tooltip tr + tr td { border-top: 1px solid rgba(255, 255, 255, 0.08); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; margin-top: 10px; }
.legend button {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer;
}
.legend button:hover { background: var(--border); }
.legend button[aria-pressed="false"] { opacity: 0.4; }
.legend button[aria-pressed="false"] .lkey { border-top-color: var(--muted) !important; }
.lkey { display: inline-block; width: 22px; height: 0; border-top: 2px solid; }
.lkey.down { border-top-style: dashed; }

.foot { color: var(--muted); font-size: 12px; margin: 10px 0 0; text-align: center; }

.table-wrap { margin-top: 12px; max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
.table-wrap th, .table-wrap td { padding: 6px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
.table-wrap th:first-child, .table-wrap td:first-child { text-align: left; }
.table-wrap thead th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; }
.table-wrap td.na { color: var(--muted); }

body.plain { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.notice { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 32px; max-width: 460px; }
.notice h1 { font-size: 20px; margin: 0 0 8px; }
.login { display: flex; flex-direction: column; gap: 8px; min-width: 260px; margin-top: 12px; }
.login label { font-size: 13px; color: var(--ink-2); }
.login input { font: inherit; padding: 9px 12px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); color: var(--ink); }
.login button { font: inherit; font-weight: 600; padding: 9px 12px; border: 0; border-radius: 8px; background: var(--bar); color: var(--bar-ink); cursor: pointer; }
.login .err { color: #d03b3b; margin: 0; font-size: 13px; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .page { padding: 16px; }
  .card { padding: 16px; }
  .controls { flex-direction: column; align-items: stretch; }
  .seg { overflow-x: auto; }
  .datebox { justify-content: space-between; }
  #chart { height: 340px; }
  .tooltip { min-width: 0; }
}
