/* ============================================================
   WORLD DEVELOPMENT DASHBOARD — Main Stylesheet
   Dark "Global Command Center" Theme
   ============================================================ */

/* ────────────────────────────────────────────────────────────
   0. CSS CUSTOM PROPERTIES
   ──────────────────────────────────────────────────────────── */

:root {
  /* ── Color System ─────────────────────────────────────── */
  --color-bg:              #0a0e17;
  --color-surface:         #111827;
  --color-surface-elevated:#1a2332;
  --color-surface-hover:   #1f2b3d;
  --color-surface-active:  #243047;
  --color-border:          #1e293b;
  --color-border-light:    #2d3d53;
  --color-border-focus:    #3b82f6;

  --color-text-primary:    #e2e8f0;
  --color-text-secondary:  #94a3b8;
  --color-text-muted:      #64748b;
  --color-text-inverse:    #0a0e17;

  --color-accent-primary:  #3b82f6;
  --color-accent-success:  #10b981;
  --color-accent-warning:  #f59e0b;
  --color-accent-danger:   #ef4444;
  --color-accent-info:     #06b6d4;

  --color-accent-primary-dim: rgba(59, 130, 246, 0.15);
  --color-accent-success-dim: rgba(16, 185, 129, 0.15);
  --color-accent-warning-dim: rgba(245, 158, 11, 0.15);
  --color-accent-danger-dim:  rgba(239, 68, 68, 0.15);
  --color-accent-info-dim:    rgba(6, 182, 212, 0.15);

  --glow-blue:   0 0 8px rgba(59, 130, 246, 0.25);
  --glow-green:  0 0 8px rgba(16, 185, 129, 0.25);
  --glow-red:    0 0 8px rgba(239, 68, 68, 0.25);
  --glow-amber:  0 0 8px rgba(245, 158, 11, 0.25);
  --glow-cyan:   0 0 8px rgba(6, 182, 212, 0.25);

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

  --text-label:    11px;
  --text-body:     13px;
  --text-emphasis:  14px;
  --text-heading:   18px;
  --text-hero:      24px;

  --leading-tight:  1.2;
  --leading-normal: 1.5;
  --leading-relaxed:1.65;

  --tracking-tight:  -0.01em;
  --tracking-normal:  0;
  --tracking-wide:    0.04em;
  --tracking-wider:   0.08em;

  /* ── Layout ───────────────────────────────────────────── */
  --header-h:        56px;
  --left-rail-w:     48px;
  --right-rail-w:    320px;
  --bottom-panel-h:  280px;
  --country-panel-w: 420px;

  /* ── Radius ───────────────────────────────────────────── */
  --radius-xs:  3px;
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  12px;
  --radius-pill: 9999px;

  /* ── Shadows ──────────────────────────────────────────── */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.5);
  --shadow-xl:  0 12px 40px rgba(0,0,0,0.6);

  /* ── Transitions ──────────────────────────────────────── */
  --transition-fast:    150ms ease;
  --transition-normal:  200ms ease;
  --transition-panel:   300ms ease-out;
  --transition-map:     500ms ease-in-out;

  /* ── Z-index layers ───────────────────────────────────── */
  --z-base:       1;
  --z-rail:       10;
  --z-panel:      20;
  --z-overlay:    30;
  --z-tooltip:    40;
  --z-header:     50;
  --z-modal:      60;
  --z-toast:      70;
}


/* ────────────────────────────────────────────────────────────
   1. RESET & BASE
   ──────────────────────────────────────────────────────────── */

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

html, body {
  height: 100%;
  overflow: hidden;             /* No page-level scrolling */
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--color-accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: #60a5fa; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

ul, ol { list-style: none; }

img, svg { display: block; max-width: 100%; }


/* ────────────────────────────────────────────────────────────
   2. DASHBOARD SHELL — Fixed-position Grid
   ──────────────────────────────────────────────────────────── */

.dashboard {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--bottom-panel-h);
  grid-template-columns: var(--left-rail-w) 1fr var(--right-rail-w);
  grid-template-areas:
    "header  header  header"
    "left    map     right"
    "bottom  bottom  bottom";
  background: var(--color-bg);
  overflow: hidden;
}

/* Collapsed right rail */
.dashboard.right-rail-collapsed {
  grid-template-columns: var(--left-rail-w) 1fr 0;
}
.dashboard.right-rail-collapsed .right-rail {
  width: 0;
  overflow: hidden;
  border-left: none;
  padding: 0;
}

