/* Prosperity Diffusion Dashboard — Main Stylesheet */
/* Dark command-center aesthetic with precise typography */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* === CSS CUSTOM PROPERTIES === */
:root {
  --bg: #060a13;
  --bg-alt: #0a0e17;
  --surface: #0f1625;
  --surface-2: #151d30;
  --surface-3: #1a2340;
  --border: #1a2438;
  --border-light: #253350;
  --text: #e0e6ed;
  --text-secondary: #8892a4;
  --text-dim: #5a6478;
  --accent: #00d4ff;
  --accent-dim: #0088aa;
  --accent-bg: rgba(0, 212, 255, 0.08);
  --positive: #00e676;
  --positive-dim: #00a152;
  --negative: #ff5252;
  --negative-dim: #c62828;
  --warning: #ffab00;
  --purple: #b388ff;
  --pink: #ff80ab;
  --orange: #ff9100;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.6);
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --header-h: 52px;
  --right-rail-w: 320px;
  --bottom-h: 280px;
  --left-rail-w: 44px;
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* === LAYOUT === */
#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: var(--left-rail-w) 1fr var(--right-rail-w);
  grid-template-areas:
    "header header header"
    "left   map    right"
    "bottom bottom bottom";
  overflow: hidden;
}

/* === HEADER === */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  min-width: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-logo svg { width: 22px; height: 22px; }

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

/* Year controls */
.year-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.year-display {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  min-width: 50px;
  text-align: center;
}

.year-slider {
  width: 160px;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-icon:hover { border-color: var(--accent-dim); color: var(--accent); background: var(--accent-bg); }
.btn-icon.active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.btn-icon svg { width: 14px; height: 14px; }

/* Scenario selector */
.scenario-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.scenario-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.scenario-btn:hover { border-color: var(--border-light); color: var(--text); }
.scenario-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

/* View mode pills */
.view-modes {
  display: flex;
  align-items: center;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-width: 0;
}

.view-modes::-webkit-scrollbar { display: none; }

.view-mode-btn {
  flex: 1;
  padding: 4px 8px;
  font-size: 10.5px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-align: center;
}

.view-mode-btn:hover { color: var(--text-secondary); background: var(--surface-2); }
.view-mode-btn.active { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-dim); }

/* Search */
.header-search {
  position: relative;
  flex-shrink: 0;
}

.header-search input {
  width: 180px;
  padding: 5px 10px 5px 28px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: var(--transition);
}

.header-search input::placeholder { color: var(--text-dim); }
.header-search input:focus { border-color: var(--accent-dim); background: var(--surface-3); }

.header-search svg {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-dim);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

.search-results.visible { display: block; }

.search-result-item {
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--accent-bg); color: var(--accent); }

.search-result-item .region {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 8px;
}

/* === LEFT RAIL === */
.left-rail {
  grid-area: left;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 50;
}

.left-rail .rail-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.left-rail .rail-btn:hover { color: var(--text-secondary); background: var(--surface-2); }
.left-rail .rail-btn.active { color: var(--accent); background: var(--accent-bg); }
.left-rail .rail-btn svg { width: 16px; height: 16px; }
.left-rail .rail-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  padding: 4px 8px;
  font-size: 11px;
  white-space: nowrap;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 100;
}
.left-rail .rail-btn:hover[data-tooltip]::after { opacity: 1; }

.rail-spacer { flex: 1; }

/* === MAP PANEL === */
.map-panel {
  grid-area: map;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.map-container {
  width: 100%;
  height: 100%;
}

.map-container svg {
  width: 100%;
  height: 100%;
}

/* Map overlay controls */
.map-overlay-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.map-overlay-btn {
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(15, 22, 37, 0.9);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(8px);
}

.map-overlay-btn:hover { border-color: var(--border-light); color: var(--text); }
.map-overlay-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(0, 212, 255, 0.1); }

/* Map legend */
.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15, 22, 37, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.map-legend-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.map-legend-bar {
  width: 160px;
  height: 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.map-legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

/* Map tooltip */
.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 22, 37, 0.95);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 100;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  min-width: 200px;
  opacity: 0;
  transition: opacity 0.15s;
}

.map-tooltip.visible { opacity: 1; }

.map-tooltip-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.map-tooltip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  padding: 2px 0;
}

.map-tooltip-label { color: var(--text-secondary); }
.map-tooltip-value { font-family: var(--font-mono); font-weight: 500; color: var(--text); }

/* Map zoom controls */
.map-zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 10;
}

.map-zoom-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: rgba(15, 22, 37, 0.9);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 16px;
  backdrop-filter: blur(8px);
}

