/* ═══════════════════════════════════════════════════════
   Louisiana Community Wellbeing Index
   Design System — Precision Data Platform
   ═══════════════════════════════════════════════════════ */

:root {
  /* Brand */
  --purple:        #461D7C;
  --purple-dark:   #2D0F54;
  --purple-mid:    #5E2D9A;
  --purple-pale:   #F0EBF8;
  --gold:          #FDD023;
  --gold-deep:     #B89200;

  /* Category identity colors */
  --cat-social:    #6366f1;
  --cat-exposure:  #059669;
  --cat-hazard:    #d97706;
  --cat-health:    #dc2626;

  /* Surfaces & neutrals */
  --bg:            #F7F5FC;
  --surface:       #ffffff;
  --text:          #1A0A2E;
  --text-2:        #6B5890;
  --border:        #E2DBF0;
  --border-2:      #C5B6E0;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(70,29,124,.07);
  --shadow-sm:  0 2px 8px rgba(70,29,124,.09);
  --shadow:     0 4px 20px rgba(70,29,124,.13);
  --shadow-lg:  0 8px 36px rgba(70,29,124,.18);

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', 'Courier New', monospace;

  /* Layout */
  --header-h: 66px;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

body.nav-menu-open,
body.sidebar-open {
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════ */

.header {
  position: sticky;
  top: 0;
  z-index: 2000;
  flex-shrink: 0;
  background: var(--purple-dark);
  background-image:
    repeating-linear-gradient(
      -55deg,
      transparent,
      transparent 22px,
      rgba(253,208,35,.028) 22px,
      rgba(253,208,35,.028) 23px
    );
  border-bottom: 2px solid var(--gold);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 66px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  background: var(--gold);
  color: var(--purple-dark);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
}

.brand-text p {
  font-size: 10.5px;
  color: rgba(255,255,255,.48);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-top: 2px;
  line-height: 1;
}

/* ── Navigation ── */

.nav {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav a {
  display: inline-flex;
  align-items: center;
  padding: 7px 15px;
  border-radius: 6px;
  text-decoration: none;
  color: rgba(255,255,255,.65);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.nav a:hover {
  background: rgba(255,255,255,.10);
  color: #fff;
}

.nav a.active {
  background: var(--gold);
  color: var(--purple-dark);
  font-weight: 700;
}

.nav a.active:hover {
  background: #ffe94e;
}

/* ═══════════════════════════════════════════════════════
   DASHBOARD (index.html — chat + map)
   ═══════════════════════════════════════════════════════ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dashboard {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 0;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.chat-header {
  flex-shrink: 0;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--purple-pale) 0%, var(--surface) 100%);
}

.chat-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 4px;
}

.chat-header p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.chat-message {
  display: flex;
  max-width: 92%;
}

.chat-message--user {
  align-self: flex-end;
}

.chat-message--assistant {
  align-self: flex-start;
}

.chat-bubble {
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-message--user .chat-bubble {
  background: var(--purple);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message--assistant .chat-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-xs);
}

.chat-message--assistant .chat-bubble strong {
  color: var(--purple);
}

.chat-quick-questions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-quick-btn {
  padding: 5px 10px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--bg);
  color: var(--purple);
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}

.chat-quick-btn:hover {
  background: var(--purple-pale);
  border-color: var(--purple);
}

.chat-quick-btn:active {
  transform: scale(0.97);
}

/* Typing indicator dots */
.chat-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.chat-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--purple, #7c5cbf);
  opacity: 0.4;
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Token banner ────────────────────────────────────────────────────────── */
.chat-token-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 12px 7px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-token-banner--full {
  background: #fff5f5;
  border-color: #fc8181;
}
.chat-token-bar {
  height: 4px;
  border-radius: 4px;
  background: #e2e8f0;
  overflow: hidden;
}
.chat-token-bar__fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #48bb78 0%, #f6ad55 65%, #fc8181 100%);
  transition: width 0.4s ease;
}
.chat-token-label {
  font-size: 0.67rem;
  color: #94a3b8;
  line-height: 1.3;
}
.chat-token-banner--full .chat-token-label {
  color: #c53030;
  font-weight: 600;
}

/* ── Map tooltip ─────────────────────────────────────────────────────────── */
.cwbi-tooltip {
  background: rgba(20, 10, 40, 0.88);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  padding: 5px 9px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.cwbi-tooltip::before { border-top-color: rgba(20,10,40,0.88) !important; }

/* ── Map popup ───────────────────────────────────────────────────────────── */
.cwbi-popup-wrap .leaflet-popup-content-wrapper {
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}
.cwbi-popup-wrap .leaflet-popup-content { margin: 0; width: auto !important; }
.cwbi-popup-wrap .leaflet-popup-tip { background: #fff; }

.cwbi-popup { font-family: var(--font-body, sans-serif); min-width: 220px; }

.cwbi-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #1e0a3c;
  color: #fff;
  padding: 10px 14px;
}
.cwbi-popup__name { font-weight: 600; font-size: 14px; }
.cwbi-popup__badge {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.cwbi-popup__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  padding: 10px 14px;
  display: block;
}
.cwbi-popup__table tr { border-bottom: 1px solid #f0eaf8; }
.cwbi-popup__table tr:last-child { border-bottom: none; }
.cwbi-popup__table th {
  text-align: left;
  color: #6b5b8a;
  font-weight: 500;
  padding: 5px 6px 5px 0;
  white-space: nowrap;
  width: 50%;
}
.cwbi-popup__table td { color: #1a0a2e; font-weight: 600; padding: 5px 0; }
.cwbi-popup__sub { font-weight: 400; color: #999; font-size: 11px; margin-left: 2px; }

.cwbi-popup__note {
  font-size: 10px;
  color: #999;
  text-align: center;
  padding: 6px 14px 10px;
  margin: 0;
  border-top: 1px solid #f0eaf8;
}

/* ── Map legend ──────────────────────────────────────────────────────────── */
.cwbi-legend {
  background: rgba(255,255,255,0.95);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  font-family: var(--font-body, sans-serif);
  font-size: 12px;
  line-height: 1.6;
}
.cwbi-legend strong { display: block; font-size: 12px; color: #1a0a2e; margin-bottom: 6px; }
.cwbi-legend__items { display: flex; flex-direction: column; gap: 3px; }
.cwbi-legend__items span {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.chat-input-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(70,29,124,.10);
}

.chat-send-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  transition: filter .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.chat-send-btn:hover { filter: brightness(1.15); }
.chat-send-btn:active { transform: scale(0.94); }

.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}

.map-panel-header {
  flex-shrink: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.map-panel-header h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 2px;
}

.map-panel-header p {
  font-size: 12.5px;
  color: var(--text-2);
}

.map-panel .map-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ═══════════════════════════════════════════════════════
   APP LAYOUT (legacy / other pages)
   ═══════════════════════════════════════════════════════ */

.app {
  flex: 1;
  min-height: 0;
  display: flex;
}

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar h2 {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.content {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

/* ── Map ── */

#map { height: 100%; width: 100%; }

.map-wrap { position: relative; height: 100%; width: 100%; }

.loading {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1000;
  background: var(--purple-dark);
  color: rgba(255,255,255,.85);
  border: 1px solid rgba(253,208,35,.4);
  padding: 7px 13px;
  border-radius: 6px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  display: none;
}

.panel {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 1000;
  background: rgba(20,8,42,.90);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(253,208,35,.22);
  border-radius: 10px;
  padding: 14px 16px;
  width: min(300px, calc(100% - 28px));
  box-shadow: var(--shadow-lg);
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(253,208,35,.18);
}

.panel .row {
  font-size: 12px;
  margin: 4px 0;
  color: rgba(255,255,255,.58);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.panel .row strong {
  color: rgba(255,255,255,.82);
  font-weight: 500;
}

/* ── Sidebar controls ── */

.control { margin-bottom: 18px; }

.control label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 7px;
}

select {
  width: 100%;
  padding: 9px 32px 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--surface);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%236B5890' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(70,29,124,.12);
}

input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 8px 0 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--purple);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
  cursor: pointer;
  transition: transform .15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--purple);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
  cursor: pointer;
  border: none;
}

.range-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-2);
  margin-top: 2px;
}

.btn-row { display: flex; gap: 8px; margin-top: 4px; }

.btn {
  flex: 1;
  padding: 9px 13px;
  border-radius: 6px;
  border: 1.5px solid var(--purple);
  cursor: pointer;
  font-weight: 700;
  font-size: 12.5px;
  font-family: var(--font-body);
  letter-spacing: 0.03em;
  background: var(--purple);
  color: #fff;
  transition: filter .15s, transform .1s;
}

.btn:hover { filter: brightness(1.18); }
.btn:active { transform: scale(.97); }

.btn.secondary {
  background: transparent;
  color: var(--purple);
}

.btn.secondary:hover {
  background: var(--purple-pale);
  filter: none;
}

/* ═══════════════════════════════════════════════════════
   PAGE LAYOUT (data.html, methodology.html, simulate.html)
   ═══════════════════════════════════════════════════════ */

.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--bg);
}

/* Page load entrance */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page > * { animation: fadeUp .3s ease both; }
.page > *:nth-child(1) { animation-delay: .04s; }
.page > *:nth-child(2) { animation-delay: .09s; }
.page > *:nth-child(3) { animation-delay: .14s; }
.page > *:nth-child(4) { animation-delay: .19s; }
.page > *:nth-child(5) { animation-delay: .24s; }

.page-header { margin-bottom: 22px; }

.page-header h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--purple);
  line-height: 1.2;
  margin-bottom: 5px;
}

