:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #006300;
  --bad: #b42b2b;
  --warn-bg: #fff4d6;
  --cell-empty: #efeee9;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --status-good: #0ca30c; --status-warning: #fab219; --status-serious: #ec835a; --status-critical: #d03b3b;
  --seq: #b7d3f6, #86b6ef, #5598e7, #2a78d6, #1c5cab, #104281;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --good: #0ca30c; --bad: #e66767;
    --warn-bg: #3a2f12; --cell-empty: #262624;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --seq: #104281, #184f95, #256abf, #3987e5, #6da7ec, #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --good: #0ca30c; --bad: #e66767;
  --warn-bg: #3a2f12; --cell-empty: #262624;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --seq: #104281, #184f95, #256abf, #3987e5, #6da7ec, #9ec5f4;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.ghost { background: transparent; }
button:hover { filter: brightness(0.97); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0; }

#app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
#side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 650; font-size: 15px; padding: 0 6px 16px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
#nav a { color: var(--ink-2); padding: 7px 10px; border-radius: 8px; }
#nav a:hover { background: var(--surface-2); text-decoration: none; }
#nav a.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
#nav .nav-head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; color: var(--ink-2); font-size: 13px; }
.side-actions { display: flex; gap: 6px; margin-top: 8px; }
#main { padding: 24px 28px 48px; min-width: 0; }
body.bare #app { grid-template-columns: 1fr; }
body.bare #side { display: none; }

h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.sub { color: var(--ink-2); margin: 0 0 20px; }
.loading, .empty { color: var(--muted); padding: 24px 0; }
.error { background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; }

.cards { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.note { color: var(--muted); font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .k { color: var(--ink-2); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 650; margin-top: 2px; }
.tile .d { font-size: 12px; color: var(--muted); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 4px 10px; color: var(--ink-2); }
.seg button.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; }
th .arrow { color: var(--muted); font-size: 10px; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.span-4 th, .span-4 td { padding: 6px 4px; }
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.table-tools input { flex: 1; max-width: 280px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 8px; color: var(--ink-2); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); font-size: 12px; color: var(--ink-2); }
.dotlive { width: 7px; height: 7px; border-radius: 50%; background: var(--status-good); display: inline-block; }
.status { display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: var(--c); display: inline-block; }
.up { color: var(--good); } .down { color: var(--bad); } .flat { color: var(--muted); }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .rule { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dash { stroke-dasharray: 5 4; }
.chart .area { opacity: .14; stroke: none; }
.chart .area.solid { opacity: .85; }
.chart .cross { stroke: var(--baseline); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .bar:hover, .chart .cell:hover, .chart .slice:hover { opacity: .8; }
.chart .slice { stroke: var(--surface); stroke-width: 2; }
.chart .donut-total { fill: var(--ink); font-size: 15px; font-weight: 650; }
.tip { position: absolute; display: none; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0,0,0,.12); font-size: 12px; min-width: 140px; }
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-label { color: var(--ink-2); flex: 1; }
.tip-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sw.dash { height: 3px; border-radius: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; color: var(--ink-2); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { width: 132px; flex: none; }
.donut-legend { flex: 1; min-width: 160px; display: grid; gap: 4px; }
.donut-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center; font-size: 13px; }
.donut-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-value { font-variant-numeric: tabular-nums; }
.donut-pct { color: var(--muted); font-variant-numeric: tabular-nums; width: 3em; text-align: right; }

.auth { max-width: 380px; margin: 10vh auto; }
.auth .card { padding: 24px; }
.auth form { display: grid; gap: 12px; }
.auth label { display: grid; gap: 4px; color: var(--ink-2); font-size: 13px; }
.code { font: 600 22px/1.2 ui-monospace, monospace; letter-spacing: .12em; background: var(--surface-2); padding: 10px; border-radius: 8px; text-align: center; user-select: all; }
.cmd { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; user-select: all; }
.query-form { margin-bottom: 16px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.filters label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.checks label { display: inline-flex; gap: 4px; align-items: center; }
.player-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.avatar { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 20px; color: #fff; flex: none; }
.names { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 1000px) {
  .span-8, .span-6, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  #side { position: static; height: auto; min-width: 0; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  #nav { flex: none; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  #nav .nav-head { display: none; }
  #nav a { white-space: nowrap; }
  .brand { padding-bottom: 8px; }
  .side-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; }
  .side-actions { margin-top: 0; }
  #main { padding: 16px 16px 40px; }
  .span-3 { grid-column: span 12; }
}
@media (forced-colors: active) { .chart .area { opacity: 1; } }
