/*
 * MeshCheck design system — the single stylesheet for every web surface
 * (the Phase 8 dashboard and the public result page).
 *
 * Source of truth: doc/decisions/design-system.md. Components reference the
 * tokens in :root below; they never hardcode a color, size, or radius.
 */

:root {
  color-scheme: light;

  /* --- Color: neutrals (blue-gray / slate) --- */
  --c-ink:       #0f172a;
  --c-ink-soft:  #334155;
  --c-muted:     #64748b;
  --c-faint:     #94a3b8;
  --c-border:    #e2e8f0;
  --c-surface:   #ffffff;
  --c-surface-2: #f1f5f9;
  --c-surface-soft: #f8fafc; /* recessed inset rows / disabled fields */
  --c-bg:        #f8fafc;

  /* --- Color: accent (blue) --- */
  --c-accent:       #2563eb;
  --c-accent-hover: #1d4ed8;
  --c-accent-soft:  #dbeafe;

  /* --- Color: status (semantic, fixed) --- */
  --c-pass-bg: #dcfce7; --c-pass-fg: #166534;
  --c-fail-bg: #fee2e2; --c-fail-fg: #991b1b;
  --c-warn-bg: #fef9c3; --c-warn-fg: #854d0e;

  /* --- Typography --- */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs:   0.78rem;
  --text-sm:   0.88rem;
  --text-base: 1rem;
  --text-lg:   1.1rem;
  --text-xl:   1.3rem;

  /* --- Spacing scale --- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* --- Shape & elevation --- */
  --radius-sm:   6px;
  --radius:      10px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.10);
}

/* --- Color: dark theme -------------------------------------------------- */

/* Applied when /assets/theme.js sets <html data-theme="dark"> — either from
 * a stored choice or, by default, from the OS color-scheme preference. It is
 * the same slate scale inverted: surfaces darken, text lightens, and the
 * accent and status hues shift to readable-on-dark variants. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --c-ink:       #e2e8f0;
  --c-ink-soft:  #cbd5e1;
  --c-muted:     #94a3b8;
  --c-faint:     #64748b;
  --c-border:    #334155;
  --c-surface:   #1e293b;
  --c-surface-2: #334155;
  --c-surface-soft: #172033; /* recessed inset rows / disabled fields */
  --c-bg:        #0f172a;

  --c-accent:       #3b82f6;
  --c-accent-hover: #60a5fa;
  --c-accent-soft:  #1e3a5f;

  --c-pass-bg: #14532d; --c-pass-fg: #86efac;
  --c-fail-bg: #7f1d1d; --c-fail-fg: #fca5a5;
  --c-warn-bg: #713f12; --c-warn-fg: #fde68a;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* The global nav bar and the sign-in backdrop are chrome, not content: they
 * stay dark in both themes. In dark mode --c-ink is a light text color, so
 * these surfaces take an explicit near-black instead. */
:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .auth-page { background: #020617; }
:root[data-theme="dark"] .topbar .btn-soft { background: var(--c-surface-2); color: #cbd5e1; }
:root[data-theme="dark"] .topbar .btn-soft:hover { background: var(--c-border); color: #fff; }
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select { border-color: var(--c-border); }

/* --- Base --------------------------------------------------------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  line-height: 1.5;
  background: var(--c-bg);
  color: var(--c-ink);
}

a { color: var(--c-accent); }
a:hover { color: var(--c-accent-hover); }

.mono { font-family: var(--font-mono); word-break: break-all; }
.muted { color: var(--c-faint); }

/* --- Shared global nav bar (every page) --------------------------------- */

.topbar {
  background: var(--c-ink);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.topbar-brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: #fff;
  text-decoration: none;
}
.topbar-nav { display: flex; gap: var(--space-1); flex: 1; flex-wrap: wrap; }
.topbar-nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.topbar-nav a:hover { background: var(--c-ink-soft); color: #fff; }
.topbar-nav a.active { background: var(--c-accent); color: #fff; }
.topbar-account { display: flex; align-items: center; gap: var(--space-3); }
.topbar-account form { margin: 0; }
.topbar-who { font-size: var(--text-sm); color: var(--c-faint); }

/* Dark-mode toggle — an icon button on the global nav bar. It shows the
 * theme it switches *to*: a moon while light, a sun while dark. */
.theme-toggle {
  background: transparent;
  border: 0;
  color: #cbd5e1;
  cursor: pointer;
  font-size: var(--text-base);
  line-height: 1;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.theme-toggle .on-light { display: inline; }
.theme-toggle .on-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .on-light { display: none; }
:root[data-theme="dark"] .theme-toggle .on-dark { display: inline; }

/* --- App shell: dashboard chrome on the global bar, main, footer -------- */

/* The dashboard folds its role-scoped nav into the single global bar: the
 * brand is followed by the role nav links (.topbar-nav, shared with the
 * public bar). */

/* The switcher to other dashboards this user may enter. */
.topbar-switch { font-size: var(--text-xs); color: var(--c-faint); }
.topbar-switch a { color: #cbd5e1; text-decoration: none; margin-left: var(--space-1); }
.topbar-switch a:hover { color: #fff; }

/* Active-organization picker (Monitor dashboard). */
.app-org { margin: 0; }
.app-org select {
  background: var(--c-surface-2);
  color: var(--c-ink);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font: inherit;
  font-size: var(--text-sm);
}

.app-main {
  max-width: 960px;
  margin: var(--space-6) auto;
  padding: 0 var(--space-5);
}
.app-footer {
  max-width: 960px;
  margin: var(--space-6) auto;
  padding: 0 var(--space-5);
  font-size: var(--text-xs);
  color: var(--c-faint);
}

/* --- Page heading ------------------------------------------------------- */

.page-title { font-size: var(--text-xl); margin: 0 0 var(--space-1); }
.page-sub { color: var(--c-muted); margin-top: 0; }

/* --- Card --------------------------------------------------------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-4) 0;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 var(--space-3); font-size: var(--text-lg); }
.card h4 { margin: var(--space-5) 0 var(--space-2); font-size: var(--text-base); }
.card-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-head h3 { margin: 0; flex: 1; }
.card-link { text-decoration: none; font-weight: 600; }

/* --- Grid & metric tiles ----------------------------------------------- */

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.metric {
  background: var(--c-surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
}
.metric .n { font-size: var(--text-xl); font-weight: 700; }
.metric .l {
  font-size: var(--text-xs);
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* --- Table -------------------------------------------------------------- */

.table { border-collapse: collapse; width: 100%; }
.table th, .table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--c-border);
  font-size: var(--text-sm);
}
.table th { color: var(--c-muted); font-weight: 600; }

/* --- Result table (check-host-style per-node rows) --------------------- */

.result-table td { vertical-align: top; }
.result-table .node-cell { line-height: 1.4; }
.result-table .node-ip { font-weight: 600; }
.result-table .node-loc { font-size: var(--text-sm); }
.result-table .node-net { font-size: var(--text-xs); }
.result-table .rtt-avg { font-weight: 600; }
.result-table .rtt-detail { font-size: var(--text-xs); }
.result-table .result-cell .muted { font-size: var(--text-xs); margin-top: 0.15rem; }
.result-table .resolved-ip { font-size: var(--text-xs); }

/* --- Traceroute: hover preview + full-route link ---------------------- */

.trace { margin-top: 0.35rem; font-size: var(--text-xs); display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.trace-toggle {
  position: relative;
  cursor: help;
  color: var(--c-accent);
  border-bottom: 1px dotted var(--c-accent);
}
.trace-link { color: var(--c-accent); text-decoration: none; }
.trace-link:hover { text-decoration: underline; }

/* The hover/focus preview card listing every hop. */
.trace-tip {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: none;
  min-width: 220px;
  max-width: 340px;
  padding: var(--space-2) var(--space-3);
  background: var(--c-surface);
  color: var(--c-ink);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
  white-space: normal;
}
.trace-toggle:hover .trace-tip,
.trace-toggle:focus .trace-tip,
.trace-toggle:focus-within .trace-tip { display: block; }
.trace-hop {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: var(--space-2);
  align-items: baseline;
  padding: 1px 0;
}
.trace-hop-n { color: var(--c-muted); text-align: right; }
.trace-hop-rtt { font-size: var(--text-xs); }

/* --- Traceroute: full-route page -------------------------------------- */

.trace-table .trace-hop-n { color: var(--c-muted); width: 3rem; }
.trace-table tr.trace-target td { font-weight: 600; }
.trace-note { margin-top: var(--space-3); font-size: var(--text-xs); }

/* --- Pill (status badge) ----------------------------------------------- */

.pill {
  display: inline-block;
  padding: 0.1rem var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--c-border);
  color: var(--c-ink-soft);
}
.pill.pass, .pill.complete, .pill.active, .pill.verified {
  background: var(--c-pass-bg); color: var(--c-pass-fg);
}
.pill.fail, .pill.suspended {
  background: var(--c-fail-bg); color: var(--c-fail-fg);
}
.pill.pending, .pill.dispatched, .pill.timeout, .pill.inconclusive,
.pill.paused, .pill.acknowledged, .pill.seen, .pill.broadcast {
  background: var(--c-warn-bg); color: var(--c-warn-fg);
}
.pill.resolved, .pill.confirmed { background: var(--c-pass-bg); color: var(--c-pass-fg); }
.pill.open, .pill.reorged, .pill.failed, .pill.failed_dispatch,
.pill.insufficient_balance { background: var(--c-fail-bg); color: var(--c-fail-fg); }

/* Live connection state, separate from the admin active/suspended status. A
   node can be active yet offline; offline is neutral grey, not red. */
.pill.online  { background: var(--c-pass-bg);  color: var(--c-pass-fg); }
.pill.offline { background: var(--c-surface-2); color: var(--c-ink-soft); }

/* Cost-preview box used on the Check and Scheduled Check submission forms. */
.quote-box {
  margin-top: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.5rem;
  border: 1px solid var(--c-border);
  font-size: 0.95rem;
}
.quote-box.quote-free { background: var(--c-pass-bg); color: var(--c-pass-fg); }
.quote-box.quote-paid { background: var(--c-accent-soft); color: var(--c-accent); }

/* Billing-ledger entry types. */
.pill.deposit { background: var(--c-pass-bg); color: var(--c-pass-fg); }
.pill.platform_fee, .pill.check_charge { background: var(--c-warn-bg); color: var(--c-warn-fg); }
.pill.adjustment { background: var(--c-accent-soft); color: var(--c-accent); }

/* Signed amounts in the billing ledger. */
.amount-pos { color: var(--c-pass-fg); font-variant-numeric: tabular-nums; }
.amount-neg { color: var(--c-fail-fg); font-variant-numeric: tabular-nums; }

/* --- Buttons ------------------------------------------------------------ */

.btn, .btn-soft {
  display: inline-block;
  border: 0;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn { background: var(--c-accent); color: #fff; }
.btn:hover { background: var(--c-accent-hover); }
.btn-soft { background: var(--c-surface-2); color: var(--c-ink-soft); }
.btn-soft:hover { background: var(--c-border); }

/* The log-out control sits on the dark global nav bar. */
.topbar .btn-soft { background: var(--c-ink-soft); color: #cbd5e1; }
.topbar .btn-soft:hover { background: #475569; color: var(--c-bg); }

/* HTMX sets this on an element while its request is in flight. */
.htmx-request.btn, .htmx-request .btn { opacity: 0.6; }

/* A row of filter links above a table. */
.filters a { margin-right: var(--space-3); }

/* A row of action buttons, each its own little form. */
.actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}
.actions form { margin: 0; }

/* --- Public result page: the verdict banner ---------------------------- */

.summary {
  font-size: var(--text-lg);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  margin: var(--space-4) 0;
}

/* --- Sign-in page ------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--c-ink);
}
.auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.auth-box {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: var(--space-6) calc(var(--space-6) + var(--space-1));
  /* Fluid up to a comfortable width so the box scales down on narrow phones
     instead of overflowing the viewport padding. */
  width: 100%;
  max-width: 20rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.auth-box h1 { font-size: var(--text-xl); margin: 0 0 var(--space-1); }
.field { display: block; }
.field label {
  display: block;
  font-size: var(--text-xs);
  color: var(--c-ink-soft);
  font-weight: 600;
  margin: var(--space-4) 0 var(--space-1);
}
.field input, .field select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: inherit;
}
.auth-box .btn { width: 100%; margin-top: var(--space-5); padding: var(--space-3); }
/* Footer link ("New to MeshCheck?" / "Already have an account?") sits below the
   submit button; give it room so it doesn't crowd the button. */
.auth-box .page-sub { margin-top: var(--space-4); }
.form-error {
  background: var(--c-fail-bg);
  color: var(--c-fail-fg);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  margin-top: var(--space-3);
}
.form-ok {
  background: var(--c-pass-bg);
  color: var(--c-pass-fg);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}

/* --- Sign-up page: two-pane (pitch + form) ----------------------------- */

/* A wide card split into a value-prop panel and the form. Below 48rem the
   panel drops away and the form behaves like the single sign-in card. */
.auth-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  max-width: 56rem;
  background: var(--c-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
/* Inside the split the form sheds its own shell — the split owns it. */
.auth-split .auth-box {
  width: auto;
  max-width: none;
  border-radius: 0;
  box-shadow: none;
}

/* The brand/value panel. Stays brand-blue in both themes (accent is
   readable-on-white text in light and dark variants alike). */
.auth-aside {
  background: var(--c-accent);
  color: #fff;
  padding: var(--space-6) calc(var(--space-6) + var(--space-1));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  justify-content: center;
}
.auth-aside-brand { margin: 0; font-size: var(--text-xl); font-weight: 700; }
.auth-aside-tag { margin: 0; font-size: var(--text-lg); }
.auth-aside-points {
  margin: 0;
  padding-left: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.85);
}

/* --- Role picker: two selectable cards --------------------------------- */
.role-picker { border: 0; margin: var(--space-5) 0 0; padding: 0; }
.role-picker legend {
  padding: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--c-ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--c-faint);
}
.role-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.role-card {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.role-card:hover { border-color: var(--c-accent); }
.role-card:has(input:checked) {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
}
.role-card input { margin-top: 0.2rem; accent-color: var(--c-accent); }
.role-card-body { display: flex; flex-direction: column; gap: var(--space-1); }
.role-card-title { font-weight: 700; color: var(--c-ink); }
.role-card-desc { font-size: var(--text-xs); color: var(--c-muted); }

/* Stack to one column and drop the brand panel on narrow screens. */
@media (max-width: 48rem) {
  .auth-split { grid-template-columns: 1fr; max-width: 26rem; }
  .auth-aside { display: none; }
  .role-cards { grid-template-columns: 1fr; }
}

/* --- Admin settings form ----------------------------------------------- */

.settings-group { margin-bottom: var(--space-6); }
.settings-group + .settings-group {
  border-top: 1px solid var(--c-border);
  padding-top: var(--space-5);
}
.settings-group-title {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-faint);
}
.settings-form .setting { margin-bottom: var(--space-5); }
.settings-form .setting:last-child { margin-bottom: 0; }
.settings-form .setting label { font-weight: 600; }
.setting-help { margin: var(--space-1) 0 var(--space-2); font-size: var(--text-sm); }
.setting-input {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.settings-form input {
  width: 12rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font: inherit;
}
.setting-unit { font-size: var(--text-sm); color: var(--c-faint); }
.setting-convert {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--c-accent);
}
.setting-meta { margin: var(--space-2) 0 0; font-size: var(--text-sm); }

/* On/off toggle for boolean settings (e.g. public module flags). The native
 * checkbox is hidden but stays focusable; the pill + knob is drawn from it. */
.setting-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-weight: 600;
}
.setting-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.setting-toggle-track {
  position: relative;
  flex: none;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: 999px;
  background: var(--c-border);
  transition: background 0.15s ease;
}
.setting-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.4rem - 4px);
  height: calc(1.4rem - 4px);
  border-radius: 50%;
  /* The knob is intentionally light in both themes (conventional switch look);
   * the shadow keeps it defined against the light off-track. */
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.setting-toggle input:checked + .setting-toggle-track {
  background: var(--c-accent);
}
.setting-toggle input:checked + .setting-toggle-track::after {
  transform: translateX(1.1rem);
}
.setting-toggle input:focus-visible + .setting-toggle-track {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

/* --- Feature flags (menu item visibility) ------------------------------ */

/* Each flag stacks its toggle, audience choice, and (when "Selected users")
 * a scrollable user picker. */
.flag-audience {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: var(--space-2) 0 0;
}
.flag-radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 400;
  cursor: pointer;
}
.flag-radio input { width: auto; }
.flag-users {
  margin-top: var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  max-height: 14rem;
  overflow-y: auto;
  background: var(--c-surface-soft);
}
.flag-users[hidden] { display: none; }
.flag-users-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--space-2) var(--space-4);
}
.flag-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 400;
  font-size: var(--text-sm);
  cursor: pointer;
}
.flag-user input { width: auto; }

/* --- Dashboard chooser -------------------------------------------------- */

.chooser-link {
  display: block;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--c-surface-2);
  border-radius: var(--radius-sm);
  color: var(--c-accent);
  text-decoration: none;
  font-weight: 600;
}
.chooser-link:hover { background: var(--c-accent-soft); }
.auth-box form { margin-top: var(--space-4); }

/* --- Inline form (admin actions) --------------------------------------- */

.inline-form {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: flex-end;
}
.inline-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--c-muted);
  font-weight: 600;
}
.inline-form input, .inline-form select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font: inherit;
}
.inline-form input:disabled, .inline-form select:disabled {
  background: var(--c-surface-soft);
  color: var(--c-muted);
  cursor: not-allowed;
}
/* A checkbox + label sits inline rather than stacking like a text field. */
.inline-form label.inline-check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
.inline-form .inline-check input {
  padding: 0;
  accent-color: var(--c-accent);
}

