/**
 * dashboard.css
 * WebhookWise Dashboard — Design System & Base Styles
 */

/* ═══════════════════════════════════════════════════════════════════════════
   Design Tokens
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Dark-first ops console ──────────────────────────────────────────────
     Designed for the screen this actually lives on: a wall display or a
     second monitor someone glances at for hours. Dark is the base state
     (no class), light is an override, because that is what "dark-first"
     has to mean structurally or the light values keep leaking through.

     Three rules the palette follows:
     1. Colour carries MEANING, never decoration. One interactive accent;
        everything else coloured is a severity or a state.
     2. Backgrounds step in small, even increments so elevation reads
        without borders shouting.
     3. Never pure black (#000) — it makes text edges vibrate over hours. */

  /* Interactive. The only "brand" colour, and it means "you can act here". */
  --primary: #58a6ff;
  --primary-hover: #79b8ff;
  --primary-light: #1f3350;
  --primary-bg: rgba(88, 166, 255, 0.09);
  --accent: #58a6ff;
  --accent-bg: rgba(88, 166, 255, 0.09);
  --accent-gradient: linear-gradient(135deg, #58a6ff, #388bfd);

  /* Severity. Tuned for legibility on the dark base, not for brightness:
     these get scanned peripherally, so hue must separate them, not chroma. */
  --success: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.09);
  --warning: #f5a524;
  --warning-bg: rgba(245, 165, 36, 0.09);
  --danger: #ff6169;
  --danger-bg: rgba(255, 97, 105, 0.09);
  --info: #58a6ff;
  --info-bg: rgba(88, 166, 255, 0.09);

  /* Neutrals: even elevation steps over a near-black blue-grey. */
  --text-main: #e6e9ef;
  --text-secondary: #9aa4b5;
  --text-muted: #6b7688;
  --border: #232935;
  --border-light: #1a1f29;
  --bg-base: #0b0e14;
  --bg-surface: #11151d;
  --bg-subtle: #1a202b;
  --bg-elevated: #161b24;

  /* Dark UI reads depth from borders and background steps, not from drop
     shadows; keep shadows for genuinely floating layers only. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, 0.7);
  --ring-primary: 0 0 0 3px rgba(88, 166, 255, 0.28);

  /* Tighter radii than the previous design: an ops table of hard numbers
     looks flimsy in pill shapes. */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', Consolas, monospace;

  /* Code surfaces (raw payloads, AI dumps, JSON viewer). One family of
     tokens so every mono block reads as the same material in both themes —
     the old component carried its own hardcoded slate palette and stayed a
     dark island inside the light theme. */
  --code-bg: #0a0d13;
  --code-fg: #d7dde6;
  --code-key: #79b8ff;
  --code-string: #f0a6ca;
  --code-number: #7ee2a8;
  --code-literal: #6fd7e8;
}

/* ── Light override ──────────────────────────────────────────────────────
   Kept fully usable for daylight and for screenshots, but it is the
   override: dark is what the design is tuned against. */
.theme-light {
  --primary: #0969da;
  --primary-hover: #0550ae;
  --primary-light: #ddf4ff;
  --primary-bg: #ddf4ff;
  --accent: #0969da;
  --accent-bg: #ddf4ff;
  --accent-gradient: linear-gradient(135deg, #0969da, #0550ae);

  --success: #1a7f37;
  --success-bg: #dafbe1;
  --warning: #9a6700;
  --warning-bg: #fff8c5;
  --danger: #cf222e;
  --danger-bg: #ffebe9;
  --info: #0969da;
  --info-bg: #ddf4ff;

  --text-main: #1f2328;
  --text-secondary: #59636e;
  --text-muted: #818b98;
  --border: #d1d9e0;
  --border-light: #e4e8ec;
  --bg-base: #f6f8fa;
  --bg-surface: #ffffff;
  --bg-subtle: #f0f3f6;
  --bg-elevated: #ffffff;

  --shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.06);
  --shadow-md: 0 3px 8px rgba(31, 35, 40, 0.10);
  --shadow-lg: 0 12px 28px rgba(31, 35, 40, 0.16);
  --ring-primary: 0 0 0 3px rgba(9, 105, 218, 0.24);

  --code-bg: #f6f8fa;
  --code-fg: #1f2328;
  --code-key: #0550ae;
  --code-string: #b31d5b;
  --code-number: #1a7f37;
  --code-literal: #0e7490;
}

/* Motion is decoration here, never information — honour the OS setting. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Tighten Inter's rendering for a crisper, more premium feel. */
html { -webkit-text-size-adjust: 100%; }
body { text-rendering: optimizeLegibility; -moz-osx-font-smoothing: grayscale; }
/* Any figure an operator compares column-to-column must align. */
.stat-value, .info-value, .outbox-id, .da-summary-runtime, .da-duration, .kbd,
.alert-time, .badge, td, .metric, .count { font-variant-numeric: tabular-nums; }

