:root {
  --bg: #08110e;
  --bg-2: #0c1713;
  --panel: #101c17;
  --panel-2: #14231d;
  --line: #1f332b;
  --text: #e9efe9;
  --muted: #8ba397;
  --accent: #3fd49a;
  --accent-ink: #04120b;
  --ok: #3fd49a;
  --warn: #e8b84a;
  --bad: #ef6a5e;
  --info: #5db4e8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f1ebdd;
  --bg-2: #ebe4d3;
  --panel: #faf6ec;
  --panel-2: #f3eddf;
  --line: #ddd3bc;
  --text: #2a2822;
  --muted: #6f6a5b;
  --accent: #1e7a58;
  --accent-ink: #ffffff;
  --ok: #1e7a58;
  --warn: #a8700f;
  --bad: #b3352b;
  --info: #1d6c9c;
  --shadow: 0 10px 30px rgba(70, 55, 20, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  overflow: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent); }
p { margin: 0 0 8px; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); height: 100vh; max-width: 100vw; }
.side {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px; min-height: 0; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 2px 4px 14px; }
.mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; letter-spacing: 0.5px;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--text); text-decoration: none; padding: 7px 10px; border-radius: 6px; border: 1px solid transparent;
}
.nav a:hover { background: var(--panel); }
.nav a.active { background: var(--panel-2); border-color: var(--line); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding-top: 14px; }
.aside-note { color: var(--muted); font-size: 12px; border-left: 2px solid var(--accent); padding-left: 8px; }
.side-buttons { display: flex; flex-direction: column; gap: 6px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.top h1 { font-size: 17px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.view { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 14px 18px 28px; }

.banner-stack { display: flex; flex-direction: column; }
.banner { padding: 7px 18px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, var(--bg)); color: var(--text); }
.banner.error { background: color-mix(in srgb, var(--bad) 18%, var(--bg)); }
.banner.info { background: color-mix(in srgb, var(--info) 14%, var(--bg)); }

/* ---- controls ---- */
.btn {
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: 6px;
  padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--panel); }
.btn.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.btn.small { padding: 3px 9px; font-size: 12px; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font: inherit; min-width: 0; max-width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="checkbox"], input[type="radio"] { padding: 0; accent-color: var(--accent); }
textarea { resize: vertical; width: 100%; font-family: var(--mono); font-size: 12px; }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-size: 13px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 160px; }

/* ---- panels and cards ---- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; min-width: 0;
}
.panel > h2 { font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h3 { font-size: 12.5px; margin: 10px 0 6px; color: var(--muted); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-width: 0; }
.card .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; }
.card .v { font-size: 26px; font-weight: 700; line-height: 1.15; margin-top: 2px; }
.card .s { color: var(--muted); font-size: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.cols > .panel { margin-bottom: 0; }
.cols.mb { margin-bottom: 12px; }
.empty { color: var(--muted); padding: 14px 4px; text-align: center; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; background: var(--panel-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--panel-2); }
td.path { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; min-width: 160px; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* ---- pills, chip, tabs ---- */
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted); background: transparent;
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.pill.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 55%, transparent); }
.pill.smb { color: var(--info); border-color: color-mix(in srgb, var(--info) 55%, transparent); }
.pill.nfs { color: #c58af0; border-color: color-mix(in srgb, #c58af0 55%, transparent); }
[data-theme="light"] .pill.nfs { color: #7b3fa3; }
.pills { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; text-decoration: none;
  border: 1px solid var(--line); color: var(--muted);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip-ok { color: var(--ok); } .chip-ok::before { background: var(--ok); }
.chip-sample { color: var(--info); } .chip-sample::before { background: var(--info); }
.chip-auth_failed, .chip-unreachable, .chip-tls_error, .chip-error { color: var(--bad); }
.chip-auth_failed::before, .chip-unreachable::before, .chip-tls_error::before, .chip-error::before { background: var(--bad); }
.chip-not_configured { color: var(--warn); } .chip-not_configured::before { background: var(--warn); }
.chip-connected { color: var(--ok); } .chip-connected::before { background: var(--ok); }
.chip-no_peers, .chip-no_routes, .chip-needs_login { color: var(--warn); }
.chip-no_peers::before, .chip-no_routes::before, .chip-needs_login::before { background: var(--warn); }
.chip-inward_blocked, .chip-not_running, .chip-not_installed { color: var(--bad); }
.chip-inward_blocked::before, .chip-not_running::before, .chip-not_installed::before { background: var(--bad); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 7px 12px; font: inherit; cursor: pointer;
}
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---- capacity bar ---- */
.bar { height: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.bar.thin { height: 8px; border-radius: 4px; min-width: 70px; }
.bar-legend { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 12px; flex-wrap: wrap; gap: 6px; }
.delta-up { color: var(--warn); } .delta-down { color: var(--ok); }

/* ---- scans / status ---- */
.worker-strip { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.group-title { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 6px; font-weight: 600; }
.log {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; height: 300px; overflow: auto;
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.log .lvl-WARNING { color: var(--warn); } .log .lvl-ERROR { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: var(--panel-2); min-width: 0; }
.stat .k { color: var(--muted); font-size: 11.5px; }
.stat .v { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
details > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.note { color: var(--muted); font-size: 12.5px; }
.metric-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.metric-list label { display: flex; gap: 8px; padding: 2px 0; align-items: baseline; }

/* ---- drawer, toasts, gate ---- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 92vw); background: var(--panel); border-left: 1px solid var(--line);
  z-index: 21; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 10px; }
.drawer-body { margin: 0; padding: 12px 14px; overflow: auto; flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 40; max-width: min(420px, 92vw); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px; padding: 8px 12px; box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--bad); }
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 16px; }
.gate-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; box-shadow: var(--shadow); }
.gate-card .brand { padding-bottom: 10px; }
.gate-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.gate-error { color: var(--bad); min-height: 18px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 10px; }
  .brand { padding: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0; padding: 0; }
  .aside-note { display: none; }
  .side-buttons { flex-direction: row; }
}

tr.group-row td { background: var(--panel-2); border-bottom: 1px solid var(--line); padding-top: 8px; }
.scan-table td:nth-child(1) { min-width: 150px; }
.panel.inner { margin: 12px 0; background: transparent; box-shadow: none; border-style: dashed; }
