:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --page: #f4f5f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --gridline: #e1e0d9;
  --accent: #184f95;
  --accent-2: #256abf;
  --good: #0ca30c;
  --critical: #d03b3b;
  --sidebar-w: 320px;
  --rightpanel-w: 300px;
  --header-h: auto;
  --shadow: 0 1px 3px rgba(11,11,11,0.06), 0 1px 2px rgba(11,11,11,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------------- Header ---------------- */
.app-header {
  background: linear-gradient(100deg, #0d366b 0%, #184f95 55%, #256abf 100%);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  z-index: 20;
}
.app-header .brand { display: flex; flex-direction: column; gap: 2px; max-width: 720px; }
.app-header h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: 0.2px; }
.app-header .tagline { font-size: 12.5px; color: rgba(255,255,255,0.85); line-height: 1.4; }
.app-header .about-btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.app-header .about-btn:hover { background: rgba(255,255,255,0.24); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.app-header .tour-launch { background: rgba(255,255,255,0.95); color: var(--accent); border-color: #fff; font-weight: 700; }
.app-header .tour-launch:hover { background: #fff; }

/* ---------------- Stat cards ---------------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-card .stat-value { font-size: 24px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-card .stat-label { font-size: 11.5px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; }
.stat-card .stat-sub { font-size: 11px; color: var(--text-muted); }

/* ---------------- Body layout ---------------- */
.body-row {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0 40px;
}
.sidebar-intro {
  padding: 10px 16px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.sidebar-intro b { color: var(--text-primary); }

.reset-btn {
  margin: 8px 16px;
  width: calc(100% - 32px);
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.reset-btn:hover { background: var(--gridline); }

.filter-group {
  border-bottom: 1px solid var(--border);
}
.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
}
.filter-group-header:hover { background: var(--page); }
.filter-group-header .title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.filter-group-header .chev { font-size: 10px; color: var(--text-muted); transition: transform 0.15s; }
.filter-group.collapsed .chev { transform: rotate(-90deg); }
.filter-group.collapsed .filter-group-body { display: none; }

.filter-group-desc {
  padding: 0 16px 8px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

.attr-row {
  padding: 7px 16px;
  border-top: 1px dashed var(--gridline);
}
.attr-row:first-child { border-top: none; }
.attr-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.attr-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.attr-desc {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
  margin-bottom: 5px;
}
.color-by-btn {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.color-by-btn:hover { border-color: var(--accent-2); color: var(--accent-2); }
.color-by-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.filter-widget { margin-top: 3px; }
.range-values { font-size: 10.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; margin-bottom: 2px; }

/* Dual-handle range slider: two range inputs overlaid on one track. */
.dual-range { position: relative; height: 22px; }
.dual-range .slider-track,
.dual-range .slider-fill {
  position: absolute; top: 9px; height: 4px; border-radius: 3px;
}
.dual-range .slider-track { left: 0; right: 0; background: var(--gridline); }
.dual-range .slider-fill { background: var(--accent-2); }
.dual-range input[type=range] {
  -webkit-appearance: none; appearance: none;
  position: absolute; top: 0; left: 0; width: 100%; height: 22px;
  margin: 0; background: none; pointer-events: none;
}
.dual-range input[type=range]:focus { outline: none; }
.dual-range input[type=range]::-webkit-slider-runnable-track { background: none; border: none; }
.dual-range input[type=range]::-moz-range-track { background: none; border: none; }
.dual-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  height: 16px; width: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(11,11,11,0.35);
  cursor: pointer; pointer-events: auto;
}
.dual-range input[type=range]::-moz-range-thumb {
  height: 16px; width: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(11,11,11,0.35);
  cursor: pointer; pointer-events: auto;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.chip.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.bool-toggle { display: flex; gap: 6px; }
.bool-toggle .chip { flex: 1; text-align: center; }

/* ---------------- Map area ---------------- */
.map-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.map-caption {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.map-caption .current-attr { font-weight: 700; color: var(--accent); }
#map { flex: 1; background: #dfe6ee; }

.leaflet-tooltip.policy-tooltip {
  font-size: 11.5px;
  line-height: 1.5;
  min-width: 190px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-primary);
}
.leaflet-tooltip.policy-tooltip b { font-size: 12.5px; }
.leaflet-tooltip.policy-tooltip .popup-row { display: flex; justify-content: space-between; gap: 10px; }
.leaflet-tooltip.policy-tooltip .popup-row span:first-child { color: var(--text-secondary); }

.leaflet-popup-content { font-size: 12px; line-height: 1.5; min-width: 200px; }
.leaflet-popup-content b { font-size: 13px; }
.popup-row { display: flex; justify-content: space-between; gap: 10px; }
.popup-row span:first-child { color: #666; }

/* ---------------- Right panel ---------------- */
.right-panel {
  width: var(--rightpanel-w);
  flex-shrink: 0;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface-1);
}
.panel-card h3 {
  font-size: 12.5px;
  margin: 0 0 6px;
  color: var(--text-primary);
}
.panel-card .panel-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 8px;
}

/* Legend */
#legend-content .legend-swatch-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 2px 0;
}
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.15); }
.legend-gradient-bar {
  height: 12px;
  border-radius: 4px;
  margin: 6px 0 4px;
  border: 1px solid rgba(0,0,0,0.1);
}
.legend-gradient-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); }

/* Blended risk panel - standout styling */
.blend-card {
  border: 1.5px solid var(--accent-2);
  background: linear-gradient(180deg, #eef4fc 0%, var(--surface-1) 100%);
}
.blend-card h3 { color: var(--accent); display: flex; align-items: center; gap: 6px; }
.blend-badge {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.4px;
  background: var(--accent);
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
}
.blend-toggle {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
}
.blend-toggle:hover { background: var(--accent-2); }
.blend-toggle.active { background: var(--critical); }
.blend-controls { margin-top: 10px; display: none; flex-direction: column; gap: 8px; }
.blend-controls.show { display: flex; }
.blend-controls label { font-size: 11px; font-weight: 700; color: var(--text-secondary); }
.blend-controls select { width: 100%; padding: 5px 6px; border-radius: 5px; border: 1px solid var(--border); font-size: 12px; }
.blend-weight-row { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-muted); }
.blend-weight-row input { flex: 1; accent-color: var(--accent); }
.blend-presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.blend-presets button {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-2);
  background: #fff;
  color: var(--accent-2);
  cursor: pointer;
}
.blend-presets button:hover { background: var(--accent-2); color: #fff; }

/* Selected policy */
#detail-content { font-size: 11.5px; color: var(--text-secondary); }
#detail-content .empty { color: var(--text-muted); font-style: italic; }
#detail-content .drow { display: flex; justify-content: space-between; padding: 2px 0; border-top: 1px dashed var(--gridline); }
#detail-content .drow:first-child { border-top: none; }

/* ---------------- About modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11,11,11,0.5);
  display: none; align-items: center; justify-content: center;
  /* Above Leaflet panes/controls, which stack up to z-index 1000. */
  z-index: 5000;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface-2);
  border-radius: 12px;
  max-width: 560px;
  width: 92%;
  max-height: 82vh;
  overflow-y: auto;
  padding: 22px 26px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; font-size: 18px; color: var(--accent); }
