/* ── reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:       #0b1120;
  --surface:  #111827;
  --surface2: #1e2d3d;
  --surface3: #243447;
  --border:   #1f3352;
  --primary:  #3b82f6;
  --primary-h:#2563eb;
  --accent:   #60a5fa;
  --success:  #10b981;
  --warn:     #f59e0b;
  --danger:   #ef4444;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --muted2:   #94a3b8;
  --code-bg:  #0d1b2a;
  --radius:   8px;
  --sidebar:  240px;
  --sidebar-min: 48px;
  --sidebar-max: 480px;
}
html, body { height: 100%; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
code {
  font: 12px/1 "Cascadia Code", "Fira Code", "SF Mono", monospace;
  background: var(--code-bg);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
}
/* ── scrollbars ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── sidebar ────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar);
  /* min/max enforced in JS — no CSS constraint so inline style wins cleanly */
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  z-index: 20;
  overflow: hidden;
}
#sidebar-resize {
  width: 6px;
  min-height: 100vh;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  z-index: 21;
  position: relative;
  transition: background .15s;
  touch-action: none; /* required so pointer events aren't stolen for panning */
}
#sidebar-resize:hover,
#sidebar-resize.dragging {
  background: var(--primary);
}
.logo {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.logo-text { font-weight: 700; font-size: 15px; color: var(--text); }
.logo-text span { color: var(--accent); }
#sidebar > nav { flex: 1; padding: .75rem 0; }
.nav-section { padding: .25rem .75rem .1rem; font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: .5rem; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px .5rem;
  color: var(--muted2);
  font-size: 13px;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(59,130,246,.15); color: var(--accent); }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--primary); color: #fff; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 10px; }
.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: space-between;
}
#status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  display: inline-block; margin-right: .35rem;
}
#status-dot.ok { background: var(--success); box-shadow: 0 0 6px var(--success); }

/* ── main content ───────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
}
.topbar h2 { font-size: 15px; font-weight: 600; flex: 1; }
.topbar .actions { display: flex; gap: .5rem; }
.content { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── cards / stats ──────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card .sub { font-size: 12px; color: var(--muted2); margin-top: .25rem; }
.stat-card .icon { float: right; font-size: 22px; opacity: .25; margin-top: -2px; }

/* ── panels ─────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.panel-header {
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface2);
}
.panel-header h3 { font-size: 13px; font-weight: 600; flex: 1; }
.panel-body { padding: 1rem 1.25rem; }

/* ── tables ─────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  padding: .6rem .75rem;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
td { padding: .55rem .75rem; vertical-align: middle; }
td.mono { font-family: "Cascadia Code","Fira Code","SF Mono",monospace; font-size: 12px; color: var(--accent); }
td.muted { color: var(--muted2); font-size: 12px; }

/* ── badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.badge.managed  { background: rgba(59,130,246,.15);  color: var(--accent); }
.badge.static   { background: rgba(245,158,11,.15);  color: var(--warn); }
.badge.gateway  { background: rgba(16,185,129,.15);  color: var(--success); }
.badge.nomad    { background: rgba(139,92,246,.15);  color: #a78bfa; }
.badge.offline  { background: rgba(100,116,139,.15); color: var(--muted2); }
.badge.online   { background: rgba(16,185,129,.15);  color: var(--success); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ── forms ──────────────────────────────────────────────────── */
.form-row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .75rem; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: 11px; color: var(--muted2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
input, select, textarea {
  padding: .45rem .65rem;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,.2); }
input::placeholder { color: var(--muted); }
select option { background: var(--surface2); }

/* ── buttons ────────────────────────────────────────────────── */
btn, .btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .85rem; border-radius: 5px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .15s;
  white-space: nowrap;
}
button { font: inherit; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); }
.btn-ghost { background: transparent; color: var(--muted2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.1); }
.btn-sm { padding: .25rem .55rem; font-size: 12px; }
.btn-icon { padding: .3rem .4rem; }

/* ── checks list ────────────────────────────────────────────── */
.checks {
  display: flex; flex-direction: column; gap: .3rem;
  max-height: 10rem; overflow-y: auto;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .5rem .65rem;
}
.checks label {
  display: flex; gap: .5rem; align-items: center;
  font-size: 13px; cursor: pointer; padding: .15rem 0;
  color: var(--muted2);
}
.checks label:hover { color: var(--text); }
.checks input[type=checkbox] { accent-color: var(--primary); }