/* --- Admin nodes: per-row actions and the MaxMind detail row ------------ */

.node-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.node-extra > td { background: var(--c-surface-soft); }
.node-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--space-3);
  margin: var(--space-2) 0;
}
.node-detail .dt {
  display: block;
  font-size: var(--text-xs);
  color: var(--c-muted);
  font-weight: 600;
}
.node-detail .dd { font-size: var(--text-sm); }
/* Capability badges: the check types a node self-declares it serves. */
.caps { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.pill.cap { background: var(--c-accent-soft); color: var(--c-accent); }

/* --- Admin data tables: single-line rows, row menus, bulk actions ------- */
/* Shared by the admin Nodes and Organizations tables (.data-table). */

/* The table always fits the page width — it never scrolls horizontally; only
   the page scrolls, vertically. Text-heavy columns wrap and the timestamp wraps
   at its space; only the compact atomic columns (checkbox, tier/status pills,
   row menu) stay on a single line via .col-nowrap. */
.table-wrap { overflow-x: visible; }
.data-table { width: 100%; }
.data-table th, .data-table td { vertical-align: middle; }
.data-table .col-select { width: 1%; white-space: nowrap; }
.data-table .col-actions { width: 1%; text-align: right; white-space: nowrap; }
.data-table .col-nowrap { white-space: nowrap; }
.data-table input[type="checkbox"] { accent-color: var(--c-accent); }

/* Highlight a checked row across its full width — the same accent wash as the
   bulk-action toolbar, legible in both light and dark themes. */
.data-table tbody tr:has(input[data-bulk-select]:checked) {
  background: var(--c-accent-soft);
}

/* Node cell: bold resolved name, the override marker, and a short id — all on
   one line, with the full ULID on hover and in the edit panel. */
.node-name-line { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); }
.node-name .node-id { font-size: var(--text-xs); }