.map-zoom-btn:first-child { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.map-zoom-btn:last-child { border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.map-zoom-btn:hover { color: var(--accent); border-color: var(--accent-dim); }

/* Trade flow arcs */
.trade-arc {
  fill: none;
  stroke: var(--accent);
  stroke-opacity: 0.3;
  stroke-width: 1;
}

.trade-arc-glow {
  fill: none;
  pointer-events: none;
}

.trade-arc.animated {
  stroke-dasharray: 8, 4;
  animation: flowDash 1.5s linear infinite;
}

.flow-particle {
  pointer-events: none;
  filter: url(#flow-glow);
}

@keyframes flowDash {
  to { stroke-dashoffset: -12; }
}

/* Diffusion nodes */
.node-label {
  pointer-events: none;
  text-shadow: 0 0 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
}

.node-core {
  cursor: pointer;
  transition: fill-opacity 0.2s;
}

.node-core:hover {
  fill-opacity: 1;
}

.node-pulse {
  pointer-events: none;
}

/* === RIGHT RAIL (CONTROLS) === */
.right-rail {
  grid-area: right;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 50;
}

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

.control-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.control-section-header:hover { background: var(--surface-2); }

.control-section-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

.control-section-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-dim);
  transition: transform 0.2s;
}

.control-section.collapsed .control-section-chevron { transform: rotate(-90deg); }
.control-section.collapsed .control-section-body { display: none; }

.control-section-body {
  padding: 4px 14px 14px;
}

/* Slider controls */
.slider-group {
  margin-bottom: 10px;
}

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

.slider-name {
  font-size: 11px;
  color: var(--text-secondary);
}

.slider-value {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
  min-width: 32px;
  text-align: right;
}

.control-slider {
  width: 100%;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  transition: var(--transition);
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0, 212, 255, 0.3);
  transition: var(--transition);
}

.control-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.control-slider:active::-webkit-slider-thumb {
  background: #33e0ff;
}

/* Toggle controls */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
}

.toggle-name {
  font-size: 11px;
  color: var(--text-secondary);
}

.toggle-switch {
  position: relative;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: var(--transition);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent-dim);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
}

/* Shock sliders with colored value */
.shock-slider .slider-value { color: var(--warning); }
.shock-slider .control-slider::-webkit-slider-thumb { background: var(--warning); box-shadow: 0 0 6px rgba(255, 171, 0, 0.3); }

/* === BOTTOM ANALYTICS PANEL === */
.bottom-panel {
  grid-area: bottom;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 60;
  overflow: hidden;
  height: var(--bottom-h);
}

.bottom-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.bottom-tabs::-webkit-scrollbar { display: none; }

.bottom-tab {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
}

.bottom-tab:hover { color: var(--text-secondary); }
.bottom-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.bottom-tab-content {
  flex: 1;
  overflow: hidden;
  display: none;
}

.bottom-tab-content.active {
  display: flex;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 8px;
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
}

.kpi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: var(--transition);
  cursor: default;
}

.kpi-card:hover {
  border-color: var(--border-light);
  background: var(--surface-3);
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.kpi-card-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.kpi-card-delta {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  padding: 1px 4px;
  border-radius: 3px;
}

.kpi-card-delta.positive { color: var(--positive); background: rgba(0, 230, 118, 0.1); }
.kpi-card-delta.negative { color: var(--negative); background: rgba(255, 82, 82, 0.1); }
.kpi-card-delta.neutral { color: var(--text-dim); }

.kpi-card-value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 4px;
}

.kpi-card-subtitle {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.kpi-sparkline {
  width: 100%;
  height: 24px;
}

.kpi-sparkline path {
  fill: none;
  stroke-width: 1.5;
}

/* Trend Charts panel */
.trend-panel {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  overflow-x: auto;
  flex: 1;
}

.trend-chart-container {
  flex: 0 0 280px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.trend-chart-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.trend-chart-canvas {
  width: 100%;
  height: 160px;
}

/* Comparison panel */
.comparison-panel {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  overflow: auto;
  flex: 1;
}

.comparison-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.comparison-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.comparison-add-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}

.comparison-add-btn:hover { border-color: var(--accent-dim); color: var(--accent); }

.comparison-charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  flex: 1;
}

.comparison-chart-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.comparison-chart-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Contribution (waterfall) */
.waterfall-panel {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  overflow-x: auto;
  flex: 1;
}