/* ═══════════════════════════════════════════════════════════════════════════
   CSS Reset & Base
   ═══════════════════════════════════════════════════════════════════════════ */

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

/* Subtle slate scrollbars (WebKit + Firefox). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: padding-box; }

body {
  font-family: var(--font-sans);
  /* Flat. The previous design floated two indigo light sources over the page;
     on a console that is read for hours it is decoration competing with the
     only thing that should draw the eye, which is a severity colour. */
  background: var(--bg-base);
  color: var(--text-main);
  /* 1.7 was a reading-page rhythm. An operator scans rows, so trade the air
     for how many alerts fit above the fold. */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Navbar
   ═══════════════════════════════════════════════════════════════════════════ */

.navbar {
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.03), 0 8px 24px -18px rgba(16, 24, 40, 0.35);
}

.theme-light .navbar {
  background: rgba(255, 255, 255, 0.88);
}

.navbar-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 64px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.02em;
}

.logo .icon { color: var(--primary); }






/* Gradient underline that grows in, instead of a flat border. */


.nav-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

/* Utility actions are chrome, not content: ghost until hovered. Five bordered
   chips in a row outweighed every real signal on the bar (worst in the light
   theme, where they rendered as a run of solid blocks). */
.nav-actions .btn,
.nav-actions .btn-icon {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.nav-actions .btn:hover,
.nav-actions .btn-icon:hover {
  background: var(--bg-subtle);
  border-color: var(--border);
  transform: none;
  box-shadow: none;
}

/* Compact health indicator: just a pulsing dot, with the full status in a
   tooltip — replaces the verbose "Service running" pill to declutter the bar. */
.nav-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14);
  margin: 0 0.35rem;
  flex: 0 0 auto;
  cursor: default;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  /* Healthy breathes too — a still dot reads as a dead pixel. Slower and
     shallower than the unhealthy states on purpose: "alive" and "look at me"
     must not move the same way. */
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

/* Healthy is STILL. This dot pulsed forever, so the one moving thing in the
   toolbar was the thing with nothing to report; motion now means something
   needs looking at. */
.nav-status-dot.is-degraded {
  background: var(--warning);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.18);
  animation: pulse 2s infinite;
}
.nav-status-dot.is-offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
  animation: pulse 1s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .nav-status-dot.is-degraded,
  .nav-status-dot.is-offline { animation: none; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Visually-hidden but exposed to assistive tech (icon buttons keep their label
   for screen readers while showing only the icon). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Square icon-only buttons for the nav utility actions. */
.btn-icon {
  padding: 0;
  width: 38px;
  height: 38px;
  justify-content: center;
  gap: 0;
  font-size: var(--fs-lg);
}

.btn-icon.btn-lang {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════════════════════════════ */

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  background: var(--bg-surface);
  border-color: var(--primary-light);
  color: var(--text-main);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn.active {
  background: var(--primary-bg);
  border-color: var(--primary-light);
  color: var(--primary-hover);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  font-weight: 600;
  border-color: transparent;
  box-shadow: 0 2px 6px -1px rgba(99, 102, 241, 0.45);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--accent));
  border-color: transparent;
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -4px rgba(99, 102, 241, 0.5);
}

/* Tonal button variants. These class names were already used all over the
   renderers (quick-silence, dead-letter replay, the danger confirm in
   wwConfirm) but never defined, so every "dangerous" button rendered as a
   plain one. Colour stays in the point — text and border — never a fill. */
.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.btn-warn {
  color: var(--warning);
  border-color: var(--warning);
}

.btn-warn:hover {
  background: var(--warning-bg);
  border-color: var(--warning);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-subtle);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: var(--fs-xs);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════════════════════════════════ */

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease-in;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Stats Cards
   ═══════════════════════════════════════════════════════════════════════════ */

.stats-section {
  margin-bottom: 2rem;
}

.section-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

/* Small gradient tick before each section label. */
.section-title::before {
  content: "";
  width: 3px;
  height: 0.95em;
  border-radius: 2px;
  background: var(--accent-gradient);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

.stat-card {
  position: relative;
  background: var(--bg-surface);
  padding: 1.5rem;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.22s ease, border-color 0.22s ease;
  overflow: hidden;
}

/* Hairline gradient accent along the top edge — subtle, premium. */
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent-gradient);
  opacity: 0;
  transform: scaleX(0.4);
  transform-origin: left;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg);
}

.stat-card:hover::before { opacity: 1; transform: scaleX(1); }

