/* =============================================================================
   CCDR Dashboard — custom.css
   Complements Bootstrap 5.3. Handles: WB brand colours, full-screen SPA
   layout, Leaflet map containers, sidebar grids, LISA cluster colours,
   checkbox lists, PTI sliders, and all non-Bootstrap CCDR-specific styles.
   ============================================================================= */

/* ── Brand colour tokens ──────────────────────────────────────────────────── */
:root {
  --wb-blue:               #002244;  /* dark navy — text & brand accents only */
  --wb-blue-mid:           #003366;
  --wb-blue-light:         #e8f0f8;
  --wb-blue-primary:       #0058A0;  /* WB medium blue — navbar, headers, buttons */
  --wb-blue-primary-hover: #004d8f;
  --wb-orange:             #f5a623;
  --wb-orange-dark:        #d4891e;
  --sidebar-w:             260px;
  --navbar-h:              50px;
  --subtab-h:              36px;
  --meta-h:                32px;
}

/* ── Bootstrap colour utilities (WB palette) ──────────────────────────────── */
.bg-wb-blue       { background-color: var(--wb-blue-primary) !important; }
.bg-wb-orange     { background-color: var(--wb-orange) !important; }
.text-wb-blue     { color: var(--wb-blue) !important; }
.text-wb-orange   { color: var(--wb-orange) !important; }
.btn-wb-blue      { background-color: var(--wb-blue-primary);   color: #fff; border-color: var(--wb-blue-primary); }
.btn-wb-blue:hover { background-color: var(--wb-blue-primary-hover); border-color: var(--wb-blue-primary-hover); color: #fff; }
.btn-wb-orange    { background-color: var(--wb-orange); color: #212529; border-color: var(--wb-orange); }
.btn-wb-orange:hover { background-color: var(--wb-orange-dark); border-color: var(--wb-orange-dark); color: #212529; }

/* ── Full-screen SPA body ─────────────────────────────────────────────────── */
body.bisd-dashboard {
  overflow: hidden;
  height: 100vh;
  font-size: 14px;
}

/* ── Navbar ───────────────────────────────────────────────────────────────── */
#navbar {
  height: var(--navbar-h);
  min-height: var(--navbar-h);
  max-height: var(--navbar-h);
  padding-left: 12px !important;
  padding-right: 10px !important;
  overflow: hidden;
}
/* Brand name 16px, tabs 14px */
.navbar-brand span { font-size: 16px !important; font-weight: 700; }
.nav-tab-btn { font-size: 14px; padding: 3px 10px; }
/* hide scrollbar on tab-bar */
#tab-bar { scrollbar-width: none; }
#tab-bar::-webkit-scrollbar { display: none; }

/* ── Tab / pane layer ─────────────────────────────────────────────────────── */
/* All panes are flex by default; Alpine x-cloak hides them before init,      */
/* then x-show toggles an inline style="display:none" for inactive tabs.      */
.tab-pane {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--navbar-h);
  left: 0; right: 0; bottom: 0;
}
[x-cloak] { display: none !important; }

/* ── Generic pane-body (sidebar + map) ───────────────────────────────────── */
.pane-body, .charts-body, .tables-body, .pti-body, .pca-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

/* ── Sidebar (25% of pane-body) ──────────────────────────────────────────── */
.sidebar, .pti-sidebar, .pca-sidebar {
  flex: 0 0 25%;
  width: 25%;
  min-width: 180px;
  max-width: 320px;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #dee2e6;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 12px;
}
.form-group { margin-bottom: 8px; }
.form-group .form-label { margin-bottom: 2px; font-size: 11px; }
.form-text { font-size: 11px; margin-top: 2px; color: #6c757d; }
/* Compact form controls */
.sidebar .form-select-sm,
.pti-sidebar .form-select-sm,
.pca-sidebar .form-select-sm,
.cmp-sidebar .form-select-sm { font-size: 0.8125rem !important; padding-top: 2px; padding-bottom: 2px; }
.sidebar .btn-sm,
.pti-sidebar .btn-sm,
.pca-sidebar .btn-sm,
.cmp-sidebar .btn-sm { font-size: 0.8125rem !important; padding: 3px 8px; }
/* form-check (radio) labels in sidebar */
.sidebar .form-check-label,
.pti-sidebar .form-check-label,
.pca-sidebar .form-check-label { font-size: 12px; }

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--wb-blue);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sidebar-hint {
  font-size: 12px;
  color: #6c757d;
  margin-bottom: 10px;
  line-height: 1.4;
}

/* ── Map area — fills remaining space when right panel absent ────────────── */
.map-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.map-container > div[id$="-map"],
.map-container > #map {
  width: 100%;
  height: 100%;
}

/* ── Meta strip ───────────────────────────────────────────────────────────── */
.meta-strip {
  min-height: var(--meta-h);
  background: var(--wb-blue-light);
  border-top: 1px solid #c3d6e8;
  padding: 4px 12px;
  font-size: 12px;
  color: #444;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.meta-strip b { color: var(--wb-blue); }

/* ── Sub-tab bar (Data Explorer) ──────────────────────────────────────────── */
.subtab-bar {
  height: var(--subtab-h);
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
}
.subtab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.subtab-btn.active,
.subtab-btn:hover { color: var(--wb-blue); border-bottom-color: var(--wb-blue); }
/* charts tab: flex-column so subtab-bar / charts-body / meta-strip stack cleanly */
#tab-charts { flex-direction: column !important; }
.charts-body { flex: 1; overflow: hidden; }
#chart-area { flex: 1; overflow: auto; display: flex; flex-direction: column; }
#plotly-chart { flex: 1; min-height: 300px; }

/* ── Comparison layout ────────────────────────────────────────────────────── */
.comparison-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.comparison-panel {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  position: relative;
  min-width: 0;
}
.comparison-panel + .comparison-panel { border-left: 2px solid #dee2e6; }
.cmp-map-wrap { flex: 1; position: relative; overflow: hidden; min-width: 0; }
.cmp-map-wrap > div { width: 100%; height: 100%; }
.cmp-sidebar {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
  background: #fff;
  border-left: 1px solid #dee2e6;   /* sidebar is on the RIGHT — left border */
  overflow-y: auto;
  z-index: 400;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  transition: width .2s, min-width .2s;
}
/* Collapsed comparison sidebar: shrink to header-only strip */
.cmp-sidebar.minimized {
  width: 28px;
  min-width: 28px;
  max-width: 28px;
  overflow: hidden;
}
.cmp-sidebar.minimized .ctrl-body { display: none; }
.cmp-sidebar.minimized .ctrl-title { display: none; }
.ctrl-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--wb-blue-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  cursor: pointer;
}
.ctrl-toggle {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
  flex-shrink: 0;
}
.ctrl-body { padding: 8px 10px; flex: 1; overflow-y: auto; }
.cmp-meta { margin-top: 6px !important; font-size: 11px !important; }
.cmp-charts { font-size: 11px !important; }

/* ── Tables layout ────────────────────────────────────────────────────────── */
.tables-content {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
#table-container table {
  font-size: 12px;
  border-collapse: collapse;
  width: 100%;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  overflow: hidden;
}
#table-container th {
  background: var(--wb-blue-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px;
  letter-spacing: 0.3px;
  border-right: 1px solid rgba(255,255,255,0.15);
}
#table-container th:last-child { border-right: none; }
#table-container td {
  padding: 8px 14px;
  border-bottom: 1px solid #eaecf0;
  border-right: 1px solid #f0f2f5;
  vertical-align: middle;
  line-height: 1.4;
}
#table-container td:last-child { border-right: none; }
#table-container tbody tr:last-child td { border-bottom: none; }
#table-container tr:hover td { background: var(--wb-blue-light); }
#table-container tbody tr:nth-child(even) td { background: #fafbfc; }
#table-container tbody tr:nth-child(even):hover td { background: var(--wb-blue-light); }

/* ── Checkbox lists (PTI / PCA / Spatial) ─────────────────────────────────── */
.checkbox-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 4px 0;
  background: #fff;
}
.checkbox-list label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.35;
}
.checkbox-list label:hover { background: var(--wb-blue-light); }
.checkbox-group-header {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #1a6fad;
  padding: 3px 8px;
  margin-top: 2px;
  letter-spacing: .03em;
}
.checkbox-list-actions { display: flex; gap: 4px; align-items: center; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 11px;
  color: var(--wb-blue);
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--wb-orange-dark); }
.link-sep { color: #aaa; font-size: 10px; }
.select-count { font-size: 10px; color: #888; text-align: right; margin-top: 2px; }
.checkbox-loading { padding: 8px; font-size: 11px; color: #888; text-align: center; }

/* ── PTI indicator weight sliders ─────────────────────────────────────────── */
.pti-weight-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  font-size: 12px;
}
.pti-weight-row input[type=range] { flex: 1; height: 4px; }
.pti-weight-val { min-width: 20px; text-align: right; color: #555; font-size: 11px; }

/* ── PCA variance bar ─────────────────────────────────────────────────────── */
.pca-variance-bar {
  margin-top: 8px;
  font-size: 11px;
}
/* NB: JS uses .pca-var-row / .pca-var-track / .pca-var-fill */
.pca-var-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.pca-var-track {
  flex: 1;
  height: 10px;
  background: #e9ecef;
  border-radius: 2px;
  overflow: hidden;
}
.pca-var-fill {
  height: 100%;
  background: var(--wb-blue);
  border-radius: 2px;
}

/* ── Mini-chart overlays (Comparison Maps only) ──────────────────────────── */
.maps-mini-charts, .pca-charts-overlay {
  position: absolute;
  bottom: 40px;
  right: 8px;
  width: 310px;
  background: rgba(255,255,255,0.96);
  border: 1px solid #dee2e6;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  z-index: 500;
}
.mini-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--wb-blue-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px 5px 0 0;
}
.mini-chart-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
}
.mini-chart-plot { height: 145px; }

/* ── Map right panel (25% — Spatial Analysis LISA legend only) ───────────── */
.map-right-panel {
  flex: 0 0 22%;
  width: 22%;
  min-width: 160px;
  max-width: 280px;
  overflow-y: auto;
  background: #f8f9fa;
  border-left: 1px solid #dee2e6;
  display: flex;
  flex-direction: column;
  font-size: 11px;
}
.right-panel-header {
  background: var(--wb-blue-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 12px;
  flex-shrink: 0;
  letter-spacing: 0.2px;
}
.right-panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid #dee2e6;
  background: #fff;
}
.right-panel-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--wb-blue);
  margin-bottom: 8px;
}
.right-panel-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #adb5bd;
  font-size: 12px;
  text-align: center;
  padding: 20px;
  line-height: 1.5;
}
/* mini-chart-plot for direct Plotly render targets */
.mini-chart-plot { height: 130px; }

