:root {
  color-scheme: light;
  --surface-0: #f4f4f1;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --grid: #ecebe6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;
  --series-muted: #b9b8b1;
  --hover: #f0efea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #2e2e2c;
    --grid: #262624;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --series-muted: #55544f;
    --hover: #232321;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --border: #2e2e2c;
  --grid: #262624;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --series-1: #3987e5;
  --series-muted: #55544f;
  --hover: #232321;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header, main { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 28px; }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 17px; }
.sub { margin: 4px 0 20px; color: var(--text-secondary); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile, .chart, .table-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile-label { color: var(--text-secondary); font-size: 12px; }
.tile-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-value.small { font-size: 14px; font-weight: 500; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-bottom: 16px; }
.chart { margin: 0; padding: 14px 16px; min-width: 0; }
figcaption { font-weight: 600; margin-bottom: 10px; }
.note { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.bars { display: grid; grid-template-columns: max-content 1fr; column-gap: 10px; row-gap: 2px; max-height: 460px; overflow-y: auto; }
.bar-row { display: contents; }
.bar-label { color: var(--text-secondary); font-size: 12px; align-self: center; white-space: nowrap; }
.bar-track { position: relative; height: 20px; display: flex; align-items: center; gap: 6px; cursor: default; }
.bar-fill { height: 14px; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-fill.other { background: var(--series-muted); }
.bar-value { color: var(--text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row:hover .bar-label, .bar-row:hover .bar-value { color: var(--text-primary); }
.bar-row:hover .bar-fill { filter: brightness(1.1); }
.empty { color: var(--text-muted); grid-column: 1 / -1; }

.table-section { padding: 14px 16px; margin-bottom: 32px; }
.table-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
input, select, button {
  font: inherit; color: var(--text-primary); background: var(--surface-0);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}
input[type="search"] { width: min(320px, 100%); }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }
tbody tr:hover { background: var(--hover); }
td.muted { color: var(--text-muted); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--text-secondary); }

.tip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
  font-size: 12px; box-shadow: 0 4px 14px rgb(0 0 0 / .15);
}

.admin-card { max-width: 560px; }
.admin-card h3 { font-size: 14px; margin: 14px 0 6px; color: var(--text-secondary); }
.admin-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.admin-form input { flex: 1; min-width: 200px; }
.admin-msg { color: var(--text-secondary); min-height: 1.4em; margin: 10px 0 0; }
.admin-pre { background: var(--surface-0); border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow-x: auto; font-size: 12px; margin: 0; }
a { color: var(--series-1); }