/* "admin" marker beside an overridden datum. */
.ovr {
  display: inline-block;
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Tier pills: FREE reads quiet/neutral, PAID picks up the accent. */
.pill.tier-free { background: var(--c-surface-2); color: var(--c-ink-soft); }
.pill.tier-paid { background: var(--c-accent-soft); color: var(--c-accent); }

/* Row action menu — a compact dropdown modelled on the account menu. */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 20;
  min-width: 12rem;
  padding: var(--space-1);
  display: none;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu.open .menu-list { display: block; }
.menu-item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-ink-soft);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover { background: var(--c-surface-2); color: var(--c-ink); }
.menu-item.danger { color: var(--c-fail-fg); }
.menu-item.danger:hover { background: var(--c-fail-bg); color: var(--c-fail-fg); }

/* Bulk action toolbar — appears above the table when rows are selected. */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--c-accent-soft);
  border: 1px solid var(--c-accent);
  border-radius: var(--radius-sm);
}
.bulk-count { font-size: var(--text-sm); color: var(--c-ink-soft); }
.bulk-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.btn-soft.danger { color: var(--c-fail-fg); }
.btn-soft.danger:hover { background: var(--c-fail-bg); }

/* The per-row override editor revealed under a node. */
.override-form { margin: var(--space-2) 0; }
.override-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: var(--space-3);
  margin: var(--space-3) 0;
}
.override-grid label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--c-muted);
  font-weight: 600;
}
.override-grid input, .override-grid select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--c-surface);
  color: var(--c-ink);
}
.override-grid .hint { font-weight: 400; color: var(--c-faint); }
.override-foot { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.override-foot .node-meta { font-size: var(--text-xs); color: var(--c-muted); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0);
}