/* ── Spatial Analysis ─────────────────────────────────────────────────────── */
.spatial-result-tabs {
  height: 32px;
  background: #f1f3f5;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  align-items: stretch;
  overflow-x: auto;
}
.spatial-result-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  color: #555;
}
.spatial-result-tab-btn.active { color: var(--wb-blue); border-bottom-color: var(--wb-blue); }
/* ── Spatial Analysis — Global Moran's I stats panel ─────────────────────── */
.spatial-global-stats {
  margin-top: 12px;
  background: #fff;
  border: 1px solid #c3d6e8;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,34,68,.07);
}
.stats-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  background: var(--wb-blue-primary);
  padding: 6px 10px;
  margin: 0;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: #dee2e6;
  border-bottom: 1px solid #dee2e6;
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7px 4px 6px;
  background: #fff;
  text-align: center;
}
.stat-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #8c9ab0;
  margin-bottom: 3px;
}
.stat-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--wb-blue);
  line-height: 1;
}
.interpretation-badge {
  display: block;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  text-align: center;
  border-bottom: 1px solid #dee2e6;
}
.badge-cluster   { background: #fff0f0; color: #c0392b; border-bottom-color: #f5b3b3; }
.badge-disperse  { background: #f0f4ff; color: #1a56db; border-bottom-color: #b3c4f5; }
.badge-neutral   { background: #f8f9fa; color: #6c757d; }
.badge-positive  { background: #eaf6ec; color: #155724; }
.badge-negative  { background: #fdf0f1; color: #721c24; }
/* Cluster distribution summary */
.cluster-summary { padding: 8px 10px; }
.cluster-summary-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8c9ab0;
  margin-bottom: 6px;
}
.cluster-bar-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 5px;
}
.cluster-bar-label {
  width: 30px;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  color: #444;
}
.cluster-bar-track {
  flex: 1;
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}
.cluster-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .4s ease;
}
.cluster-bar-count {
  width: 22px;
  text-align: right;
  font-size: 10px;
  color: #8c9ab0;
  flex-shrink: 0;
}
.lisa-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.12);
  vertical-align: middle;
}
.cluster-table { font-size: 11px; width: 100%; border-collapse: collapse; }
.cluster-table th { background: var(--wb-blue-primary); color: #fff; padding: 4px 8px; font-weight: 600; text-align: left; }
.cluster-table td { padding: 4px 8px; border-bottom: 1px solid #eee; vertical-align: middle; }

/* ── About / Docs page ────────────────────────────────────────────────────── */
.about-body {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.about-subtabs {
  display: flex;
  border-bottom: 1px solid #dee2e6;
  background: #fff;
  flex-shrink: 0;
}
.about-subtabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: #555;
}
.about-subtabs button.active { color: var(--wb-blue); border-bottom-color: var(--wb-blue); }
.about-content {
  padding: 24px 32px;
  max-width: 1000px;
  overflow-y: auto;
}
.about-content h1 { font-size: 18px; font-weight: 700; color: var(--wb-blue); margin-bottom: 12px; }
.about-content h2 { font-size: 15px; font-weight: 700; color: var(--wb-blue); margin: 20px 0 8px; }
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.contact-card {
  background: var(--wb-blue-light);
  border: 1px solid #c3d6e8;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
}
.contact-name  { font-weight: 700; margin-bottom: 2px; }
.contact-role  { color: #555; font-size: 12px; margin-bottom: 4px; }
.doc-download-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 10px;
}
.doc-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--wb-blue);
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
.doc-download-btn:hover { background: var(--wb-blue-mid); color: #fff; }
.github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #24292f;
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.github-link:hover { background: #444; color: #fff; }

/* ── Category / classification info blocks ────────────────────────────────── */
.classif-method { margin-bottom: 12px; }
.classif-method strong { color: var(--wb-blue); }
.classif-method p { font-size: 13px; margin: 4px 0 0; color: #444; }

/* ── Mobile sidebar toggle ────────────────────────────────────────────────── */
.sidebar-mobile-toggle {
  display: none;
  width: 100%;
  padding: 8px 12px;
  background: var(--wb-blue-primary);
  color: #fff;
  border: none;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Mobile hamburger button (hidden on desktop) ─────────────────────────── */
#nav-hamburger { display: none; }

/* ── Mobile navigation drawer ────────────────────────────────────────────── */
#nav-mobile-drawer {
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  right: 0;
  z-index: 1040;
  background: var(--wb-blue-primary);
  border-bottom: 3px solid var(--wb-orange);
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}
.nav-mobile-tab-btn {
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: rgba(255,255,255,0.85);
  text-align: left;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  width: 100%;
}
.nav-mobile-tab-btn:hover,
.nav-mobile-tab-btn.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-left-color: var(--wb-orange);
}

/* ── ≤992px — tablet / small laptop ──────────────────────────────────────── */
@media (max-width: 992px) {
  .sidebar, .pti-sidebar, .pca-sidebar {
    flex: 0 0 220px;
    width: 220px;
    min-width: 160px;
    max-width: 220px;
  }
  .nav-tab-btn { font-size: 13px; padding: 2px 8px; }
}

/* ── ≤768px — tablet portrait / large phone ──────────────────────────────── */
@media (max-width: 768px) {
  /* ---------- Body & SPA shell ---------- */
  /* Switch from fixed-height SPA to natural document scroll on mobile */
  body.bisd-dashboard {
    overflow-y: auto;
    height: auto;
    min-height: 100dvh;
  }

  /* Tab panes: drop position:fixed, become normal block flow */
  .tab-pane {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    min-height: calc(100svh - var(--navbar-h));
    flex-direction: column !important;
  }

  /* Show hamburger, hide desktop tab-bar */
  #nav-hamburger { display: flex; }
  #tab-bar { display: none !important; }

  /* ---------- Sidebars (all tabs) ---------- */
  /* Cancel the overlay/transform approach — sidebars sit inline above content */
  .sidebar, .pti-sidebar, .pca-sidebar {
    position: relative !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    flex: none !important;
    overflow-y: visible !important;
    z-index: auto !important;
    border-right: none;
    border-bottom: 2px solid var(--wb-orange);
    padding: 12px 14px;
  }

  /* ---------- Pane bodies: stack everything vertically ---------- */
  .pane-body,
  .charts-body,
  .tables-body,
  .pti-body,
  .pca-body {
    flex-direction: column;
    overflow: visible;
    height: auto;
    flex: none;
  }

  /* ---------- Map area ---------- */
  .map-area {
    width: 100%;
    min-width: 0;
    flex: none;
  }
  .map-container {
    /* Default for 768px and below */
    height: 60vmax;
    min-height: 300px;
    max-height: 70vh;
    position: relative;
  }
  /* Maps right panel (distribution charts): go full-width below map */
  .map-right-panel {
    flex: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 2px solid #dee2e6;
    display: flex;
    flex-direction: column;
  }

  /* ---------- Comparison maps: fully vertical ---------- */
  .comparison-body {
    flex-direction: column;
    overflow: visible;
    height: auto;
  }
  .comparison-panel {
    flex: none;
    width: 100%;
    flex-direction: column;
    min-height: 0;
  }
  .comparison-panel + .comparison-panel {
    border-left: none;
    border-top: 2px solid #dee2e6;
  }
  .cmp-map-wrap {
    height: 55vmax;
    min-height: 280px;
    max-height: 65vh;
  }
  .cmp-map-wrap > div { width: 100%; height: 100%; }
  /* Comparison sidebars go full-width below their map */
  .cmp-sidebar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    border-left: none;
    border-top: 1px solid #dee2e6;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .cmp-sidebar.minimized {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: auto;
    overflow: visible;
  }
  .ctrl-header { width: 100%; }
  .ctrl-body { width: 100%; padding: 10px 12px; }

  /* ---------- Data Explorer ---------- */
  #tab-charts { flex-direction: column !important; }
  #chart-area { min-height: 320px; overflow: visible; flex: none; }
  #plotly-chart { min-height: 320px; }

  /* ---------- Data Tables ---------- */
  .tables-content { overflow-x: auto; }
  #table-container { overflow-x: auto; }
  #table-container table { min-width: 540px; }

  /* ---------- Floating overlays: disable absolute positioning ---------- */
  .map-hist-overlay,
  .pca-chart-overlay,
  .maps-mini-charts {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid #dee2e6;
    border-left: none;
    border-right: none;
  }

  /* Legend: keep visible but non-draggable on mobile — no room  */
  .map-legend, .legend-custom {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    cursor: default;
    display: inline-block;
    margin: 8px;
    max-width: calc(100% - 16px);
  }

  /* ────────────────────────────────────────────────────────────────────────
     FLOATING ACTION BUTTONS (FABs) & OVERLAY STATE MANAGEMENT (mobile)
     ──────────────────────────────────────────────────────────────────────── */

  /* FAB Container — positioned over map, accessible button group */
  .map-fab-container {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 600;
    pointer-events: auto;
  }

  /* Floating Action Button style */
  .map-fab {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    border: none;
    background-color: var(--wb-blue-primary);
    color: #fff;
    font-size: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 88, 160, 0.4);
    transition: all 0.2s ease;
  }

  .map-fab:hover {
    background-color: var(--wb-blue-primary-hover);
    box-shadow: 0 6px 16px rgba(0, 88, 160, 0.5);
    transform: scale(1.1);
  }

  .map-fab:active {
    transform: scale(0.95);
  }

  /* FAB visibility control — hide when overlay is expanded */
  .map-fab-container.overlay-expanded {
    pointer-events: none;
  }

  .map-fab-container.overlay-expanded .map-fab {
    opacity: 0.3;
    pointer-events: none;
  }

  /* ────── Overlay State: HIDDEN (default) ────── */
  /* When overlay is hidden, it takes no space and FAB is visible/clickable */
  .map-container.overlay-legend-hidden .map-legend {
    display: none !important;
    height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
  }

  .map-container.overlay-histogram-hidden .map-hist-overlay {
    display: none !important;
    height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
  }

  /* ────── Overlay State: COLLAPSED ────── */
  /* Overlay shows header only, body hidden */
  .map-container.overlay-histogram-collapsed .map-hist-overlay {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    max-height: 50px;
    overflow: hidden;
  }

  .map-container.overlay-histogram-collapsed #maps-histogram {
    display: none;
  }

  .map-container.overlay-legend-collapsed .map-legend {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    max-height: 45px;
    overflow: hidden;
  }

  .map-container.overlay-legend-collapsed .map-legend.minimized .legend-body {
    display: none;
  }

  /* ────── Overlay State: EXPANDED ────── */
  /* Overlay shows full content, scrollable if needed, below map */
  .map-container.overlay-histogram-expanded .map-hist-overlay {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    width: 100% !important;
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid #dee2e6;
    margin-top: 8px;
  }

  .map-container.overlay-legend-expanded .map-legend {
    position: relative !important;
    left: auto !important;
    bottom: auto !important;
    right: auto !important;
    width: 100% !important;
    max-width: none !important;
    margin: 8px 0;
    display: block !important;
    max-height: 180px;
    overflow-y: auto;
  }

  /* Hide FAB when overlay is expanded (user can scroll to see full overlay) */
  .map-container.overlay-histogram-expanded .map-fab-container,
  .map-container.overlay-legend-expanded .map-fab-container {
    opacity: 0.5;
    pointer-events: none;
  }

  /* Ensure map controls (zoom, attribution) aren't blocked by FABs */
  .map-container .map-fab-container {
    bottom: 50px;
    right: 10px;
  }

  /* Adjust FAB position if legend is visible below map */
  .map-container.overlay-legend-expanded .map-fab-container {
    bottom: 20px;
  }
}

