:root {
  --bg:        #0a0b0d;
  --bg-deep:   #050608;
  --surface:   #121317;
  --surface-2: #1a1c22;
  --border:    #262932;
  --border-2:  #353945;
  --text:      #e9e9ee;
  --muted:     #7d8195;
  --dim:       #4d5163;
  --accent:    #f59e0b;
  --accent-2:  #fbbf24;
  --ok:        #10b981;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --danger-2:  #f87171;
  --info:      #60a5fa;
  --purple:    #c084fc;
  --rest:      #3a3d49;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "SF Pro Display", "Inter", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* pre-flicker layer selection (set by inline script in <head>) */
html[data-initial="login"] #dash { display: none; }
html[data-initial="dash"]  #login { display: none; }
html, body {
  margin: 0; padding: 0; background: var(--bg-deep); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; min-height: 100vh;
  background-image:
    radial-gradient(900px 500px at 20% -10%, rgba(245,158,11,.06), transparent 60%),
    radial-gradient(700px 500px at 90% 10%, rgba(99,102,241,.04), transparent 60%);
}
a { color: var(--accent); text-decoration: none; }
::selection { background: rgba(245,158,11,.35); }

button, input { font: inherit; color: inherit; }
input[type=text], input[type=password] {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; color: var(--text); outline: none; font-family: var(--mono);
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,158,11,.12); }
button {
  background: var(--accent); color: #0a0a0a; border: none; border-radius: 6px;
  padding: 10px 16px; cursor: pointer; font-weight: 600; font-family: var(--mono);
  transition: background .15s, transform .05s;
}
button:hover:not(:disabled) { background: var(--accent-2); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { color: var(--text); border-color: var(--border-2); background: var(--surface); }
button.danger {
  background: transparent; color: var(--danger-2);
  border: 1px solid rgba(239,68,68,.4); font-weight: 500;
}
button.danger:hover {
  background: rgba(239,68,68,.12); border-color: var(--danger);
}

/* --- brand mark --- */
.brand {
  font-family: var(--mono); user-select: none;
}
.brand .ascii {
  color: var(--dim); font-size: 11px; line-height: 1.15;
  margin-bottom: 8px; white-space: pre;
}
.brand .mark {
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em;
  display: flex; align-items: baseline; gap: 0;
}
.brand .ns { color: var(--accent); }
.brand .slash { color: var(--dim); margin: 0 6px; font-weight: 400; }
.brand .leaf { color: var(--text); }
.brand .cursor {
  display: inline-block; width: 9px; height: 1.05em; background: var(--accent);
  margin-left: 6px; vertical-align: text-top; animation: blink 1.1s steps(2) infinite;
  transform: translateY(3px);
}
@keyframes blink { 50% { opacity: 0; } }
.brand .tagline {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  margin-top: 10px; letter-spacing: 0.01em;
}
.brand .tagline .c { color: var(--dim); }
.brand .tagline .h { color: var(--ok); }

/* --- login --- */
#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
#login .card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 40px 36px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45), 0 1px 0 rgba(255,255,255,.03) inset;
}
#login .brand { margin-bottom: 28px; }
#login form { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
#login button { width: 100%; padding: 11px; }
#login .error { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 2px;
                 font-family: var(--mono); }
#login .pw-toggle {
  width: auto; padding: 0; margin-top: 4px;
  font-size: 10px; color: var(--dim); background: none; border: none;
  cursor: pointer; text-align: center; font-family: var(--mono);
}
#login .pw-toggle:hover { color: var(--muted); }

/* utility classes */
.flex-fill { flex: 1 1 0; min-width: 0; }
.mt16 { margin-top: 16px; }

