:root {
  color-scheme: dark;
  --bg: #0e1216;
  --surface: #151a1f;
  --surface-2: #1b2128;
  --border: rgba(255,255,255,0.09);
  --text: #f2f4f5;
  --text-2: #b9c0c6;
  --muted: #858d94;
  --grid: #252c33;
  --axis: #39424b;
  --accent: #3987e5;
  --accent-ink: #fff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f6f7f8; --surface: #fcfcfb; --surface-2: #f0f1f2;
    --border: rgba(11,11,11,0.10); --text: #0b0b0b; --text-2: #52514e; --muted: #77756f;
    --grid: #e6e5df; --axis: #c3c2b7; --accent: #2a78d6;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f8; --surface: #fcfcfb; --surface-2: #f0f1f2;
  --border: rgba(11,11,11,0.10); --text: #0b0b0b; --text-2: #52514e; --muted: #77756f;
  --grid: #e6e5df; --axis: #c3c2b7; --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

/* header + nav */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--accent); }
.brand-name { font-weight: 650; color: var(--text); font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.top-right { display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.ok i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.live.stale i { background: var(--warning); }
.live.run i { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px;
  color: var(--muted); font-size: 11px; min-height: 56px;
}
.tabs a svg { width: 22px; height: 22px; fill: currentColor; }
.tabs a.on { color: var(--accent); }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 57px; bottom: auto; justify-content: flex-start; gap: 4px; padding: 0 16px;
          border-top: 0; border-bottom: 1px solid var(--border); background: var(--bg); z-index: 19; }
  .tabs a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 12px 14px; font-size: 14px; min-height: 0;
            border-bottom: 2px solid transparent; }
  .tabs a svg { width: 18px; height: 18px; }
  .tabs a.on { border-bottom-color: var(--accent); }
}

