/* Default theme = Dark (admin's original slate palette). Themes are selected via
   <html data-theme> — the pre-paint script in index.html sets it before first paint.
   Parity with the PWA/Pro: Light, Dark, High contrast, Noir. (feat_theme_parity_pro_admin) */
:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111c30;
  --surface-2: #1c2942;
  --border: #2a3a55;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-dim: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius: 10px;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5f9; --surface: #ffffff; --surface-2: #e2e8f0; --border: #cbd5e1;
  --text: #0f172a; --text-secondary: #475569; --text-dim: #64748b;
  --primary: #2563eb; --primary-hover: #1d4ed8;
}
/* High contrast — white surfaces, black borders, AAA-tuned blue (white-on-accent stays legible). */
[data-theme="high-contrast"] {
  color-scheme: light;
  --bg: #ffffff; --surface: #ffffff; --surface-2: #e6e6e6; --border: #000000;
  --text: #000000; --text-secondary: #1a1a1a; --text-dim: #1a1a1a;
  --primary: #0033cc; --primary-hover: #002299;
  --danger: #b00000; --success: #006b2d; --warning: #6b4500;
}
[data-theme="high-contrast"] :focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
/* Noir — true-black with a MONOCHROME white accent. Primary-filled controls need dark
   text (the chrome otherwise hardcodes white-on-primary). Semantic colours stay coloured. */