/* Collapsed bottom panel */
.dashboard.bottom-collapsed {
  grid-template-rows: var(--header-h) 1fr 36px;
}

/* Expanded bottom panel */
.dashboard.bottom-expanded {
  grid-template-rows: var(--header-h) 1fr 480px;
}


/* ────────────────────────────────────────────────────────────
   3. HEADER BAR
   ──────────────────────────────────────────────────────────── */

.header {
  grid-area: header;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 16px;
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
}

.header__brand-icon {
  width: 28px;
  height: 28px;
  color: var(--color-accent-primary);
}

.header__brand-title {
  font-size: var(--text-emphasis);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-primary);
}

.header__brand-subtitle {
  font-size: var(--text-label);
  color: var(--color-text-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* Scenario Tabs */
.header__scenarios {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.header__scenario-tab {
  padding: 6px 14px;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.header__scenario-tab:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.header__scenario-tab--active {
  color: var(--color-accent-primary);
  background: var(--color-accent-primary-dim);
}

.header__scenario-tab--add {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-light);
  font-size: 16px;
}
.header__scenario-tab--add:hover {
  color: var(--color-text-secondary);
  border-color: var(--color-text-muted);
}

/* Year Display & Playback */
.header__playback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding-left: 16px;
  border-left: 1px solid var(--color-border);
}

.header__year {
  font-size: var(--text-hero);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-primary);
  min-width: 56px;
  text-align: center;
}

.header__playback-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}
.header__playback-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}
.header__playback-btn--play {
  color: var(--color-accent-primary);
}
.header__playback-btn--play:hover {
  background: var(--color-accent-primary-dim);
}

.header__year-slider {
  width: 160px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  outline: none;
}
.header__year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent-primary);
  box-shadow: var(--glow-blue);
  cursor: pointer;
}
.header__year-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent-primary);
  box-shadow: var(--glow-blue);
  cursor: pointer;
  border: none;
}

/* Header actions */
.header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 16px;
  border-left: 1px solid var(--color-border);
}

.header__action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
  position: relative;
}
.header__action-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.header__action-btn .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent-danger);
}


/* ────────────────────────────────────────────────────────────
   4. LEFT MINI-RAIL
   ──────────────────────────────────────────────────────────── */

.left-rail {
  grid-area: left;
  z-index: var(--z-rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  width: var(--left-rail-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}

.left-rail__btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  position: relative;
}

.left-rail__btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.left-rail__btn--active {
  color: var(--color-accent-primary);
  background: var(--color-accent-primary-dim);
}

.left-rail__btn-tooltip {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 10px;
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip);
  box-shadow: var(--shadow-md);
}

.left-rail__btn:hover .left-rail__btn-tooltip {
  display: block;
}

.left-rail__separator {
  width: 24px;
  height: 1px;
  background: var(--color-border);
  margin: 4px 0;
}

.left-rail__spacer {
  flex: 1;
}


/* ────────────────────────────────────────────────────────────
   5. RIGHT CONTROL RAIL
   ──────────────────────────────────────────────────────────── */

.right-rail {
  grid-area: right;
  z-index: var(--z-rail);
  display: flex;
  flex-direction: column;
  width: var(--right-rail-w);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow: hidden;
  transition: width var(--transition-panel);
}

.right-rail__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.right-rail__title {
  font-size: var(--text-emphasis);
  font-weight: 600;
  color: var(--color-text-primary);
}

.right-rail__collapse-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}
.right-rail__collapse-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.right-rail__body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

/* ── Control Section ──────────────────────────────────────── */

.control-section {
  border-bottom: 1px solid var(--color-border);
}

.control-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}
.control-section__header:hover {
  background: var(--color-surface-hover);
}

.control-section__label {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.control-section__chevron {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  transition: transform var(--transition-normal);
}

.control-section--collapsed .control-section__chevron {
  transform: rotate(-90deg);
}

.control-section__body {
  padding: 4px 16px 16px;
  overflow: hidden;
  transition: max-height var(--transition-panel), padding var(--transition-panel);
}

.control-section--collapsed .control-section__body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* ── Control Row ──────────────────────────────────────────── */

.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.control-row:last-child { margin-bottom: 0; }

.control-row__label-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-row__label {
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-secondary);
  letter-spacing: var(--tracking-wide);
}

.control-row__value {
  font-size: var(--text-label);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  font-family: var(--font-mono);
}


/* ────────────────────────────────────────────────────────────
   6. CUSTOM RANGE SLIDERS
   ──────────────────────────────────────────────────────────── */

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-border);
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.range-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent-primary);
  border: 2px solid var(--color-surface);
  box-shadow: var(--glow-blue);
  margin-top: -5px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.range-slider::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-border);
}

