:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series: #2a78d6;
  --band: #b7d3f6;
  --hover: rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series: #3987e5;
    --band: #184f95;
    --hover: rgba(255, 255, 255, 0.05);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.page { max-width: 1160px; margin: 0 auto; padding: 28px 20px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 14px; font-weight: 600; margin: 0; }
.sub { margin: 4px 0 0; color: var(--text-secondary); }
.head-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.head-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.fetch-picker { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); white-space: nowrap; flex-wrap: wrap; justify-content: flex-end; }
#fetch-select { min-width: 0; font-size: 12px; padding: 3px 8px; border-radius: 999px; max-width: 100%; }
#refresh { cursor: pointer; font-size: 13px; padding: 4px 12px; }
#refresh:hover:not(:disabled) { background: var(--hover); }
#refresh:disabled { cursor: progress; color: var(--text-secondary); }
.refresh-status { font-size: 12px; color: var(--text-secondary); text-align: right; max-width: 360px; }
.refresh-status.error { color: #c0392b; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
select, input[type="search"], button {
  font: inherit; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
select { min-width: 150px; }
button.ghost { background: transparent; cursor: pointer; color: var(--text-secondary); }
button.ghost:hover { background: var(--hover); color: var(--text-primary); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.tile { padding: 16px 18px; }
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-value { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile-note { color: var(--muted); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; margin-bottom: 12px; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } }
.card { margin: 0 0 12px; padding: 16px 18px; min-width: 0; }
.grid .card { margin: 0; }
figcaption { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chart { width: 100%; height: 260px; }
.chart svg { display: block; overflow: visible; }
.axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis-title { fill: var(--text-secondary); font-size: 11px; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 14px; }
.swatch.line { height: 2px; background: var(--series); }
.swatch.band { height: 10px; background: var(--band); border-radius: 2px; }

.loc-list { display: grid; grid-template-columns: minmax(80px, 170px) minmax(60px, 1fr) 56px 76px; gap: 2px 10px; align-items: center; }
.loc-list .hdr { font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.loc-list .name { color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-list .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.loc-list .bar-track { height: 22px; display: flex; align-items: center; }
.loc-list .bar { height: 14px; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }
.loc-row { display: contents; }
.loc-row > * { padding: 3px 0; }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.table-head input { min-width: 240px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; user-select: none; }
th:hover { color: var(--text-primary); }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td { color: var(--text-secondary); }
td:first-child { color: var(--text-primary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--hover); }
.table-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--muted); font-size: 12px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); font-size: 12px; min-width: 140px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .tt-row b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
a { color: var(--series); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.page-foot { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--grid); color: var(--text-secondary); font-size: 12px; }
.page-foot code { font-size: 11px; }
.empty { color: var(--muted); display: flex; height: 100%; align-items: center; justify-content: center; }
