/* ==========================================================================
   EpiTrace Design System v2 — Contact Tracing Dashboard
   All visual tokens are CSS custom properties.
   To reskin: override the :root variables in a downstream stylesheet.
   ========================================================================== */

/* --------------------------------------------------------------------------
   LAYER 1 — Raw Palette (internal use only — don't reference in components)
   -------------------------------------------------------------------------- */
:root {
  --palette-navy-950:  #060910;
  --palette-navy-900:  #0b0f1a;
  --palette-navy-800:  #131928;
  --palette-navy-700:  #1a2035;
  --palette-navy-600:  #212840;
  --palette-navy-500:  #2d3654;

  --palette-blue-300:  #93c5fd;
  --palette-blue-400:  #60a5fa;
  --palette-blue-500:  #4f8ef7;
  --palette-blue-600:  #3b78e7;

  --palette-violet-400: #a78bfa;
  --palette-violet-500: #7c6af7;

  --palette-teal-400:   #2dd4bf;
  --palette-teal-500:   #14b8a6;
  --palette-teal-600:   #0d9488;

  --palette-red-400:    #f87171;
  --palette-red-500:    #ef4444;
  --palette-red-600:    #dc2626;

  --palette-orange-400: #fb923c;
  --palette-orange-500: #f97316;
  --palette-orange-600: #ea580c;

  --palette-amber-400:  #fbbf24;
  --palette-amber-500:  #f59e0b;
  --palette-amber-600:  #d97706;

  --palette-green-400:  #34d399;
  --palette-green-500:  #10b981;
  --palette-green-600:  #059669;

  --palette-slate-300:  #cbd5e1;
  --palette-slate-400:  #94a3b8;
  --palette-slate-500:  #64748b;
  --palette-slate-600:  #475569;
  --palette-slate-700:  #334155;
}

/* --------------------------------------------------------------------------
   LAYER 2 — Semantic Tokens (use these everywhere in component CSS)
   -------------------------------------------------------------------------- */