/* ── ≤576px — phone portrait ─────────────────────────────────────────────── */
@media (max-width: 576px) {
  /* ────────────────────────────────────────────────────────────────────────
     TOUCH TARGET IMPROVEMENTS
     ──────────────────────────────────────────────────────────────────────── */

  /* Ensure all interactive elements on overlays have sufficient touch targets */
  .hist-overlay-header button,
  .hist-overlay-minimize,
  .hist-overlay-close,
  .overlay-download-btn,
  .legend-toggle {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 16px;
  }

  /* Histogram header: more spacious on mobile */
  .hist-overlay-header {
    padding: 10px 12px;
    gap: 8px;
  }

  /* Legend body items: larger spacing */
  .legend-row {
    padding: 6px 4px;
    min-height: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .legend-swatch {
    min-width: 20px;
    min-height: 20px;
  }

  /* Sidebar buttons: ensure 44px minimum */
  .sidebar .btn-sm,
  .pti-sidebar .btn-sm,
  .pca-sidebar .btn-sm {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 14px;
  }

  /* Form controls: increase padding on mobile */
  .form-select-sm,
  .form-check-input {
    min-height: 40px;
    min-width: 40px;
  }

  /* Larger touch targets */
  .sidebar-mobile-toggle {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 14px;
  }

  /* Slightly shorter map on very small screens */
  .map-container { height: 55vmax; min-height: 260px; }
  .cmp-map-wrap  { height: 50vmax; min-height: 240px; }

  /* Landscape orientation: reduce map height to leave room for controls */
  @media (orientation: landscape) {
    .map-container { height: 50vh; max-height: 55vh; min-height: 200px; }
    .cmp-map-wrap  { height: 45vh; max-height: 50vh; min-height: 180px; }
  }


  /* Meta strip: stack items vertically */
  .meta-strip {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    font-size: 11px;
    padding: 6px 10px;
  }

  /* Wider table scroll area */
  #table-container table { min-width: 480px; font-size: 11px; }
  #table-container th, #table-container td { padding: 6px 10px; }

  /* About page padding */
  .about-content { padding: 14px; }

  /* Comparison sidebar histogram */
  .cmp-sidebar-hist { height: 85px; }

  /* Navbar brand: hide subtitle text if too long */
  .navbar-brand span { font-size: 14px !important; }
}

/* ── Landing page extras ──────────────────────────────────────────────────── */
.hero-section {
  background: linear-gradient(135deg, var(--wb-blue) 0%, var(--wb-blue-mid) 70%, #004488 100%);
  padding-top: 60px;
  padding-bottom: 60px;
}
.hero-map-placeholder {
  width: 340px;
  height: 280px;
  background: rgba(255,255,255,0.06);
}
.feature-card { transition: transform .2s, box-shadow .2s; }
.feature-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,.12) !important;
}