.stat-label {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

/* Captions are context, not celebration: muted by default. Anything green
   here painted "20 failed" and "170 need attention" as good news; colour in
   a caption must be earned by a real state span, never by the container. */
.stat-trend {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.stat-trend.tone-warn { color: var(--warning); }
.stat-trend.tone-crit { color: var(--danger); }

/* Overview band: queue health beside skip reasons instead of two lonely
   full-width strips over an empty bottom half. */
.ov-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  align-items: stretch;
}

@media (max-width: 960px) {
  .ov-row { grid-template-columns: 1fr; }
}

/* Row-level primary action: accent at the point (text/border), not a filled
   pill repeated twenty times down the inbox. */
.btn-quiet-primary {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, transparent);
  background: transparent;
}

.btn-quiet-primary:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
  color: var(--primary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Filter Bar
   ═══════════════════════════════════════════════════════════════════════════ */

.filter-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.filter-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 1rem;
}

/* Single-row variant: six controls, search widest. Collapses stepwise so
   narrow screens never get six 90px selects. */
.filter-grid-inline {
  grid-template-columns: minmax(180px, 2fr) repeat(5, minmax(120px, 1fr));
  gap: 0.75rem;
}

@media (max-width: 1180px) {
  .filter-grid-inline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .filter-grid-inline { grid-template-columns: 1fr 1fr; }
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  background: var(--bg-base);
  transition: all 0.2s;
}

.filter-input {
  color: var(--text-main);
}

.filter-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-surface);
  box-shadow: var(--ring-primary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Form Elements
   ═══════════════════════════════════════════════════════════════════════════ */

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  background: var(--bg-surface);
  /* Never declared a colour, so it inherited the UA default — near-black text
     on a near-black surface. Legible in light mode by luck, unreadable in the
     dark theme that is this dashboard's default. */
  color: var(--text-main);
  transition: all 0.2s;
}

.form-input::placeholder { color: var(--text-muted); }
/* Password managers and Chromium's autofill repaint the field with their own
   light background; the inset shadow trick keeps the themed surface. */
.form-input:-webkit-autofill,
.form-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-surface) inset;
  caret-color: var(--text-main);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring-primary);
}

.form-input:disabled {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Info Grid (Overview tab)
   ═══════════════════════════════════════════════════════════════════════════ */

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  padding: 0.5rem 0;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.info-value {
  font-size: var(--fs-md);
  color: var(--text-main);
  font-family: var(--font-mono);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Tab Panels (AI Cost, Deep Analyses, Forward Rules)
   ═══════════════════════════════════════════════════════════════════════════ */

.ai-cost-section,
.forward-rules-section,
.deep-analyses-section {
  padding: 20px 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════════════════════════════════════ */

#toastContainer {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 10000;
  pointer-events: none;
}

/* Colour stays in a point (the 3px state edge) on an opaque elevated surface,
   so toasts stay readable over any content and follow both themes. */
.toast {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.45;
  white-space: pre-wrap;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease-out;
  max-width: 420px;
  pointer-events: auto;
}

.toast--success { border-left-color: var(--success); }
.toast--error { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast--info { border-left-color: var(--info); }

.toast-exit {
  animation: toastOut 0.3s ease-in forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(1rem); }
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 1280px) and (min-width: 769px) {
  .navbar { padding: 0 1rem; }
  .logo { font-size: var(--fs-lg); }
  .nav-actions { gap: 0.2rem; }
  .btn-icon {
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0 1rem;
    margin: 1rem auto;
  }

  .navbar {
    padding: 0 1rem;
  }

  /* Two rows, not five: [menu · logo ······ actions] over [breadcrumb · search].
     A column layout gave every child its own row and the chrome ate a third
     of a phone screen before any content. */
  .navbar-content {
    flex-direction: row;
    flex-wrap: wrap;
    height: auto;
    padding: 0.6rem 0;
    gap: 0.5rem 0.75rem;
    align-items: center;
  }

  .sidebar-toggle-mobile { order: 0; }
  .logo { order: 1; }
  #incidentsBadge { order: 2; }

  .nav-actions {
    order: 3;
    margin-left: auto;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
  }

  .breadcrumb {
    order: 4;
    flex: 0 1 auto;
    margin-left: 0;
    padding-left: 2px;
    border-left: none;
  }

  .palette-trigger {
    order: 5;
    flex: 1 1 160px;
  }

  /* Icon buttons keep their square size on mobile rather than stretching. */
  .nav-actions .btn-icon {
    flex: 0 0 auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  .stat-card {
    padding: 1rem;
    border-radius: var(--radius-lg);
  }

  .stat-value {
    font-size: 1.45rem;
  }

  .filter-section { padding: 1rem; }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
  }

  .section-header > div, .section-header > button {
    width: 100%;
    flex-wrap: wrap;
  }

  .section-header select { flex: 1; }

  .noise-center-grid {
    grid-template-columns: 1fr !important;
  }

}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}


/* ── Form controls must not fall back to platform chrome ──────────────────
   WebKit renders <select>, <input type="search"> and friends with native
   macOS appearance and IGNORES `background` unless appearance is turned off.
   So on Safari the filter row came out as a white search field and a light
   grey dropdown in the middle of a dark page — the CSS was correct and simply
   was not being applied. Firefox honours the background, which is why this
   survived every screenshot taken here. */
.form-input,
.filter-input,
select.form-input,
select.filter-input,
input[type="search"].filter-input,
input[type="search"].form-input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  color: var(--text-main);
}