:root {
  /* Backgrounds */
  --color-bg:          var(--palette-navy-900);
  --color-bg-surface:  var(--palette-navy-800);
  --color-bg-panel:    var(--palette-navy-700);
  --color-bg-elevated: var(--palette-navy-600);
  --color-bg-input:    var(--palette-navy-800);

  /* Brand */
  --color-brand:        var(--palette-blue-500);
  --color-brand-hover:  var(--palette-blue-400);
  --color-brand-dim:    rgba(79, 142, 247, 0.12);
  --color-brand-border: rgba(79, 142, 247, 0.35);

  /* Case status */
  --color-confirmed:    var(--palette-red-500);
  --color-suspected:    var(--palette-amber-500);
  --color-recovered:    var(--palette-green-500);
  --color-deceased:     var(--palette-slate-500);

  --color-confirmed-bg: rgba(239, 68,  68,  0.12);
  --color-suspected-bg: rgba(245, 158, 11,  0.12);
  --color-recovered-bg: rgba(16,  185, 129, 0.12);
  --color-deceased-bg:  rgba(100, 116, 139, 0.12);

  /* Generation colors (transmission chain coloring) */
  --color-gen-0:  #dc2626;   /* Patient zero — deep red */
  --color-gen-1:  #ea580c;   /* Generation 1 — orange */
  --color-gen-2:  #ca8a04;   /* Generation 2 — amber */
  --color-gen-3:  #16a34a;   /* Generation 3 — green */
  --color-gen-4:  #2563eb;   /* Generation 4+ — blue */

  --color-gen-0-bg: rgba(220, 38,  38,  0.15);
  --color-gen-1-bg: rgba(234, 88,  12,  0.15);
  --color-gen-2-bg: rgba(202, 138, 4,   0.15);
  --color-gen-3-bg: rgba(22,  163, 74,  0.15);
  --color-gen-4-bg: rgba(37,  99,  235, 0.15);

  /* Exposure / transmission risk */
  --color-risk-intimate:  var(--palette-red-500);
  --color-risk-prolonged: var(--palette-amber-500);
  --color-risk-brief:     var(--palette-blue-400);

  --color-risk-intimate-bg:  rgba(239, 68,  68,  0.15);
  --color-risk-prolonged-bg: rgba(245, 158, 11,  0.15);
  --color-risk-brief-bg:     rgba(96,  165, 250, 0.15);

  /* Node types (chain graph) */
  --color-node-case:     var(--palette-blue-400);
  --color-node-exposure: var(--palette-slate-400);
  --color-node-flight:   var(--palette-teal-400);
  --color-node-port:     var(--palette-green-500);

  /* Edge types */
  --color-edge-infected-by:   var(--palette-red-400);
  --color-edge-exposed-to:    var(--palette-slate-500);
  --color-edge-traveled-on:   var(--palette-teal-400);
  --color-edge-flight:        var(--palette-blue-400);
  --color-edge-cabin:         var(--palette-red-400);
  --color-edge-dining:        var(--palette-violet-400);
  --color-edge-deck:          var(--palette-amber-400);
  --color-edge-crew:          var(--palette-orange-400);
  --color-edge-hvac:          var(--palette-slate-400);
  --color-edge-default:       var(--palette-slate-500);

  /* Flight risk levels */
  --color-risk-high:   var(--palette-red-500);
  --color-risk-medium: var(--palette-amber-500);
  --color-risk-low:    var(--palette-blue-400);
  --color-risk-minimal: var(--palette-slate-600);
  --color-risk-source: #ff0000;

  /* Text */
  --color-text:       #e2e8f0;
  --color-text-muted: var(--palette-slate-400);
  --color-text-faint: var(--palette-slate-600);

  /* Borders */
  --color-border:       rgba(255, 255, 255, 0.07);
  --color-border-mid:   rgba(255, 255, 255, 0.12);
  --color-border-focus: var(--palette-blue-500);

  /* --------------------------------------------------------------------------
     Typography
     -------------------------------------------------------------------------- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --text-xs:   0.6875rem;
  --text-sm:   0.8125rem;
  --text-base: 0.9375rem;
  --text-lg:   1.0625rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;

  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  --leading-tight: 1.25;
  --leading-base:  1.5;

  /* --------------------------------------------------------------------------
     Spacing
     -------------------------------------------------------------------------- */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;

  /* --------------------------------------------------------------------------
     Shape & Effects
     -------------------------------------------------------------------------- */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  --shadow-sm:  0 1px 3px  rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 8px 28px rgba(0, 0, 0, 0.6);
  --shadow-xl:  0 16px 48px rgba(0, 0, 0, 0.7);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 120ms;
  --duration-base: 220ms;
  --duration-slow: 380ms;

  /* --------------------------------------------------------------------------
     Layout dims
     -------------------------------------------------------------------------- */
  --sidebar-width:   272px;
  --header-height:   60px;
  --tab-nav-height:  42px;
  --controls-height: 52px;
}

/* ==========================================================================
   Global Reset + Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: var(--leading-base);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   App Layout — 4-row × 2-col Grid
   ========================================================================== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) var(--tab-nav-height) 1fr var(--controls-height);
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
  grid-column: 1 / -1;
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}
.header-brand-icon {
  width: 30px; height: 30px;
  background: var(--color-brand-dim);
  border: 1px solid var(--color-brand-border);
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  font-size: 15px;
}
.header-brand-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}
.header-brand-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 1px;
}

.header-divider { width: 1px; height: 32px; background: var(--color-border); flex-shrink: 0; }

.header-stats { display: flex; gap: var(--space-2); flex: 1; overflow: hidden; }

.stat-chip {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  border: 1px solid transparent;
}
.stat-chip--total     { background: var(--color-bg-elevated); color: var(--color-text); border-color: var(--color-border-mid); }
.stat-chip--confirmed { background: var(--color-confirmed-bg); color: var(--color-confirmed); border-color: rgba(239,68,68,0.4); }
.stat-chip--suspected { background: var(--color-suspected-bg); color: var(--color-suspected); border-color: rgba(245,158,11,0.4); }
.stat-chip--recovered { background: var(--color-recovered-bg); color: var(--color-recovered); border-color: rgba(16,185,129,0.4); }
.stat-chip-count { font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }

.scraper-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  white-space: nowrap;
  cursor: default;
  background: var(--color-surface-2);
}
.scraper-run-btn {
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.scraper-run-btn:hover:not(:disabled) {
  background: var(--color-accent, #3b82f6);
  border-color: var(--color-accent, #3b82f6);
  color: #fff;
}
.scraper-run-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.scraper-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-faint);
  flex-shrink: 0;
  transition: background 0.3s;
}
.scraper-status-dot--ok      { background: #22c55e; box-shadow: 0 0 5px #22c55e88; }
.scraper-status-dot--error   { background: #ef4444; box-shadow: 0 0 5px #ef444488; }
.scraper-status-dot--loading { background: #f59e0b; box-shadow: 0 0 5px #f59e0b88; }

.header-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
#csv-file-input { display: none; }

/* ==========================================================================
   Tab Navigation
   ========================================================================== */