/* ── Leaflet map legends (maps, comparison, PTI, PCA) ─────────────────────── */
/* .map-legend   — used by maps.js and comparison.js (has header + collapsible body) */
/* .legend-custom — used by pti.js and pca.js (simpler, no collapse) */
.map-legend, .legend-custom {
  background: rgba(255,255,255,0.97);
  border: 1px solid rgba(0,0,0,.2);
  border-radius: 5px;
  font-size: 11px;
  min-width: 130px;
  max-width: 190px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  cursor: move;
  user-select: none;
  pointer-events: auto;
  /* Leaflet resets pointer-events on controls — override */
}
.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px 4px 10px;
  background: var(--wb-blue-primary);
  color: #fff;
  border-radius: 4px 4px 0 0;
}
.legend-title {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.legend-toggle {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 0 0 6px;
  flex-shrink: 0;
}
.legend-body { padding: 6px 10px 6px; }
/* For .legend-custom the title and rows sit directly in the container */
.legend-custom { padding: 6px 10px 6px; }
.legend-custom > .legend-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--wb-blue);
  margin-bottom: 5px;
  display: block;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  font-size: 12px;
  white-space: nowrap;
}
/* *** The key fix: legend swatches need explicit width/height/display *** */
.legend-swatch {
  display: inline-block;
  width:  14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,.18);
  flex-shrink: 0;
}
/* Minimised state — hide body */
.map-legend.minimized .legend-body { display: none; }

