:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e3e7ee;
  --border-strong: #cfd6e0;
  --text: #191d24;
  --text-2: #5d6675;
  --text-3: #8a93a3;
  --brand: #1f5fbf;
  --brand-hover: #184e9f;
  --brand-soft: #e9f1fc;
  --side: #111a2b;
  --side-text: #aab4c6;
  --danger: #c93435;
  --danger-soft: #fdeeee;
  /* dataviz */
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --st-good: #0aac23;
  --st-warning: #fbb315;
  --st-critical: #dc3c3d;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; }
.brand-mark::before, .brand-mark::after { content: ""; grid-area: 1/1; width: 15px; height: 5px; border-radius: 2px; background: #fff; }
.brand-mark::before { transform: translateY(-4px); }
.brand-mark::after { transform: translateY(4px); opacity: .75; }
.server-pick { margin: 0 12px 10px; padding: 9px 10px; border-radius: 8px; background: rgba(255,255,255,.06); font-size: 12.5px; }
.server-pick b { display: block; color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; }
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12.5px; }
.side-foot .who { color: #fff; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; }
.side-foot button { background: none; border: 0; padding: 0; color: var(--side-text); cursor: pointer; margin-right: 12px; }
.side-foot button:hover { color: #fff; }
.main { padding: 22px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); font-size: 13px; }
.spacer { flex: 1; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 26px; font-weight: 650; margin: 4px 0 2px; letter-spacing: -.01em; }
.tile .value small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 3px; }
.tile .note { color: var(--text-2); font-size: 12.5px; min-height: 17px; }
.meter { height: 6px; border-radius: 3px; background: #edf0f4; margin-top: 10px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--series-1); transition: width .4s; }
.meter.warn > i { background: var(--st-warning); }
.meter.crit > i { background: var(--st-critical); }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; padding: 10px 16px; border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap; }
td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: #f8fafd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--text-2); }
.table-wrap { overflow-x: auto; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: #f5f7fa; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--danger); border-color: #ecc5c5; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-weight: 550; margin-bottom: 5px; }
label.field > small { display: block; color: var(--text-2); margin-top: 4px; font-size: 12.5px; }
input[type=text], input[type=password], input[type=email], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline select, .inline input { width: auto; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; background: #eef1f5; color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #9aa3b2; }
.badge.ok { background: #e8f6ea; color: #0b6b1a; } .badge.ok::before { background: var(--st-good); }
.badge.bad { background: var(--danger-soft); color: #a32526; } .badge.bad::before { background: var(--st-critical); }
.badge.warn { background: #fff5d9; color: #7a5300; } .badge.warn::before { background: var(--st-warning); }
.badge.plain::before { display: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--brand-soft); color: var(--brand-hover); font-weight: 550; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 13px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

pre.log { background: #0f1724; color: #d8dee9; padding: 14px; border-radius: 8px; overflow: auto; max-height: 520px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 120px; }
pre.out { background: #f4f6f9; border: 1px solid var(--border); padding: 10px; border-radius: 8px; overflow: auto; max-height: 300px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 10px 0 0; }
.secret { background: #f4f6f9; border: 1px dashed var(--border-strong); border-radius: 8px; padding: 10px 12px; margin-top: 4px; user-select: all; overflow-wrap: anywhere; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,36,.45); display: grid; place-items: start center; padding: 6vh 16px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 720px; }
.modal header { padding: 16px 20px 0; font-size: 16px; font-weight: 650; }
.modal .body { padding: 14px 20px 6px; }
.modal footer { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: #1b2434; color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.error { background: #a32526; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 26px 26px 20px; }
.auth .brand { color: var(--text); padding: 0 0 16px; }
.auth .btn { width: 100%; justify-content: center; padding: 9px; }
.form-error { color: var(--danger); min-height: 18px; margin-bottom: 8px; font-size: 13px; }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .tick { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; color: var(--text-2); font-size: 12.5px; margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tip { position: absolute; pointer-events: none; background: #1b2434; color: #fff; padding: 7px 10px; border-radius: 7px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%); display: none; z-index: 2; }
.tip b { font-weight: 600; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a span { display: none; }
  .server-pick, .side-foot .who { display: none; }
  .main { padding: 16px 14px 40px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}
