/* VPN Portal design system. Flat 2D: solid fills, 1px borders, no shadows or gradients. */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #15202b;
  --muted: #5b6777;
  --line: #dde2ea;
  --brand: #0b6e69;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --ok: #067647;
  --ok-soft: #e4f5ec;
  --info: #1d4f91;
  --info-soft: #e7eef9;
  --side: #10233a;
  --side-ink: #d7e1ec;
  --radius: 10px;
  --focus: 0 0 0 3px rgba(11, 110, 105, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1620; --surface: #17222e; --surface-2: #1c2a38; --ink: #e7edf4; --muted: #97a4b4; --line: #2a3848;
    --brand: #2bb3ad; --brand-ink: #06201f; --brand-soft: #173b3a;
    --danger: #ff8a80; --danger-soft: #3b1f1d; --warn: #f5c15c; --warn-soft: #3a2f14;
    --ok: #5fd39a; --ok-soft: #153325; --info: #8ab4f8; --info-soft: #1b2a40;
    --side: #0a1520; --side-ink: #b7c5d4; --focus: 0 0 0 3px rgba(43, 179, 173, .45);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1620; --surface: #17222e; --surface-2: #1c2a38; --ink: #e7edf4; --muted: #97a4b4; --line: #2a3848;
  --brand: #2bb3ad; --brand-ink: #06201f; --brand-soft: #173b3a;
  --danger: #ff8a80; --danger-soft: #3b1f1d; --warn: #f5c15c; --warn-soft: #3a2f14;
  --ok: #5fd39a; --ok-soft: #153325; --info: #8ab4f8; --info-soft: #1b2a40;
  --side: #0a1520; --side-ink: #b7c5d4; --focus: 0 0 0 3px rgba(43, 179, 173, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); min-height: 100vh;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
p { margin: 0; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }

svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  min-height: 36px; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }
.icon-btn { border: 0; background: transparent; padding: 6px; cursor: pointer; color: var(--muted); border-radius: 6px; }
.icon-btn svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Form fields ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field label, .label { font-size: 13px; color: var(--muted); font-weight: 550; }
.input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 11px; width: 100%; min-height: 36px;
}
.input:focus { border-color: var(--brand); box-shadow: var(--focus); outline: none; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { font-size: 12px; color: var(--danger); min-height: 0; }
.hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.form-section { display: flex; flex-direction: column; gap: 4px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ── Auth screens ────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 40px; height: 40px; }
.brand strong { font-size: 17px; display: block; }
.brand span { font-size: 13px; color: var(--muted); }
.auth-card form { margin-top: 20px; }

/* ── Shell ───────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.side .brand strong { color: #fff; }
.side .brand span { color: #8fa2b8; }
.nav { margin-top: 16px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--side-ink); text-decoration: none;
}
.nav a:hover { background: #17304a; }
.nav a[aria-current="page"] { background: #1c3550; color: #fff; }
.nav .badge { margin-left: auto; background: var(--brand); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; }
.side-foot { margin-top: auto; }
.side-foot .btn { width: 100%; background: transparent; color: var(--side-ink); border-color: #2a4560; }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.topbar .crumb { color: var(--muted); font-size: 13px; }
.main { padding: 24px 28px 40px; width: 100%; max-width: 1180px; }
.main > div { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin-top: 2px; }

/* ── Cards, stats and sections ───────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 8px; }
.stat-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.stat-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Service panel */
.service-state { display: flex; align-items: center; gap: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; font-weight: 550; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.muted { border: 1px solid var(--line); color: var(--muted); }

/* Warning band */
.warn-box { display: flex; gap: 12px; align-items: center; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.warn-box > div { flex: 1 1 0; min-width: 0; }
.warn-box strong { color: var(--ink); }
.warn-box p { color: var(--ink); margin-top: 2px; }
.warn-box svg.i { width: 22px; height: 22px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td .btn-row { flex-wrap: nowrap; }
td.wrap { white-space: normal; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty svg.i { width: 28px; height: 28px; color: var(--muted); margin-bottom: 6px; }

/* Segmented filter */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* Event log entries */
.ev-type { display: inline-flex; align-items: center; gap: 6px; }

/* ── Dialogs ─────────────────────────────────────────────────────────── */
.dialog-host { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(9, 16, 24, .55); }
.dialog {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
}
.dialog.wide { max-width: 680px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 0; gap: 12px; }
.dialog-body { padding: 14px 18px; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dialog-foot:empty { display: none; }
.dialog-foot .btn { min-width: 96px; }
.dialog .danger-note { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-top: 10px; }
.changes { margin: 8px 0 0; padding-left: 18px; color: var(--ink); }
.changes li { margin: 3px 0; }
.secret-box { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-size: 14px; }
.qr { display: block; margin: 8px auto; width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 8px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ── Snackbars ───────────────────────────────────────────────────────── */
.snackbars { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.snackbar {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 12px 14px;
  border-radius: 10px; background: var(--side); color: #fff; border-left: 4px solid #8fa2b8; animation: slide-in .18s ease-out;
}
.snackbar.success { border-left-color: var(--ok); }
.snackbar.error { border-left-color: var(--danger); }
.snackbar.info { border-left-color: var(--info); }
.snackbar .msg { flex: 1; font-size: 14px; }
.snackbar .msg strong { display: block; font-size: 14px; }
.snackbar .msg span { color: #c4d0de; font-size: 13px; }
.snackbar button { border: 0; background: transparent; color: #c4d0de; cursor: pointer; padding: 2px; border-radius: 6px; }
.snackbar button svg { width: 16px; height: 16px; }
@keyframes slide-in { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Phone layout ────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px 14px; }
  .nav { flex-direction: row; overflow-x: auto; margin-top: 10px; }
  .nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .topbar { padding: 12px 16px; }
  .main { padding: 18px 16px 32px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .snackbars { top: auto; bottom: 16px; left: 16px; right: 16px; width: auto; }
}