/* Make sure Leaflet doesn't strip pointer events */
.leaflet-control .map-legend,
.leaflet-control .legend-custom { pointer-events: auto; }

/* ── Scrollbar thin styling ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ═══════════════════════════════════════════════════════════════════════════
   HISTOGRAM OVERLAYS — Maps & PCA transparent floating charts
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Interactive Maps / single-map histogram overlay ─────────────────────── */
.map-hist-overlay {
  position: absolute;
  bottom: 45px;
  left: 10px;
  width: 230px;
  background: rgba(255,255,255,0.90);
  border: 1px solid rgba(0,0,0,.10);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
  z-index: 500;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow: hidden;
}
.hist-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 9px;
  background: rgba(0,88,160,0.88);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.hist-overlay-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.hist-overlay-close:hover { opacity: .75; }

/* ── Comparison Maps — sidebar histogram (static, one per panel) ─────────── */
.comparison-body { flex: 1; min-height: 0; }
.cmp-sidebar-hist-wrap {
  margin-top: 8px;
  border-top: 1px solid #dee2e6;
  padding-top: 6px;
}
.cmp-sidebar-hist-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--wb-blue);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 3px;
  padding: 0 2px;
}
.cmp-sidebar-hist { width: 100%; height: 100px; }
/* Minimized state for map/PCA draggable overlays */
.map-hist-overlay.minimized .mini-chart-plot,
#pca-mini-charts.minimized #pca-overlay-body { display: none !important; }