/* Turning appearance off also removes the dropdown arrow, so it has to be
   drawn — as a token-coloured chevron, not a hex literal. */
select.form-input,
select.filter-input {
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
                    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 2px), calc(100% - 10px) calc(50% + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* The native search cancel button is a dark-on-dark blob once the field is
   themed; the field clears fine without it. */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

.filter-input::placeholder { color: var(--text-muted); }

/* Autofill repaints with the browser's own light background and drags the
   text colour with it — same treatment as .form-input. */
.filter-input:-webkit-autofill,
.filter-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-base) inset;
  caret-color: var(--text-main);
}


/* ── Every form control, whether or not it remembered a class ─────────────
   The class-based rules missed six controls that carry only inline layout
   styles (the payload sandbox's source field and its textarea among them),
   and `textarea` had no rule anywhere in the stylesheet at all — so those
   stayed white-on-white in the dark theme after the .form-input fix.

   Typing the ELEMENT is the fix that ends the game: a control cannot forget
   to be an input. Checked first that no inline style declares background or
   color, so nothing here is fighting a `style=` attribute it would lose to.
   Class rules still win where they are more specific. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
textarea,
select {
  background-color: var(--bg-base);
  color: var(--text-main);
  border-color: var(--border);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

/* Turning appearance off deletes the native arrow, so EVERY select needs the
   drawn one and the room to put it — not just the two that carry a class.
   Scoping the arrow to .form-input/.filter-input left the others with no
   arrow at all and text running to the edge. */
select {
  /* Left/right padding lives here now. Seven selects carried their own inline
     padding, which beat the stylesheet and squeezed the drawn arrow into the
     text — the inline styles are gone rather than fought with !important. */
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
                    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 2px), calc(100% - 10px) calc(50% + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;   /* Firefox dims placeholders by default; the token already is muted. */
}

textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono, ui-monospace, monospace);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring-primary);
}

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--text-main);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-base) inset;
  caret-color: var(--text-main);
}


/* The popup list is drawn by the OS, which picks its own colours unless the
   select declares them. Left alone it opens as a light grey sheet over a dark
   page — the one part of a themed control the page does not own. */
select option {
  background: var(--bg-surface);
  color: var(--text-main);
}

/* The investigator's own progress, streamed while a run is pending. Monospace
   and scrolled: it is a transcript, not prose. */
.da-live {
  margin-top: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.5rem 0.6rem;
  background: var(--bg-subtle, rgba(127, 127, 127, 0.06));
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text-secondary);
}
.da-live-bar { margin-top: 0.4rem; }

/* Picking an alert rule off the traffic, because the match is exact and a typo
   excludes nothing silently. */
.ir-picker-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; margin-top: 6px; }
.ir-pick { display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 7px 10px; background: none;
  border: none; border-bottom: 1px solid var(--border); color: var(--text-main); cursor: pointer; text-align: left; }
.ir-pick:last-child { border-bottom: none; }
.ir-pick:hover { background: var(--bg-subtle, rgba(127,127,127,0.08)); }
.ir-pick-name { font-size: var(--fs-sm); }
.ir-pick-meta { font-size: var(--fs-sm); color: var(--text-secondary); white-space: nowrap; }

/* Shift handoff: a few counts, then the brief itself in monospace because it
   is markdown meant to be copied, not read as prose. */
.handoff-window { display: flex; gap: 8px; margin-bottom: 14px; }
.handoff-sources { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: 12px; }
.handoff-brief-bar { margin-bottom: 6px; }
/* Layout only — the code surface itself is .ww-pre, the one shared design. */
.handoff-brief { max-height: 320px; overflow-y: auto; white-space: pre-wrap; font-size: var(--fs-sm); line-height: 1.6; }
.audit-list { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.25rem 0.9rem; }
.audit-row { display: flex; gap: 10px; align-items: baseline; padding: 0.55rem 0; border-top: 1px solid var(--border); }
.audit-row:first-child { border-top: 0; }
.audit-row .badge { flex-shrink: 0; }
.audit-what { flex: 1; color: var(--text-main); min-width: 0; overflow-wrap: anywhere; }
.audit-who { color: var(--text-secondary); font-size: var(--fs-sm); white-space: nowrap; }
