/* ============================================================
   Human Survivability Risk — World Map Dashboard
   Professional Dark Theme · Fixed Layout WebApp
   ============================================================ */

/* ----- CSS Variables / Design Tokens ----- */
:root {
  /* Core palette */
  --bg-primary: #0a0e14;
  --bg-secondary: #111720;
  --bg-tertiary: #161c26;
  --bg-elevated: #1c2330;
  --bg-surface: #222a38;

  /* Accent */
  --accent-blue: #4d9eff;
  --accent-cyan: #00d4aa;
  --accent-amber: #f5a623;
  --accent-red: #ff4757;
  --accent-orange: #ff6b35;
  --accent-purple: #a855f7;
  --accent-green: #22c55e;
  --accent-pink: #ec4899;

  /* Risk scale */
  --risk-low: #22c55e;
  --risk-moderate: #f5a623;
  --risk-elevated: #ff6b35;
  --risk-high: #ff4757;
  --risk-extreme: #991b1b;

  /* Text */
  --text-primary: #e8edf4;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0a0e14;

  /* Borders */
  --border-subtle: rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.16);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

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

  /* Layout */
  --top-bar-height: 72px;
  --timeline-height: 64px;
  --side-panel-width: 420px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

/* ----- App Layout (Fixed Position WebApp) ----- */
body {
  display: flex;
  flex-direction: column;
}

/* ============================================================
   TOP BAR
   ============================================================ */
.top-bar {
  height: var(--top-bar-height);
  min-height: var(--top-bar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-xl);
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.top-bar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.app-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.top-bar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

/* KPI Cards */
.kpi-row {
  display: flex;
  gap: var(--space-lg);
}

.kpi-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: var(--space-sm) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
  transition: border-color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}

.kpi-card:hover {
  border-color: var(--border-default);
  background: var(--bg-elevated);
}

.kpi-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.kpi-change {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.kpi-temp .kpi-value { color: var(--accent-orange); }
.kpi-risk .kpi-value { color: var(--accent-red); }
.kpi-composite .kpi-value { color: var(--accent-amber); }
.kpi-displaced .kpi-value { color: var(--accent-purple); }

/* Scenario Buttons */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.scenario-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-left: var(--space-xs);
}

.btn-scenario {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  letter-spacing: 0.01em;
}

.btn-scenario:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-scenario.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ----- MAP PANEL ----- */
.map-panel {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
}

#world-map {
  width: 100%;
  height: 100%;
  background: #0d1117;
}

/* Leaflet overrides */
.leaflet-container {
  background: #0d1117 !important;
  font-family: var(--font-sans) !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border-default) !important;
  border-radius: 8px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-subtle) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-surface) !important;
}

.leaflet-control-attribution {
  background: rgba(10,14,20,0.85) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  padding: 4px 8px !important;
  border-radius: 4px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 24px;
  left: 16px;
  background: rgba(17, 23, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  padding: var(--space-md) var(--space-lg);
  z-index: 1000;
  min-width: 180px;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}

.legend-gradient {
  height: 10px;
  border-radius: 5px;
  margin-bottom: 4px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Map overlay info */
.map-overlay-info {
  position: absolute;
  top: 12px;
  right: 16px;
  background: rgba(17, 23, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 8px 14px;
  z-index: 1000;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ============================================================
   SIDE PANEL
   ============================================================ */
.side-panel {
  width: var(--side-panel-width);
  min-width: var(--side-panel-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.side-panel::-webkit-scrollbar {
  width: 4px;
}

.side-panel::-webkit-scrollbar-track {
  background: transparent;
}

.side-panel::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 2px;
}

.panel-section {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* Layer Toggles */
.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  text-align: left;
  width: 100%;
}

.layer-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.layer-btn.active {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.composite-dot { background: var(--accent-purple); }
.temp-dot { background: var(--accent-orange); }
.pollution-dot { background: #64748b; }
.water-dot { background: var(--accent-blue); }
.poverty-dot { background: var(--accent-red); }
.inequality-dot { background: var(--accent-pink); }
.population-dot { background: var(--accent-cyan); }

/* Country Detail */
.country-detail h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.detail-item {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Chart containers */
.chart-container {
  position: relative;
  width: 100%;
  height: 180px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ============================================================
   TIMELINE BAR
   ============================================================ */
.timeline-bar {
  height: var(--timeline-height);
  min-height: var(--timeline-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-lg);
  z-index: 1000;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.timeline-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.timeline-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.timeline-btn.playing {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.speed-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 48px;
  text-align: center;
}

.timeline-slider-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.timeline-year {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 36px;
}

.timeline-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: 2px solid var(--bg-secondary);
  box-shadow: 0 0 12px rgba(77, 158, 255, 0.4);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out);
}

.timeline-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.timeline-year-display {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  min-width: 72px;
  text-align: right;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  :root {
    --side-panel-width: 360px;
  }
  .kpi-card {
    min-width: 110px;
    padding: var(--space-sm) var(--space-md);
  }
  .kpi-value {
    font-size: 18px;
  }
}

@media (max-width: 900px) {
  :root {
    --top-bar-height: 56px;
    --timeline-height: 56px;
    --side-panel-width: 100%;
  }

  .main-content {
    flex-direction: column;
  }

  .map-panel {
    height: 55%;
  }

  .side-panel {
    width: 100%;
    min-width: 100%;
    height: 45%;
    flex-shrink: 0;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
  }

  .top-bar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--top-bar-height);
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
  }

  .kpi-row {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .kpi-card {
    min-width: 80px;
    flex: 1;
  }

  .app-title {
    font-size: 14px;
  }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.loading-pulse {
  animation: pulse 1.5s var(--ease-in-out) infinite;
}

/* Info tooltip on map */
.leaflet-tooltip.country-tooltip {
  background: rgba(17, 23, 32, 0.95);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 10px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.leaflet-tooltip.country-tooltip::before {
  border-top-color: rgba(17, 23, 32, 0.95);
}