.waterfall-chart-container {
  flex: 1;
  min-width: 400px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

/* === COUNTRY DETAIL PANEL (DRAWER) === */
.country-drawer {
  position: fixed;
  top: var(--header-h);
  right: var(--right-rail-w);
  bottom: var(--bottom-h);
  width: 420px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 80;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: var(--shadow-lg);
}

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

.country-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 5;
}

.country-drawer-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.country-drawer-region {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 8px;
}

.country-drawer-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}

.country-drawer-close:hover { color: var(--negative); border-color: var(--negative-dim); }

.country-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}

.country-section-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* Country metric rows */
.country-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-item {
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.metric-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.metric-value {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text);
}

/* Country charts */
.country-chart-container {
  margin-top: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow: hidden;
  min-width: 0;
}

.country-chart-container canvas {
  max-width: 100%;
}

.country-chart-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* Bottleneck bars */
.bottleneck-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bottleneck-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottleneck-name {
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 100px;
}

.bottleneck-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.bottleneck-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.bottleneck-value {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

/* Recommendation cards */
.rec-card {
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.rec-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
}

.rec-card-policy {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.rec-card-impact {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
}

.rec-card-impact.critical { color: var(--negative); background: rgba(255, 82, 82, 0.12); }
.rec-card-impact.high { color: var(--warning); background: rgba(255, 171, 0, 0.12); }
.rec-card-impact.medium { color: var(--accent); background: var(--accent-bg); }

.rec-card-reason {
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Country actions */
.country-actions {
  display: flex;
  gap: 6px;
  padding: 14px 16px;
}

.country-action-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.country-action-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.country-action-btn.primary { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }

/* === COMPARISON MODAL === */
.comparison-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.comparison-modal.open { display: flex; }

.comparison-modal-content {
  width: 90%;
  max-width: 1100px;
  max-height: 80vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.comparison-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.comparison-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.comparison-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.comparison-country-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.country-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.country-tag .remove {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 10px;
  opacity: 0.6;
}

.country-tag .remove:hover { opacity: 1; }

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.comparison-chart-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
  min-width: 0;
}

.comparison-chart-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* === LOADING STATE === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* === BOTTOM PANEL HANDLE (visible on mobile only) === */
.bottom-panel-handle {
  display: none;
  width: 100%;
  height: 24px;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.bottom-panel-handle .handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-light);
  transition: background 0.2s;
}

.bottom-panel-handle:hover .handle-bar,
.bottom-panel-handle:active .handle-bar {
  background: var(--accent-dim);
}

/* === MOBILE RESPONSIVE === */

/* Large tablets */
@media (max-width: 1200px) {
  :root {
    --right-rail-w: 260px;
  }
  .country-drawer { width: 360px; }
}

/* Tablets / small laptops */
@media (max-width: 1024px) {
  :root {
    --right-rail-w: 0px;
    --left-rail-w: 0px;
    --bottom-h: 220px;
  }

  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "map"
      "bottom";
  }

  .left-rail { display: none; }

  .right-rail {
    position: fixed;
    top: var(--header-h);
    right: 0;
    bottom: 0;
    width: 300px;
    z-index: 150;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }

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

  .country-drawer {
    right: 0;
    width: 100%;
    max-width: 400px;
    bottom: 0;
  }

  .header {
    gap: 6px;
    padding: 0 10px;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
  }

  .year-slider { width: 100px; }
  
  /* Keep scenarios visible but scrollable */
  .scenario-selector {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 1;
    min-width: 0;
  }
  .scenario-selector::-webkit-scrollbar { display: none; }

  .mobile-menu-btn { display: flex !important; }
}

/* Phones landscape / small tablets */
@media (max-width: 768px) {
  :root {
    --bottom-h: 44px; /* collapsed by default — just the tab bar */
  }

  /* Two-row header */
  .header {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 6px 10px;
    height: auto;
    min-height: 0;
  }

  /* Row 1: logo, year controls, speed, menu */
  .header-logo { order: 1; }
  .header-logo span { display: none; }
  .header-logo svg { width: 20px; height: 20px; }

  .year-controls { order: 2; flex: 1; justify-content: center; min-width: 0; }
  .year-display { font-size: 15px; min-width: 42px; }
  .year-slider { flex: 1; min-width: 60px; max-width: 120px; }

  /* Speed button */
  #speed-btn { order: 3; }

  .mobile-menu-btn { order: 4; }

  /* Hide header dividers and search on mobile */
  .header-divider { display: none; }
  .header-search { display: none; }

  /* Row 2: view modes and scenarios go to second row */
  .view-modes {
    order: 10;
    flex-basis: 100%;
    max-width: 100%;
    padding-bottom: 2px;
    gap: 2px;
  }

  .scenario-selector {
    order: 11;
    flex-basis: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .scenario-selector::-webkit-scrollbar { display: none; }

  .view-mode-btn {
    padding: 3px 7px;
    font-size: 10px;
    min-height: 28px;
  }

  .scenario-btn {
    padding: 3px 8px;
    font-size: 10px;
    min-height: 28px;
  }

  /* Bottom panel: collapsible */
  .bottom-panel {
    height: auto;
    max-height: 44px;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .bottom-panel.expanded {
    max-height: 55vh;
    overflow: auto;
  }

  .bottom-panel-handle {
    display: flex;
  }

  .bottom-panel.expanded .bottom-panel-handle .handle-bar {
    background: var(--accent);
  }

  /* Bottom tabs: horizontal scrollable */
  .bottom-tabs { 
    padding: 0 8px; 
    flex-shrink: 0;
  }
  .bottom-tab { 
    padding: 6px 10px; 
    font-size: 10.5px;
    min-height: 36px;
  }

  /* KPI grid */
  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
    padding: 8px;
  }
  .kpi-card { padding: 8px 10px; }
  .kpi-card-value { font-size: 18px; }
  .kpi-card-title { font-size: 9px; }

  /* Trend charts */
  .trend-chart-container { flex: 0 0 240px; }
  .trend-panel { padding: 8px; gap: 8px; }

  /* Country drawer: full screen */
  .country-drawer {
    width: 100%;
    max-width: 100%;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 200;
  }

  .country-chart-container { padding: 8px; }
  .country-chart-container canvas { height: 80px !important; }
  .country-section { padding: 10px 12px; }

  /* Right rail: position below header  */
  .right-rail {
    top: 0;
  }

  .comparison-modal-content {
    width: 95%;
    max-height: 90vh;
  }

  /* Map legend + zoom: adjust for mobile */
  .map-legend { bottom: 8px; left: 8px; padding: 6px 10px; }
  .map-zoom-controls { bottom: 8px; right: 8px; }
  .map-zoom-btn { width: 36px; height: 36px; font-size: 18px; }

  /* Larger touch targets for map overlay */
  .map-overlay-btn { padding: 6px 10px; font-size: 11px; min-height: 32px; }
}

/* Small phones portrait */
@media (max-width: 480px) {
  .header { padding: 4px 8px; }

  .year-controls .btn-icon:not(.play-btn):not(#speed-btn) { display: none; }
  .play-btn { width: 34px; height: 34px; }
  .play-btn svg { width: 16px; height: 16px; }

  .view-modes { gap: 1px; }
  .view-mode-btn { padding: 3px 5px; font-size: 9px; }

  .bottom-tab { padding: 5px 7px; font-size: 9.5px; }

  .kpi-grid { grid-template-columns: 1fr 1fr; }

  .country-metrics { grid-template-columns: 1fr; }

  .comparison-grid { grid-template-columns: 1fr; }

  .waterfall-chart-container { min-width: 280px; }
}

/* Mobile menu button - hidden by default */
.mobile-menu-btn { display: none !important; }
@media (max-width: 1024px) {
  .mobile-menu-btn { display: flex !important; }
}

/* Mobile overlay */
.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 140;
  display: none;
}

.mobile-overlay.visible { display: block; }

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

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

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 4px rgba(0, 212, 255, 0.2); }
  50% { box-shadow: 0 0 12px rgba(0, 212, 255, 0.4); }
}

.animate-in {
  animation: fadeIn 0.3s ease;
}

/* Country hover highlight on map */
.country-path {
  stroke: var(--border);
  stroke-width: 0.4;
  cursor: pointer;
  transition: stroke-width 0.15s, stroke 0.15s;
}

.country-path:hover {
  stroke: var(--accent);
  stroke-width: 1.2;
}

.country-path.selected {
  stroke: var(--accent);
  stroke-width: 1.5;
  filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.4));
}

.country-path.comparison {
  stroke: var(--purple);
  stroke-width: 1.2;
}

/* Graticule lines */
.graticule {
  fill: none;
  stroke: var(--border);
  stroke-width: 0.2;
  stroke-opacity: 0.4;
}

/* Ocean / sphere */
.sphere {
  fill: var(--bg-alt);
  stroke: var(--border);
  stroke-width: 0.5;
}

/* Print/export friendly */
@media print {
  .right-rail, .left-rail, .header { display: none !important; }
  .map-panel { grid-area: 1 / 1 / 2 / -1; }
  .bottom-panel { grid-area: 2 / 1 / 3 / -1; }
}
