/* ==========================================================================
   server3 control panel — stylesheet

   Colour comes from the validated reference data-viz palette: categorical
   slots 1–3 (blue / orange / aqua), the fixed status palette, and the chart
   chrome + ink roles. Slots 1–3 are the documented all-pairs-safe subset, so
   every chart here caps at three series by construction.

   Dark mode is *selected*, not an inversion: each role has its own step
   chosen for the dark surface. Values are declared in three scopes so the
   toggle wins in both directions over the OS preference.
   ========================================================================== */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --surface-2:      #f2f1ed;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --border-strong:  rgba(11, 11, 11, 0.18);
  --wash:           rgba(11, 11, 11, 0.04);

  /* categorical series (slots 1–3 of the reference theme) */
  --series-1: #2a78d6;   /* blue   */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a;   /* aqua   */

  /* status — fixed, never themed */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11,11,11,.05), 0 4px 12px rgba(11,11,11,.04);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.18);
    --wash:           rgba(255, 255, 255, 0.05);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface:        #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.18);
  --wash:           rgba(255, 255, 255, 0.05);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
}

/* -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 14px; }

/* ── top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
  padding: 5px clamp(14px, 3vw, 28px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: #2fae5f;
  color: #000;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; letter-spacing: -0.5px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 13px; letter-spacing: -0.02em; }
.brand-sub {
  font-size: 10.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-stats {
  display: flex; gap: 14px; flex: 1 1 auto; flex-wrap: wrap;
  min-width: 0;
}
.mini { display: flex; flex-direction: column; line-height: 1.15; }
.mini-label {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 600;
}
.mini-value { font-size: 12.5px; font-weight: 600; color: var(--text-primary); }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

.conn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-secondary);
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap; flex-shrink: 0;
}
.conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent);
}
.conn.is-stale .conn-dot { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 22%, transparent); }
.conn.is-down .conn-dot { background: var(--critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 22%, transparent); }

.btn-icon {
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); font-size: 13px; line-height: 1;
}
.btn-icon:hover { background: var(--wash); color: var(--text-primary); }

/* ── tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex; gap: 2px; overflow-x: auto;
  padding: 0 clamp(14px, 3vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 38px; z-index: 30;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 7px 12px; font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary); white-space: nowrap;
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }

.tab-badge {
  font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.tab-badge:empty { display: none; }
.tab-badge.is-alert { background: color-mix(in srgb, var(--critical) 15%, transparent);
  color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }

/* ── layout ──────────────────────────────────────────────────────────────── */

main { padding: clamp(14px, 3vw, 24px); max-width: 1600px; margin: 0 auto; }