/* --- Public landing page ----------------------------------------------- */

/* A check-host.net-inspired surface: one prominent target input and a grid
 * of described check-type buttons, below the shared global nav bar. */

.landing { display: flex; flex-direction: column; gap: var(--space-5); }

.check-inputs { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
.target-input, .port-input {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-lg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
}
.target-input { flex: 1 1 18rem; }
.port-input { width: 7rem; }
.target-input:focus, .port-input:focus {
  outline: 2px solid var(--c-accent-soft);
  border-color: var(--c-accent);
}
.hint-line { font-size: var(--text-xs); margin: var(--space-2) 0 var(--space-5); }

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: var(--space-3);
}
.type-btn {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.1s, background 0.1s;
}
.type-btn:hover { border-color: var(--c-accent); background: var(--c-accent-soft); }
.type-btn .t { font-weight: 700; color: var(--c-accent); }
.type-btn .d { font-size: var(--text-xs); color: var(--c-muted); }

.callout { border-left: 3px solid var(--c-accent); }
.callout p { max-width: 60ch; color: var(--c-ink-soft); }

/* The in-page live result. On submit it replaces the check form inside
 * #check-stage: a slim status bar (with a link back to a fresh form) sits above
 * the result card, so the result lands in view instead of below the fold. The
 * bar and card re-render together as the panel polls itself while running. */
