:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --up: #006300;
  --down: #d03b3b;
  --other: #b5b3ab;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab; --seq-5: #0d366b;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --up: #0ca30c;
    --down: #e66767;
    --other: #5c5b57;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-0: #232322; --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #5598e7; --seq-5: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --up: #0ca30c;
  --down: #e66767;
  --other: #5c5b57;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-0: #232322; --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #5598e7; --seq-5: #9ec5f4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--down); margin: 0; }
code { font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

button, select, input {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 12px;
}
button:hover { background: var(--surface-2); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.ghost:hover { background: var(--surface-2); }

/* layout */
main { max-width: 1360px; margin: 0 auto; padding: 16px 24px 40px; display: grid; gap: 16px; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  padding: 8px 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand strong { font-size: 18px; letter-spacing: -0.01em; }
.brand .home { color: inherit; text-decoration: none; }
a.ghost { color: var(--ink-2); text-decoration: none; border-radius: 8px; padding: 5px 10px; }
a.ghost:hover { background: var(--surface-2); }
.user { display: inline-flex; align-items: center; gap: 8px; }
.user img { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); }
.access-help { color: var(--ink-2); margin: 0 0 12px; max-width: 880px; }
.token-created {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
}
.token-created span { color: var(--ink-2); font-size: 13px; }
.token-created code { font-size: 13px; padding: 4px 8px; word-break: break-all; background: var(--surface); }
.controls, .card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border); font-weight: 600; }
.seg.small button { padding: 2px 8px; font-size: 12px; }

.select {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  padding: 0 4px 0 10px; height: 32px;
}
.select span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.select select { border: 0; background: transparent; padding: 4px 2px; max-width: 180px; outline: none; }
.select select option { background: var(--surface); color: var(--ink); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: 1.6fr repeat(5, 1fr); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: grid; gap: 2px; min-width: 0;
}
.kpi .label { color: var(--ink-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.hero .value { font-size: 48px; line-height: 1.1; }
.kpi .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart { width: 100%; height: 300px; }
.chart.tall { height: 380px; }
#chart-heatmap { height: 280px; }

/* tables */
.table-wrap { overflow: auto; max-height: 560px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; z-index: 1; background: var(--surface); }
th:first-child, td:first-child { text-align: left; }
td { font-variant-numeric: tabular-nums; }
td.name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
tr:hover td { background: var(--surface-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.bar-cell { position: relative; min-width: 120px; }
.bar-cell i { position: absolute; left: 10px; top: 50%; height: 6px; transform: translateY(-50%); border-radius: 3px; background: var(--accent); opacity: 0.25; }
.bar-cell span { position: relative; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); margin-left: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: #0ca30c; }
.dot.stale { background: #fab219; }
.dot.off { background: var(--muted); }
td button.danger { padding: 1px 8px; font-size: 12px; color: var(--down); }

footer { text-align: center; padding-top: 8px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi.hero { grid-column: span 3; }
}
@media (max-width: 760px) {
  main { padding: 8px 16px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi.hero { grid-column: span 2; }
  .kpi.hero .value { font-size: 40px; }
  .topbar { position: static; }
  .chart.tall { height: 320px; }
  .select select { max-width: 120px; }
}