.page-header p {
  font-size: 13.5px;
  color: var(--text-2);
}

/* ── Search input ── */

.table-search {
  width: 100%;
  max-width: 380px;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B5890' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.8-3.8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  margin-bottom: 16px;
  transition: border-color .15s, box-shadow .15s;
}

.table-search:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(70,29,124,.10);
}

/* ── Table ── */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--purple);
  color: rgba(255,255,255,.80);
  text-align: left;
  padding: 11px 14px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background .15s;
}

thead th:hover { background: var(--purple-mid); color: #fff; }

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

/* Numeric columns in monospace */
tbody td:nth-child(n+3) {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
}

tbody tr:nth-child(even) td { background: rgba(240,235,248,.35); }
tbody tr:hover td { background: var(--purple-pale); }
tbody tr:last-child td { border-bottom: none; }

th.sort-asc::after  { content: " ↑"; color: var(--gold); }
th.sort-desc::after { content: " ↓"; color: var(--gold); }

/* ═══════════════════════════════════════════════════════
   METHODOLOGY PAGE
   ═══════════════════════════════════════════════════════ */

.tree {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 22px;
}

.node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--purple);
  border-radius: 8px;
  padding: 13px 15px;
  margin: 9px 0;
  cursor: pointer;
  transition: box-shadow .15s, background .15s;
}