[data-theme="noir"] {
  color-scheme: dark;
  --bg: #000000; --surface: #0a0a0a; --surface-2: #161616; --border: #1c1c1c;
  --text: #f5f5f5; --text-secondary: #8a8a8a; --text-dim: #6e6e6e;
  --primary: #ffffff; --primary-hover: #e0e0e0;
  --danger: #ef4444; --success: #22c55e; --warning: #f59e0b;
}
[data-theme="noir"] .btn-primary,
[data-theme="noir"] .nav-notif-badge { color: #000; }
/* A surface (black) button on pure black is nearly invisible — the default --border
   (#1c1c1c) is too faint on the small button footprint. Give every button a slim
   #333 edge so it reads. Mirrors the PWA's noir fix. (fix_admin_noir_button_border) */
[data-theme="noir"] .btn { border: 1px solid #333; }
/* Fully black & white: desaturate everything the palette can't reach — the coloured
   emoji nav icons (🏠 👥 💪 …), charts, etc. Grayscale on the document ROOT does it in
   one stroke; the root is exempt from creating a containing block, so fixed overlays
   aren't broken. Mirrors the PWA's Noir. (user 2026-06-30) */
html[data-theme="noir"] { filter: grayscale(1); }
/* Blanc — the inverse of Noir: paper-white surfaces, near-black text, a MONOCHROME black
   accent. --primary is black and the chrome hardcodes white-on-primary, so filled controls
   stay legible. Grayscales the document like Noir. Mirrors the PWA/Pro Blanc. (feat_blanc_theme) */
[data-theme="blanc"] {
  color-scheme: light;
  --bg: #ffffff; --surface: #f7f7f7; --surface-2: #ededed; --border: #e0e0e0;
  --text: #0a0a0a; --text-secondary: #6b6b6b; --text-dim: #8a8a8a;
  --primary: #000000; --primary-hover: #1f1f1f;
  --danger: #ef4444; --success: #22c55e; --warning: #f59e0b;
}
html[data-theme="blanc"] { filter: grayscale(1); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
#app { min-height: 100vh; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Pin the rail and let it scroll internally so a long nav never pushes the foot
     (Settings cog) off-screen. (feat_admin_settings_and_nav_polish) */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-brand h1 { font-size: 18px; margin: 0; }
.sidebar-brand .small { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.sidebar a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 24px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-notif-badge {
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  border-radius: 10px;
  background: var(--primary, #3b82f6);
  color: #fff;
}
.nav-notif-badge[hidden] { display: none; }
.sidebar a:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.sidebar a.active { color: var(--text); background: rgba(59,130,246,0.10); border-left-color: var(--primary); }
.sidebar-footer { margin-top: auto; padding: 12px 24px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.sidebar-footer button {
  background: none; border: 0; color: var(--text-secondary); padding: 0; cursor: pointer;
  font-size: 12px; text-decoration: underline;
}
.sidebar-footer button:hover { color: var(--text); }

/* ── Collapsible sidebar (feat_collapsible_sidebars) ──
   Desktop toggle shrinks the nav to a 64px icon rail; labels/brand/email hidden,
   Sign out becomes an icon. Persisted via localStorage 'admin_sidebar_collapsed'. */
.sidebar-brand { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
/* The anvil mark + the wordmark form one left group; the collapse button stays right.
   (feat_admin_console_icon) */
.brand-lead { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* The app hammer-and-tongs mark in a red rounded box (owner 2026-06-30 — use the real app
   anvil, not the simplified glyph). (feat_admin_settings_and_nav_polish) */
.brand-mark {
  flex: none; width: 30px; height: 30px; border-radius: 7px; background: #b91c1c;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark img { display: block; }
.brand-text { min-width: 0; }
/* Settings cog in the foot — looks like a nav row; the ⚙️ stays visible (override the
   default `.so-ico{display:none}`). Beats `.sidebar-footer button` on specificity. */
.sidebar-footer .foot-settings {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--text-secondary); cursor: pointer;
  padding: 8px 24px; font-size: 14px; font-weight: 500; text-decoration: none;
}
.sidebar-footer .foot-settings:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.sidebar-footer .foot-settings.active { color: var(--text); }
.sidebar-footer .foot-settings .so-ico { display: inline; }
/* Settings page theme buttons. */
.theme-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.nav-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-ico { width: 1.3em; text-align: center; flex: none; }
.nav-collapse-btn {
  background: none; border: 0; color: var(--text-secondary); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: var(--radius-sm); flex: none;
}
.nav-collapse-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
/* Theme picker (feat_theme_parity_pro_admin) — full-width select; hidden in the collapsed rail. */
.foot-theme { width: 100%; margin-bottom: 4px; }
.theme-select {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 6px; font-size: 12px;
}
.so-ico { display: none; }
.nav-sep { display: none; }
@media (min-width: 801px) {
  .layout.nav-collapsed { grid-template-columns: 64px 1fr; }
  /* Collapsed rail hides the labels, so logical sections run together — show a
     separator between them. (owner UX 2026-06-29) */
  .nav-collapsed .nav-sep { display: block; height: 1px; background: var(--border); margin: 6px 10px; }
  .nav-collapsed .brand-text,
  .nav-collapsed .nav-label,
  .nav-collapsed .foot-text,
  .nav-collapsed .so-label,
  .nav-collapsed .foot-theme,
  .nav-collapsed .nav-notif-badge { display: none; }
  /* Stack the anvil above the collapse button so neither is squashed in the 64px rail
     (owner 2026-06-30). (feat_admin_settings_and_nav_polish) */
  .nav-collapsed .sidebar-brand { flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding-left: 0; padding-right: 0; }
  .nav-collapsed .foot-settings { justify-content: center; padding-left: 0; padding-right: 0; }
  .nav-collapsed .sidebar a { justify-content: center; padding: 10px 0; }
  .nav-collapsed .nav-row { justify-content: center; gap: 0; }
  .nav-collapsed .nav-ico { width: auto; font-size: 18px; }
  .nav-collapsed .sidebar-footer { align-items: center; padding-left: 0; padding-right: 0; }
  .nav-collapsed .so-ico { display: inline; }
  .nav-collapsed #admin-logout { text-decoration: none; font-size: 16px; }
}
@media (max-width: 800px) { .nav-collapse-btn { display: none; } } /* collapse is desktop-only */

.main { padding: 24px 32px; max-width: 1400px; }
.main h1 { font-size: 26px; margin: 0 0 4px; }
.main .subtitle { color: var(--text-secondary); margin: 0 0 24px; }

/* ── Typography ──────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.2; }
h2 { font-size: 18px; margin: 24px 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 12px; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
.muted { color: var(--text-secondary); }
.dim { color: var(--text-dim); }
code { background: rgba(255,255,255,0.06); padding: 1px 6px; border-radius: 4px; font-size: 0.92em; font-family: 'SF Mono', Consolas, Menlo, monospace; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-size: 14px; font-weight: 500; font-family: inherit; text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(255,255,255,0.05); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin-top: 0; }
.card-row { display: flex; gap: 16px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.card-row:last-child { border-bottom: 0; }
.card-row-label { color: var(--text-secondary); font-size: 13px; min-width: 140px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0;
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody tr.clickable { cursor: pointer; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table-wrap-scroll { max-height: 70vh; overflow: auto; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
/* Custom dropdown chevron, inset from the right edge (the native arrow sits flush to the box
   edge — owner 2026-06-30). select:not([multiple]) (0,1,1) beats single-class select rules. */
select:not([multiple]) {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 34px;
}
textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-primary { background: rgba(59,130,246,0.20); color: var(--primary); }
.badge-success { background: rgba(34,197,94,0.20); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.20); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.20); color: var(--danger); }
.badge-muted { background: rgba(148,163,184,0.15); color: var(--text-secondary); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 400px; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; top: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; font-size: 14px;
  z-index: 200; max-width: 420px; box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.15); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Test dashboard ───────────────────────────────────────────────────────── */
.badge-pass { background: rgba(34,197,94,0.20); color: var(--success); }
.badge-fail { background: rgba(239,68,68,0.20); color: var(--danger); }
.badge-skip { background: rgba(245,158,11,0.18); color: var(--warning); }
.badge-gap  { background: rgba(148,163,184,0.15); color: var(--text-secondary); }
.badge-none { background: rgba(148,163,184,0.12); color: var(--text-dim); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }

.area-h { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); margin: 18px 0 8px; }
.journey-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 6px; }
.journey-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: inherit; }
.journey-row:hover { border-color: var(--primary); background: rgba(59,130,246,0.06); }
.journey-id { font-family: ui-monospace, monospace; font-size: 12px; font-weight: 600; }
.journey-title { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 5px 0; }

.mermaid-wrap { overflow-x: auto; background: var(--bg-elevated, #0b1220); border-radius: 8px; padding: 14px; }
.mermaid-wrap svg { max-width: 100%; height: auto; }
.mermaid-src { white-space: pre-wrap; font-size: 12px; color: var(--text-secondary); }
.err-line { color: var(--danger); font-size: 12px; margin-top: 3px; max-width: 60ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