.range-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent-primary);
  border: 2px solid var(--color-surface);
  box-shadow: var(--glow-blue);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.range-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.range-slider::-moz-range-progress {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-primary);
}

/* Slider color variants */
.range-slider--success::-webkit-slider-thumb { background: var(--color-accent-success); box-shadow: var(--glow-green); }
.range-slider--success::-moz-range-thumb     { background: var(--color-accent-success); box-shadow: var(--glow-green); }
.range-slider--success::-moz-range-progress  { background: var(--color-accent-success); }

.range-slider--warning::-webkit-slider-thumb { background: var(--color-accent-warning); box-shadow: var(--glow-amber); }
.range-slider--warning::-moz-range-thumb     { background: var(--color-accent-warning); box-shadow: var(--glow-amber); }
.range-slider--warning::-moz-range-progress  { background: var(--color-accent-warning); }

.range-slider--danger::-webkit-slider-thumb  { background: var(--color-accent-danger); box-shadow: var(--glow-red); }
.range-slider--danger::-moz-range-thumb      { background: var(--color-accent-danger); box-shadow: var(--glow-red); }
.range-slider--danger::-moz-range-progress   { background: var(--color-accent-danger); }


/* ────────────────────────────────────────────────────────────
   7. TOGGLE SWITCHES
   ──────────────────────────────────────────────────────────── */

.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle__track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--color-border-light);
  transition: background var(--transition-normal), box-shadow var(--transition-normal);
  cursor: pointer;
}

.toggle__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  transition: transform var(--transition-normal), background var(--transition-normal);
}

.toggle input:checked + .toggle__track {
  background: var(--color-accent-primary);
  box-shadow: var(--glow-blue);
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(16px);
  background: #fff;
}

.toggle input:focus-visible + .toggle__track {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

/* Toggle row helper */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.toggle-row__label {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
}


/* ────────────────────────────────────────────────────────────
   8. MAP CONTAINER & OVERLAYS
   ──────────────────────────────────────────────────────────── */

.map-container {
  grid-area: map;
  position: relative;
  overflow: hidden;
  background: var(--color-bg);
}

.map-container canvas,
.map-container svg,
.map-container .mapboxgl-map,
.map-container .leaflet-container {
  width: 100%;
  height: 100%;
}

/* ── Map Layer Toggles ────────────────────────────────────── */

.map-layers {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-layers__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-secondary);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.map-layers__btn:hover {
  color: var(--color-text-primary);
  background: rgba(26, 35, 50, 0.9);
}
.map-layers__btn--active {
  color: var(--color-accent-primary);
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.1);
}

.map-layers__btn-icon {
  width: 14px;
  height: 14px;
}

/* ── Map Legend ────────────────────────────────────────────── */

.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: var(--z-overlay);
  padding: 12px 16px;
  background: rgba(17, 24, 39, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  min-width: 160px;
}

.map-legend__title {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: 8px;
}

.map-legend__scale {
  display: flex;
  align-items: stretch;
  height: 10px;
  border-radius: var(--radius-xs);
  overflow: hidden;
  margin-bottom: 4px;
}

.map-legend__scale-segment {
  flex: 1;
}

.map-legend__labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

.map-legend__item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.map-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
}

.map-legend__item-label {
  font-size: var(--text-label);
  color: var(--color-text-secondary);
}

/* ── Zoom Controls ────────────────────────────────────────── */

