:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,.10); --wash: rgba(11,11,11,.05);
  --s2: #2a78d6; --s3: #eb6834; --s4: #1baf7a;
  --good: #006300; --bad: #d03b3b; --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,.10); --wash: rgba(255,255,255,.06);
    --s2: #3987e5; --s3: #d95926; --s4: #199e70;
    --good: #0ca30c; --bad: #e66767; --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,.10); --wash: rgba(255,255,255,.06);
  --s2: #3987e5; --s3: #d95926; --s4: #199e70;
  --good: #0ca30c; --bad: #e66767; --accent: #3987e5;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.page { max-width: 1240px; margin: 0 auto; padding: 20px 16px 40px; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--ink2); }
.run { color: var(--ink2); font-size: 13px; text-align: right; }
.run .err { color: var(--bad); }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 12px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; position: sticky; top: 0; z-index: 5;
  background: var(--page); padding: 8px 0; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--ink2); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button:hover { background: var(--wash); }
.seg button.on { background: var(--ink); color: var(--surface); }
.seg.small button { padding: 4px 9px; font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; }
.tile .k { color: var(--ink2); font-size: 13px; }
.tile .v { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -.01em; }
.tile .u { font-size: 14px; font-weight: 500; color: var(--ink2); }
.tile .d { font-size: 13px; color: var(--ink2); margin-top: 2px; }
.up { color: var(--bad); } .down { color: var(--good); }

.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; }
.grid2 .card { margin-bottom: 14px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.legend i.dot { width: 8px; height: 8px; border-radius: 50%; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .base { stroke: var(--axis); }
.chart .empty { fill: var(--muted); font-size: 13px; }
.chart .dot { stroke: var(--surface); stroke-width: 2; cursor: pointer; }
.chart .dot:hover, .chart .dot.hl { stroke: var(--ink); }

.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--ring);
  box-shadow: 0 6px 24px rgba(0,0,0,.18); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 140px; max-width: 280px; }
.tip .t { color: var(--ink2); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r i { width: 12px; height: 2px; display: inline-block; border-radius: 2px; }

.tbl-wrap { overflow-x: auto; margin-bottom: 10px; }
.tbl-wrap.tall { max-height: 640px; overflow-y: auto; }
.tbl-wrap.tall thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tbl td.n, .tbl th.n { text-align: right; }
.tbl.flats th { cursor: pointer; user-select: none; }
.tbl.flats th.sorted::after { content: " ↓"; }
.tbl.flats th.sorted.asc::after { content: " ↑"; }
.tbl.flats tbody tr { cursor: pointer; }
.tbl.flats tbody tr:hover { background: var(--wash); }
.tbl tr.gone td { color: var(--muted); text-decoration: line-through; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--ring); color: var(--ink2); margin-left: 4px; }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
select { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--ring); background: var(--surface); color: var(--ink); }
.chk { color: var(--ink2); display: inline-flex; gap: 4px; align-items: center; }

.feed { list-style: none; margin: 0; padding: 0; max-height: 440px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 112px 22px 1fr auto; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--grid); align-items: baseline; }
.feed .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed .what { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.feed .val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.feed .empty { display: block; color: var(--muted); }

dialog { border: 1px solid var(--ring); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 18px; width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .x { position: absolute; right: 10px; top: 8px; font-size: 22px; background: none; border: 0; color: var(--ink2); cursor: pointer; }
.flat-grid { display: grid; grid-template-columns: 1fr 180px; gap: 14px; }
.flat-grid img { width: 100%; background: #fff; border-radius: 8px; border: 1px solid var(--ring); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.foot { color: var(--muted); font-size: 12px; margin-top: 18px; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .tile .v { font-size: 21px; }
  .tile .u { display: block; font-size: 12px; }
  .seg button { padding: 5px 9px; }
  .filters { gap: 6px; }
  .feed li { grid-template-columns: 64px 20px 1fr; }
  .flat-grid { grid-template-columns: 1fr; }
  .feed .val { grid-column: 3; text-align: left; }
  .run { text-align: left; }
}