.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.tile-grid {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.chart-grid {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}
.split-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* ── cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin: 0;
}

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 13px 15px 11px;
  border-bottom: 1px solid var(--border);
}
.card-sub { margin: 2px 0 0; font-size: 11.5px; color: var(--text-muted); }
.card-body { padding: 13px 15px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── stat tiles ──────────────────────────────────────────────────────────── */

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 7px;
  position: relative; overflow: hidden;
}
.tile-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.tile-value {
  font-size: 27px; font-weight: 600; line-height: 1;
  letter-spacing: -0.03em; color: var(--text-primary);
}
.tile-value .unit { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile-note { font-size: 11.5px; color: var(--text-secondary); }

/* meter: a thin magnitude bar with a 4px rounded data-end on the baseline */
.meter {
  height: 5px; border-radius: 3px; background: var(--surface-2);
  overflow: hidden; border: 1px solid var(--border);
}
.meter-fill {
  height: 100%; border-radius: 0 3px 3px 0;
  background: var(--series-1);
  transition: width .45s cubic-bezier(.4,0,.2,1), background-color .3s;
}
.meter-fill[data-status="good"]     { background: var(--good); }
.meter-fill[data-status="warning"]  { background: var(--warning); }
.meter-fill[data-status="serious"]  { background: var(--serious); }
.meter-fill[data-status="critical"] { background: var(--critical); }

.status-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border);
}
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-chip[data-status="good"]     { color: var(--good-text);  background: color-mix(in srgb, var(--good) 12%, transparent); }
.status-chip[data-status="warning"]  { color: #7a5200;           background: color-mix(in srgb, var(--warning) 20%, transparent); }
.status-chip[data-status="serious"]  { color: #8c3d18;           background: color-mix(in srgb, var(--serious) 20%, transparent); }
.status-chip[data-status="critical"] { color: var(--critical);   background: color-mix(in srgb, var(--critical) 13%, transparent); }
.status-chip[data-status="neutral"]  { color: var(--text-secondary); background: var(--surface-2); }
:root[data-theme="dark"] .status-chip[data-status="warning"] { color: var(--warning); }
:root[data-theme="dark"] .status-chip[data-status="serious"] { color: var(--serious); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .status-chip[data-status="warning"] { color: var(--warning); }
  :root:where(:not([data-theme="light"])) .status-chip[data-status="serious"] { color: var(--serious); }
}

/* ── charts ──────────────────────────────────────────────────────────────── */

.chart-card { display: flex; flex-direction: column; }
.chart-host { position: relative; padding: 10px 8px 4px; height: 190px; }
.chart-host canvas { width: 100%; height: 100%; display: block; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-secondary); white-space: nowrap;
}
.legend-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend-value {
  font-weight: 600; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 7px 9px; font-size: 11.5px; min-width: 128px;
  opacity: 0; transition: opacity .12s;
}
.chart-tip.is-on { opacity: 1; }
.chart-tip-time { color: var(--text-muted); font-size: 10.5px; margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tip-row span:first-child { display: inline-flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.chart-tip-row b { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── tables ──────────────────────────────────────────────────────────────── */

.table-scroll { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  text-align: left; font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  padding: 9px 13px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface); z-index: 1;
}
tbody td { padding: 9px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--wash); }
td.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
td.mono, .mono { font-family: var(--mono); font-size: 11.5px; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; align-items: center; }
.kv dt { color: var(--text-secondary); font-size: 12px; }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.bar-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12px; }
.bar-head b { font-variant-numeric: tabular-nums; }

/* stacked composition bar — 2px surface gap between segments */
.stack { display: flex; height: 9px; border-radius: 4px; overflow: hidden; background: var(--surface-2);
  border: 1px solid var(--border); gap: 2px; }
.stack-seg { height: 100%; }
.stack-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 9px; }

/* ── controls ────────────────────────────────────────────────────────────── */

.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 12px; font-weight: 500;
  padding: 5px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-primary);
}
.btn:hover { background: var(--wash); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }

.input {
  font: inherit; font-size: 12px; padding: 5px 9px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-primary); min-width: 150px;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--series-1) 45%, transparent); outline-offset: -1px; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.switch input { accent-color: var(--series-1); }

.actions { display: flex; gap: 5px; justify-content: flex-end; }

/* ── logs ────────────────────────────────────────────────────────────────── */

.logbox {
  margin: 0; padding: 13px 15px; font-family: var(--mono); font-size: 11.5px;
  line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  max-height: 62vh; overflow: auto; color: var(--text-secondary);
  background: var(--surface);
}

/* ── toasts ──────────────────────────────────────────────────────────────── */