.live-panel { display: flex; flex-direction: column; gap: var(--space-4); }

.live-bar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.live-bar-title { flex: 1; font-weight: 600; }
.live-back {
  border: 0;
  background: none;
  color: var(--c-accent);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}
.live-back:hover { background: var(--c-accent-soft); }

.progress {
  min-width: 90px;
  height: 9px;
  background: var(--c-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  width: 0;
  background: var(--c-accent);
  transition: width 0.4s ease;
}
.progress .bar.pass { background: var(--c-pass-fg); }
.progress .bar.fail { background: var(--c-fail-fg); }
.progress .bar.timeout { background: var(--c-warn-fg); }

/* The live countdown bar is taller than the static progress bar so its
   remaining-seconds number fits, and it depletes as a node's deadline
   approaches. countdown.js updates the width and the number each tick; the
   text-shadow keeps the number legible over both the filled (accent) and
   empty (surface) track in either theme. */
.progress.countdown {
  position: relative;
  height: 18px;
}
.progress.countdown .bar { transition: width 0.25s linear; }
.progress-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--c-ink);
  text-shadow: 0 0 2px var(--c-surface), 0 1px 2px var(--c-surface);
  pointer-events: none;
}

.live-table td { vertical-align: middle; }

.live-actions { margin-top: var(--space-4); }

