:root {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255,255,255,0.10); --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b; --idle: #6d6c66; --info: #3987e5;
  --good-bg: rgba(12,163,12,.14); --warning-bg: rgba(250,178,25,.14); --critical-bg: rgba(208,59,59,.16);
  --info-bg: rgba(57,135,229,.14); --idle-bg: rgba(137,135,129,.12);
  --radius: 10px; --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ef; --surface-3: #e9e8e3;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10); --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --idle: #a3a29c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.brand svg { width: 22px; height: 22px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--surface-3); color: var(--ink); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 11px; padding: 0 7px; border-radius: 10px; background: var(--critical); color: #fff; font-weight: 700; }
.nav .count.warn { background: var(--warning); color: #111; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; display: grid; gap: 6px; }
.main { padding: 18px 22px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h2 { font-size: 14px; margin: 0 0 10px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.card h3 { font-size: 13px; margin: 14px 0 6px; color: var(--ink-2); font-weight: 600; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.section-title .right { margin-left: auto; text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 8px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right-align { text-align: right; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge svg { width: 12px; height: 12px; flex: none; }
.lv-ok { color: var(--good); background: var(--good-bg); }
.lv-warn { color: var(--warning); background: var(--warning-bg); }
.lv-crit { color: var(--critical); background: var(--critical-bg); }
:root[data-theme="light"] .lv-warn { color: #8a5d00; }
:root[data-theme="light"] .lv-ok { color: #006300; }
.lv-info { color: var(--info); background: var(--info-bg); }
.lv-idle { color: var(--muted); background: var(--idle-bg); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--good); } .dot.warn { background: var(--warning); } .dot.crit { background: var(--critical); }
.dot.idle { background: var(--idle); } .dot.info { background: var(--info); }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }

/* server cards */
.srv-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.srv-head .name { font-size: 16px; font-weight: 650; }
.srv-head .meta { font-size: 12px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.kpi .label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.kpi .value { font-size: 22px; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.kpi .value .unit { font-size: 13px; color: var(--ink-2); font-weight: 500; margin-left: 2px; }
.kpi .foot { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.meter.warn > i { background: var(--warning); } .meter.crit > i { background: var(--critical); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; } .tbl th.sortable:hover { color: var(--ink); }
.tbl th.sorted::after { content: " ▾"; } .tbl th.sorted.asc::after { content: " ▴"; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--surface-2); }
.tbl .sub { font-size: 11.5px; color: var(--muted); }
.bar-cell { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.bar-cell .b { width: 46px; height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.bar-cell .b i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 14px; height: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.seg button.on { background: var(--surface-3); color: var(--ink); font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=datetime-local], select, textarea { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; font-family: var(--mono); font-size: 12.5px; }
label.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
label.field input, label.field select { color: var(--ink); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart text { 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 .area { opacity: .12; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .empty { fill: var(--muted); font-size: 12px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.35); min-width: 140px; max-width: 320px; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; }
.tip .r b { font-variant-numeric: tabular-nums; }
.tip .r .k { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tip .r .n { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.legend span.off { opacity: .4; }
.legend i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.spark { display: block; width: 100%; height: 28px; margin-top: 4px; }

/* logs */
.logbox { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12px; line-height: 1.5; height: calc(100vh - 290px); min-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.logbox .l-err { color: #ff8a80; } .logbox .l-warn { color: var(--warning); } .logbox .l-dim { color: var(--muted); }
:root[data-theme="light"] .logbox .l-err { color: #b3261e; } :root[data-theme="light"] .logbox .l-warn { color: #8a5d00; }
.logbox mark { background: rgba(250,178,25,.35); color: inherit; border-radius: 2px; }
.output { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow: auto; margin: 0; }

/* misc */
.alert-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .body { flex: 1; min-width: 0; }
.alert-row .title { font-weight: 600; }
.alert-row .detail { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.event { display: grid; grid-template-columns: 140px 70px 110px 1fr; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; align-items: baseline; }
.event .ts { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.empty-state { color: var(--muted); padding: 18px; text-align: center; font-size: 13px; }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--good); border-radius: 8px; padding: 10px 14px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.35); white-space: pre-wrap; font-size: 13px; }
.toast.err { border-left-color: var(--critical); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 10px; }
.login { max-width: 360px; margin: 12vh auto; }
.tunnel { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tunnel:last-child { border-bottom: 0; }
.where { display: flex; gap: 6px; flex-wrap: wrap; }
.app-tile { background: var(--surface-2); border-radius: 8px; padding: 9px 11px; display: grid; gap: 3px; min-width: 0; cursor: pointer; border: 1px solid transparent; }
.app-tile:hover { border-color: var(--border); }
.app-tile .nm { font-weight: 600; font-size: 13px; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.core { height: 38px; background: var(--surface-3); border-radius: 4px; position: relative; overflow: hidden; }
.core i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--s1); }
.core span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--ink); }
.cmd { display: flex; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 6px; padding: 4px 4px 4px 10px; }
.cmd code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 80; left: 0; width: 230px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 14px 16px 40px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event { grid-template-columns: 1fr; gap: 0; }
}

/* public demo banner */
.demo-banner { position: sticky; top: 0; z-index: 85; display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 8px 18px; background: var(--info-bg); border-bottom: 1px solid var(--border); font-size: 13px; color: var(--ink); }
.demo-banner b { color: var(--accent); }
.demo-banner span { color: var(--ink-2); flex: 1; min-width: 200px; }
.has-demo-banner .side { top: 37px; height: calc(100vh - 37px); }

[hidden] { display: none !important; }
.range-picker .seg button { padding: 4px 8px; }
