/* VPN Admin UI v2 — self-contained (no CDN), works offline on LAN. */
:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --bg-elev: #11151c;
  --surface: #151a22;
  --surface-2: #1b212b;
  --surface-3: #232a36;
  --border: #252d39;
  --border-strong: #334052;
  --text: #e8eef6;
  --text-2: #a7b3c4;
  --text-3: #6f7d90;
  --accent: #2fd0e4;
  --accent-ink: #04222a;
  --accent-soft: rgba(47, 208, 228, .12);
  --ok: #3fd29b;
  --ok-soft: rgba(63, 210, 155, .13);
  --warn: #f2b84b;
  --warn-soft: rgba(242, 184, 75, .14);
  --danger: #f47272;
  --danger-soft: rgba(244, 114, 114, .14);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 248px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --bottom-nav-height: 0px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { overflow-wrap: anywhere; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 14px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand b { display: block; font-size: 15px; }
.brand span { display: block; font-size: 11.5px; color: var(--text-3); }
.nav-label { margin: 14px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); text-align: left; text-decoration: none;
  font-size: 14px; font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .count { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--text-3); background: var(--surface-2); padding: 1px 7px; border-radius: 999px; }
.nav-item.active .count { color: var(--accent); background: rgba(47, 208, 228, .16); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 6px 0; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text); font-weight: 700; text-transform: uppercase; flex: none; }
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who b { display: block; font-size: 13px; }
.sidebar-foot .who span { font-size: 11.5px; color: var(--text-3); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 17px; height: 17px; }

.main { min-width: 0; padding: 26px 32px 48px; }
.mobile-top { display: none; }
.page { display: none; max-width: 1280px; margin: 0 auto; animation: fade .18s ease-out; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin-top: 4px; color: var(--text-2); font-size: 13.5px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { font-size: 14.5px; font-weight: 600; }
.card-head p { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.card-body { padding: 18px; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.ov-top { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }

.hero { position: relative; overflow: hidden; padding: 22px; }
.hero::after { content: ""; position: absolute; inset: auto -60px -80px auto; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, rgba(47,208,228,.18), transparent 70%); pointer-events: none; }
.hero-name { margin-top: 10px; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.hero-meta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: 13px; }
.hero-meta span { display: inline-flex; align-items: center; gap: 6px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(63,210,155,.6); animation: pulse 2s infinite; flex: none; }
.pulse.warn { background: var(--warn); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(63,210,155,.55); } 70% { box-shadow: 0 0 0 9px rgba(63,210,155,0); } 100% { box-shadow: 0 0 0 0 rgba(63,210,155,0); } }

.stat { padding: 14px 16px; }
.stat .v { margin-top: 6px; font-size: 26px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .v.ok { color: var(--ok); } .stat .v.bad { color: var(--danger); } .stat .v.dim { color: var(--text-2); }

.health { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.health-item { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); min-width: 0; }
.health-item .hv { margin-top: 6px; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.health-item .hd { margin-top: 4px; font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--danger); }

.shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.shortcut { display: flex; gap: 12px; align-items: flex-start; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-align: left; color: var(--text); }
.shortcut:hover { border-color: var(--border-strong); background: var(--surface-2); }
.shortcut .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.shortcut .ic svg { width: 18px; height: 18px; }
.shortcut b { display: block; font-size: 14px; }
.shortcut small { display: block; margin-top: 2px; font-size: 12px; color: var(--text-3); }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font-size: 13.5px; font-weight: 500; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #5adcec; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-apply { border-color: rgba(242,184,75,.55); color: var(--warn); background: var(--warn-soft); }
.btn-apply:hover { background: rgba(242,184,75,.24); }
.btn-danger { border-color: rgba(244,114,114,.5); color: var(--danger); background: var(--danger-soft); }
.btn-danger:hover { background: rgba(244,114,114,.24); }
.btn-ok { border-color: rgba(63,210,155,.5); color: var(--ok); background: var(--ok-soft); }
.btn-warn { border-color: rgba(242,184,75,.5); color: var(--warn); background: var(--warn-soft); }

.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--text); font-size: 14px; outline: none;
}
.textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row { display: grid; gap: 12px; align-items: end; }
.hint { font-size: 12px; color: var(--text-3); }
.hint.warn { color: var(--warn); }