.permalink { margin-top: var(--space-5); }
.permalink h4 { margin-top: 0; }

.link-copy {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  font-size: var(--text-sm);
}

/* --- Device pairing QR code -------------------------------------------- */

/* The deep-link + copy-code row shown to Android visitors pairing on-device. */
.pair-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-4) 0 var(--space-2);
}

.qr-box {
  display: inline-block;
  padding: var(--space-4);
  margin: var(--space-4) 0;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
}
.qr-box img, .qr-box canvas { display: block; }

.qr-manual { margin-top: var(--space-2); }
.qr-manual summary { cursor: pointer; color: var(--c-ink-soft); font-size: var(--text-sm); }

/* --- Install a node ---------------------------------------------------- */

/* Secondary install methods sit quieter than the recommended one. */
.install-method[data-secondary] { background: var(--c-surface-2); }
.install-method .more { margin-top: var(--space-3); }
.install-method .more summary {
  cursor: pointer;
  color: var(--c-ink-soft);
  font-size: var(--text-sm);
}

/* A copyable command block: monospace, scrollable, with a Copy button. It is a
 * terminal-style surface, so its colours are pinned to constants — NOT theme
 * tokens — and stay legible (light text on dark) in both light and dark mode. */
.code-block { position: relative; margin: var(--space-3) 0; }
.code-block pre {
  margin: 0;
  padding: var(--space-4);
  padding-right: 4.5rem;
  background: #0f172a;
  color: #e5edff;
  border: 1px solid #1e293b;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.code-block code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: pre;
}
.code-copy {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.code-copy:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.45);
}

/* ======================================================================= */
/* Dashboard app shell: collapsible sidebar + slim topbar                  */
/*                                                                         */
/* The authenticated dashboard has its own chrome — a left sidebar and a   */
/* slim .app-topbar — and never the public .topbar above. Everything below */
/* draws from the same theme tokens, so light and dark are both covered.   */
/* ======================================================================= */

:root { --sidebar-w: 248px; --rail-w: 68px; }

.app-shell { display: flex; min-height: 100vh; }

/* --- Sidebar ----------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.18s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 60px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--c-border);
}
.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--c-ink);
  font-weight: 700;
  font-size: var(--text-lg);
}
.brand-logo { width: 26px; height: 26px; color: var(--c-accent); flex-shrink: 0; }
.brand-name { white-space: nowrap; overflow: hidden; }
.rail-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-muted);
  cursor: pointer;
}
.rail-toggle:hover { background: var(--c-surface-2); color: var(--c-ink); }
.rail-toggle .icon { width: 18px; height: 18px; }

/* --- Sidebar nav ------------------------------------------------------- */
.sidebar-nav { padding: var(--space-3) var(--space-2) var(--space-5); }
.nav-group + .nav-group { margin-top: var(--space-2); }

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--c-faint);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-group-toggle:hover { color: var(--c-muted); }
.nav-group-label { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; }
.nav-group-chevron { width: 14px; height: 14px; flex-shrink: 0; transition: transform 0.18s ease; }
.nav-group[data-collapsed] .nav-group-chevron { transform: rotate(-90deg); }