.tab-nav {
  grid-column: 1 / -1;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: var(--tab-nav-height);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--duration-fast), border-color var(--duration-fast);
  position: relative;
}
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active {
  color: var(--color-brand);
  border-bottom-color: var(--color-brand);
}
.tab-btn .tab-icon { font-size: 14px; }
.tab-badge {
  font-size: 10px;
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  padding: 1px 5px;
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
}
.tab-btn.active .tab-badge {
  background: var(--color-brand-dim);
  color: var(--color-brand);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  background: var(--color-bg-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.sidebar-section {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
}

.search-input-wrap { position: relative; }
.search-input-wrap svg {
  position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%);
  color: var(--color-text-faint); width: 13px; height: 13px; pointer-events: none;
}
.search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-3) + 18px);
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--duration-fast);
}
.search-input:focus { border-color: var(--color-border-focus); }
.search-input::placeholder { color: var(--color-text-faint); }

.filter-pills { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.filter-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  transition: opacity var(--duration-fast);
}
.filter-pill input[type="checkbox"] { display: none; }
.filter-pill--confirmed { background: var(--color-confirmed-bg); color: var(--color-confirmed); border-color: rgba(239,68,68,0.4); }
.filter-pill--suspected { background: var(--color-suspected-bg); color: var(--color-suspected); border-color: rgba(245,158,11,0.4); }
.filter-pill--recovered { background: var(--color-recovered-bg); color: var(--color-recovered); border-color: rgba(16,185,129,0.4); }
.filter-pill--all       { background: var(--color-bg-elevated); color: var(--color-text-muted); border-color: var(--color-border-mid); }
.filter-pill.inactive   { opacity: 0.35; }

/* Generation filter pills */
.filter-pill--gen-0 { background: var(--color-gen-0-bg); color: var(--color-gen-0); border-color: rgba(220,38,38,0.4); }
.filter-pill--gen-1 { background: var(--color-gen-1-bg); color: var(--color-gen-1); border-color: rgba(234,88,12,0.4); }
.filter-pill--gen-2 { background: var(--color-gen-2-bg); color: var(--color-gen-2); border-color: rgba(202,138,4,0.4); }
.filter-pill--gen-3 { background: var(--color-gen-3-bg); color: var(--color-gen-3); border-color: rgba(22,163,74,0.4); }

.case-list {
  flex: 1; overflow-y: auto; padding: var(--space-1) 0;
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.case-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: background var(--duration-fast);
  border-left: 2px solid transparent;
}
.case-item:hover { background: var(--color-bg-panel); }
.case-item.active { background: var(--color-brand-dim); border-left-color: var(--color-brand); }
.case-item.hidden { display: none; }

.case-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.case-dot--confirmed { background: var(--color-confirmed); }
.case-dot--suspected { background: var(--color-suspected); }
.case-dot--recovered { background: var(--color-recovered); }
.case-dot--deceased  { background: var(--color-deceased); }

