:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --grid: #ecebe7;
  --ok: #008300;
  --warn: #c98500;
  --bad: #e34948;
  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #86b6ef;
  --seq-3: #3987e5;
  --seq-4: #1c5cab;
  --seq-5: #0d366b;
  --series-use: #2a78d6;
  --series-other: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --grid: #2a2a28;
    --ok: #2fa52f;
    --warn: #e0a020;
    --bad: #e66767;
    --seq-0: #262624;
    --seq-1: #104281;
    --seq-2: #1c5cab;
    --seq-3: #2a78d6;
    --seq-4: #5598e7;
    --seq-5: #9ec5f4;
    --series-use: #3987e5;
    --series-other: #d95926;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; }
h1 { margin: 0; font-size: 28px; letter-spacing: 0.04em; }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
h3 { margin: 18px 0 8px; font-size: 14px; }
code { font-size: 12px; }

input, select, button {
  font: inherit; color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
a.csv { color: var(--accent); font-size: 12px; cursor: pointer; text-decoration: none; border: 1px solid var(--border); padding: 2px 8px; border-radius: 6px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card label { display: grid; gap: 4px; color: var(--text-2); }

/* Shell */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 8px; align-items: baseline; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 6px; color: var(--text-2); }
.tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.user { display: flex; gap: 8px; align-items: center; color: var(--text-2); }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  padding: 12px 20px;
}
.filters label { display: grid; gap: 2px; font-size: 12px; color: var(--text-2); }
.presets { display: flex; gap: 4px; }
.presets button { font-size: 12px; }

.tab { padding: 0 20px 32px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar { gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .tabs button { white-space: nowrap; }
  .user { margin-left: auto; font-size: 12px; }
  .tab .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tab .tile-value { font-size: 22px; }
  .topbar, .filters, .tab { padding-left: 16px; padding-right: 16px; }
}

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.tile-value { font-size: 28px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* Charts */
.chart { position: relative; height: 260px; }
.chart.tall { height: 420px; }

/* Heatmap */
.heatmap { display: grid; grid-template-columns: 36px repeat(var(--cols, 14), 1fr); gap: 2px; font-size: 11px; color: var(--text-2); }
.heatmap .cell { height: 24px; border-radius: 3px; background: var(--seq-0); }
.heatmap .lbl { display: flex; align-items: center; }
.heatmap .hlbl { text-align: center; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; border-bottom: 1px solid var(--border); padding: 6px 8px; white-space: nowrap; }
.table td { border-bottom: 1px solid var(--grid); padding: 6px 8px; vertical-align: top; }
.table td.num, .table th.num { text-align: right; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover { background: var(--bg); }
.scroll { max-height: 520px; overflow: auto; }
.scroll.short { max-height: 300px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.table td:has(> .bar-inline) { width: 22%; min-width: 80px; }
.bar-inline { height: 6px; border-radius: 3px; background: var(--accent); min-width: 2px; }
.token { background: var(--bg); padding: 10px; border-radius: 6px; white-space: pre-wrap; word-break: break-all; }

/* Analytics */
.defs { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px 24px; }
.def { display: flex; gap: 10px; align-items: flex-start; }
.def > div { display: grid; gap: 2px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; margin-top: 4px; display: inline-block; }
.swatch.sm { width: 9px; height: 9px; margin-top: 0; }
.swatch.use { background: var(--series-use); }
.swatch.other { background: var(--series-other); }
.swatch.total { background: linear-gradient(to top, var(--series-use) 0 50%, var(--series-other) 50% 100%); }
.meter { height: 8px; border-radius: 4px; background: var(--series-other); margin-top: 10px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--series-use); border-right: 2px solid var(--surface); }
.split { display: flex; height: 8px; border-radius: 4px; overflow: hidden; min-width: 80px; background: var(--series-other); }
.split > span { background: var(--series-use); border-right: 2px solid var(--surface); }
.table td:has(> .split) { width: 22%; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.checks .muted { font-size: 11px; }

/* Wide tables scroll inside their card instead of widening the page on phones */
@media (max-width: 640px) {
  .card { overflow-x: auto; }
  .table th, .table td { white-space: nowrap; }
  .defs { grid-template-columns: 1fr; }
}
a { color: var(--accent); }
