/* ==========================================================================
   Mailman — theme: Linear (dark-mode native)
   Near-black canvas, Inter with cv01/ss03, single indigo accent, whisper-thin
   translucent borders, elevation via background luminance (not shadows).
   Status colours are the only additional chromatic layer, and are always
   paired with a text label so colour is never the sole signal (WCAG 1.4.1).
   ========================================================================== */

:root {
  /* Surfaces — luminance stacking, never pure black */
  --bg: #08090a;
  --bg-panel: #0f1011;
  --bg-surface: #191a1b;
  --bg-raised: #202123;
  --bg-hover: #28282c;

  /* Text */
  --text: #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-muted: #8a8f98;
  --text-faint: #62666d;

  /* Brand — the only chromatic chrome colour */
  --brand: #5e6ad2;
  --accent: #7170ff;
  --accent-hover: #828fff;
  --accent-soft: rgba(113, 112, 255, 0.12);
  --lavender: #7a7fad;

  /* Borders — semi-transparent white, never solid grey */
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Semantic status — AA contrast on --bg-panel */
  --pass: #3fb950;
  --pass-bg: rgba(63, 185, 80, 0.12);
  --warn: #d29922;
  --warn-bg: rgba(210, 153, 34, 0.12);
  --fail: #f85149;
  --fail-bg: rgba(248, 81, 73, 0.12);
  --info: #8a8f98;
  --info-bg: rgba(138, 143, 152, 0.10);
  --error: #db6d28;
  --error-bg: rgba(219, 109, 40, 0.12);

  /* Type */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-pill: 9999px;

  --maxw: 1280px;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-feature-settings: "cv01", "ss03";
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 510; line-height: 1.2; }
h1 { font-size: 28px; letter-spacing: -0.6px; }
h2 { font-size: 20px; letter-spacing: -0.3px; }
h3 { font-size: 16px; font-weight: 590; letter-spacing: -0.2px; }
h4 { font-size: 14px; font-weight: 590; }
p { margin: 0 0 12px; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------------------------------------------------------------- focus -- */
:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--r-xs);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--r-md) 0;
}
.skip-link:focus { left: 0; }

/* --------------------------------------------------------------- layout -- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar-brand img { width: 28px; height: 28px; display: block; }
.sidebar-brand span { font-weight: 590; font-size: 16px; letter-spacing: -0.3px; }

.nav { padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  padding: 14px 10px 6px;
  font-weight: 510;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 510;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav a svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.85; }

.sidebar-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-user { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.sidebar-user strong { color: var(--text-secondary); font-weight: 510; font-size: 13px; }
.sidebar-user span { color: var(--text-faint); font-size: 11.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 16, 17, 0.85);
  backdrop-filter: blur(18px) saturate(180%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 17px; font-weight: 590; letter-spacing: -0.2px; }
.topbar .spacer { flex: 1; }

.content { padding: 24px; max-width: var(--maxw); width: 100%; }

/* ---------------------------------------------------------------- cards -- */
.card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.card-header h2, .card-header h3 { flex: 1; }
.card-sub { color: var(--text-muted); font-size: 13px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* --------------------------------------------------------------- stats -- */
.stat {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  font-weight: 510;
  margin-bottom: 8px;
}
.stat-value { font-size: 30px; font-weight: 510; letter-spacing: -1px; line-height: 1; }
.stat-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }

/* --------------------------------------------------------------- score -- */
.score-ring { display: inline-flex; align-items: center; gap: 8px; }
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  font-weight: 590;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
}
.score-good { color: var(--pass); background: var(--pass-bg); border-color: rgba(63,185,80,.3); }
.score-ok   { color: var(--warn); background: var(--warn-bg); border-color: rgba(210,153,34,.3); }
.score-warn { color: var(--error); background: var(--error-bg); border-color: rgba(219,109,40,.3); }
.score-bad  { color: var(--fail); background: var(--fail-bg); border-color: rgba(248,81,73,.3); }
.score-none { color: var(--text-muted); background: var(--info-bg); }