.case-item-info { min-width: 0; flex: 1; }
.case-item-id   { font-size: var(--text-sm); font-weight: var(--weight-semibold); font-family: var(--font-mono); display: flex; align-items: center; gap: var(--space-1); }
.case-item-loc  { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-item-date { font-size: var(--text-xs); color: var(--color-text-faint); white-space: nowrap; font-family: var(--font-mono); }
.gen-badge {
  font-size: 9px; padding: 1px 4px;
  border-radius: 3px;
  font-weight: var(--weight-bold);
  font-family: var(--font-sans);
}
.gen-badge--0 { background: var(--color-gen-0-bg); color: var(--color-gen-0); }
.gen-badge--1 { background: var(--color-gen-1-bg); color: var(--color-gen-1); }
.gen-badge--2 { background: var(--color-gen-2-bg); color: var(--color-gen-2); }
.gen-badge--3 { background: var(--color-gen-3-bg); color: var(--color-gen-3); }

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex; gap: var(--space-2); flex-shrink: 0;
}
.sidebar-footer .btn { flex: 1; justify-content: center; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: var(--weight-medium);
  cursor: pointer; border: 1px solid transparent;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
  text-decoration: none; white-space: nowrap;
}
.btn--primary { background: var(--color-brand); color: #fff; border-color: var(--color-brand); }
.btn--primary:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); }
.btn--ghost { background: transparent; color: var(--color-text-muted); border-color: var(--color-border-mid); }
.btn--ghost:hover { background: var(--color-bg-elevated); color: var(--color-text); border-color: rgba(255,255,255,0.18); }
.btn--sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn--xs { padding: 2px var(--space-2); font-size: var(--text-xs); }
.btn--success { background: var(--color-recovered-bg); color: var(--color-recovered); border-color: rgba(16,185,129,0.4); }
.btn--success:hover { background: rgba(16,185,129,0.25); }

/* ==========================================================================
   Tab Content Area
   ========================================================================== */