.map-zoom {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.map-zoom__btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: rgba(17, 24, 39, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
}
.map-zoom__btn:hover {
  color: var(--color-text-primary);
  background: rgba(26, 35, 50, 0.92);
}
.map-zoom__btn:first-child { border-radius: var(--radius-md) var(--radius-md) 0 0; }
.map-zoom__btn:last-child  { border-radius: 0 0 var(--radius-md) var(--radius-md); }

/* ── Country Tooltip (follows cursor) ─────────────────────── */

.country-tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  pointer-events: none;
  padding: 10px 14px;
  max-width: 260px;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.country-tooltip--visible {
  opacity: 1;
  transform: translateY(0);
}

.country-tooltip__name {
  font-size: var(--text-emphasis);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.country-tooltip__region {
  font-size: var(--text-label);
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.country-tooltip__metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
}

.country-tooltip__metric-label {
  font-size: var(--text-label);
  color: var(--color-text-secondary);
}

.country-tooltip__metric-value {
  font-size: var(--text-body);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
}

.country-tooltip__arrow {
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: rgba(17, 24, 39, 0.92);
  border-right: 1px solid var(--color-border-light);
  border-bottom: 1px solid var(--color-border-light);
}


/* ────────────────────────────────────────────────────────────
   9. COUNTRY DETAIL PANEL (slides in from left)
   ──────────────────────────────────────────────────────────── */

.country-panel {
  position: absolute;
  top: 0;
  left: 0;
  z-index: var(--z-panel);
  width: var(--country-panel-w);
  height: 100%;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-xl);
  transform: translateX(-100%);
  transition: transform var(--transition-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.country-panel--open {
  transform: translateX(0);
}

.country-panel__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.country-panel__flag {
  width: 36px;
  height: 24px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  border: 1px solid var(--color-border);
}

.country-panel__name {
  font-size: var(--text-heading);
  font-weight: 700;
  color: var(--color-text-primary);
  flex: 1;
}

.country-panel__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}
.country-panel__close:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

/* Country Panel Tabs */
.country-panel__tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.country-panel__tab {
  flex: 1;
  padding: 10px 0;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--color-text-muted);
  text-align: center;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
}
.country-panel__tab:hover {
  color: var(--color-text-secondary);
}
.country-panel__tab--active {
  color: var(--color-accent-primary);
  border-bottom-color: var(--color-accent-primary);
}

.country-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* ── Metric Cards ─────────────────────────────────────────── */

.metric-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  margin-bottom: 8px;
  transition: border-color var(--transition-fast);
}
.metric-card:hover {
  border-color: var(--color-border-light);
}

.metric-card__info {
  flex: 1;
  min-width: 0;
}

.metric-card__label {
  font-size: var(--text-label);
  color: var(--color-text-muted);
  letter-spacing: var(--tracking-wide);
  margin-bottom: 2px;
}

.metric-card__value {
  font-size: var(--text-heading);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  line-height: var(--leading-tight);
}

.metric-card__change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-label);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.metric-card__change--up   { color: var(--color-accent-success); }
.metric-card__change--down { color: var(--color-accent-danger); }

.metric-card__sparkline {
  width: 64px;
  height: 28px;
  flex-shrink: 0;
}

.metric-card__sparkline svg {
  width: 100%;
  height: 100%;
}

/* ── Sector Breakdown Bars ────────────────────────────────── */

.sector-bar {
  margin-bottom: 10px;
}

.sector-bar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sector-bar__label {
  font-size: var(--text-label);
  color: var(--color-text-secondary);
}

.sector-bar__value {
  font-size: var(--text-label);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
}

.sector-bar__track {
  height: 6px;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.sector-bar__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--color-accent-primary);
  transition: width var(--transition-map);
}

.sector-bar__fill--success { background: var(--color-accent-success); }
.sector-bar__fill--warning { background: var(--color-accent-warning); }
.sector-bar__fill--danger  { background: var(--color-accent-danger); }
.sector-bar__fill--info    { background: var(--color-accent-info); }


/* ────────────────────────────────────────────────────────────
   10. COMPARISON PANEL (full-width overlay)
   ──────────────────────────────────────────────────────────── */

.comparison-panel {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: var(--z-modal);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-panel);
}

.comparison-panel--open {
  opacity: 1;
  pointer-events: auto;
}

.comparison-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.comparison-panel__title {
  font-size: var(--text-heading);
  font-weight: 700;
}

.comparison-panel__grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}

.comparison-panel__card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.comparison-panel__card-title {
  font-size: var(--text-emphasis);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.comparison-panel__chart {
  flex: 1;
  min-height: 200px;
}


/* ────────────────────────────────────────────────────────────
   11. BOTTOM ANALYTICS PANEL
   ──────────────────────────────────────────────────────────── */

.bottom-panel {
  grid-area: bottom;
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  overflow: hidden;
  transition: grid-template-rows var(--transition-panel);
}

/* Drag handle */
.bottom-panel__handle {
  height: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  flex-shrink: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.bottom-panel__handle::after {
  content: '';
  width: 40px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-border-light);
  transition: background var(--transition-fast);
}

.bottom-panel__handle:hover::after {
  background: var(--color-text-muted);
}

/* Tab bar */
.bottom-panel__tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  overflow-x: auto;
}

.bottom-panel__tab {
  padding: 10px 14px;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
}
.bottom-panel__tab:hover {
  color: var(--color-text-secondary);
}
.bottom-panel__tab--active {
  color: var(--color-accent-primary);
  border-bottom-color: var(--color-accent-primary);
}