.node:hover {
  box-shadow: var(--shadow-sm);
  background: rgba(240,235,248,.45);
}

.node[data-node="root"]     { border-left-color: var(--purple); }
.node[data-node="social"]   { border-left-color: var(--cat-social); }
.node[data-node="exposure"] { border-left-color: var(--cat-exposure); }
.node[data-node="hazard"]   { border-left-color: var(--cat-hazard); }
.node[data-node="health"]   { border-left-color: var(--cat-health); }

.node .hdr {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
  font-size: 13.5px;
}

/* Expand chevron */
.node > .hdr::before {
  content: '▸';
  font-size: 9px;
  color: var(--text-2);
  flex-shrink: 0;
  transition: transform .2s ease;
  display: inline-flex;
  align-items: center;
}

.node.expanded > .hdr::before { transform: rotate(90deg); }

.node .hdr > span:first-child { flex: 1; }

.node .w {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  background: var(--purple-pale);
  color: var(--purple);
}

.node[data-node="social"]   .w { background: rgba(99,102,241,.09);  color: var(--cat-social); }
.node[data-node="exposure"] .w { background: rgba(5,150,105,.09);   color: var(--cat-exposure); }
.node[data-node="hazard"]   .w { background: rgba(217,119,6,.09);   color: var(--cat-hazard); }
.node[data-node="health"]   .w { background: rgba(220,38,38,.09);   color: var(--cat-health); }