.tab-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-pane {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.tab-pane.active { display: flex; flex-direction: column; }

/* ---------- Tab 1: Overview (Map) ---------- */
.overview-layout {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  min-height: 0;
}
.panel-header {
  height: 38px;
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  flex-shrink: 0;
}
.panel-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.panel-badge {
  font-size: var(--text-xs); color: var(--color-text-faint);
  background: var(--color-bg-elevated); padding: 1px var(--space-2);
  border-radius: var(--radius-full); font-variant-numeric: tabular-nums;
}
.panel-actions { margin-left: auto; display: flex; gap: var(--space-2); }
#map { flex: 1; min-height: 0; }

/* Legend */
.map-legend, .edge-legend {
  display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap;
}
.legend-item, .edge-legend-item {
  display: flex; align-items: center; gap: 4px;
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.edge-swatch { width: 18px; height: 2px; border-radius: 1px; }

/* ---------- Tab 2: Transmission Chains ---------- */
.chain-layout {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.chain-toolbar {
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; flex-wrap: wrap;
}
.chain-toolbar-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.08em;
}
.btn-group { display: flex; border: 1px solid var(--color-border-mid); border-radius: var(--radius-md); overflow: hidden; }
.btn-group .btn {
  border-radius: 0; border: none; border-right: 1px solid var(--color-border-mid);
  padding: 4px var(--space-3);
}
.btn-group .btn:last-child { border-right: none; }
.btn-group .btn.active { background: var(--color-brand-dim); color: var(--color-brand); }

.chain-legend {
  display: flex; gap: var(--space-4); flex-wrap: wrap;
}
.chain-legend-item {
  display: flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.chain-legend-node { width: 10px; height: 10px; border-radius: 50%; }
.chain-legend-node--square { border-radius: 2px; }
.chain-legend-node--diamond {
  width: 10px; height: 10px; border-radius: 1px;
  transform: rotate(45deg);
}

#chain-cy { flex: 1; min-height: 0; background: var(--palette-navy-950); }

/* Generation legend */
.gen-legend { display: flex; gap: var(--space-3); }
.gen-legend-item { display: flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--color-text-muted); }
.gen-dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Tab 3: Exposure Map ---------- */
.exposure-layout {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr;
  gap: 0; min-height: 0; overflow: hidden;
}
.exposure-deck-panel {
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.exposure-table-panel { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

.deck-view {
  flex: 1; overflow-y: auto; padding: var(--space-4);
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.deck-section { margin-bottom: var(--space-6); }
.deck-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: var(--space-2);
}
.cabin-cell {
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-1);
  text-align: center;
  font-size: var(--text-xs);
  border: 1px solid var(--color-border);
  background: var(--color-bg-panel);
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
  position: relative;
}
.cabin-cell:hover { border-color: var(--color-brand); }
.cabin-cell.has-case { background: var(--color-confirmed-bg); border-color: rgba(239,68,68,0.5); }
.cabin-cell.has-exposure { background: var(--color-suspected-bg); border-color: rgba(245,158,11,0.35); }
.cabin-cell.crew-area { background: var(--color-bg-elevated); }
.cabin-cell.selected { border-color: var(--color-brand); background: var(--color-brand-dim); }
.cabin-name { font-family: var(--font-mono); font-weight: var(--weight-semibold); color: var(--color-text); }
.cabin-indicator { margin-top: 2px; }
.cabin-case-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin: 0 1px; }

.exposure-table {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.exposure-row {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background var(--duration-fast);
}
.exposure-row:hover { background: var(--color-bg-panel); }
.exposure-row.selected { background: var(--color-brand-dim); }
.exposure-risk-badge {
  flex-shrink: 0; padding: 2px var(--space-2);
  border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em;
  width: 68px; text-align: center;
}
.risk-intimate  { background: var(--color-risk-intimate-bg);  color: var(--color-risk-intimate); }
.risk-prolonged { background: var(--color-risk-prolonged-bg); color: var(--color-risk-prolonged); }
.risk-brief     { background: var(--color-risk-brief-bg);     color: var(--color-risk-brief); }
.exposure-info { flex: 1; min-width: 0; }
.exposure-title { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text); }
.exposure-meta  { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.exposure-participants { margin-top: var(--space-1); display: flex; flex-wrap: wrap; gap: 4px; }
.participant-tag {
  font-family: var(--font-mono); font-size: 10px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--color-bg-elevated); color: var(--color-text-muted);
  cursor: pointer; transition: background var(--duration-fast);
}
.participant-tag:hover { background: var(--color-brand-dim); color: var(--color-brand); }
.participant-tag.active { background: var(--color-brand-dim); color: var(--color-brand); }

/* ---------- Tab 4: Flight Risk ---------- */
.flights-layout {
  flex: 1; display: grid; grid-template-columns: 220px 1fr;
  min-height: 0; overflow: hidden;
}
.flights-selector-panel {
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; overflow: hidden;
}
.flights-main-panel {
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.flights-main-inner {
  flex: 1; display: grid; grid-template-rows: auto 1fr;
  min-height: 0; overflow: hidden;
}

.flight-option {
  padding: var(--space-3) var(--space-4);
  cursor: pointer; border-bottom: 1px solid var(--color-border);
  transition: background var(--duration-fast);
  border-left: 2px solid transparent;
}
.flight-option:hover { background: var(--color-bg-panel); }
.flight-option.active { background: var(--color-brand-dim); border-left-color: var(--color-brand); }
.flight-number { font-family: var(--font-mono); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.flight-route { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.flight-date-badge { font-size: var(--text-xs); color: var(--color-text-faint); font-family: var(--font-mono); }

/* Seat map */
.seat-map-container {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  overflow-x: auto;
}
.seat-map-title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold); margin-bottom: var(--space-3);
  display: flex; align-items: center; gap: var(--space-3);
}
.seat-map-legend { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.seat-legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.seat-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.15); }

.seat-map-grid {
  display: flex; flex-direction: column; gap: 3px;
  margin-top: var(--space-3); overflow-x: auto; width: max-content;
}
.seat-row-header {
  display: flex; gap: 3px; align-items: center; margin-bottom: var(--space-1);
}
.seat-col-label {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); color: var(--color-text-faint); font-family: var(--font-mono);
}
.seat-aisle { width: 10px; }
.seat-row-num-label { width: 28px; font-size: var(--text-xs); color: var(--color-text-faint); font-family: var(--font-mono); text-align: right; padding-right: 4px; }
.seat-row { display: flex; gap: 3px; align-items: center; }
.seat {
  width: 26px; height: 26px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer; position: relative; flex-shrink: 0;
  transition: transform var(--duration-fast);
}
.seat:hover { transform: scale(1.2); z-index: 10; }
.seat--case-confirmed { background: rgba(220,38,38,0.8); border-color: #dc2626; color: #fff; }
.seat--case-suspected { background: rgba(245,158,11,0.8); border-color: #f59e0b; color: #fff; }
.seat--case-recovered { background: rgba(16,185,129,0.8); border-color: #10b981; color: #fff; }
.seat--risk-high      { background: rgba(239,68,68,0.35);  border-color: rgba(239,68,68,0.6); }
.seat--risk-medium    { background: rgba(245,158,11,0.25); border-color: rgba(245,158,11,0.5); }
.seat--risk-low       { background: rgba(96,165,250,0.15); border-color: rgba(96,165,250,0.35); }
.seat--risk-minimal   { background: var(--color-bg-panel); border-color: var(--color-border); color: var(--color-text-faint); }
.seat--empty          { background: var(--palette-navy-950); border-color: var(--color-border); }
.seat.selected        { outline: 2px solid var(--color-brand); outline-offset: 1px; z-index: 20; }

.seat-tooltip {
  position: fixed; z-index: 1000;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-mid);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  box-shadow: var(--shadow-lg);
  max-width: 200px;
  pointer-events: none;
  display: none;
}
.seat-tooltip.visible { display: block; }

/* Manifest table */
.manifest-table-wrap {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.manifest-table {
  width: 100%; border-collapse: collapse; font-size: var(--text-xs);
}
.manifest-table th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-weight: var(--weight-semibold);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0;
  background: var(--color-bg-surface);
  z-index: 1;
}
.manifest-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  font-family: var(--font-mono);
  vertical-align: middle;
}
.manifest-table tr:hover td { background: var(--color-bg-panel); }
.manifest-table tr.row--case td { background: var(--color-confirmed-bg); }
.manifest-table tr.selected td { background: var(--color-brand-dim); }
.risk-bar {
  display: flex; align-items: center; gap: var(--space-2);
}
.risk-fill {
  height: 6px; border-radius: 3px; min-width: 2px;
  transition: width var(--duration-base);
}
.risk-value { font-size: 10px; color: var(--color-text-muted); min-width: 32px; }

/* ---------- Tab 5: Timeline ---------- */
.timeline-layout {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.timeline-toolbar {
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; flex-wrap: wrap;
}
.gantt-wrapper {
  flex: 1; overflow: auto;
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
  background: var(--color-bg-surface);
}
#gantt-svg {
  display: block;
}

/* ==========================================================================
   Controls Bar (bottom)
   ========================================================================== */
.controls-bar {
  grid-column: 1 / -1;
  background: var(--color-bg-surface);
  border-top: 1px solid var(--color-border);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-5);
  z-index: 100;
}
.controls-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.08em;
  white-space: nowrap; flex-shrink: 0;
}
.controls-date-group { display: flex; align-items: center; gap: var(--space-2); }
.date-input {
  padding: var(--space-1) var(--space-2);
  background: var(--color-bg-input); border: 1px solid var(--color-border-mid);
  border-radius: var(--radius-md); color: var(--color-text);
  font-family: var(--font-sans); font-size: var(--text-xs); outline: none;
  transition: border-color var(--duration-fast); color-scheme: dark;
}
.date-input:focus { border-color: var(--color-border-focus); }
.controls-sep { color: var(--color-text-faint); font-size: var(--text-sm); }
.date-range-label {
  font-size: var(--text-xs); color: var(--color-text-muted);
  background: var(--color-bg-elevated); padding: 2px var(--space-2);
  border-radius: var(--radius-sm); font-family: var(--font-mono);
}
.controls-spacer { flex: 1; }

