:root {
  --bg: #0f1419;
  --panel: #171d25;
  --panel-2: #1e2630;
  --line: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a8;
  --ok: #3fb950;
  --warn: #e3a008;
  --crit: #f85149;
  --nodata: #6e7b8b;
  --accent: #58a6ff;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme=dark]) {
    --bg: #f4f6f9; --panel: #ffffff; --panel-2: #eef1f5; --line: #dbe1e8;
    --text: #15202b; --muted: #5b6776; --ok: #1a7f37; --warn: #b45309;
    --crit: #cf222e; --nodata: #8a94a1; --accent: #0969da;
    color-scheme: light;
  }
}
/* выбор темы в настройках: «Светлая» / «Тёмная» сильнее системной */
:root[data-theme=light] {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #eef1f5; --line: #dbe1e8;
  --text: #15202b; --muted: #5b6776; --ok: #1a7f37; --warn: #b45309;
  --crit: #cf222e; --nodata: #8a94a1; --accent: #0969da;
  color-scheme: light;
}
:root[data-theme=dark] {
  --bg: #0f1419; --panel: #171d25; --panel-2: #1e2630; --line: #2a3441; --text: #e6edf3; --muted: #8b98a8;
  --ok: #3fb950; --warn: #e3a008; --crit: #f85149; --nodata: #6e7b8b; --accent: #58a6ff;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }

header { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.banner { flex: 1; display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; }
.banner .sub { font-weight: 400; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--nodata); flex: none; }
.banner.ok .dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.banner.warn { border-color: var(--warn); }
.banner.warn .dot { background: var(--warn); }
.banner.crit { border-color: var(--crit); }
.banner.crit .dot { background: var(--crit); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--crit) 30%, transparent); } }
.sub { color: var(--muted); font-size: 12.5px; }

.icon-btn { background: var(--panel); color: var(--text); border: 1px solid var(--line);
  width: 44px; height: 44px; border-radius: 12px; font-size: 18px; cursor: pointer; }

main { padding: 12px; max-width: 1100px; margin: 0 auto; }
.group { margin-bottom: 22px; }
.group h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 8px 2px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.tile { position: relative; text-align: left; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--ok); border-radius: 12px; padding: 12px; color: inherit;
  cursor: pointer; font: inherit; min-height: 104px; }
.tile.warn { border-left-color: var(--warn); }
.tile.crit { border-left-color: var(--crit); background: color-mix(in srgb, var(--crit) 8%, var(--panel)); }
.tile.nodata { border-left-color: var(--nodata); opacity: .75; }
.tile .name { color: var(--muted); font-size: 12.5px; }
.tile .val { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile.warn .val { color: var(--warn); }
.tile.crit .val { color: var(--crit); }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .4s; }
.tile.warn .bar i { background: var(--warn); }
.tile.crit .bar i { background: var(--crit); }

.devices { display: flex; flex-direction: column; gap: 6px; }
.dev { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; }
.dev .dot.up { background: var(--ok); }
.dev .dot.down { background: var(--crit); }
.dev .info { flex: 1; min-width: 0; }
.dev .info div:first-child { font-weight: 600; }
.dev .info .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end;
  justify-content: center; z-index: 20; }
.modal.hidden { display: none; }
.sheet { width: 100%; max-width: 640px; background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.m-title { font-size: 17px; font-weight: 700; }
.m-value { font-size: 30px; font-weight: 700; margin-top: 2px; }
.ranges { display: flex; gap: 6px; margin: 8px 0; }
.ranges button { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit; }
.ranges button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
canvas { width: 100%; height: 220px; display: block; }
.m-stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 8px; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--line); }
.btn { background: var(--accent); color: #fff; border: 0; padding: 10px 14px; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.offline { background: var(--warn); color: #000; text-align: center; padding: 4px; font-size: 12.5px; }
