:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --accent-h: #2f6fe0;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #eab308;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.offscreen { position: fixed; top: 0; left: 0; opacity: 0; pointer-events: none; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 12px; }
.grow { flex: 1; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
}
button:hover { background: var(--accent-h); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.ghost:hover { background: var(--panel-2); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); padding: 4px 10px; }
button.danger:hover { background: rgba(239,68,68,.12); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input {
  font: inherit; padding: 9px 11px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.login-card button { margin-top: 4px; }
.error { color: var(--danger); margin: 0; }

/* App shell */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
main { padding: 20px; display: flex; flex-direction: column; gap: 20px; max-width: 1100px; margin: 0 auto; }

/* Node panel */
#nodes { display: flex; flex-direction: column; gap: 16px; }
.node { padding: 0; overflow: hidden; }
.node-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.node-head h2 { margin: 0; font-size: 16px; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.online { color: var(--ok); border-color: rgba(34,197,94,.4); }
.pill.stale { color: var(--warn); border-color: rgba(234,179,8,.4); }
.pill.offline { color: var(--muted); }
.node-meta { color: var(--muted); font-size: 12px; }

/* Remote/Local sliding switch in the node header. */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative; width: 38px; height: 20px; flex: 0 0 auto;
  border-radius: 999px; background: var(--line); transition: background .15s ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--text); transition: transform .15s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-state { font-size: 12px; color: var(--muted); min-width: 42px; }

/* Advertised subnets subsection inside a node card. */
.subnets { border-top: 1px solid var(--line); padding: 12px 18px 4px; }
.subnets-head h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.subnet-table th, .subnet-table td { padding: 6px 0; }
.subnet-table th:not(:last-child), .subnet-table td:not(:last-child) { padding-right: 18px; }
.subnet-add { gap: 8px; flex-wrap: wrap; }
.subnet-add input, .subnet-add select {
  font: inherit; padding: 7px 9px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.pill.mode-masquerade { color: var(--accent); border-color: var(--accent); }
.pill.mode-routed { color: var(--ok); border-color: rgba(34,197,94,.4); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 18px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.online { background: var(--ok); }
.dot.stale { background: var(--warn); }
.dot.offline { background: var(--muted); }

.add-row { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel-2); }
.add-row input {
  font: inherit; padding: 7px 10px; border-radius: 6px; flex: 1; max-width: 260px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.link-btn { background: none; color: var(--accent); padding: 4px 8px; border: 1px solid var(--line); }
.link-btn:hover { background: var(--panel-2); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 20px; }
.modal-box { width: min(720px, 100%); padding: 18px; }
.modal-head { display: flex; align-items: center; }
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; }
.conf-grid { display: grid; grid-template-columns: 1fr auto; gap: 18px; margin: 14px 0; }
.conf { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0; overflow: auto; max-height: 320px; white-space: pre; font-family: ui-monospace, monospace; font-size: 12px; }
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-wrap #qr { background: #fff; padding: 10px; border-radius: 8px; line-height: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 620px) { .conf-grid { grid-template-columns: 1fr; } }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-left: 16px; }
.tab { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 6px 12px; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }

/* Proxy status panel */
.proxy-status { padding: 16px 18px; }
.proxy-status-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.proxy-status-head h2 { margin: 0; font-size: 16px; }
#proxy-disabled { margin: 10px 0 0; }
#proxy-disabled code, .muted code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
tr.row-off td { opacity: 0.5; }
td.cert-error { color: var(--danger); cursor: help; }

/* Route form */
.form-grid { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-grid input[type=text], .form-grid input:not([type]), .form-grid input[type=password], .form-grid select {
  font: inherit; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.form-grid input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.subfields { display: flex; flex-direction: column; gap: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 30; }
.toast.err { border-color: var(--danger); color: #fecaca; }