.toast-host {
  position: fixed; bottom: 16px; right: 16px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--series-1);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 9px 13px; font-size: 12.5px; max-width: 340px;
  animation: slide .2s ease;
}
.toast[data-kind="error"] { border-left-color: var(--critical); }
.toast[data-kind="ok"]    { border-left-color: var(--good); }
@keyframes slide { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.empty { padding: 26px 15px; text-align: center; color: var(--text-muted); font-size: 12.5px; }

@media (max-width: 720px) {
  .tabs { top: 0; position: static; }
  .topbar { position: static; }
  .topbar-stats { order: 3; width: 100%; gap: 14px; }
  .chart-host { height: 165px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── login page ──────────────────────────────────────────────────────────
   Served to unauthenticated visitors, so it deliberately reveals nothing
   about the host: no hostname, no version, no service list. */

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

.login-shell { width: 100%; max-width: 380px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px 22px;
  display: flex; flex-direction: column; gap: 16px;
}

.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand h1 { font-size: 19px; letter-spacing: -0.02em; }
.login-sub { margin: 1px 0 0; font-size: 12px; color: var(--text-muted); }

.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field span {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-secondary);
}
.login-field input {
  font: inherit; font-size: 15px; padding: 10px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--plane); color: var(--text-primary); width: 100%;
}
.login-field input:focus {
  outline: 2px solid color-mix(in srgb, var(--series-1) 50%, transparent);
  outline-offset: 1px; border-color: var(--series-1);
}

.login-btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--series-1); color: #fff; width: 100%;
}
.login-btn:hover { filter: brightness(1.06); }
.login-btn:active { transform: translateY(1px); }
.login-btn[disabled] { opacity: .6; cursor: progress; }

.login-error {
  margin: 0; font-size: 12.5px; color: var(--critical);
  min-height: 0; opacity: 0; transition: opacity .15s;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--critical) 30%, transparent);
}
.login-error.is-on { opacity: 1; }
.login-error:not(.is-on) { padding: 0; border-color: transparent; background: none; }

.login-foot {
  margin: 0; font-size: 11px; line-height: 1.5; color: var(--text-muted);
  border-top: 1px solid var(--border); padding-top: 13px;
}

/* ── forms (site creation) ───────────────────────────────────────────────── */

.form-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  align-items: start;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-secondary);
}
.field small { font-size: 11px; color: var(--text-muted); line-height: 1.45; }
.field select.input { cursor: pointer; }

.form-actions {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-top: 13px;
}
.form-actions .btn { margin-left: auto; }

.btn-primary {
  background: var(--series-1); color: #fff; border-color: transparent; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.07); background: var(--series-1); }

.form-error {
  margin: 12px 0 0; font-size: 12.5px; color: var(--critical);
  padding: 9px 11px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--critical) 30%, transparent);
  display: none;
}
.form-error.is-on { display: block; }
.form-error.is-ok {
  display: block; color: var(--good-text);
  background: color-mix(in srgb, var(--good) 12%, transparent);
  border-color: color-mix(in srgb, var(--good) 30%, transparent);
}

.note-box {
  margin: 14px 0 0; font-size: 12px; line-height: 1.55;
  color: var(--text-secondary);
  padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
}
.note-box strong { color: var(--text-primary); }

/* ── backup scope picker ─────────────────────────────────────────────────── */

.scope-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.scope {
  display: flex; flex-direction: column; gap: 7px;
  padding: 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
}
.scope h3 { font-size: 13px; }
.scope p { margin: 0; font-size: 11.5px; color: var(--text-muted); line-height: 1.5; flex: 1; }
.scope .btn { align-self: flex-start; }

.backup-run { margin-top: 16px; display: flex; flex-direction: column; gap: 7px; }
.meter.indeterminate { position: relative; overflow: hidden; }
.meter.indeterminate .meter-fill {
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--series-1) 25%, transparent) 0%,
    var(--series-1) 50%,
    color-mix(in srgb, var(--series-1) 25%, transparent) 100%);
  background-size: 200% 100%;
  animation: sweep 1.1s linear infinite;
}
@keyframes sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.site-domains { display: flex; flex-wrap: wrap; gap: 4px; }
.domain-chip {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--series-1) 12%, transparent);
  color: var(--series-1); border: 1px solid color-mix(in srgb, var(--series-1) 30%, transparent);
  font-family: var(--mono);
}

/* The sign-out control is an <a> so it works without JavaScript; these
   rules make an anchor sit correctly in a button-shaped box. */