main { max-width: 1280px; margin: 0 auto; padding: 14px 16px; }
.page { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.grid2.inner { gap: 16px; }
.row { display: flex; align-items: center; }
.wrap { flex-wrap: wrap; }
.gap { gap: 10px; }
.grow { flex: 1; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -.01em; white-space: nowrap; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 3px; }
.tile .d { font-size: 12px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tiles-sm { margin-top: 12px; }
.tiles-sm .tile { background: var(--surface-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; flex: none; }

/* grades & badges */
.grade { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 26px; padding: 0 6px;
         border-radius: 7px; font-weight: 700; font-size: 15px; color: #0b0b0b; }
.g-Ap, .g-A { background: var(--good); } .g-B { background: #8bc34a; } .g-C { background: var(--warning); }
.g-D { background: var(--serious); } .g-F { background: var(--critical); color: #fff; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.badge.done { color: var(--good); } .badge.error { color: var(--critical); }

/* buttons, chips, forms */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
       padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-sm { white-space: nowrap; padding: 6px 12px; min-height: 34px; font-size: 13px; display: inline-flex; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { appearance: none; border: 1px solid var(--border); background: transparent; color: var(--text-2); padding: 7px 14px;
        border-radius: 99px; font: inherit; font-size: 13.5px; cursor: pointer; min-height: 36px; }
.chip.on { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); color: var(--text); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; min-height: 38px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.controls { margin-bottom: 10px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form input { width: 100%; }

/* profiles */
.profiles { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 12px 0; }
@media (min-width: 700px) { .profiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .profiles { grid-template-columns: repeat(5, 1fr); } }
.profile { text-align: left; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
           cursor: pointer; color: var(--text); font: inherit; }
.profile b { display: block; font-size: 14px; margin-bottom: 2px; }
.profile span { font-size: 12.5px; color: var(--text-2); }
.profile.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* run panel */
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 10px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.log { font-family: var(--mono); font-size: 12px; line-height: 1.5; background: var(--bg); border: 1px solid var(--border);
       border-radius: 8px; padding: 10px; max-height: 240px; overflow: auto; margin: 0; white-space: pre-wrap; color: var(--text-2); }
.live-mbps { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 12px; }
.live-mbps .num { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.live-mbps .unit { color: var(--text-2); }
.live-mbps .lbl { color: var(--muted); font-size: 13px; margin-left: auto; }

/* tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: right; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
                padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.l, table.data th.l { text-align: left; }
table.data tr.grp td { background: var(--surface-2); font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data .sub { display: block; font-size: 11.5px; color: var(--muted); }
table.data.small { font-size: 12px; }
.warn { color: var(--warning); } .bad { color: var(--critical); } .ok { color: var(--good); }
.hops td.bar { min-width: 120px; width: 22%; }
.hbar { height: 8px; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.hbar-wrap { position: relative; background: var(--surface-2); border-radius: 4px; height: 8px; }
.hbar-wrap .rng { position: absolute; top: 3px; height: 2px; background: var(--muted); opacity: .6; }

/* facts */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }

/* events */
.events { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 340px; overflow: auto; }
.events li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12px; min-width: 88px; }
.sev { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; white-space: nowrap; }
.sev-critical { background: var(--critical); color: #fff; } .sev-warning { background: var(--warning); color: #0b0b0b; }
.sev-good { background: var(--good); color: #0b0b0b; } .sev-info { background: var(--surface-2); color: var(--text-2); }
.sev-serious { background: var(--serious); color: #0b0b0b; }

/* charts */
.chart-wrap { position: relative; height: 240px; }
.h180 { height: 180px; } .h220 { height: 220px; } .h300 { height: 300px; }
@media (max-width: 600px) { .chart-wrap { height: 210px; } .h300 { height: 260px; } }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* heatmap */
.heatmap { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10.5px; color: var(--muted); }
.heatmap .c { aspect-ratio: 1 / 1.1; border-radius: 3px; background: var(--surface-2); position: relative; }
.heatmap .c:hover { outline: 2px solid var(--text); z-index: 2; }
.heatmap .hl { display: flex; align-items: center; }
.heatmap .hh { text-align: center; }
.hm-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.hm-legend .ramp { height: 8px; flex: 0 1 200px; border-radius: 4px; }

/* paths */
.path-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.path-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); cursor: pointer;
             text-align: left; color: var(--text); font: inherit; }
.path-item.on { border-color: var(--accent); }
.path-item b { font-size: 13.5px; }
.path-item .m { font-size: 12px; color: var(--text-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.fam { font-size: 10.5px; font-weight: 700; padding: 1px 5px; border-radius: 4px; background: var(--surface); color: var(--text-2); margin-left: 6px; }
.aspath { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 12.5px; }
.aspath .as { padding: 3px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.aspath .as.ix { border-color: var(--s3); }
.aspath .arr { color: var(--muted); }

/* insights */
.insights { display: flex; flex-direction: column; gap: 8px; }
.ins { border: 1px solid var(--border); border-left-width: 4px; border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.ins.s-serious { border-left-color: var(--critical); } .ins.s-warning { border-left-color: var(--warning); }
.ins.s-info { border-left-color: var(--s1); } .ins.s-good { border-left-color: var(--good); }
.ins-h { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.ins-h b { font-size: 14px; }
.ins p { margin: 6px 0 0; font-size: 13.5px; color: var(--text-2); }
.ins .act { margin-top: 6px; font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--surface); }
.ins .metric { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.sugg { list-style: none; margin: 14px 0 0; padding: 0; }
.sugg li { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.vote { display: flex; flex-direction: column; align-items: center; min-width: 44px; border: 1px solid var(--border); border-radius: 8px;
        background: var(--surface-2); color: var(--text); padding: 4px; cursor: pointer; font: inherit; font-size: 13px; }
.sugg .meta { font-size: 12px; color: var(--muted); }
.sugg p { margin: 2px 0 0; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.roadmap { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.roadmap b { color: var(--text); }

.result-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.kv div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.kv .k { font-size: 11.5px; color: var(--muted); }
.kv .v { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.phases { display: flex; height: 12px; border-radius: 4px; overflow: hidden; gap: 2px; min-width: 120px; }
.phases i { display: block; height: 100%; }
.empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
.foot { text-align: center; padding: 18px 16px 24px; }