.tab-nav-spacer { flex: 1; }
.dealdossier-tab-link {
  display: inline-flex; align-items: center;
  padding: 0 14px; line-height: 0; flex-shrink: 0;
  border-left: 1px solid var(--color-border);
}
.dealdossier-tab-img {
  height: 36px; width: auto; max-width: 300px;
  object-fit: contain; opacity: 0.82;
  transition: opacity 0.15s;
}
.dealdossier-tab-link:hover .dealdossier-tab-img { opacity: 1; }
.export-group { display: flex; gap: var(--space-2); }

/* ==========================================================================
   Case Detail Panel (right slide-in)
   ========================================================================== */
.case-detail {
  position: fixed;
  top: calc(var(--header-height) + var(--tab-nav-height));
  right: 0;
  width: 300px;
  height: calc(100vh - var(--header-height) - var(--tab-nav-height) - var(--controls-height));
  background: var(--color-bg-surface);
  border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-out);
  z-index: 1500;
  box-shadow: var(--shadow-xl);
}
.case-detail.open { transform: translateX(0); }

.case-detail-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0;
}
.case-detail-close {
  margin-left: auto; background: none; border: none;
  color: var(--color-text-muted); cursor: pointer; font-size: 17px;
  padding: 2px; border-radius: var(--radius-sm);
  transition: color var(--duration-fast), background var(--duration-fast);
}
.case-detail-close:hover { color: var(--color-text); background: var(--color-bg-elevated); }
.case-detail-id { font-family: var(--font-mono); font-size: var(--text-lg); font-weight: var(--weight-bold); }

