:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #161a1f;
  --muted: #5a6672;
  --line: #dde2e8;
  --accent: #2a628f;
  --accent-ink: #ffffff;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn-bg: #fff4dc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101316;
    --card: #181c20;
    --ink: #e7ebef;
    --muted: #9aa7b3;
    --line: #2a3138;
    --accent: #6aa0cb;
    --accent-ink: #101316;
    --bad: #ff8a7a;
    --bad-bg: #3a1a17;
    --warn-bg: #3a2f14;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.brand small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}
.topbar nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0; font-size: 1.15rem; }
.note, .source-note, .meta { color: var(--muted); font-size: 0.9rem; }
.note { margin: 8px 0 20px; }

.range { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.range button {
  padding: 8px 14px;
  border: 0;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.range button + button { border-left: 1px solid var(--line); }
.range button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.range button:focus-visible, .retry:focus-visible, .topbar a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bad-bg);
  color: var(--bad);
}

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.source-note { margin: 4px 0 14px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tile .value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.tile .label { color: var(--muted); font-size: 0.85rem; }

.chart h3, .tables h3 { margin: 0 0 6px; font-size: 0.95rem; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .bar { fill: var(--accent); }
.chart .axis, .chart .empty { fill: var(--muted); font-size: 15px; }

.tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
td { padding: 5px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
td.num { text-align: right; padding-left: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); }

.state { padding: 14px; border-radius: 10px; background: var(--bg); color: var(--muted); }
.state.error { background: var(--bad-bg); color: var(--bad); }
.retry {
  margin-left: 10px;
  padding: 4px 12px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.warnings { margin: 14px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); font-size: 0.9rem; list-style: none; }

@media (max-width: 520px) {
  .page { padding-top: 16px; }
  .panel { padding: 14px; }
  .range { width: 100%; }
  .range button { flex: 1; padding: 8px 4px; }
}