.btn-logout {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.btn-logout:hover { color: var(--critical); }

/* ── traffic ─────────────────────────────────────────────────────────────── */

.seg {
  display: inline-flex; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); overflow: hidden; background: var(--surface);
}
.seg-btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-size: 12px;
  padding: 5px 10px; background: none; color: var(--text-secondary);
  border-right: 1px solid var(--border); white-space: nowrap;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--wash); color: var(--text-primary); }
.seg-btn.is-on {
  background: var(--series-1); color: #fff; font-weight: 600;
  border-right-color: transparent;
}

.top-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
}

.top-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); overflow: hidden;
}
.top-card h3 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-secondary);
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: baseline;
}
.top-card h3 span { text-transform: none; letter-spacing: 0; color: var(--text-muted); font-weight: 500; }
.top-list { list-style: none; margin: 0; padding: 6px 0; }

.top-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  padding: 5px 12px; align-items: baseline; position: relative;
}
.top-row:hover { background: var(--wash); }
/* The share bar sits behind the label rather than beside it: at ten rows a
   separate bar column would halve the space available for long values like
   referrer hostnames. */
.top-row::before {
  content: ""; position: absolute; left: 0; top: 2px; bottom: 2px;
  width: var(--share, 0%); background: color-mix(in srgb, var(--series-1) 13%, transparent);
  border-radius: 0 3px 3px 0; pointer-events: none;
}
.top-name {
  font-size: 12.5px; color: var(--text-primary); position: relative;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top-val {
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-secondary);
  position: relative; white-space: nowrap;
}
.top-val b { color: var(--text-primary); }
.top-empty { padding: 14px 12px; font-size: 12px; color: var(--text-muted); }

/* ── version chip (was the connection indicator) ─────────────────────────
   Still carries the connection dot: replacing the live/stale/disconnected
   signal with a version number would mean a dead backend looked exactly
   like an idle one. */
.conn-btn {
  appearance: none; cursor: pointer; font: inherit;
  font-size: 11.5px; font-variant-numeric: tabular-nums;
}
.conn-btn:hover { background: var(--wash); color: var(--text-primary); }
.conn-btn:active { transform: translateY(1px); }

/* ── notes ───────────────────────────────────────────────────────────────*/

#view-notes .card + .card { margin-top: 12px; }

textarea.input {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  resize: vertical; min-height: 120px; width: 100%;
}

.note-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); }

.note {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 13px 15px;
  display: flex; flex-direction: column; gap: 8px;
}
.note.is-pinned { border-left: 3px solid var(--series-2); }

.note-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.note-title { font-size: 13.5px; font-weight: 600; }
.note-title:empty::before { content: "Untitled"; color: var(--text-muted); font-weight: 400; }
.note-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.note-body { font-size: 12.5px; line-height: 1.6; color: var(--text-secondary); overflow-wrap: anywhere; }
.note-body > :first-child { margin-top: 0; }
.note-body > :last-child { margin-bottom: 0; }

.note-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.note-tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px; cursor: pointer;
  background: color-mix(in srgb, var(--series-1) 12%, transparent);
  color: var(--series-1); border: 1px solid color-mix(in srgb, var(--series-1) 28%, transparent);
}
.note-tag:hover { background: color-mix(in srgb, var(--series-1) 22%, transparent); }
.note-actions { display: flex; gap: 5px; justify-content: flex-end; margin-top: auto; padding-top: 4px; }

/* ── rendered markdown (notes and the About docs) ─────────────────────── */