.bottom-panel__expand-btn {
  margin-left: auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.bottom-panel__expand-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

/* Content area */
.bottom-panel__content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
}


/* ────────────────────────────────────────────────────────────
   12. KPI CARDS (scrollable row in bottom panel)
   ──────────────────────────────────────────────────────────── */

.kpi-row {
  display: flex;
  gap: 12px;
  padding-bottom: 4px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.kpi-card {
  flex: 0 0 180px;
  scroll-snap-align: start;
  padding: 14px 16px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: default;
}

.kpi-card:hover {
  border-color: var(--color-border-light);
  box-shadow: var(--shadow-sm);
}

.kpi-card__label {
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  line-height: var(--leading-tight);
}

.kpi-card__value {
  font-size: var(--text-hero);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  line-height: var(--leading-tight);
}

.kpi-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.kpi-card__change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-label);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.kpi-card__change--positive { color: var(--color-accent-success); }
.kpi-card__change--negative { color: var(--color-accent-danger); }
.kpi-card__change--neutral  { color: var(--color-text-muted); }

.kpi-card__sparkline {
  width: 48px;
  height: 20px;
  flex-shrink: 0;
}

.kpi-card__sparkline svg {
  width: 100%;
  height: 100%;
}

/* Accent border variants */
.kpi-card--blue    { border-left: 3px solid var(--color-accent-primary); }
.kpi-card--green   { border-left: 3px solid var(--color-accent-success); }
.kpi-card--amber   { border-left: 3px solid var(--color-accent-warning); }
.kpi-card--red     { border-left: 3px solid var(--color-accent-danger); }
.kpi-card--cyan    { border-left: 3px solid var(--color-accent-info); }


/* ────────────────────────────────────────────────────────────
   13. CHART CONTAINERS
   ──────────────────────────────────────────────────────────── */

.chart-container {
  position: relative;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.chart-container__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.chart-container__title {
  font-size: var(--text-emphasis);
  font-weight: 600;
  color: var(--color-text-primary);
}

.chart-container__subtitle {
  font-size: var(--text-label);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.chart-container__actions {
  display: flex;
  gap: 4px;
}

.chart-container__body {
  flex: 1;
  position: relative;
  min-height: 0;
}

/* Chart legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 8px;
  flex-shrink: 0;
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-label);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: opacity var(--transition-fast);
}
.chart-legend__item--dimmed {
  opacity: 0.35;
}

.chart-legend__swatch {
  width: 10px;
  height: 3px;
  border-radius: var(--radius-pill);
}

/* Chart grid and axis (for SVG/Canvas charts) */
.chart-grid-line {
  stroke: var(--color-border);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-axis-label {
  font-size: 10px;
  fill: var(--color-text-muted);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
}

.chart-axis-line {
  stroke: var(--color-border);
  stroke-width: 1;
}

/* Chart grid layout for multiple charts */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}


/* ────────────────────────────────────────────────────────────
   14. TOOLTIPS (general)
   ──────────────────────────────────────────────────────────── */

.tooltip {
  position: absolute;
  z-index: var(--z-tooltip);
  padding: 8px 12px;
  font-size: 12px;
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.tooltip--visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip__arrow {
  position: absolute;
  width: 8px;
  height: 8px;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--color-border-light);
  transform: rotate(45deg);
}

.tooltip__arrow--bottom {
  bottom: -5px;
  left: 50%;
  margin-left: -4px;
  border-top: none;
  border-left: none;
}

.tooltip__arrow--top {
  top: -5px;
  left: 50%;
  margin-left: -4px;
  border-bottom: none;
  border-right: none;
}

.tooltip__arrow--left {
  left: -5px;
  top: 50%;
  margin-top: -4px;
  border-top: none;
  border-right: none;
}

.tooltip__arrow--right {
  right: -5px;
  top: 50%;
  margin-top: -4px;
  border-bottom: none;
  border-left: none;
}

.tooltip__title {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
}

.tooltip__label {
  color: var(--color-text-secondary);
}

.tooltip__value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}


/* ────────────────────────────────────────────────────────────
   15. LOADING & SKELETON STATES
   ──────────────────────────────────────────────────────────── */

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-elevated) 25%,
    var(--color-surface-hover) 50%,
    var(--color-surface-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton--text {
  height: 12px;
  width: 80%;
  margin-bottom: 8px;
}

.skeleton--heading {
  height: 20px;
  width: 50%;
  margin-bottom: 12px;
}

.skeleton--card {
  height: 80px;
  border-radius: var(--radius-lg);
}

.skeleton--chart {
  height: 200px;
  border-radius: var(--radius-lg);
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Live data indicator */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent-success);
  box-shadow: var(--glow-green);
  animation: pulse 2s ease-in-out infinite;
}

/* Spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner--sm { width: 14px; height: 14px; border-width: 1.5px; }
.spinner--lg { width: 32px; height: 32px; border-width: 3px; }


/* ────────────────────────────────────────────────────────────
   16. CUSTOM SCROLLBARS
   ──────────────────────────────────────────────────────────── */

/* WebKit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: var(--radius-pill);
  transition: background var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}


/* ────────────────────────────────────────────────────────────
   17. ANIMATIONS & TRANSITIONS
   ──────────────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.fade-in          { animation: fadeIn 300ms ease-out both; }
.slide-in-left    { animation: slideInLeft 300ms ease-out both; }
.slide-in-right   { animation: slideInRight 300ms ease-out both; }
.slide-up         { animation: slideUp 300ms ease-out both; }
.slide-down       { animation: slideDown 300ms ease-out both; }
.scale-in         { animation: scaleIn 200ms ease-out both; }

/* Staggered animation delay helpers */
.delay-1 { animation-delay: 50ms; }
.delay-2 { animation-delay: 100ms; }
.delay-3 { animation-delay: 150ms; }
.delay-4 { animation-delay: 200ms; }
.delay-5 { animation-delay: 250ms; }
.delay-6 { animation-delay: 300ms; }


/* ────────────────────────────────────────────────────────────
   18. UTILITY CLASSES
   ──────────────────────────────────────────────────────────── */

