:root {
  --bg: #0b1020; --bg2: #111830; --panel: #141c36; --panel2: #1a2344; --line: #243055; --line2: #2e3c68;
  --text: #e6eaf5; --muted: #8b97b8; --dim: #5d6a8f;
  --ok: #34d399; --warn: #fbbf24; --crit: #f87171; --info: #60a5fa; --paused: #a78bfa; --removed: #64748b;
  --accent: #22d3ee; --accent2: #818cf8;
  --c1: #22d3ee; --c2: #a78bfa; --c3: #34d399; --c4: #fbbf24; --c5: #f472b6;
  --radius: 12px; --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--text); font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); } .dim { color: var(--dim); }
.small { font-size: 12px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .crit { color: var(--crit); } .info { color: var(--info); }

#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
#app.noauth { grid-template-columns: 1fr; }
#nav { position: sticky; top: 0; height: 100vh; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; }
#nav .brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 18px; }
#nav .brand small { display: block; color: var(--muted); font-size: 11.5px; font-family: var(--mono); }
.logo { width: 30px; height: 30px; border-radius: 8px; background: url(/favicon.svg) center/cover; flex: none; }
#nav nav { display: flex; flex-direction: column; gap: 2px; }
#nav nav a { color: var(--muted); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
#nav nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
#nav nav a.active { background: var(--panel2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; font-size: 12px; }
main { padding: 24px 28px 60px; min-width: 0; max-width: 1500px; }
.loading { color: var(--muted); padding: 40px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel + .panel, .section { margin-top: 14px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush > h2 { padding: 14px 16px 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }
.bar.thin { height: 4px; margin-top: 4px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px #34d39922; }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px #fbbf2422; }
.dot.down, .dot.crit { background: var(--crit); box-shadow: 0 0 0 3px #f8717133; }
.dot.paused { background: var(--paused); } .dot.removed { background: var(--removed); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--panel2); color: var(--muted); border: 1px solid var(--line2); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: #34d39944; background: #34d39914; }
.chip.warn { color: var(--warn); border-color: #fbbf2444; background: #fbbf2414; }
.chip.crit, .chip.down { color: var(--crit); border-color: #f8717144; background: #f8717114; }
.chip.info { color: var(--info); border-color: #60a5fa44; background: #60a5fa14; }
.chip.paused { color: var(--paused); border-color: #a78bfa44; background: #a78bfa14; }

.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: border-color .15s, transform .15s; display: flex; flex-direction: column; gap: 8px; color: var(--text); }
.pcard:hover { border-color: var(--line2); transform: translateY(-1px); text-decoration: none; }
.pcard.down { border-color: #f8717166; } .pcard.warn { border-color: #fbbf2444; } .pcard.paused, .pcard.removed { opacity: .7; }
.pcard .top { display: flex; align-items: center; gap: 8px; }
.pcard .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .domain { color: var(--muted); font-size: 12px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 12px; }
.pcard .stats b { display: block; font-size: 13px; font-variant-numeric: tabular-nums; }
.pcard .stats span { color: var(--dim); font-size: 11px; }
.pcard .issue { font-size: 12px; color: var(--warn); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard.down .issue { color: var(--crit); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; } th.sortable:hover { color: var(--text); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #ffffff05; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.panel.flush .table-wrap { max-height: 560px; overflow: auto; }
td .sub { color: var(--dim); font-size: 11.5px; }
.break { word-break: break-all; }

.alerts { display: flex; flex-direction: column; gap: 6px; }
.alert { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); font-size: 13px; }
.alert .scope { color: var(--muted); font-size: 12px; white-space: nowrap; }
.alert.crit { border-color: #f8717155; } .alert.warn { border-color: #fbbf2433; }

.btn { appearance: none; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #04131a; border-color: var(--accent); font-weight: 600; }
.btn.danger { background: #f871711a; color: var(--crit); border-color: #f8717155; }
.btn.danger:hover { background: #f8717133; border-color: var(--crit); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btns { display: flex; gap: 4px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--panel2); color: var(--text); }

input[type=text], input[type=password], input[type=search], select, textarea { background: var(--bg2); border: 1px solid var(--line2); color: var(--text); padding: 8px 10px; border-radius: 8px; font: inherit; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #22d3ee55; border-color: var(--accent); }
input.code { font-family: var(--mono); letter-spacing: .3em; font-size: 18px; text-align: center; max-width: 180px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; color: var(--text); font-size: 13px; margin: 0; cursor: pointer; }
.check input { margin-top: 3px; }
.check.disabled { color: var(--dim); cursor: not-allowed; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chart .legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
#tip { position: fixed; z-index: 100; pointer-events: none; background: #0b1020f2; border: 1px solid var(--line2); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; box-shadow: 0 8px 24px #0008; }
.strip { display: flex; gap: 1px; height: 18px; align-items: stretch; }
.strip i { flex: 1; background: var(--ok); border-radius: 1px; opacity: .85; }
.strip i.bad { background: var(--crit); opacity: 1; } .strip i.none { background: var(--line); }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.auth h1 { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.auth .err { color: var(--crit); margin-top: 12px; font-size: 13px; min-height: 18px; }
.auth .btn { width: 100%; margin-top: 18px; padding: 10px; }
.qr { background: #fff; border-radius: 10px; padding: 10px; width: max-content; margin: 12px auto; }
.qr svg { display: block; }
.secret { font-family: var(--mono); font-size: 13px; background: var(--bg2); border: 1px dashed var(--line2); padding: 8px; border-radius: 8px; word-break: break-all; text-align: center; }

.modal-bg { position: fixed; inset: 0; background: #02040acc; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; width: 100%; max-width: 640px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 24px 60px #000a; }
.modal.wide { max-width: 1100px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px 18px; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.modal footer .err { color: var(--crit); font-size: 13px; margin-right: auto; }
pre.log { margin: 0; background: #070b17; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.5 var(--mono); color: #cbd5f0; white-space: pre-wrap; word-break: break-word; max-height: 65vh; overflow: auto; }
pre.log .e { color: #fca5a5; }
.warnbox { background: #fbbf2412; border: 1px solid #fbbf2444; color: #fde68a; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; }
.dangerbox { background: #f8717112; border: 1px solid #f8717144; color: #fecaca; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; }
details { border-top: 1px solid var(--line); }
details > summary { cursor: pointer; padding: 8px 0; color: var(--muted); font-size: 12.5px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 280px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; padding: 10px 14px; box-shadow: 0 10px 30px #0009; max-width: 420px; }
.toast.err { border-color: var(--crit); }
.empty { color: var(--dim); padding: 14px; text-align: center; font-size: 13px; }

@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  #nav .brand { padding: 0; }
  #nav nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  #nav nav a { white-space: nowrap; }
  .nav-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; }
  main { padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