.children {
  display: none;
  margin-top: 10px;
  padding-left: 6px;
}

.node.expanded .children { display: block; }

.leaf {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  margin: 6px 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
}

.leaf strong {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--purple);
  background: var(--purple-pale);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Calculation steps card */
.calc-steps {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: var(--shadow-xs);
}

.calc-steps h2 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 12px;
}

.calc-steps p {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.75;
}

.calc-steps strong {
  color: var(--text);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════
   SIMULATOR PAGE
   ═══════════════════════════════════════════════════════ */

.simulator-page {
  /* page layout handled by .page; inner container controls max-width */
}

.simulator-container {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 22px;
}

.simulator-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Weight controls card */
.weight-controls {
  background: var(--surface);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.weight-controls h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 16px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--border);
}

.input-group { margin-bottom: 14px; }

.input-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
}

.input-group label strong {
  font-weight: 700;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* Category label colors */
.ig-social   label strong { color: var(--cat-social); }
.ig-exposure label strong { color: var(--cat-exposure); }
.ig-hazard   label strong { color: var(--cat-hazard); }
.ig-health   label strong { color: var(--cat-health); }

/* Category border accent */
.ig-social   .weight-input:focus { border-color: var(--cat-social);   box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.ig-exposure .weight-input:focus { border-color: var(--cat-exposure); box-shadow: 0 0 0 3px rgba(5,150,105,.12); }
.ig-hazard   .weight-input:focus { border-color: var(--cat-hazard);   box-shadow: 0 0 0 3px rgba(217,119,6,.12); }
.ig-health   .weight-input:focus { border-color: var(--cat-health);   box-shadow: 0 0 0 3px rgba(220,38,38,.12); }

.weight-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-align: center;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

.weight-input:focus { outline: none; }

.weight-summary {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sum-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.sum-display #weightSum {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 700;
  color: var(--purple);
  line-height: 1;
  transition: color .2s;
}

.btn-calculate {
  width: 100%;
  margin-top: 14px;
  padding: 12px 20px;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13.5px;
  font-family: var(--font-body);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}

.btn-calculate:hover { filter: brightness(1.18); }
.btn-calculate:active { transform: scale(.97); }

.validation-message {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
}

.validation-message.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.validation-message.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #86efac;
}

/* Scenario presets card */
.scenario-presets {
  background: var(--surface);
  padding: 18px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.scenario-presets h4 {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 11px;
}

.preset-buttons {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 10px;
}

.preset-btn {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 500;
  font-size: 12.5px;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
  transition: all .15s;
}

.preset-btn:hover {
  border-color: var(--purple);
  background: var(--purple-pale);
  color: var(--purple);
}

.preset-btn.active {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
}

.scenario-description {
  padding: 9px 12px;
  background: var(--bg);
  border-left: 3px solid var(--purple);
  border-radius: 0 5px 5px 0;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.65;
  display: none;
}

/* Results section */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.results-section > h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--purple);
  padding-bottom: 9px;
  border-bottom: 2px solid var(--gold);
}

.results-section h4,
.chart-container h4,
.rankings-panel h4,
.map-container-simulator h4 {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 13px;
}

