:root {
  color-scheme: dark light;
  --bg: #0b0b10;
  --surface: #13131a;
  --surface-2: #1a1a23;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #ececf1;
  --muted: #9c9cab;
  --faint: #6c6c7a;
  --accent: #a78bfa;
  --accent-bg: rgba(167, 139, 250, 0.14);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --off: #52525e;
  --ok-bg: rgba(52, 211, 153, 0.12);
  --warn-bg: rgba(251, 191, 36, 0.12);
  --bad-bg: rgba(248, 113, 113, 0.13);
  --radius: 14px;
  --pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f8;
    --surface: #ffffff;
    --surface-2: #f3f3f7;
    --line: rgba(15, 15, 30, 0.08);
    --line-2: rgba(15, 15, 30, 0.14);
    --text: #14141c;
    --muted: #5c5c6b;
    --faint: #8a8a98;
    --accent: #7c3aed;
    --accent-bg: rgba(124, 58, 237, 0.1);
    --ok: #059669;
    --warn: #d97706;
    --bad: #dc2626;
    --off: #b4b4c0;
    --ok-bg: rgba(5, 150, 105, 0.1);
    --warn-bg: rgba(217, 119, 6, 0.12);
    --bad-bg: rgba(220, 38, 38, 0.1);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--pad) 40px; }

/* ---------- top bar ---------- */
.top {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(11, 11, 16, 0.82);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
@media (prefers-color-scheme: light) { .top { background: rgba(245, 245, 248, 0.85); } }
.top-in {
  max-width: 1120px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--pad);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; min-width: 0; }
.brand svg { width: 28px; height: 28px; flex: none; display: block; }
.brand span { white-space: nowrap; }
.spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 13px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.ok .dot { background: var(--ok); }
.pill.warn .dot { background: var(--warn); }
.pill.bad .dot { background: var(--bad); }

.icon-btn {
  -webkit-appearance: none; appearance: none;
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }
.icon-btn svg { width: 18px; height: 18px; display: block; }
.logout { margin: 0; }

/* ---------- sections ---------- */
section { margin-top: 26px; }
.sec-h { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.sec-h h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.sec-h .sub { font-size: 13px; color: var(--faint); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; background: var(--off); }
.s-up .dot, .dot.up { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.s-degraded .dot, .dot.degraded { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.s-down .dot, .dot.down { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.s-up .dot { animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 50% { box-shadow: 0 0 0 5px transparent; } }
@media (prefers-reduced-motion: reduce) { .s-up .dot { animation: none; } }

/* ---------- nodes ---------- */
.nodes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.node { padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.node.s-down { border-color: rgba(248, 113, 113, 0.35); }
.node.s-degraded { border-color: rgba(251, 191, 36, 0.3); }
.node.s-paused { opacity: 0.6; }
.n-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.n-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-rtt { margin-left: auto; white-space: nowrap; color: var(--muted); font-size: 13px; }
.n-rtt b { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -0.02em; margin-right: 3px; }
.s-down .n-rtt, .s-down .n-rtt b { color: var(--bad); }
.s-degraded .n-rtt b { color: var(--warn); }
.n-rtt .lbl { font-size: 15px; font-weight: 600; }

.spark { display: block; width: 100%; height: 44px; overflow: visible; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .ar { fill: var(--accent); opacity: 0.08; stroke: none; }
.s-paused .spark .miss { fill: var(--off); }
.s-paused .bars i { background: var(--off) !important; opacity: 0.35 !important; }
.spark .miss { fill: var(--bad); }
.spark .base { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }

.bars { display: flex; gap: 2px; height: 16px; }
.bars i { flex: 1; border-radius: 2px; background: var(--off); opacity: 0.35; min-width: 0; }
.bars i.l0 { background: var(--ok); opacity: 1; }
.bars i.l1 { background: var(--warn); opacity: 1; }
.bars i.l2 { background: var(--bad); opacity: 1; }
.bars-cap { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: -6px; }

.n-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.n-meta .bad { color: var(--bad); }
.n-meta .warn { color: var(--warn); }
.n-meta .ok { color: var(--ok); }

/* ---------- proxy ---------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { padding: 12px 14px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.t-k { font-size: 12px; color: var(--faint); }
.t-v { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-v small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.t-s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-s.bad { color: var(--bad); }
.meter { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }
.tile .spark { height: 28px; margin-top: 4px; }
.spark .ln2 { fill: none; stroke: var(--ok); stroke-width: 1.4; vector-effect: non-scaling-stroke; opacity: 0.85; }

.list-h { padding: 12px 14px 4px; font-size: 12px; color: var(--faint); }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); min-width: 0; font-size: 14px; }
.row:first-of-type { border-top: 0; }
.row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .rt { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.row .rt b { color: var(--text); font-weight: 600; }
.row .why { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.s-down .why { color: var(--bad); }
.row.s-degraded .why { color: var(--warn); }
.empty { padding: 14px; color: var(--faint); font-size: 14px; }

/* ---------- events ---------- */
.ev .when { color: var(--faint); font-size: 12.5px; white-space: nowrap; margin-left: auto; }
.ev .dur { color: var(--muted); font-size: 12.5px; white-space: nowrap; min-width: 64px; text-align: right; }
.ev.done .dot { background: var(--off); box-shadow: none; }

.stale {
  position: -webkit-sticky; position: sticky; bottom: max(12px, env(safe-area-inset-bottom));
  margin: 20px auto 0; width: max-content; max-width: calc(100% - 32px);
  padding: 8px 14px; border-radius: 999px;
  background: var(--bad-bg); color: var(--bad); font-size: 13px;
  border: 1px solid rgba(248, 113, 113, 0.3);
}

@media (max-width: 520px) {
  :root { --pad: 12px; }
  .brand span { display: none; }
  .n-rtt b { font-size: 20px; }
  .ev .when { display: none; }
}

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 360px; padding: 28px 24px 24px;
  display: flex; flex-direction: column; gap: 18px; align-items: stretch;
}
.login .brand { justify-content: center; font-size: 18px; }
.login .brand svg { width: 34px; height: 34px; }
.login .brand span { display: inline; }
.field {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 48px; padding: 0 14px;
  font-size: 16px; /* меньше 16px — iOS зумит страницу при фокусе */
  border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--text);
  outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.key-wrap { position: relative; }
.key-wrap .field { padding-right: 48px; }
.field.masked { -webkit-text-security: disc; text-security: disc; }
.eye {
  -webkit-appearance: none; appearance: none;
  position: absolute; top: 4px; right: 4px; width: 40px; height: 40px;
  display: grid; place-items: center; border: 0; border-radius: 9px;
  background: transparent; color: var(--faint);
}
.eye:hover, .eye[aria-pressed="true"] { color: var(--text); }
.eye svg { width: 20px; height: 20px; display: block; }
.btn {
  -webkit-appearance: none; appearance: none;
  height: 48px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
}
@media (prefers-color-scheme: dark) { .btn { color: #160b2e; } }
.btn:disabled { opacity: 0.6; }
.err { margin: -6px 0 0; min-height: 18px; font-size: 13px; color: var(--bad); text-align: center; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