/* ── Glass effect ─────────────────────────────────────────── */
.glass {
  background: rgba(17, 24, 39, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ── Glow borders ─────────────────────────────────────────── */
.glow-blue  { box-shadow: var(--glow-blue);  border-color: rgba(59, 130, 246, 0.3); }
.glow-green { box-shadow: var(--glow-green); border-color: rgba(16, 185, 129, 0.3); }
.glow-red   { box-shadow: var(--glow-red);   border-color: rgba(239, 68, 68, 0.3); }
.glow-amber { box-shadow: var(--glow-amber); border-color: rgba(245, 158, 11, 0.3); }
.glow-cyan  { box-shadow: var(--glow-cyan);  border-color: rgba(6, 182, 212, 0.3); }

/* ── Typography helpers ───────────────────────────────────── */
.text-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-tabular {
  font-variant-numeric: tabular-nums;
}

.text-label {
  font-size: var(--text-label);
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-weight: 500;
}

.text-secondary { color: var(--color-text-secondary); }
.text-muted     { color: var(--color-text-muted); }
.text-primary   { color: var(--color-accent-primary); }
.text-success   { color: var(--color-accent-success); }
.text-warning   { color: var(--color-accent-warning); }
.text-danger    { color: var(--color-accent-danger); }
.text-info      { color: var(--color-accent-info); }

/* ── Scrollable container ─────────────────────────────────── */
.scrollable {
  overflow-y: auto;
  overflow-x: hidden;
}

.scrollable-x {
  overflow-x: auto;
  overflow-y: hidden;
}

/* ── Chip / Tag ───────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: var(--text-label);
  font-weight: 500;
  border-radius: var(--radius-pill);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  white-space: nowrap;
  line-height: 1.6;
}

.chip--blue  { color: var(--color-accent-primary); background: var(--color-accent-primary-dim); border-color: rgba(59, 130, 246, 0.2); }
.chip--green { color: var(--color-accent-success); background: var(--color-accent-success-dim); border-color: rgba(16, 185, 129, 0.2); }
.chip--amber { color: var(--color-accent-warning); background: var(--color-accent-warning-dim); border-color: rgba(245, 158, 11, 0.2); }
.chip--red   { color: var(--color-accent-danger);  background: var(--color-accent-danger-dim);  border-color: rgba(239, 68, 68, 0.2); }
.chip--cyan  { color: var(--color-accent-info);    background: var(--color-accent-info-dim);    border-color: rgba(6, 182, 212, 0.2); }

.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Flex/Grid helpers ────────────────────────────────────── */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.flex-center { align-items: center; justify-content: center; }
.flex-between { align-items: center; justify-content: space-between; }
.gap-xs      { gap: 4px; }
.gap-sm      { gap: 8px; }
.gap-md      { gap: 12px; }
.gap-lg      { gap: 16px; }
.gap-xl      { gap: 24px; }

/* ── Spacing helpers ──────────────────────────────────────── */
.p-0  { padding: 0; }
.p-xs { padding: 4px; }
.p-sm { padding: 8px; }
.p-md { padding: 12px; }
.p-lg { padding: 16px; }
.p-xl { padding: 24px; }

.mt-xs { margin-top: 4px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 16px; }
.mt-xl { margin-top: 24px; }

.mb-xs { margin-bottom: 4px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 12px; }
.mb-lg { margin-bottom: 16px; }
.mb-xl { margin-bottom: 24px; }

/* ── Misc ─────────────────────────────────────────────────── */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.no-select {
  user-select: none;
  -webkit-user-select: none;
}

.pointer { cursor: pointer; }

.relative { position: relative; }
.absolute { position: absolute; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded    { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }

.border     { border: 1px solid var(--color-border); }
.border-b   { border-bottom: 1px solid var(--color-border); }

.bg-surface  { background: var(--color-surface); }
.bg-elevated { background: var(--color-surface-elevated); }


/* ────────────────────────────────────────────────────────────
   19. BUTTONS
   ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: var(--text-body);
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  white-space: nowrap;
  min-height: 32px;
}

.btn--primary {
  color: #fff;
  background: var(--color-accent-primary);
}
.btn--primary:hover {
  background: #2563eb;
  box-shadow: var(--glow-blue);
}

.btn--secondary {
  color: var(--color-text-secondary);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
}
.btn--secondary:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
  border-color: var(--color-border-light);
}

.btn--ghost {
  color: var(--color-text-secondary);
}
.btn--ghost:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}

.btn--danger {
  color: #fff;
  background: var(--color-accent-danger);
}
.btn--danger:hover {
  background: #dc2626;
  box-shadow: var(--glow-red);
}

.btn--sm {
  padding: 4px 10px;
  font-size: var(--text-label);
  min-height: 26px;
}

.btn--icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.btn--icon.btn--sm {
  width: 26px;
  height: 26px;
}


/* ────────────────────────────────────────────────────────────
   20. SELECT / DROPDOWN
   ──────────────────────────────────────────────────────────── */

.select-wrap {
  position: relative;
  display: inline-flex;
}

.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  padding: 6px 32px 6px 10px;
  font-size: var(--text-body);
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
  min-height: 32px;
}

.select-wrap select:hover {
  border-color: var(--color-border-light);
}

.select-wrap select:focus {
  border-color: var(--color-accent-primary);
  box-shadow: 0 0 0 2px var(--color-accent-primary-dim);
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-text-muted);
  pointer-events: none;
}

select option {
  background: var(--color-surface);
  color: var(--color-text-primary);
}


/* ────────────────────────────────────────────────────────────
   21. MODALS & OVERLAYS
   ──────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

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

.modal {
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-panel);
}

.modal-backdrop--open .modal {
  transform: scale(1) translateY(0);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  font-size: var(--text-heading);
  font-weight: 700;
}

.modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
}


/* ────────────────────────────────────────────────────────────
   22. TOAST / NOTIFICATIONS
   ──────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  min-width: 280px;
  max-width: 420px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: slideDown 300ms ease-out, fadeIn 300ms ease-out;
}

.toast--success { border-left: 3px solid var(--color-accent-success); }
.toast--warning { border-left: 3px solid var(--color-accent-warning); }
.toast--error   { border-left: 3px solid var(--color-accent-danger); }
.toast--info    { border-left: 3px solid var(--color-accent-info); }

.toast__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.toast__message {
  flex: 1;
  font-size: var(--text-body);
  color: var(--color-text-primary);
}

.toast__dismiss {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.toast__dismiss:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-hover);
}


/* ────────────────────────────────────────────────────────────
   23. INPUT FIELDS
   ──────────────────────────────────────────────────────────── */

.input {
  width: 100%;
  padding: 6px 10px;
  font-size: var(--text-body);
  color: var(--color-text-primary);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 32px;
}

.input::placeholder {
  color: var(--color-text-muted);
}

.input:hover {
  border-color: var(--color-border-light);
}

.input:focus {
  border-color: var(--color-accent-primary);
  box-shadow: 0 0 0 2px var(--color-accent-primary-dim);
}

.input--sm {
  padding: 4px 8px;
  font-size: var(--text-label);
  min-height: 26px;
}

/* Search input with icon */
.search-input {
  position: relative;
}

.search-input__icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.search-input .input {
  padding-left: 32px;
}


/* ────────────────────────────────────────────────────────────
   24. TABLES (data grids)
   ──────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body);
  font-variant-numeric: tabular-nums;
}

.data-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.data-table th--sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}
.data-table th--sortable:hover {
  color: var(--color-text-secondary);
}

.data-table td {
  padding: 8px 12px;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
}

.data-table tr:hover td {
  background: var(--color-surface-hover);
  color: var(--color-text-primary);
}

.data-table td--numeric {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--color-text-primary);
}


/* ────────────────────────────────────────────────────────────
   25. RESPONSIVE — Tablet (< 1024px)
   ──────────────────────────────────────────────────────────── */

@media (max-width: 1023px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr var(--bottom-panel-h);
    grid-template-areas:
      "header"
      "map"
      "bottom";
  }

  /* Hide left rail on tablet */
  .left-rail {
    display: none;
  }

  /* Right rail becomes bottom sheet */
  .right-rail {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-modal);
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--color-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
    transition: transform var(--transition-panel);
    box-shadow: var(--shadow-xl);
  }

  .right-rail--open {
    transform: translateY(0);
  }

  .right-rail__body {
    max-height: calc(70vh - 56px);
  }

  /* Country panel full width */
  .country-panel {
    width: 100%;
  }

  /* Ensure touch targets */
  .left-rail__btn,
  .header__action-btn,
  .bottom-panel__tab {
    min-width: 44px;
    min-height: 44px;
  }

  /* Bottom panel adjustments */
  .bottom-panel {
    min-height: 200px;
  }

  .kpi-card {
    flex: 0 0 160px;
  }
}