.md h1, .md h2, .md h3 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 17px; }
.md h2 { font-size: 15px; padding-bottom: 5px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 13.5px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code {
  font-family: var(--mono); font-size: .92em;
  background: var(--wash); padding: 1px 5px; border-radius: 4px;
}
.md pre {
  background: var(--plane); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; overflow-x: auto; margin: 10px 0;
}
.md pre code { background: none; padding: 0; font-size: 11.5px; line-height: 1.55; }
.md blockquote {
  margin: 10px 0; padding: 8px 13px; border-left: 3px solid var(--warning);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md blockquote > :first-child { margin-top: 0; }
.md blockquote > :last-child { margin-bottom: 0; }
.md table { width: auto; min-width: 60%; margin: 10px 0; font-size: 12px; }
.md th, .md td { padding: 6px 11px; border-bottom: 1px solid var(--border); text-align: left; }
.md th { font-weight: 600; color: var(--text-secondary); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.md a { color: var(--series-1); }
.md strong { color: var(--text-primary); font-weight: 600; }

.doc-body { max-height: 70vh; overflow-y: auto; }
.doc-body .md { max-width: 74ch; }

/* Terminal — the xterm.js renderer fills this box; the fit addon sizes the
   shell's rows/cols to whatever height we give it here. */
.term-host {
  height: 62vh;
  min-height: 320px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 6px 8px 10px;
  border-radius: 10px;
  background: #0a0e16;                 /* xterm paints its own text; this is the surround */
  border: 1px solid var(--border);
}
.term-host .xterm { height: 100%; }
.term-host .xterm-viewport { border-radius: 8px; }
/* When no shell is attached yet, hint that the box is interactive. */
.term-host:empty::before {
  content: "Press Connect to open a shell.";
  color: #5b6577;
  font: 13px/1.4 var(--mono, ui-monospace, monospace);
  display: block;
  padding: 6px 4px;
}

/* Public address, shown beside the hostname in the topbar. */
.brand-line { display: flex; align-items: baseline; gap: 6px; }
.brand-ip {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Copyable command line: the code scrolls rather than wrapping, so the
   command stays selectable as one line and never reflows the card. */
.copy-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.copy-row code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-inset, rgba(128,128,128,.12));
  font-size: 12px;
  line-height: 1.5;
}
.copy-row .btn { flex: 0 0 auto; }

/* ── session view ──────────────────────────────── */
.session-wrap {
  max-width: 560px;
  margin: 0 auto;
}
.session-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 2px;
}
.session-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.session-header h2 { margin: 0; font-size: 15px; }
.session-header .card-sub { margin: 2px 0 0; }
.session-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.session-grid .card { margin: 0; }
.session-grid .card-head { padding: 10px 14px 0; }
.session-grid .card-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-dim); }
.session-grid .card-body { padding: 6px 14px 12px; }
.session-grid .kv { gap: 4px 10px; }
.session-grid .kv dt { font-size: 11.5px; }
.session-grid .kv dd { font-size: 12px; }
@media (max-width: 520px) {
  .session-grid { grid-template-columns: 1fr; }
}

/* ── file explorer ─────────────────────────────── */
.file-bar {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 10px;
}
.file-crumbs {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  font-size: 12.5px; min-width: 0; flex: 1;
}
.file-crumbs a {
  color: var(--accent); text-decoration: none;
  padding: 2px 5px; border-radius: 5px; cursor: pointer;
  font-family: var(--mono, ui-monospace, monospace);
}
.file-crumbs a:hover { background: var(--wash); text-decoration: underline; }
.file-crumbs .sep { color: var(--text-secondary); opacity: .5; }
.file-crumbs .cur { padding: 2px 5px; font-weight: 600;
  font-family: var(--mono, ui-monospace, monospace); }
.file-goto { display: flex; gap: 6px; align-items: center; }
.file-goto .input { height: 30px; font-size: 12px; min-width: 220px; }
.file-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 6px;
}
.file-meta { font-size: 11.5px; color: var(--text-secondary); }
.file-toolbar-actions { display: flex; gap: 6px; }