.case-detail-body {
  flex: 1; overflow-y: auto; padding: var(--space-4);
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.detail-field { margin-bottom: var(--space-4); }
.detail-field-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.07em;
  margin-bottom: var(--space-1);
}
.detail-field-value { font-size: var(--text-sm); color: var(--color-text); line-height: var(--leading-base); }
.detail-field-value--mono { font-family: var(--font-mono); }
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.status-badge--confirmed { background: var(--color-confirmed-bg); color: var(--color-confirmed); }
.status-badge--suspected { background: var(--color-suspected-bg); color: var(--color-suspected); }
.status-badge--recovered { background: var(--color-recovered-bg); color: var(--color-recovered); }
.status-badge--deceased  { background: var(--color-deceased-bg);  color: var(--color-deceased); }
.detail-connections { display: flex; flex-direction: column; gap: var(--space-2); }
.detail-connection-item {
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-panel); border-radius: var(--radius-md);
  border: 1px solid var(--color-border); font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}
.detail-connection-item:hover { border-color: var(--color-brand); background: var(--color-brand-dim); }
.detail-connection-id    { font-family: var(--font-mono); font-weight: var(--weight-semibold); }
.detail-connection-event { color: var(--color-text-muted); margin-top: 2px; }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal { display: none; position: fixed; inset: 0; z-index: 500; }
.modal.open { display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.65); backdrop-filter: blur(4px); }
.modal-content {
  position: relative; background: var(--color-bg-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl); width: 90%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent;
}
.modal-header {
  position: sticky; top: 0; background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-5);
  display: flex; align-items: center; gap: var(--space-3); z-index: 1;
}
.modal-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.modal-close {
  margin-left: auto; background: none; border: none;
  color: var(--color-text-muted); cursor: pointer; font-size: 20px;
  padding: 2px; border-radius: var(--radius-sm);
  transition: color var(--duration-fast), background var(--duration-fast);
}
.modal-close:hover { color: var(--color-text); background: var(--color-bg-elevated); }
.modal-body { padding: var(--space-5); }
.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: var(--space-3);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }
.form-group--full { grid-column: 1 / -1; }
.form-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.07em;
}
.form-label .required { color: var(--color-confirmed); }
.form-input, .form-select, .form-textarea {
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-input); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); color: var(--color-text);
  font-family: var(--font-sans); font-size: var(--text-sm); outline: none; width: 100%;
  transition: border-color var(--duration-fast); color-scheme: dark;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--color-border-focus); }
.form-input::placeholder { color: var(--color-text-faint); }
.form-select option { background: var(--color-bg-surface); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-section-title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border); padding-bottom: var(--space-2);
  margin-top: var(--space-2); grid-column: 1 / -1;
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-container {
  position: fixed; bottom: calc(var(--controls-height) + var(--space-4));
  right: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 1000; pointer-events: none;
}
.toast {
  padding: var(--space-3) var(--space-4); background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-mid); border-radius: var(--radius-md);
  font-size: var(--text-sm); box-shadow: var(--shadow-lg);
  animation: toast-in var(--duration-base) var(--ease-out);
  pointer-events: auto; max-width: 300px;
}
.toast--success { border-color: var(--color-recovered); color: var(--color-recovered); }
.toast--error   { border-color: var(--color-confirmed); color: var(--color-confirmed); }
.toast--info    { border-color: var(--color-brand);     color: var(--color-brand); }
@keyframes toast-in { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform:translateX(0); } }

/* ==========================================================================
   Leaflet overrides
   ========================================================================== */