.modal p, .modal li { font-size: 13px; line-height: 1.6; color: var(--text-secondary); }
.modal .close-btn {
  float: right;
  background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted);
}

/* ---------------- Guided tour (coach marks) ---------------- */
.tour-blocker {
  position: fixed; inset: 0; z-index: 6000;
  background: transparent; /* dimming is drawn by the spotlight's box-shadow */
}
.tour-spotlight {
  position: fixed; z-index: 6001; pointer-events: none;
  border-radius: 10px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(11,11,11,0.62), 0 0 14px 2px rgba(37,106,191,0.7);
  transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
}
.tour-tooltip {
  position: fixed; z-index: 6002;
  width: 320px; max-width: calc(100vw - 24px);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  border: 1px solid var(--border);
}
.tour-tooltip .tour-step-count {
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--accent-2); margin-bottom: 4px;
}
.tour-tooltip h4 { margin: 0 0 6px; font-size: 15px; color: var(--text-primary); }
.tour-tooltip p { margin: 0 0 12px; font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.tour-tooltip .tour-progress { display: flex; gap: 5px; margin-bottom: 12px; }
.tour-tooltip .tour-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gridline); }
.tour-tooltip .tour-dot.active { background: var(--accent); }
.tour-tooltip .tour-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tour-tooltip .tour-nav-right { display: flex; gap: 8px; }
.tour-tooltip button {
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 7px 14px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-secondary);
}
.tour-tooltip .tour-skip { border: none; background: none; color: var(--text-muted); padding-left: 0; }
.tour-tooltip .tour-skip:hover { color: var(--text-secondary); }
.tour-tooltip .tour-next { background: var(--accent); border-color: var(--accent); color: #fff; }
.tour-tooltip .tour-next:hover { background: var(--accent-2); }
.tour-tooltip .tour-back:hover { background: var(--gridline); }

.modal-tour-cta {
  margin-top: 16px; width: 100%;
  padding: 11px 14px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.modal-tour-cta:hover { background: var(--accent-2); }

/* Scrollbars */
.sidebar::-webkit-scrollbar, .right-panel::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .right-panel::-webkit-scrollbar-thumb { background: var(--gridline); border-radius: 4px; }

@media (max-width: 1100px) {
  .right-panel { display: none; }
}