#file-listing table { width: 100%; }
#file-listing td, #file-listing th { white-space: nowrap; }
.file-name {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; max-width: 46ch; overflow: hidden; text-overflow: ellipsis;
}
.file-name:hover .file-label { text-decoration: underline; }
.file-name.is-plain { cursor: default; }
.file-name.is-plain:hover .file-label { text-decoration: none; }
.file-ico { width: 15px; text-align: center; flex-shrink: 0; opacity: .85; }
.file-ico.dir { color: var(--accent); }
.file-label { overflow: hidden; text-overflow: ellipsis; }
.file-link-target { color: var(--text-secondary); font-size: 11px; }
.file-mode { font-family: var(--mono, ui-monospace, monospace); font-size: 11.5px; }
.file-owner { font-size: 11.5px; color: var(--text-secondary); }
.file-actions { display: flex; gap: 3px; justify-content: flex-end; }
.file-actions .btn-icon { width: 24px; height: 24px; font-size: 11px; }
.file-row-danger td { color: var(--critical); }
td.num, th.num { text-align: right; }
@media (max-width: 720px) {
  .col-owner, .col-mode { display: none; }
}

/* ── per-site traffic (Sites tab) ──────────────── */
.st-row { cursor: pointer; }
.st-row:hover { background: var(--wash); }
.st-row.is-open { background: var(--wash); }
.st-caret { width: 18px; color: var(--text-secondary); text-align: center; }
.st-detail > td { padding: 0 !important; background: var(--surface-2, rgba(128,128,128,.05)); }
.st-detail-inner { padding: 14px 16px 18px; }
.st-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.st-tiles .tile { padding: 10px 12px; }
.st-tiles .tile-value { font-size: 17px; }
.st-tops { margin: 0; }
.st-group td {
  padding: 9px 12px 5px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 700; color: var(--text-muted);
  background: var(--surface-2, rgba(128,128,128,.05));
  border-bottom: 1px solid var(--border);
}
.st-group td span { opacity: .55; margin-left: 3px; }
@media (max-width: 720px) {
  .st-tiles { grid-template-columns: repeat(2, 1fr); }
}

/* ── banned addresses (Security tab) ───────────── */
.ban-row { cursor: pointer; }
.ban-row:hover { background: var(--wash); }
.ban-row.is-open { background: var(--wash); }
.ban-host { max-width: 24ch; overflow: hidden; text-overflow: ellipsis; }
.ban-detail > td { padding: 0 !important; background: var(--surface-2, rgba(128,128,128,.05)); }
.ban-detail-inner { padding: 14px 16px 18px; }
.ban-tops { margin: 0 0 4px; }
.ban-reqs { margin-top: 12px; overflow-x: auto; }
.ban-reqs table { width: 100%; font-size: 12px; }
.ban-reqs th { font-size: 10.5px; }
.ban-reqs td { padding: 5px 10px; }

/* offenders (shares the ban expand look) */
.off-row { cursor: pointer; }
.off-row:hover, .off-row.is-open { background: var(--wash); }
.off-detail > td { padding: 0 !important; background: var(--surface-2, rgba(128,128,128,.05)); }
.off-detail-inner { padding: 14px 16px 18px; }
.off-row .status-chip { margin-right: 3px; }

/* suspicious-path highlighting in the threat detail */
.top-row.is-bad .top-name { color: var(--critical); }
.ban-reqs tr.is-bad td { color: var(--critical); }
.threat-flag {
  color: var(--critical); font-weight: 700; text-transform: none;
  letter-spacing: 0;
}

/* Operator note on a ban (Security → Banned addresses, expanded row) */
.ban-note {
  margin: 0 0 14px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(128, 128, 128, 0.06);
}
.ban-note-label {
  display: block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 6px;
}
.ban-note-input {
  width: 100%; box-sizing: border-box; resize: vertical;
  font: inherit; font-size: 13px; padding: 7px 9px;
  color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
}
.ban-note-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ban-note-status.is-ok { color: var(--good); }
.ban-note-status.is-on { color: var(--critical); }
.note-badge { cursor: help; font-size: 12px; }

/* Horizontal proportion bar (watchlist progress, password frequency) */
.meter {
  height: 8px; min-width: 90px; border-radius: 4px;
  background: rgba(128, 128, 128, 0.18); overflow: hidden;
}
.meter > span { display: block; height: 100%; background: var(--warning); border-radius: 4px; }