/* ── compact peer picker (searchable, 2-col grid) ────────────── */
.peer-pick { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.peer-pick-search {
  border: none; border-bottom: 1px solid var(--border);
  background: var(--surface3); color: var(--text);
  padding: .3rem .55rem; font-size: 12px; outline: none; width: 100%;
}
.peer-pick-search::placeholder { color: var(--muted); }
.peer-pick-list {
  display: flex; flex-direction: column;
  max-height: 10rem; overflow-y: auto;
  background: var(--surface3); padding: .3rem .55rem; gap: 0;
}
.peer-pick-list label {
  display: flex; gap: .5rem; align-items: baseline;
  font-size: 13px; cursor: pointer; padding: .18rem 0;
  color: var(--muted2);
}
.peer-pick-list label:hover { color: var(--text); }
.peer-pick-list input[type=checkbox] { accent-color: var(--primary); flex-shrink: 0; align-self: center; }
.peer-pick-list label .pn { font-weight: 600; color: var(--text); }
.peer-pick-list label .pip { font: 12px/1 "Cascadia Code","Fira Code","SF Mono",monospace; color: var(--accent); background: var(--code-bg); padding: 1px 5px; border-radius: 3px; }
.peer-pick-list label .pnet { color: var(--muted); font-size: 11px; }
.peer-pick-empty { padding: .45rem .6rem; font-size: 12px; color: var(--muted); background: var(--surface3); }

/* ── modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: none; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.modal-overlay.show { display: flex; pointer-events: auto; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 36rem; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 25px 60px rgba(0,0,0,.6);
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
}
.modal-header h3 { flex: 1; font-size: 14px; font-weight: 600; }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .5rem; justify-content: flex-end;
}
.conf-warn { color: var(--warn); font-size: 12px; margin-bottom: .75rem; padding: .5rem .75rem; background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.25); border-radius: 5px; }
pre.conf {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  font: 12px/1.6 "Cascadia Code","Fira Code","SF Mono",monospace;
  color: #a5f3fc;
  overflow: auto;
  max-height: 45vh;
  white-space: pre;
}

/* ── toasts ─────────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  display: flex; flex-direction: column; gap: .5rem; z-index: 200;
}
.toast {
  display: flex; align-items: center; gap: .6rem;
  padding: .65rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: slideIn .2s ease;
  min-width: 240px; max-width: 380px;
}
.toast.success { border-color: rgba(16,185,129,.4); }
.toast.error   { border-color: rgba(239,68,68,.4); }
.toast.info    { border-color: rgba(59,130,246,.4); }
.toast-icon { font-size: 16px; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── login screen ───────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
#login-screen.show { display: flex; }
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-logo .logo-icon { width: 48px; height: 48px; font-size: 24px; margin: 0 auto .75rem; }
.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo h1 span { color: var(--accent); }
.login-logo p { font-size: 13px; color: var(--muted2); margin-top: .25rem; }
.login-field { margin-bottom: 1rem; }
.login-field label { display: block; font-size: 12px; color: var(--muted2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
.login-field input { width: 100%; }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: .75rem; min-height: 1.25em; text-align: center; }
#login-submit { width: 100%; padding: .65rem; font-size: 14px; }
.login-step { display: none; }
.login-step.active { display: block; }
.totp-hint { font-size: 12px; color: var(--muted2); text-align: center; margin-top: .75rem; }

/* ── section views ──────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── endpoint chips ─────────────────────────────────────────── */
.ep-list { display: flex; flex-wrap: wrap; gap: 3px; max-width: 260px; }
.ep { font-size: 11px; font-family: monospace; background: var(--surface3); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; color: var(--muted2); }

/* ── empty state ────────────────────────────────────────────── */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .big { font-size: 2rem; margin-bottom: .5rem; }

/* ── divider ────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }

/* ── token popup ────────────────────────────────────────────── */
.token-box {
  font: 13px/1.6 "Cascadia Code","Fira Code","SF Mono",monospace;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .75rem 1rem;
  color: var(--success);
  word-break: break-all;
  margin-bottom: .75rem;
}

/* ── narrow sidebar: hide labels, keep icons ─────────────────── */
#sidebar.narrow .nav-item span:not(.icon),
#sidebar.narrow .nav-badge,
#sidebar.narrow .nav-section,
#sidebar.narrow .logo-text,
#sidebar.narrow .sidebar-footer span:first-child { display: none; }
#sidebar.narrow .nav-item { justify-content: center; padding: .5rem; }
#sidebar.narrow .logo { justify-content: center; padding: .75rem .5rem; }
#sidebar.narrow .sidebar-footer { justify-content: center; padding: .75rem .5rem; }

/* ── responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 600px) {
  #sidebar { display: none; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}