/* -------------------------------------------------------------- status -- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 590;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-pass  { color: var(--pass);  background: var(--pass-bg);  border-color: rgba(63,185,80,.25); }
.st-warn  { color: var(--warn);  background: var(--warn-bg);  border-color: rgba(210,153,34,.25); }
.st-fail  { color: var(--fail);  background: var(--fail-bg);  border-color: rgba(248,81,73,.25); }
.st-info  { color: var(--info);  background: var(--info-bg);  border-color: rgba(138,143,152,.2); }
.st-error { color: var(--error); background: var(--error-bg); border-color: rgba(219,109,40,.25); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 510;
}

/* ------------------------------------------------------------- buttons -- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 510;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; border-color: var(--border-strong); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-danger { color: var(--fail); border-color: rgba(248,81,73,.35); }
.btn-danger:hover { background: var(--fail-bg); color: var(--fail); border-color: var(--fail); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  font-weight: 510;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
td.num { font-variant-numeric: tabular-nums; }
td.mono, th.mono { font-family: var(--mono); font-size: 12.5px; }

/* --------------------------------------------------------------- forms -- */
.form-row { margin-bottom: 16px; }
.form-row:last-child { margin-bottom: 0; }
label, .label {
  display: block;
  font-size: 12.5px;
  font-weight: 510;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 90px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8f98' d='M2 4l4 4 4-4z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.checkbox-row { display: flex; align-items: flex-start; gap: 9px; }
.checkbox-row input[type="checkbox"], .checkbox-row input[type="radio"] {
  width: 16px; height: 16px; margin-top: 3px; accent-color: var(--accent); flex: 0 0 16px;
}
.checkbox-row label { margin: 0; font-weight: 400; color: var(--text-secondary); font-size: 13.5px; }

.field-error { color: var(--fail); font-size: 12.5px; margin-top: 6px; }

/* -------------------------------------------------------------- alerts -- */
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert-success { background: var(--pass-bg); border-color: rgba(63,185,80,.3); color: #b7f0c0; }
.alert-error   { background: var(--fail-bg); border-color: rgba(248,81,73,.3); color: #ffc9c5; }
.alert-warn    { background: var(--warn-bg); border-color: rgba(210,153,34,.3); color: #f5dfa5; }
.alert-info    { background: var(--accent-soft); border-color: rgba(113,112,255,.3); color: #cdd0ff; }
.alert strong { font-weight: 590; }

/* --------------------------------------------------------------- misc --- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty h3 { color: var(--text-secondary); margin-bottom: 8px; }
.empty p { max-width: 420px; margin: 0 auto 16px; }

.divider { height: 1px; background: var(--border-subtle); margin: 20px 0; border: 0; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; } .mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.flex-1 { flex: 1; } .wrap { flex-wrap: wrap; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }

pre.record {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.include-tree {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
}

/* ------------------------------------------------------------ progress -- */
.progress {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.3s ease;
}

/* ------------------------------------------------------------ timeline -- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5px; top: 4px; bottom: 4px;
  width: 1px;
  background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -21px; top: 5px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--text-faint);
}
.timeline-item.added::before   { border-color: var(--pass); }
.timeline-item.removed::before { border-color: var(--fail); }
.timeline-item.changed::before { border-color: var(--warn); }
.timeline-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timeline-body { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.diff-before { color: var(--fail); }
.diff-after { color: var(--pass); }

/* --------------------------------------------------------------- chart -- */
.chart { width: 100%; height: 180px; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-top: 8px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------------------------------------------------------------- auth -- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(94, 106, 210, 0.16), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 24px; text-align: center; }
.auth-brand img { width: 52px; height: 52px; }
.auth-brand h1 { font-size: 22px; }
.auth-brand p { color: var(--text-muted); font-size: 13.5px; margin: 0; }
.auth-foot { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-faint); }

.qr-box {
  background: #fff;
  padding: 12px;
  border-radius: var(--r-md);
  display: inline-block;
  line-height: 0;
}
.qr-box svg { width: 190px; height: 190px; display: block; }

.secret-box {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 1.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  text-align: center;
  word-break: break-all;
  user-select: all;
}

.codes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
}
.codes-grid div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  text-align: center;
  letter-spacing: 1px;
}

/* -------------------------------------------------------------- modal --- */
dialog.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text);
  padding: 24px;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: rgba(0, 0, 0, 0.5) 0 16px 48px;
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.72); }
dialog.modal h2 { margin-bottom: 12px; }

details.disclosure { border: 1px solid var(--border); border-radius: var(--r-md); margin-top: 12px; }
details.disclosure > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 510;
  color: var(--text-secondary);
  list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: "▸ "; color: var(--text-faint); }
details.disclosure[open] > summary::before { content: "▾ "; }
details.disclosure > div { padding: 0 14px 14px; }

/* -------------------------------------------------------- responsive --- */
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--border-subtle);
  }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-label { display: none; }
  .nav a { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  h1 { font-size: 22px; }
}

@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}

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