/* --- dashboard --- */
#dash {
  max-width: 1100px; margin: 0 auto;
  min-height: 100vh;
  padding: 0;
}
.sticky-head {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg-deep);
  padding: 24px 24px 0;
  border-bottom: 1px solid var(--border);
}
header.top {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding-bottom: 14px;
  gap: 16px; flex-wrap: wrap;
}
nav.tabs {
  display: flex; gap: 4px; margin-top: 6px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs .tab {
  background: transparent; color: var(--muted); border: none; border-radius: 0;
  padding: 10px 14px 12px; font-family: var(--mono); font-size: 12px;
  border-bottom: 2px solid transparent; cursor: pointer; font-weight: 500;
  text-transform: lowercase; letter-spacing: .02em; white-space: nowrap; flex-shrink: 0;
  transition: color .12s, border-color .12s;
}
nav.tabs .tab:hover { color: var(--text); }
nav.tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel-body {
  padding: 18px 24px 36px;
}
header.top .brand .mark { font-size: 22px; }
header.top .brand .ascii { display: none; }
header.top .meta {
  color: var(--muted); font-family: var(--mono); font-size: 12px;
  display: flex; align-items: center; gap: 14px;
}
header.top .meta .stat { color: var(--text); }
header.top .meta .pulse {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(16,185,129,.6); animation: pulse 2s infinite;
}
@keyframes pulse {
  0%  { box-shadow: 0 0 0 0 rgba(16,185,129,.5); }
  70% { box-shadow: 0 0 0 10px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

.toolbar {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; margin-bottom: 14px;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.toolbar .prompt {
  font-family: var(--mono); color: var(--accent); font-weight: 700; font-size: 14px;
  padding-left: 4px;
}
.toolbar input { flex: 1; min-width: 220px; }
.toolbar .hint {
  color: var(--muted); font-size: 11px; width: 100%; font-family: var(--mono);
  padding-top: 4px;
}
.toolbar .hint code { background: var(--bg); padding: 1px 6px; border-radius: 3px;
                     border: 1px solid var(--border); color: var(--text); }

.peers {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-weight: 500; font-size: 10px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); padding: 14px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  font-family: var(--mono);
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover, tbody tr.row-active { background: var(--surface-2); }
tbody tr.row-active { outline: 1px solid var(--accent); outline-offset: -1px; border-radius: 6px; }
td.name { font-weight: 600; font-family: var(--mono); font-size: 13px; }
td.ip, td.data { font-family: var(--mono); font-size: 12px; color: var(--muted); }
td.hs { font-size: 12px; font-family: var(--mono); }
td.hs .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
             margin-right: 8px; vertical-align: 1px; }
td.hs .dot.green { background: var(--ok); box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
td.hs .dot.amber { background: var(--warn); }
td.hs .dot.grey  { background: var(--rest); }
td.actions { text-align: right; }
td.actions button { padding: 5px 10px; font-size: 11px; margin-left: 6px; border-radius: 5px; }

.empty { padding: 60px 16px; text-align: center; color: var(--muted); font-family: var(--mono); }

/* --- status dots (chain health) --- */
.chain-dots {
  display: inline-flex; gap: 10px; font-family: var(--mono); font-size: 11px;
  color: var(--muted); align-items: center;
}
.chain-dots .chip {
  display: inline-flex; align-items: center; gap: 5px;
}
.chain-dots .led {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dim); transition: background .2s, box-shadow .2s;
}
.chain-dots .led.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.chain-dots .led.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }
.chain-dots .led.bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

/* --- search + bulk bar --- */
.filter-bar {
  display: flex; gap: 10px; margin-bottom: 10px; align-items: center;
  flex-wrap: wrap;
}
.filter-bar input.search {
  flex: 1; min-width: 200px; padding: 8px 12px; font-size: 12px;
}
.filter-bar .count { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.bulk-bar {
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 8px 14px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  animation: slideUp .15s;
}
.bulk-bar button { padding: 5px 10px; font-size: 11px; }

/* sortable column headers */
thead th.sortable {
  cursor: pointer; user-select: none;
}
thead th.sortable:hover { color: var(--text); }
thead th .arrow { display: inline-block; margin-left: 4px; width: 10px; opacity: 0.6; }

/* peer row checkbox + name inline-rename */
td.sel { width: 28px; padding-right: 0; }
td.sel input[type=checkbox] {
  accent-color: var(--accent); cursor: pointer; width: 14px; height: 14px;
}
td.name .name-edit {
  background: var(--bg); border: 1px solid var(--accent);
  border-radius: 4px; padding: 3px 6px;
  font-family: var(--mono); font-size: 13px; color: var(--text);
  width: 100%; max-width: 200px; outline: none;
}
td.name .editable { cursor: text; padding: 2px 4px; border-radius: 4px; margin: -2px -4px; }
td.name .editable:hover { background: var(--surface-2); }

/* QR code box */
.qr-box {
  background: white; padding: 14px; border-radius: 6px;
  display: flex; justify-content: center; align-items: center;
  margin-bottom: 14px;
}
.qr-box img { display: block; width: 220px; height: 220px; image-rendering: pixelated; }

/* view toggle */
.view-toggle { font-size: 14px !important; padding: 2px 8px !important; }

/* peers card view */
.peers-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.pcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; transition: border-color .15s;
}
.pcard:hover { border-color: var(--border-2); }
.pcard-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; cursor: pointer; user-select: none;
  background: var(--surface-2);
}
.pcard-left { min-width: 0; flex: 1; }
.pcard-name {
  font-family: var(--mono); font-size: 14px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.pcard-name .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--dim); flex-shrink: 0;
}
.pcard-name .dot.green { background: var(--ok); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.pcard-name .dot.amber { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }
.pcard-sub {
  display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap;
}
.pcard-ip { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.pcard-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.pcard-hs { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.pcard-traffic { font-family: var(--mono); font-size: 10px; color: var(--dim); }
.pcard-body { display: none; padding: 14px 16px; border-top: 1px solid var(--border); }
.pcard.open .pcard-body { display: block; }
.pcard-header .chevron { font-size: 11px; color: var(--dim); transition: transform .15s; }
.pcard.open .pcard-header .chevron { transform: rotate(90deg); }
.pc-note {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  cursor: pointer; margin-bottom: 8px; padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.pc-note:hover { color: var(--text); }
.pc-note-empty {
  font-family: var(--mono); font-size: 11px; color: var(--dim);
  cursor: pointer; margin-bottom: 8px;
}
.pc-note-empty:hover { color: var(--muted); }
.pcard-spark { margin: 8px 0; }
.pcard-spark .spark { width: 100%; height: 32px; }
.pcard-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.pcard-actions button { flex: 1; min-width: 0; font-size: 11px; padding: 6px 10px; }
.pcard-group-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-top: 4px; }

/* group pills */
.group-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.group-pills:empty { display: none; }
.group-pills .pill {
  font-family: var(--mono); font-size: 11px; padding: 2px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  cursor: pointer; transition: all .15s;
}
.group-pills .pill:hover { background: var(--surface-2); color: var(--text); }
.group-pills .pill.active { background: var(--surface-2); color: var(--accent); border-color: var(--accent); }
.group-input { max-width: 140px; }

/* group divider in peers table */
.group-divider {
  background: var(--surface-2); cursor: pointer; user-select: none;
  padding: 12px 18px; font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--accent); border-bottom: 1px solid var(--border);
  transition: background .15s; width: 100%;
}
.group-divider:hover { background: var(--border); }
.group-divider .gd-chevron {
  font-size: 12px; color: var(--dim); transition: transform .15s;
  display: inline-block; width: 14px; text-align: center;
}
.group-divider.open .gd-chevron { transform: rotate(90deg); }
.group-divider .gd-count {
  color: var(--dim); font-weight: 400; font-size: 12px;
  background: var(--bg); padding: 1px 8px; border-radius: 10px; margin-left: 6px;
}

/* group badge on peer row */
.group-badge {
  display: inline-block; font-family: var(--mono); font-size: 9px;
  padding: 1px 6px; border-radius: 4px; margin-left: 6px;
  background: rgba(99,102,241,.12); color: #818cf8; cursor: pointer;
  border: 1px solid rgba(99,102,241,.2); vertical-align: middle;
  transition: all .12s;
}
.group-badge:hover { background: rgba(99,102,241,.2); color: #a5b4fc; }

/* config group header */
.config-group-header {
  background: var(--surface-2); cursor: pointer; user-select: none;
  padding: 12px 18px; font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--accent); border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0; margin-top: 14px;
  display: flex; align-items: center; gap: 10px;
  transition: background .15s;
  grid-column: 1 / -1;
}
.config-group-header:hover { background: var(--border); }
.config-group-header .gd-chevron {
  font-size: 12px; color: var(--dim); transition: transform .15s;
  width: 14px; text-align: center;
}
.config-group-header.open .gd-chevron { transform: rotate(90deg); }
.config-group-header .gd-count {
  color: var(--dim); font-weight: 400; font-size: 12px;
  background: var(--bg); padding: 1px 8px; border-radius: 10px;
}
.config-group-body {
  display: none; grid-column: 1 / -1;
}
.config-group-header.open + .config-group-body {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px;
}
.pill-sep { color: var(--dim); font-size: 12px; align-self: center; }
.config-group-pills { display: flex; gap: 4px; }
.config-group-pills:empty { display: none; }
.config-group-pills .pill {
  font-family: var(--mono); font-size: 10px; padding: 1px 8px; border-radius: 5px;
  border: 1px solid var(--border); background: transparent; color: var(--dim);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.config-group-pills .pill:hover { background: var(--surface-2); color: var(--text); }
.config-group-pills .pill.active { background: var(--surface-2); color: var(--accent); border-color: var(--accent); }

/* peer detail row (table expand) */
.peer-detail td { padding: 0 !important; border: none !important; }
.peer-detail .peer-detail-inner {
  padding: 14px 16px; background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.peer-detail .peer-detail-inner .pcard-spark .spark { width: 100%; height: 32px; }
.peer-detail .peer-detail-inner .pcard-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.peer-detail .peer-detail-inner .pcard-actions button { flex: 1; min-width: 0; font-size: 11px; padding: 6px 10px; }
.peer-detail .peer-detail-inner .pc-note { margin-bottom: 8px; }
.peer-detail .peer-detail-inner .pc-note-empty { margin-bottom: 8px; }
.peer-detail-row { background: var(--surface-2); }

/* geo list */
.geo-list {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px; margin-top: 12px;
}
.geo-list h3 {
  margin: 0 0 14px; font-family: var(--mono); font-size: 12px; font-weight: 500;
  color: var(--muted); text-transform: uppercase; letter-spacing: .12em;
}
.geo-rows { display: flex; flex-direction: column; gap: 2px; font-family: var(--mono); font-size: 12px; }
.geo-row {
  display: grid;
  grid-template-columns: 24px 1.3fr 1fr 1fr auto;
  gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 6px;
  transition: background .12s;
}
.geo-row:hover { background: var(--surface-2); }
.geo-row .flag { font-size: 18px; line-height: 1; }
.geo-row .name { color: var(--text); font-weight: 500; }
.geo-row .city { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.geo-row .country { color: var(--dim); font-size: 11px; }
.geo-row .ip { color: var(--dim); font-size: 11px; text-align: right; }
.geo-row .dot {
  display: inline-block; vertical-align: middle;
  width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px rgba(16,185,129,.18);
  margin-left: 6px;
}
.geo-row.idle .dot { background: var(--dim); box-shadow: none; }
.geo-row.idle .name { color: var(--muted); }
.geo-empty { padding: 32px 0; text-align: center; color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* sparkline */
.spark-cell { padding: 4px 0; }
.spark { display: block; width: 90px; height: 20px; }
.spark .bar { fill: var(--accent); opacity: .85; }
.spark .bar.zero { fill: var(--dim); opacity: .25; }
.spark-empty { color: var(--dim); font-family: var(--mono); font-size: 11px; padding-left: 6px; }

/* notes (inline, only if non-empty) */
td.name .note {
  display: block; color: var(--muted); font-size: 11px; font-family: var(--mono);
  font-weight: 400; margin-top: 4px; cursor: text;
  line-height: 1.35; max-width: 280px;
}
td.name .note::before { content: "✎ "; opacity: 0.5; }
td.name .note:hover { color: var(--text); }
td.name .note-btn {
  display: inline-block; margin-left: 6px; color: var(--dim);
  cursor: pointer; font-size: 12px; vertical-align: middle;
  padding: 0 4px; border-radius: 3px;
  transition: color .12s, background .12s;
}
td.name .note-btn:hover { color: var(--accent); background: var(--surface-2); }
td.name .note-edit {
  background: var(--bg); border: 1px solid var(--accent);
  border-radius: 4px; padding: 4px 8px;
  font-family: var(--mono); font-size: 11px; color: var(--text);
  width: 100%; max-width: 280px; outline: none; box-shadow: 0 0 0 3px rgba(245,158,11,.1);
}

/* rotation badge */
.rot-badge {
  display: inline-block; font-family: var(--mono); font-size: 10px;
  padding: 2px 6px; border-radius: 4px; margin-left: 6px;
  background: var(--surface-2); color: var(--muted); cursor: pointer;
  border: 1px solid var(--border);
  vertical-align: middle;
}
.rot-badge:hover { color: var(--text); border-color: var(--border-2); }
.rot-badge.ok { color: var(--ok); background: rgba(16,185,129,.12); }
.rot-badge.overdue { background: rgba(239,68,68,.12); color: var(--danger-2); border-color: rgba(239,68,68,.4); }
.rot-badge.due-soon { background: rgba(245,158,11,.12); color: var(--accent-2); border-color: rgba(245,158,11,.4); }

/* log view */
.log-toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 10px;
}
.log-toolbar .search { flex: 1; min-width: 200px; padding: 8px 12px; font-size: 12px; }
.log-toolbar .count { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.log-pager {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; gap: 10px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}
.log-pager button {
  padding: 6px 14px; font-size: 11px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
.log-pager button:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent);
}
.log-pager .page-info { color: var(--muted); display: flex; align-items: center; gap: 4px; }
.log-pager .page-jump {
  width: 40px; text-align: center; font-family: var(--mono); font-size: 11px;
  background: var(--bg-deep); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 4px; outline: none;
}
.log-pager .page-jump:focus { border-color: var(--accent); }
.log-list {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
  font-family: var(--mono); font-size: 12px;
}
.log-row {
  display: grid; grid-template-columns: 130px 1fr; gap: 14px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.log-row:last-child { border-bottom: none; }
.log-row .ts { color: var(--muted); }
.log-row .name { color: var(--text); }
.log-row .name a { color: var(--accent); }

.audit-badge {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-size: 10px; font-family: var(--mono); margin-right: 8px;
  text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  border: 1px solid currentColor; background: rgba(255,255,255,.02);
}
.audit-ok    { color: var(--ok); }
.audit-bad   { color: var(--danger-2); }
.audit-warn  { color: var(--accent-2); }
.audit-dim   { color: var(--muted); border-color: var(--border); }

/* system log */
.sys-pre {
  background: var(--bg-deep); border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--text);
  padding: 14px 16px; margin: 0; max-height: 70vh; overflow: auto;
  white-space: pre-wrap; word-break: break-all; line-height: 1.5;
}
.sys-pre .err-line  { color: var(--danger-2); }
.sys-pre .warn-line { color: var(--accent-2); }

/* exit selector + per-peer exit badge */
.exit-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; color: var(--text); font-family: var(--mono); font-size: 12px;
  cursor: pointer;
}
.exit-select:focus { border-color: var(--accent); outline: none; }
.exit-pill {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface-2);
  margin-left: 6px; cursor: pointer; vertical-align: middle;
}
.exit-pill:hover { color: var(--text); border-color: var(--border-2); }

/* geo toggle */
.geo-toggle {
  display: inline-flex; gap: 1px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 2px;
  margin-left: auto;
}
.geo-toggle button {
  padding: 4px 12px; font-size: 11px; background: transparent; color: var(--muted);
  border: none; border-radius: 4px; font-family: var(--mono);
}
.geo-toggle button.active { background: var(--accent); color: #0a0a0a; }
.geo-list h3 { display: flex; align-items: center; }

/* servers tab */
.server-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.server-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px;
}
.server-card h3 {
  margin: 0 0 6px; font-family: var(--mono); font-size: 14px; font-weight: 600;
  color: var(--text); display: flex; justify-content: space-between; align-items: baseline;
}
.server-card h3 .sub {
  font-size: 11px; color: var(--muted); font-weight: 400;
}
.server-card .err {
  color: var(--danger-2); font-family: var(--mono); font-size: 12px; padding: 8px 0;
}
.server-card .uptime {
  color: var(--dim); font-family: var(--mono); font-size: 11px; margin-bottom: 18px;
}
.gauge {
  display: grid; grid-template-columns: 56px 1fr 80px; gap: 10px;
  align-items: center; margin-bottom: 10px; font-family: var(--mono); font-size: 12px;
}
.gauge .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.gauge .track {
  height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.gauge .fill {
  height: 100%; background: var(--accent); transition: width .4s ease;
  border-radius: 3px;
}
.gauge .fill.warn { background: var(--warn); }
.gauge .fill.bad  { background: var(--danger); }
.gauge .v {
  text-align: right; color: var(--text); font-size: 12px;
}
.gauge .v .secondary { color: var(--muted); font-size: 10px; }

.net-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px;
}
.net-row .cell .label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.net-row .cell .val { color: var(--text); font-size: 14px; font-weight: 600; margin-top: 2px; }
.net-row .cell .arrow { color: var(--ok); margin-right: 4px; }
.net-row .cell .arrow.up { color: var(--accent); }

@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .server-grid { grid-template-columns: 1fr; }
}

/* config fields (used in peer detail view) */
.config-key-warning {
  font-family: var(--mono); font-size: 11px; color: var(--warn);
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25);
  border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; line-height: 1.5;
}
.config-key-warning a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.config-section-label {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--accent); margin: 14px 0 8px; font-weight: 600;
}
.config-section-label:first-child { margin-top: 0; }
.config-field {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 4px 0; font-family: var(--mono); font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,.03);
  cursor: pointer; border-radius: 3px; transition: background .1s;
}
.config-field:hover { background: rgba(255,255,255,.04); }
.config-field:last-child { border-bottom: none; }
.config-field .fk { color: var(--muted); white-space: nowrap; min-width: 100px; }
.config-field .fv { color: var(--text); text-align: right; word-break: break-all; }
.config-field.muted .fv { color: var(--dim); font-style: italic; }
.config-field[data-copied] .fv::after { content: " ✓"; color: var(--ok); }
.config-note-edit {
  font-family: var(--mono); font-size: 11px; color: var(--text);
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 8px; width: 100%; outline: none;
  margin-bottom: 8px; box-sizing: border-box;
}
.cc-fields-toggle {
  border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px;
}
.cc-fields-toggle summary {
  padding: 8px 12px; cursor: pointer; font-family: var(--mono); font-size: 11px;
  color: var(--muted); list-style: none; display: flex; align-items: center; gap: 6px;
  transition: color .15s;
}
.cc-fields-toggle summary::-webkit-details-marker { display: none; }
.cc-fields-toggle summary::before { content: "▸"; font-size: 9px; transition: transform .15s; }
.cc-fields-toggle[open] summary::before { transform: rotate(90deg); }
.cc-fields-toggle summary:hover { color: var(--text); }
.cc-fields-inner { padding: 0 12px 8px; }
.exit-badge {
  display: inline-block; font-family: var(--mono); font-size: 9px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 6px; border-radius: 4px; margin-left: 6px;
  background: rgba(255,255,255,.06); color: var(--muted); vertical-align: middle;
}
.exit-badge.us { color: var(--ok); background: rgba(16,185,129,.12); }
.exit-badge.pt { color: var(--info); background: rgba(96,165,250,.12); }
.exit-badge.cz { color: var(--purple); background: rgba(192,132,252,.12); }