/* ────────────────────────────────────────────────────────────
   26. RESPONSIVE — Mobile (< 768px)
   ──────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  :root {
    --header-h: 48px;
    --bottom-panel-h: 240px;
  }

  .dashboard {
    grid-template-rows: var(--header-h) 1fr auto;
    grid-template-areas:
      "header"
      "map"
      "bottom";
  }

  /* Simplified header */
  .header {
    padding: 0 10px;
    gap: 8px;
  }

  .header__brand-subtitle,
  .header__scenarios {
    display: none;
  }

  .header__year-slider {
    width: 100px;
  }

  .header__year {
    font-size: var(--text-heading);
  }

  /* Bottom panel stacks full width */
  .bottom-panel__tabs {
    padding: 0 10px;
  }

  .bottom-panel__tab {
    padding: 10px 10px;
    font-size: var(--text-label);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .bottom-panel__content {
    padding: 10px;
  }

  /* KPIs stack differently */
  .kpi-row {
    gap: 8px;
  }

  .kpi-card {
    flex: 0 0 140px;
    padding: 10px 12px;
  }

  .kpi-card__value {
    font-size: var(--text-heading);
  }

  /* Country panel full-screen on mobile */
  .country-panel {
    width: 100%;
    z-index: var(--z-modal);
  }

  /* Comparison grid single column */
  .comparison-panel__grid {
    grid-template-columns: 1fr;
  }

  /* Chart grid single column */
  .chart-grid {
    grid-template-columns: 1fr;
  }

  /* Touch-friendly elements */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  .toggle {
    width: 44px;
    height: 24px;
  }

  .toggle__track::after {
    width: 20px;
    height: 20px;
  }

  .toggle input:checked + .toggle__track::after {
    transform: translateX(20px);
  }

  .range-slider::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    margin-top: -8px;
  }

  .range-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }

  /* Bottom sheet pattern for right rail */
  .right-rail {
    max-height: 80vh;
  }

  /* Map overlays repositioned */
  .map-layers {
    top: 8px;
    left: 8px;
  }

  .map-legend {
    bottom: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
  }

  .map-zoom {
    bottom: 8px;
    right: 8px;
  }
}


/* ────────────────────────────────────────────────────────────
   27. FOCUS & ACCESSIBILITY
   ──────────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High contrast adjustments */
@media (prefers-contrast: high) {
  :root {
    --color-border: #475569;
    --color-border-light: #64748b;
    --color-text-muted: #94a3b8;
    --color-text-secondary: #cbd5e1;
  }
}


/* ────────────────────────────────────────────────────────────
   28. PRINT (minimal)
   ──────────────────────────────────────────────────────────── */

@media print {
  .dashboard {
    position: static;
    display: block;
  }

  .header,
  .left-rail,
  .right-rail,
  .map-zoom,
  .map-layers,
  .bottom-panel__handle {
    display: none !important;
  }

  .map-container {
    page-break-after: always;
  }

  * {
    color: #000 !important;
    background: #fff !important;
    box-shadow: none !important;
  }
}