.chart-container {
  background: var(--surface);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.chart-container canvas { max-height: 270px; }

.rankings-panel {
  background: var(--surface);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.map-container-simulator {
  background: var(--surface);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.simulate-map {
  width: 100%;
  height: 380px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.map-legend {
  background: var(--bg);
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.map-legend h5 {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
  margin-bottom: 9px;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.legend-color {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.10);
}

.legend-label { font-size: 12px; color: var(--text-2); }

.legend-range {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-2);
  padding-top: 7px;
  border-top: 1px solid var(--border);
}

/* Rankings table (simulator) */
.rankings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.rankings-table thead th {
  background: var(--purple);
  color: rgba(255,255,255,.82);
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  position: sticky;
  top: 0;
}

.rankings-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

.rankings-table tbody tr:nth-child(even) td { background: rgba(240,235,248,.35); }
.rankings-table tbody tr:hover td { background: var(--purple-pale); }
.rankings-table tbody tr:last-child td { border-bottom: none; }

.rankings-table .rank-num {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--gold-deep);
  background: var(--purple);
  text-align: center;
  padding: 9px 6px;
}

.rankings-table .rank-name { font-weight: 600; }

.rankings-table .rank-index {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
}

/* ═══════════════════════════════════════════════════════
   LEAFLET CUSTOMIZATION
   ═══════════════════════════════════════════════════════ */

.custom-tooltip {
  background: var(--purple-dark) !important;
  color: rgba(255,255,255,.92) !important;
  border: 1px solid rgba(253,208,35,.5) !important;
  border-radius: 6px !important;
  font-family: var(--font-body) !important;
  font-size: 12px !important;
}

.custom-popup .leaflet-popup-content-wrapper {
  border-radius: 10px;
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow);
}

.map-popup h4 {
  font-family: var(--font-display);
  margin-bottom: 8px;
  color: var(--purple);
  font-size: 14.5px;
  font-weight: 700;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--gold);
}

.popup-row {
  margin: 6px 0;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.popup-row strong { color: var(--text-2); font-weight: 500; }

/* ═══════════════════════════════════════════════════════
   MOBILE NAV & DRAWERS
   ═══════════════════════════════════════════════════════ */

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.nav-toggle-bar {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform .2s, opacity .2s;
}

.header.nav-open .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.header.nav-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.header.nav-open .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar-open-btn {
  display: none;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  z-index: 900;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--purple-dark);
  color: #fff;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(20,8,42,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.panel h3::after {
  content: '▾';
  float: right;
  font-size: 11px;
  opacity: .6;
  transition: transform .2s;
}

.panel.panel-collapsed h3::after { transform: rotate(-90deg); }

.panel.panel-collapsed #infoBody { display: none; }

/* Mobile card-style tables */
.table-mobile-cards thead { display: none; }

.table-mobile-cards tbody tr {
  display: block;
  margin-bottom: 12px;
  padding: 4px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.table-mobile-cards tbody tr:hover td { background: transparent; }

.table-mobile-cards tbody td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.table-mobile-cards tbody td:last-child { border-bottom: none; }

.table-mobile-cards tbody td::before {
  content: attr(data-label);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  flex-shrink: 0;
}

.table-mobile-cards tbody td:nth-child(n+3) {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — MOBILE-FIRST
   ═══════════════════════════════════════════════════════ */

@media (max-width: 1100px) {
  .simulator-container { grid-template-columns: 1fr; }
}

.dashboard-tabs {
  display: none;
}

@media (max-width: 768px) {
  .nav-toggle { display: flex; }

  .dashboard--mobile {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .dashboard-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    grid-column: 1 / -1;
  }

  .dashboard-tab {
    flex: 1;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-2);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }

  .dashboard-tab.active {
    background: var(--purple);
    border-color: var(--purple);
    color: #fff;
  }

  .dashboard--mobile .chat-panel,
  .dashboard--mobile .map-panel {
    min-height: 0;
    height: calc(100dvh - var(--header-h) - 58px);
  }

  .dashboard--mobile.dashboard--view-map .chat-panel { display: none; }
  .dashboard--mobile.dashboard--view-chat .map-panel { display: none; }

  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0;
    padding: 8px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: var(--purple-dark);
    border-bottom: 2px solid var(--gold);
    box-shadow: var(--shadow-lg);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: max-height .3s ease, opacity .2s;
  }

  .header.nav-open .nav {
    max-height: 320px;
    opacity: 1;
    pointer-events: auto;
  }

  .nav a {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    font-size: 15px;
    border-radius: 8px;
    white-space: normal;
  }

  .brand-text h1 {
    font-size: clamp(14px, 4vw, 17px);
    white-space: normal;
    line-height: 1.25;
  }

  .brand-text p { font-size: 9.5px; }

  /* Map page: full-height map + slide-over sidebar */
  .app {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 88vw);
    max-height: none;
    z-index: 1500;
    border-right: 1px solid var(--border);
    border-bottom: none;
    padding: 56px 18px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    transform: translateX(-105%);
    transition: transform .28s ease;
    box-shadow: var(--shadow-lg);
  }

  body.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-open-btn { display: inline-flex; }

  .sidebar-close-btn { display: flex; align-items: center; justify-content: center; }

  .sidebar-backdrop {
    display: block;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .content {
    flex: 1;
    min-height: 0;
    height: calc(100dvh - var(--header-h, 66px));
  }

  .map-wrap { height: 100%; }

  #map { min-height: 280px; }

  .loading {
    top: 62px;
    right: 12px;
    left: auto;
    font-size: 11px;
  }

  .sidebar h2 {
    margin-top: 2px;
    padding-right: 48px;
  }

  .panel {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
    max-height: 42vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel .row {
    font-size: 13px;
    padding: 2px 0;
  }

  /* Touch-friendly form controls */
  select,
  .table-search,
  input[type="text"],
  input[type="number"],
  .weight-input {
    font-size: 16px;
    min-height: 44px;
  }

  input[type="range"] {
    height: 6px;
    margin: 12px 0 6px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .btn,
  .btn-calculate,
  .preset-btn {
    min-height: 48px;
    font-size: 14px;
  }

  .chat-send-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }

  .chat-input-row input {
    padding: 10px 12px;
  }

  .page {
    padding: 20px max(14px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .page-header h2 { font-size: clamp(20px, 5.5vw, 26px); }

  .page-header p { font-size: 14px; line-height: 1.65; }

  .table-search { max-width: none; }

  .table-wrap {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  #tbl.table-mobile-cards { font-size: 14px; }

  .tree { padding: 14px; }

  .node {
    padding: 14px;
    margin: 8px 0;
  }

  .node .hdr { font-size: 14px; flex-wrap: wrap; }

  .leaf { font-size: 14px; padding: 11px 12px; }

  .calc-steps { padding: 18px 16px; }

  .simulator-container { gap: 16px; }

  .weight-controls,
  .scenario-presets,
  .chart-container,
  .rankings-panel,
  .map-container-simulator {
    padding: 16px;
  }

  .weight-input { font-size: 22px; }

  .sum-display #weightSum { font-size: 26px; }

  .simulate-map {
    height: min(45dvh, 340px);
    min-height: 240px;
  }

  .chart-container {
    min-height: 280px;
  }

  .chart-container canvas {
    width: 100% !important;
    max-height: none;
    height: 260px !important;
  }

  .legend-items { gap: 8px; }

  .rankings-panel .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .rankings-table.table-mobile-cards .rank-num {
    text-align: left;
    background: transparent;
    color: var(--gold-deep);
    font-size: 14px;
    padding: 10px 14px;
  }

  /* Leaflet controls — larger touch targets */
  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }

  .leaflet-bar { border-radius: 8px !important; }
}

@media (max-width: 480px) {
  :root { --header-h: 58px; }

  .header { min-height: 58px; }

  .brand-mark { width: 36px; height: 36px; font-size: 12px; }

  .header-brand { gap: 10px; }

  .page { padding-top: 16px; }

  .page-header { margin-bottom: 16px; }

  .btn-row { flex-direction: column; }

  .btn-row .btn { width: 100%; }

  .preset-buttons { gap: 8px; }

  .results-section > h3 { font-size: 18px; }
}

@media (min-width: 769px) {
  .sidebar-backdrop,
  .sidebar-open-btn,
  .sidebar-close-btn { display: none !important; }

  .panel h3::after { display: none; }
}