/* --- modal --- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.78); display: grid; place-items: center;
  z-index: 100; padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 14px;
  padding: 26px; width: 100%; max-width: 560px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal h2 { margin: 0 0 4px; font-size: 16px; font-family: var(--mono); }
.modal h2 .check { color: var(--ok); margin-right: 6px; }
.modal .sub { color: var(--muted); font-size: 12px; margin-bottom: 16px; font-family: var(--mono); }
.modal pre {
  background: var(--bg-deep); border: 1px solid var(--border); border-radius: 6px;
  padding: 14px; font-family: var(--mono); font-size: 11px; max-height: 240px;
  overflow: auto; margin: 0 0 16px; line-height: 1.55; color: var(--text);
  white-space: pre-wrap; word-break: break-all;
}
.modal pre .key { color: var(--accent); }
.modal .actions-row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.rot-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.rot-input { width: 80px; padding: 6px 10px; }
.rot-label { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.overdue-warn { color: var(--danger-2); }
.exit-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.exit-btn { text-align: left; padding: 10px 14px; font-family: var(--mono); font-size: 12px; }
.exit-btn.active { border-color: var(--accent); color: var(--text); }
.exit-btn-id { font-weight: 600; }
.exit-btn-label { color: var(--muted); margin-left: 8px; }
.exit-btn-current { float: right; color: var(--ok); }

.flash {
  position: fixed; right: 24px; bottom: 24px; z-index: 200;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 12px 18px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-family: var(--mono); animation: slideUp .25s;
}
.flash.error { border-color: var(--danger); color: var(--danger-2); }
.flash.ok { border-color: rgba(16,185,129,.5); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

footer.crumbs {
  margin-top: 26px; color: var(--dim); font-family: var(--mono); font-size: 11px;
  text-align: center; user-select: none;
}

/* --- stats --- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.stat .label {
  color: var(--muted); font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: 6px;
}
.stat .value {
  font-family: var(--mono); font-size: 22px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
}
.stat .value .unit { color: var(--muted); font-size: 14px; font-weight: 400; margin-left: 4px; }
.stat.accent .value { color: var(--accent); }
.stat.ok .value { color: var(--ok); }

.charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px;
}
.chart-card h3 {
  margin: 0 0 14px; font-family: var(--mono); font-size: 12px; font-weight: 500;
  color: var(--muted); text-transform: uppercase; letter-spacing: .12em;
  display: flex; justify-content: space-between; align-items: baseline;
}
.chart-card h3 .total {
  color: var(--text); font-size: 12px; text-transform: none; letter-spacing: 0;
}
.donut-wrap {
  display: flex; align-items: center; gap: 18px;
}
.donut {
  width: 140px; height: 140px; flex-shrink: 0;
}
.donut .seg { transition: opacity .12s, stroke-dasharray .4s ease, stroke-dashoffset .4s ease; }
.donut .seg:hover { opacity: .75; }
.donut .center-label {
  font-family: var(--mono); font-size: 9px; fill: var(--muted);
  text-anchor: middle; text-transform: uppercase; letter-spacing: .1em;
}
.donut .center-value {
  font-family: var(--mono); font-size: 11px; fill: var(--text);
  text-anchor: middle; font-weight: 600;
}
.legend {
  flex: 1; min-width: 0; max-height: 180px; overflow-y: auto;
  font-family: var(--mono); font-size: 11px;
  display: flex; flex-direction: column; gap: 5px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.legend .row {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 8px; align-items: center;
}
.legend .dot {
  width: 8px; height: 8px; border-radius: 2px;
}
.legend .name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .val { color: var(--muted); }
.legend .row.rest .name { color: var(--muted); font-style: italic; }
.chart-empty {
  padding: 36px 0; text-align: center; color: var(--muted);
  font-family: var(--mono); font-size: 12px;
}

/* --- mobile (<=720px) --- */
@media (max-width: 720px) {
  body { font-size: 13px; }
  #dash { padding: 0; }
  .sticky-head { padding: 14px 14px 0; }
  .panel-body { padding: 14px 14px 32px; }
  header.top { padding-bottom: 10px; align-items: flex-start;
               flex-direction: column; gap: 8px; }
  header.top .brand .mark { font-size: 20px; }
  header.top .meta { width: 100%; justify-content: space-between; }
  nav.tabs .tab { padding: 8px 12px 10px; font-size: 11px; }
  .chain-dots { font-size: 10px; gap: 6px; }
  .chain-dots .chip span:last-child { display: none; }
  .qr-box img { width: 180px; height: 180px; }

  .charts { grid-template-columns: 1fr; }
  .donut-wrap { gap: 14px; }
  .donut { width: 96px; height: 96px; flex-shrink: 0; }
  .legend { font-size: 11px; }
  .legend .name { font-size: 10px; }
  .legend .val { font-size: 10px; }
  .chart-card { padding: 14px; }
  .toolbar .prompt { display: none; }

  .brand .ascii { font-size: 9px; }
  .brand .mark { font-size: 24px; }

  #login .card { padding: 28px 22px; }

  .toolbar { padding: 12px; gap: 8px; }
  .toolbar .prompt { padding: 0; }
  .toolbar input { width: 100%; flex-basis: 100%; min-width: 0; }
  .toolbar button { width: 100%; }
  .toolbar .hint { font-size: 10px; }

  /* table -> stacked cards */
  .peers { padding: 4px 0; }
  table, tbody, tr { display: block; }
  thead { display: none; }
  tbody tr {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
    align-items: baseline;
  }
  tbody tr:last-child { border-bottom: none; }
  tbody td { padding: 0; border: none; display: block; }
  td.name { grid-column: 1; font-size: 14px; }
  td.ip { grid-column: 2; text-align: right; }
  td.hs { grid-column: 1 / 3; padding-top: 2px; }
  td.data { grid-column: 1 / 3; color: var(--dim); font-size: 11px; }
  td.spark-cell { grid-column: 1 / 3; padding-top: 4px; }
  td.spark-cell .spark { width: 100%; height: 28px; }
  td.actions { grid-column: 1 / 3; text-align: left; margin-top: 8px; }
  td.actions button { padding: 6px 12px; font-size: 12px; }
  td[data-label]::before {
    content: attr(data-label) ": "; color: var(--dim); font-size: 10px;
    text-transform: uppercase; letter-spacing: .05em;
  }

  footer.crumbs { font-size: 10px; padding: 0 8px; line-height: 1.6; }

  .modal-bg { padding: 10px; align-items: flex-start; padding-top: 30px; }
  .modal { padding: 18px; width: 100%; max-width: none; }
  .modal h2 { font-size: 14px; }
  .modal pre { font-size: 10px; padding: 10px; max-height: 200px; }
  .modal .actions-row { flex-wrap: wrap; gap: 6px; }
  .modal .actions-row button { flex: 1 1 auto; min-width: 0; padding: 8px 10px; font-size: 12px; }
  .qr-box img { width: 180px; height: 180px; }
  .qr-box { padding: 10px; }

  .flash { right: 12px; left: 12px; bottom: 12px; text-align: center; }

  /* log / audit / system toolbars: wrap controls so they don't overflow the
     row (the system tab has 2 selects + button + count → 453px on a 360px
     screen). Selects share row one, search/button/count wrap below. */
  .log-toolbar { flex-wrap: wrap; gap: 8px; }
  .log-toolbar .exit-select { flex: 1 1 45%; min-width: 0; }
  .log-toolbar .search { flex: 1 1 100%; min-width: 0; }
  .log-toolbar button { flex: 1 1 auto; }
  .log-toolbar .count { flex: 1 1 100%; text-align: right; }
  .sys-pre { font-size: 10px; padding: 10px 12px; max-height: 62vh; }

  .config-field { font-size: 11px; }
  .config-field .fk { min-width: 80px; }
}

/* accessibility: reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* accessibility: visible focus rings for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible, .tab:focus-visible, .pill:focus-visible, .ghost:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