.leaflet-control-zoom a { background: var(--color-bg-elevated) !important; color: var(--color-text) !important; border-color: var(--color-border) !important; }
.leaflet-control-zoom a:hover { background: var(--color-bg-panel) !important; }
.leaflet-bar { border: 1px solid var(--color-border) !important; }
.leaflet-popup-content-wrapper { background: var(--color-bg-elevated) !important; color: var(--color-text) !important; border: 1px solid var(--color-border-mid) !important; border-radius: var(--radius-md) !important; box-shadow: var(--shadow-lg) !important; }
.leaflet-popup-tip { background: var(--color-bg-elevated) !important; }
.leaflet-popup-content { font-family: var(--font-sans) !important; font-size: 12px !important; line-height: 1.5 !important; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.hidden { display: none !important; }

/* ==========================================================================
   Responsive — Mobile (≤768px)
   ========================================================================== */

/* Hamburger — hidden on desktop */
.sidebar-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.sidebar-toggle:hover { background: var(--color-bg-elevated); color: var(--color-text); }

/* Sidebar backdrop — hidden on desktop */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1100;
  backdrop-filter: blur(2px);
}
.sidebar-backdrop.visible { display: block; }

@media (max-width: 768px) {

  /* ── Grid: drop sidebar column ───────────────────────── */
  .app-layout {
    grid-template-columns: 1fr;
  }

  /* ── Header: compact ─────────────────────────────────── */
  .sidebar-toggle  { display: flex; }
  .header-divider  { display: none; }
  .header-stats    { display: none; }
  .header-brand-sub { display: none; }
  .scraper-status  { display: none; }
  .app-header      { gap: var(--space-2); padding: 0 var(--space-3); }
  .header-actions  { gap: var(--space-1); }
  .btn--sm         { padding: 4px 8px; font-size: 11px; }
  .disclaimer-info-btn { font-size: 10px; padding: 3px 7px; }

  /* ── Sidebar: fixed drawer from left ─────────────────── */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: min(300px, 85vw);
    height: 100dvh;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease-out);
    border-right: 1px solid var(--color-border);
  }
  .sidebar.drawer-open { transform: translateX(0); }

  /* ── Tab nav: smaller, scrollable ────────────────────── */
  .tab-btn { padding: 0 10px; font-size: 11px; gap: 4px; }
  .tab-icon { display: none; }

  /* ── Overview: map full width ────────────────────────── */
  .overview-layout { grid-template-columns: 1fr; }

  /* ── Exposure tab: stack panels ──────────────────────── */
  .exposure-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .exposure-deck-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  /* ── Flights tab: stack panels ───────────────────────── */
  .flights-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .flights-selector-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 160px;
    overflow-y: auto;
  }

  /* ── Controls bar: wrap & tighten ────────────────────── */
  .controls-bar {
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    height: auto;
    min-height: var(--controls-height);
  }
  .controls-label { display: none; }
  .controls-spacer { display: none; }
  .export-group { gap: var(--space-1); }

  /* ── Case detail: full screen ────────────────────────── */
  .case-detail {
    width: 100vw;
    top: 0;
    height: 100dvh;
    border-left: none;
  }

  /* ── Map legend: wrap ────────────────────────────────── */
  .map-legend { flex-wrap: wrap; gap: 4px; }

  /* ── Panel headers: tighten + allow wrap ─────────────── */
  .panel-header { height: auto; min-height: 38px; padding: var(--space-2) var(--space-3); flex-wrap: wrap; gap: var(--space-1); }
  .panel-title { font-size: var(--text-xs); }

  /* ── Controls bar: hide date range on mobile ─────────── */
  .controls-date-group { display: none; }
  .ctrl-reset-standalone { display: none; }

  /* ── Modals: tighter padding, safe height ────────────── */
  .modal-content { max-height: 95dvh; }
  .modal-body    { padding: var(--space-3); }
  .modal-footer  { padding: var(--space-3); gap: var(--space-2); }

  /* ── Add-case form: single column ───────────────────── */
  .form-grid { grid-template-columns: 1fr; }

  /* ── Toasts: stretch to screen width ─────────────────── */
  .toast-container {
    left: var(--space-3);
    right: var(--space-3);
    max-width: none;
  }
  .toast { max-width: none; }

  /* ── Case list: bigger touch targets ─────────────────── */
  .case-item { padding: var(--space-3) var(--space-4); }

  /* ── Filter pills: bigger touch area ─────────────────── */
  .filter-pill { padding: 5px var(--space-3); font-size: var(--text-xs); }
}
* { scrollbar-width: thin; scrollbar-color: var(--color-bg-elevated) transparent; }
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-thumb { background: var(--color-bg-elevated); border-radius: var(--radius-full); }