.nav-group-items { list-style: none; margin: var(--space-1) 0 0; padding: 0; }
.nav-group[data-collapsed] .nav-group-items { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  /* The extra left padding indents children beneath their group label. */
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  margin: 1px var(--space-1);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--c-ink-soft);
  font-size: var(--text-sm);
  white-space: nowrap;
}
.nav-item:hover { background: var(--c-surface-2); color: var(--c-ink); }
.nav-item.active { background: var(--c-accent-soft); color: var(--c-accent); font-weight: 600; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-text { overflow: hidden; text-overflow: ellipsis; }

/* --- Content column + slim topbar -------------------------------------- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 60px;
  padding: 0 var(--space-5);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); flex: 1; min-width: 0; }
.app-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-muted);
  cursor: pointer;
  font-size: var(--text-lg);
  line-height: 1;
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.icon-btn .icon { width: 20px; height: 20px; }

/* The theme toggle reuses .icon-btn here; override the dark-bar base colours
 * it inherits from the public .theme-toggle rule. */
.app-topbar .theme-toggle { color: var(--c-muted); }
.app-topbar .theme-toggle:hover { background: var(--c-surface-2); }

.hamburger { display: none; } /* shown only on mobile */

.app-topbar .app-org select {
  background: var(--c-surface-2);
  color: var(--c-ink);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
}

/* --- Account avatar + dropdown ----------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--c-accent);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
}
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-sm); }

.user-menu { position: relative; }
.user-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 14rem;
  padding: var(--space-1) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  color: var(--c-ink);
  font: inherit;
}
.user-trigger:hover { background: var(--c-surface-2); }
.user-name { font-size: var(--text-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-trigger .caret { width: 16px; height: 16px; color: var(--c-muted); transition: transform 0.15s ease; }
.user-menu.open .user-trigger .caret { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 30;
  min-width: 15rem;
  padding: var(--space-2);
  display: none;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.user-menu.open .user-dropdown { display: block; }
.user-dropdown-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); }
.user-dropdown-id { min-width: 0; }
.user-dropdown-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-dropdown-role { font-size: var(--text-xs); color: var(--c-muted); }
.user-dropdown-section {
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-faint);
}
.user-dropdown-divider { height: 1px; margin: var(--space-2) 0; background: var(--c-border); }
.user-dropdown form { margin: 0; }
.user-dropdown-item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-ink-soft);
  text-decoration: none;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}
.user-dropdown-item:hover { background: var(--c-surface-2); color: var(--c-ink); }
.user-dropdown-danger { color: var(--c-fail-fg); }
.user-dropdown-danger:hover { background: var(--c-fail-bg); color: var(--c-fail-fg); }

/* --- Mobile drawer backdrop -------------------------------------------- */
.sidebar-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, 0.5); }
.sidebar-backdrop[hidden] { display: none; }

/* --- Desktop: collapse the sidebar to an icon-rail --------------------- */
@media (min-width: 60.0625rem) {
  .sidebar-backdrop { display: none; }

  :root[data-rail] .sidebar { width: var(--rail-w); }
  :root[data-rail] .brand-name,
  :root[data-rail] .nav-text,
  :root[data-rail] .nav-group-toggle { display: none; }
  :root[data-rail] .sidebar-brand { justify-content: center; padding: 0; }
  :root[data-rail] .brand-link { flex: 0; justify-content: center; }
  :root[data-rail] .rail-toggle { display: none; }
  :root[data-rail] .nav-group + .nav-group {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--c-border);
  }
  :root[data-rail] .nav-group-items { display: block; }
  :root[data-rail] .nav-item { justify-content: center; padding: var(--space-2); margin: 2px var(--space-1); }
  :root[data-rail] .nav-icon { width: 20px; height: 20px; }
}

/* --- Mobile: sidebar becomes an off-canvas drawer ---------------------- */
@media (max-width: 60rem) {
  .hamburger { display: inline-flex; }
  .user-name { display: none; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  }
  .app-shell.drawer-open .sidebar { transform: none; }
}