.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); }
.search .input { padding-left: 34px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- Badges ---------- */
.badge, .status-ok, .status-warn, .status-error, .status-neutral, .status-timeout, .status-muted {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.status-ok { background: var(--ok-soft); color: var(--ok); }
.status-warn, .status-timeout { background: var(--warn-soft); color: var(--warn); }
.status-error { background: var(--danger-soft); color: var(--danger); }
.status-neutral, .status-muted { background: var(--surface-3); color: var(--text-2); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-outline { border: 1px solid var(--border-strong); color: var(--text-2); background: transparent; font-weight: 500; }
.badge-warn-outline { border: 1px solid rgba(242,184,75,.45); color: var(--warn); background: transparent; font-weight: 500; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(255,255,255,.015); }
.table tr.is-active td { background: rgba(47,208,228,.06); }
.table tr.is-active td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table .empty { padding: 28px 14px; text-align: center; color: var(--text-3); }
.sortBtn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; }
.sortBtn:hover { color: var(--text); }
.sortBtn [data-arrow] { color: var(--accent); }
.cell-name { max-width: 300px; }
.cell-name b { display: block; font-weight: 600; }
.cell-err { max-width: 240px; font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.metric { display: grid; gap: 3px; }
.metric small { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* ---------- Lists (mobile cards & generic) ---------- */
.list { display: grid; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { min-width: 0; flex: 1; }
.list-empty { padding: 26px 18px; text-align: center; color: var(--text-3); }
.cards { display: none; gap: 10px; padding: 12px; }
.m-card { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
.m-card.is-active { border-color: rgba(47,208,228,.5); }
.m-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.m-card-head h3 { font-size: 15px; font-weight: 600; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; margin-top: 12px; font-size: 13px; }
.kv dt { font-size: 11.5px; color: var(--text-3); }
.kv dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.actions-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.actions-grid .btn { width: 100%; min-height: 42px; }

.note { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-2); font-size: 13px; line-height: 1.5; }
.note.info { border-left: 3px solid var(--accent); }
.note.warn { border-color: rgba(242,184,75,.35); background: var(--warn-soft); color: #f6d58f; }

details.disclosure > summary { list-style: none; cursor: pointer; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .chev { transition: transform .15s; color: var(--text-3); }
details.disclosure[open] > summary .chev { transform: rotate(180deg); }
details.disclosure[open] > summary { border-bottom: 1px solid var(--border); }
details.disclosure:not([open]) > summary { border-bottom: 0; }

.more-list { display: grid; gap: 10px; }

/* ---------- Modal / sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(3, 6, 10, .72); backdrop-filter: blur(3px); }
.modal.open { display: flex; }
.modal-box { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-head p { margin-top: 3px; font-size: 12.5px; color: var(--text-3); }
.modal-body { padding: 18px 20px 20px; }
.qr { display: block; margin: 0 auto; width: 100%; max-width: 300px; border-radius: 12px; background: #fff; padding: 12px; }
.secret-pre { margin: 14px 0 0; max-height: 260px; overflow: auto; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); font: 12px/1.5 var(--mono); color: var(--text-2); white-space: pre; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 70; right: 20px; bottom: 20px; max-width: 460px;
  padding: 12px 16px 12px 14px; border-radius: 12px; border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  background: var(--surface-2); color: var(--text); box-shadow: var(--shadow); font-size: 13.5px; overflow-wrap: anywhere;
}
.toast[data-kind="error"] { border-left-color: var(--danger); }
#message:empty, #message[hidden] { display: none !important; }

/* ---------- Mobile bottom nav ---------- */
.bottom-nav { display: none; }

/* ---------- Passkeys (rendered by passkeys.js) ---------- */
#passkeyList > article { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
#passkeyList > article:last-child { border-bottom: 0; }
#passkeyList > article strong { flex: 1 1 100%; }
#passkeyList > article p { flex: 1 1 auto; color: var(--text-3); font-size: 12.5px; }
#passkeyList .soft-btn { min-height: 30px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid rgba(244,114,114,.5); color: var(--danger); background: var(--danger-soft); font-size: 12.5px; }
.security-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.security-controls .input { flex: 1 1 200px; width: auto; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(600px 400px at 50% 0%, rgba(47,208,228,.10), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { padding: 0 0 6px; }
.login-card .btn { width: 100%; min-height: 44px; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid rgba(244,114,114,.45); background: var(--danger-soft); color: #fbc0c0; font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .health { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .col-hide-lg { display: none; }
}
@media (max-width: 1024px) {
  .ov-top { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar { display: none; }
  .main { padding: max(12px, env(safe-area-inset-top)) 14px calc(var(--bottom-nav-height) + 24px); }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
  .mobile-top .brand { padding: 0; }
  .mobile-top .brand img { width: 30px; height: 30px; }
  .page-head { margin-bottom: 14px; align-items: flex-start; }
  .page-head h1 { font-size: 20px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 calc(50% - 8px); min-height: 42px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .grid-4 .stat { padding: 10px 8px; text-align: center; }
  .grid-4 .stat .eyebrow { font-size: 10px; letter-spacing: .02em; }
  .grid-4 .stat .v { font-size: 20px; }
  .health { grid-template-columns: 1fr 1fr; gap: 8px; }
  .health-item { padding: 10px 12px; }
  .shortcuts { grid-template-columns: 1fr 1fr; gap: 10px; }
  .shortcut { flex-direction: column; gap: 8px; padding: 14px; }
  .hero { padding: 18px; }
  .hero-name { font-size: 20px; }
  .desktop-only { display: none !important; }
  .cards { display: grid; }
  .toolbar { padding: 12px; }
  .search { max-width: none; flex-basis: 100%; }
  .card-head, .card-body, .card-pad { padding-left: 14px; padding-right: 14px; }
  .list-item { padding: 12px 14px; flex-wrap: wrap; }
  input, select, textarea, .input, .select, .textarea { font-size: 16px; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
  .toast { left: 12px; right: 12px; bottom: calc(var(--bottom-nav-height) + 12px); max-width: none; }
  .bottom-nav {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(13, 16, 21, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
  }
  .bottom-nav .nav-item { flex-direction: column; justify-content: center; gap: 3px; min-height: 52px; padding: 4px 2px; font-size: 10.5px; text-align: center; }
  .bottom-nav .nav-item svg { width: 21px; height: 21px; }
}
@media (min-width: 901px) {
  .mobile-only { display: none !important; }
}

/* Overflow guards */
.metric { justify-items: start; }
.toolbar > *, .card-head > div, .page-head > div, .m-card-head > div { min-width: 0; }
.chips { min-width: 0; max-width: 100%; }
.main, .page, .stack > *, .grid-2 > *, .ov-top > * { min-width: 0; }
@media (max-width: 900px) { .chips { flex: 1 1 100%; } }
a.shortcut, a.nav-item { text-decoration: none; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-4 .stat { text-align: left; padding: 12px 14px; } }