/* ── Shared overlay download/minimize buttons ─────────────────────────────── */
.overlay-download-btn {
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(255,255,255,0.40);
  color: #fff;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: auto;
  white-space: nowrap;
}
.overlay-download-btn:hover { background: rgba(255,255,255,0.38); }
.hist-overlay-minimize {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.hist-overlay-minimize:hover { opacity: .75; }
/* Extra gap in hist overlay header for multiple buttons */
.hist-overlay-header { gap: 6px; }

/* ── PCA Transparent chart overlay ────────────────────────────────────────── */
.pca-chart-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 270px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0;
  pointer-events: auto;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 8px;
  box-shadow: 0 2px 14px rgba(0,0,0,.18);
  overflow: hidden;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.pca-overlay-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--wb-blue-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}
.pca-overlay-header span { flex: 1; }
.pca-overlay-minimize {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.pca-overlay-minimize:hover { opacity: .75; }
#pca-overlay-body { display: flex; flex-direction: column; gap: 6px; padding: 6px; }
.pca-overlay-section {
  background: transparent;
  border: 1px solid rgba(0,88,160,0.15);
  border-radius: 4px;
  overflow: hidden;
}
.pca-overlay-sec-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(0,88,160,0.84);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.pca-overlay-sec-header span { flex: 1; }
.pca-sec-toggle,
.pca-overlay-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.pca-sec-toggle:hover,
.pca-overlay-close:hover { opacity: .75; }
