:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --card: #fcfcfb;
  --card-2: #f0efec;
  --line: #e4e3df;
  --line-2: #d6d5d0;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --track: #e8e7e3;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --warn: #c98500;
  --crit: #d03b3b;
  --grid: rgba(11, 11, 11, .07);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --card: #1a1a19;
    --card-2: #222220;
    --line: #2a2a28;
    --line-2: #383835;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8a897f;
    --track: #2c2c29;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --warn: #fab219;
    --grid: rgba(255, 255, 255, .06);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
button, input { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none;
  font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.btn:hover { color: var(--text); border-color: var(--line-2); }
.btn.ghost { background: transparent; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.top {
  max-width: 1320px; margin: 0 auto; display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; padding: max(24px, env(safe-area-inset-top)) 24px 8px;
}
.host-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 24px; }
.spec { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.live {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2);
  padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--card-2);
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.live.stale i { background: var(--crit); }
.top-actions { display: flex; gap: 8px; }

main { max-width: 1320px; margin: 0 auto; padding: 16px 24px 48px; display: grid; gap: 28px; }

/* ---------- overview ---------- */
.overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.ov {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.ov-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ov-head h3 { font-size: 14px; }
.ov-head .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.big { display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.big .v { font-size: 38px; font-weight: 600; line-height: 1; letter-spacing: -.02em; }
.big .u { font-size: 16px; color: var(--text-2); font-weight: 500; }
.big .l { margin-left: auto; color: var(--muted); font-size: 12px; align-self: center; white-space: nowrap; }
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width .5s ease, background .3s; }
.meter i.warn, .bar i.warn { background: var(--warn); }
.meter i.crit, .bar i.crit { background: var(--crit); }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.kv div { min-width: 0; }
.kv dt { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv dd { margin: 1px 0 0; font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { width: 100%; height: 40px; display: block; margin-top: auto; }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; margin-left: 6px; color: var(--text-2); vertical-align: 2px; }
.flag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.flag.warn::before { background: var(--warn); }
.flag.crit::before { background: var(--crit); }

/* ---------- blocks ---------- */
.block { display: grid; gap: 14px; min-width: 0; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 18px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; }
.note { margin: 0; color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--card-2); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
input[type=search] {
  border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 7px 12px; width: 240px; max-width: 100%;
}
input[type=search]:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 30px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 14px; }
.chart { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 16px 10px; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chart-title { min-width: 0; }
.chart-title h3 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-title .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.legend { display: flex; gap: 14px; flex-shrink: 0; align-items: baseline; }
.legend span { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.legend b { color: var(--text); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend i { width: 8px; height: 8px; border-radius: 2px; align-self: center; }
.chart canvas { width: 100%; height: 160px; display: block; margin-top: 10px; touch-action: pan-y; cursor: crosshair; }
.unpin { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 0 0 4px; font-size: 16px; line-height: 1; }
.unpin:hover { color: var(--text); }

/* ---------- sensors ---------- */
.cats { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.cats::-webkit-scrollbar { display: none; }
.cats a {
  flex-shrink: 0; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  color: var(--text-2); text-decoration: none; font-size: 13px;
}
.cats a:hover { color: var(--text); border-color: var(--line-2); }
.cats a span { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.cat { scroll-margin-top: 16px; display: grid; gap: 10px; margin-top: 12px; min-width: 0; }
.cat > *, #hw, .block > * { min-width: 0; }
.cat > h3 { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.devices { columns: 2 440px; column-gap: 14px; }
.dev {
  break-inside: avoid; margin-bottom: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden;
}
.dev-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; user-select: none;
  width: 100%; border: 0; background: none; text-align: left;
}
.dev-head .titles { flex: 1; min-width: 0; display: grid; gap: 1px; }
.dev-head h4 { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-head .model { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-head .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dev-head .chev { color: var(--muted); transition: transform .2s; font-size: 12px; }
.dev.closed .chev { transform: rotate(-90deg); }
.dev.closed .dev-body { display: none; }
.dev-body { padding: 0 16px 14px; display: grid; gap: 14px; }
.kind { display: grid; gap: 2px; }
.kind > h5 { margin: 0 0 4px; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.row {
  display: grid; grid-template-columns: minmax(0, 1fr) 72px 88px 78px; align-items: center; gap: 12px;
  padding: 5px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer;
}
.row:hover { background: var(--card-2); }
.row .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.row .nm::after { content: ""; }
.row.pinned .nm { color: var(--text); }
.row.pinned .nm::before { content: "●"; color: var(--accent); font-size: 8px; margin-right: 6px; vertical-align: 2px; }
.row .hint { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
.val.warn, .v.warn, dd.warn, .legend .warn { color: var(--warn); }
.val.crit, .v.crit, dd.crit, .legend .crit { color: var(--crit); }
.legend .warn b, .legend .crit b, dd.warn .u, dd.crit .u, .val.warn .u, .val.crit .u { color: inherit; }
.row .val { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .rng { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.u { color: var(--muted); font-weight: 400; font-size: .86em; margin-left: 2px; }
.bar { height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .5s ease; }
.bar.none { visibility: hidden; }
.na { color: var(--muted); }

.cells { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 6px; }
.cell {
  background: var(--card-2); border-radius: 9px; padding: 8px 10px; display: grid; gap: 4px; cursor: pointer;
  border: 1px solid transparent;
}
.cell:hover { border-color: var(--line-2); }
.cell.pinned { border-color: var(--accent); }
.cell .nm { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.procs { display: grid; gap: 2px; }
.proc { display: grid; grid-template-columns: minmax(0, 1fr) 90px 56px 72px; gap: 12px; align-items: center; padding: 5px 0; }
.proc .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); display: flex; align-items: center; gap: 10px; }
.proc .pn { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.proc .ico { width: 18px; height: 18px; flex-shrink: 0; border-radius: 4px; }
.proc .nm small { color: var(--muted); margin-left: -5px; }
.proc .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.proc .rng { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--card); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); white-space: nowrap; display: grid; gap: 3px;
}
.tip .t { color: var(--muted); }
.tip .s { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.tip .s i { width: 8px; height: 8px; border-radius: 2px; }
.tip .s b { margin-left: auto; padding-left: 12px; }

/* ---------- login ---------- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 12px; }
.login-card .brand { font-weight: 600; font-size: 18px; display: flex; gap: 8px; align-items: center; }
.login-card .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.login-card .muted { color: var(--muted); margin: -6px 0 4px; font-size: 13px; }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px; }
.login-card button { background: var(--accent); border: 0; color: #fff; font-weight: 600; padding: 11px; border-radius: 10px; cursor: pointer; }
.err { color: var(--crit); margin: 0; font-size: 13px; min-height: 1em; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .top { padding: max(16px, env(safe-area-inset-top)) 16px 4px; align-items: flex-start; }
  h1 { font-size: 20px; }
  .top-actions { width: 100%; }
  main { padding: 12px 16px 40px; gap: 24px; }
  .overview { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .ov { padding: 16px; }
  .big .v { font-size: 34px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .chart canvas { height: 140px; }
  .legend { gap: 10px; }
  .legend b { font-size: 14px; }
  .tools { width: 100%; }
  input[type=search] { flex: 1; width: auto; }
  .devices { columns: 1; }
  .row { grid-template-columns: minmax(0, 1fr) 48px 80px; }
  .row .rng { display: none; }
  .proc { grid-template-columns: minmax(0, 1fr) 60px 50px 64px; gap: 8px; }
}
