/* === CSS Custom Properties === */
:root {
  --blue-bbox: #2563eb;
  --blue-bbox-dark: #1d4ed8;
  --orange-proposed: #f59e0b;
  --orange-proposed-dark: #d97706;
  --green-covered: #22c55e;
  --green-covered-dark: #16a34a;
  --red-uncovered: #ef4444;
  --red-uncovered-dark: #dc2626;
  --green-supermarket: #16a34a;
  /* Population = orange; Demand = light blue */
  --pop-color: #f59e0b;
  --pop-color-dark: #d97706;
  --demand-color: #38bdf8;
  --demand-color-dark: #0ea5e9;
  --sidebar-bg: #1a1a2e;
  --sidebar-surface: #16213e;
  --sidebar-border: #0f3460;
  --accent: #e94560;
  --text-primary: #e0e0e0;
  --text-muted: #9ca3af;
  --text-bright: #ffffff;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

/* === Layout === */
body {
  font-family: var(--font);
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--sidebar-bg);
}

#sidebar {
  width: 360px;
  min-width: 360px;
  background: var(--sidebar-bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: margin-left 0.3s ease;
  z-index: 1000;
  border-right: 1px solid var(--sidebar-border);
}

#sidebar.collapsed {
  margin-left: -360px;
}

#sidebar::-webkit-scrollbar {
  width: 6px;
}

#sidebar::-webkit-scrollbar-track {
  background: var(--sidebar-bg);
}

#sidebar::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
  border-radius: 3px;
}

#map {
  flex: 1;
  height: 100vh;
  z-index: 1;
}

/* === Sidebar Header === */
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

#sidebar-toggle:hover {
  background: var(--sidebar-surface);
  color: var(--text-bright);
}

#sidebar-expand {
  position: fixed;
  top: 16px;
  left: 360px;           /* right edge of open sidebar on desktop */
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 36px;
  background: var(--orange-proposed);
  border: none;
  border-radius: 0 6px 6px 0;
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  transition: left 0.3s ease, background 0.2s;
}

#sidebar-expand:hover {
  background: var(--orange-proposed-dark);
}

/* Collapsed: button slides to left edge, arrow points right */
body.sidebar-collapsed #sidebar-expand {
  left: 0;
}

/* === Panels === */
.panel {
  display: none;
  padding: 16px;
  flex-direction: column;
  gap: 12px;
}

.panel.active {
  display: flex;
  flex-shrink: 0;
}

/* === Controls === */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--orange-proposed);
  min-width: 50px;
  text-align: right;
}

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--sidebar-surface);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--orange-proposed);
  cursor: pointer;
  border: 2px solid var(--sidebar-bg);
  box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--orange-proposed);
  cursor: pointer;
  border: 2px solid var(--sidebar-bg);
}

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--orange-proposed);
  width: 16px;
  height: 16px;
}

/* === Buttons === */
.btn-secondary {
  background: var(--sidebar-surface);
  color: var(--text-primary);
  border: 1px solid var(--sidebar-border);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--sidebar-border);
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.stat-card {
  background: var(--sidebar-surface);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid transparent;
}

.stat-card.stat-covered {
  border-color: rgba(34, 197, 94, 0.3);
}

.stat-card.stat-uncovered {
  border-color: rgba(239, 68, 68, 0.3);
}

.stat-card.demand-border {
  border-color: rgba(56, 189, 248, 0.3);
}

/* === Coverage Wide Card === */
.coverage-card {
  display: flex;
  background: var(--sidebar-surface);
  border-radius: 8px;
  border: 1px solid rgba(245, 158, 11, 0.25);
  overflow: hidden;
}

.coverage-half {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.coverage-divider {
  width: 1px;
  background: var(--sidebar-border);
  margin: 10px 0;
}

.cov-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.4;
}

.cov-pct {
  font-size: 26px;
  font-weight: 700;
  color: var(--pop-color);
  line-height: 1.1;
}

.cov-pct.demand {
  color: var(--demand-color);
}

.cov-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* === Planner Primary Row === */
.plan-primary-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.plan-cov-card {
  flex: 1;
}

.plan-counts {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-surface);
  border-radius: 8px;
  border: 1px solid transparent;
  overflow: hidden;
  min-width: 110px;
}

.plan-count-item {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.plan-count-divider {
  height: 1px;
  background: var(--sidebar-border);
}

.plan-count-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-bright);
}

.stat-pct {
  font-size: 14px;
  font-weight: 600;
  color: var(--pop-color);
}

.stat-pct.demand {
  color: var(--demand-color);
}

/* === Section Headers === */
.section-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--sidebar-border);
}

/* === Region List === */
.region-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.region-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: var(--sidebar-surface);
  border-radius: 4px;
  font-size: 13px;
}

.region-name {
  font-weight: 500;
}

.region-stat {
  font-weight: 600;
  color: var(--orange-proposed);
  font-size: 12px;
}

/* === Legend === */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.legend-swatch {
  width: 16px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* === Mode Toggle === */
.mode-toggle {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--sidebar-border);
}

.mode-btn {
  flex: 1;
  background: var(--sidebar-surface);
  color: var(--text-muted);
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.mode-btn:not(:last-child) {
  border-right: 1px solid var(--sidebar-border);
}

.mode-btn.active {
  background: var(--sidebar-border);
  color: var(--text-bright);
}

#mode-population.active {
  background: rgba(245, 158, 11, 0.2);
  color: var(--pop-color);
  border-bottom: 2px solid var(--pop-color);
}

#mode-demand.active {
  background: rgba(56, 189, 248, 0.15);
  color: var(--demand-color);
  border-bottom: 2px solid var(--demand-color);
}

.mode-btn:hover:not(.active) {
  color: var(--text-primary);
}

.mode-warning {
  font-size: 11px;
  color: var(--accent);
  padding: 4px 2px;
}

/* === Progress Bar === */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--sidebar-surface);
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--orange-proposed);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

/* === Chart === */
.chart-container {
  background: var(--sidebar-surface);
  border-radius: 8px;
  padding: 12px;
  height: 200px;
  margin: 4px 0;
}

/* === Table === */
.table-container {
  max-height: 300px;
  overflow-y: auto;
  border-radius: 6px;
  border: 1px solid var(--sidebar-border);
}

.table-container::-webkit-scrollbar {
  width: 4px;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
}

#planner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#planner-table thead {
  position: sticky;
  top: 0;
  background: var(--sidebar-surface);
  z-index: 1;
}

#planner-table th {
  text-align: left;
  padding: 8px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--sidebar-border);
}

#planner-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(15, 52, 96, 0.3);
  color: var(--text-primary);
}

#planner-table tbody tr:hover {
  background: var(--sidebar-surface);
}

/* === Loading Overlay === */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.95);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

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

.loader-content {
  text-align: center;
  color: var(--text-primary);
}

.loader-content .progress-bar-container {
  width: 240px;
  margin: 12px auto 0;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--sidebar-surface);
  border-top-color: var(--orange-proposed);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

#loading-text {
  font-size: 14px;
  color: var(--text-muted);
}

/* === Leaflet Overrides === */

/* Sector tooltip */
.sector-tooltip {
  background: var(--sidebar-bg) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--sidebar-border) !important;
  border-radius: 6px !important;
  padding: 8px 12px !important;
  font-family: var(--font) !important;
  font-size: 12px !important;
  line-height: 1.5 !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
}

.sector-tooltip::before {
  border-top-color: var(--sidebar-border) !important;
}

/* Leaflet popup styling */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
}

.leaflet-popup-content {
  margin: 10px 14px;
  line-height: 1.6;
}

/* === Redundant placements note === */
.redundant-note {
  font-size: 11px;
  color: var(--green-covered);
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 4px;
  line-height: 1.4;
}

/* === Map Highlight Pulse === */
.highlight-pulse {
  animation: pulse-ring 1s ease-out infinite;
}

@keyframes pulse-ring {
  0%   { opacity: 0.9; stroke-width: 3; }
  50%  { opacity: 0.4; stroke-width: 5; }
  100% { opacity: 0.9; stroke-width: 3; }
}

/* === Walkthrough Tour === */
#wt-overlay {
  position: fixed;
  inset: 0;
  z-index: 2999;
  background: rgba(0, 0, 0, 0.20);
  transition: opacity 0.25s ease;
}

#wt-overlay.hidden,
#wt-tooltip.hidden {
  display: none;
}

#wt-tooltip {
  position: fixed;
  z-index: 3001;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  padding: 22px 24px 16px;
  width: 370px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  transition: top 0.3s ease, left 0.3s ease;
}

#wt-step-indicator {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

#wt-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: 10px;
}

#wt-body {
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 16px;
}

#wt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#wt-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.wt-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: background 0.2s;
}

.wt-btn-back {
  background: var(--sidebar-surface);
  color: var(--text-muted);
  border: 1px solid var(--sidebar-border);
}

.wt-btn-back:hover {
  color: var(--text-bright);
}

.wt-btn-next {
  background: var(--pop-color);
  color: #000;
}

.wt-btn-next:hover {
  background: var(--pop-color-dark);
}

.wt-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.wt-checkbox-label input[type="checkbox"] {
  accent-color: var(--pop-color);
  width: 14px;
  height: 14px;
}

/* Spotlight ring on highlighted element */
.wt-spotlight {
  position: relative;
  z-index: 3000;
  border-radius: 8px;
  outline: 3px solid var(--orange-proposed);
  outline-offset: 3px;
  filter: brightness(1.15);
  box-shadow: 0 0 18px 6px rgba(255, 255, 255, 0.12);
}

/* =============================================
   MOBILE RESPONSIVE — Level 1 (≤600px)
   ============================================= */


@media (max-width: 600px) {

  /* Sidebar: fixed overlay leaving 60px map sliver, hidden by default */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: calc(100vw - 60px);
    min-width: 0;
    height: 100vh;
    z-index: 1100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    margin-left: 0;
  }

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

  /* Map fills full screen on mobile */
  #map {
    width: 100vw;
    flex: none;
  }

  /* Arrow toggle button: sits at right edge of open sidebar on mobile */
  #sidebar-expand {
    left: calc(100vw - 60px);
    top: 16px;
  }

  body.sidebar-collapsed #sidebar-expand {
    left: 0;
  }

  /* Stats grid: 3-col → 2-col */
  .stats-grid-3 {
    grid-template-columns: 1fr 1fr;
  }

  /* Third card spans full width when it wraps */
  .stats-grid-3 .stat-card:last-child {
    grid-column: 1 / -1;
  }

  /* Walkthrough tooltip: cap to viewport width, let JS handle position */
  #wt-tooltip {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    transform: none !important;
  }

} /* end @media (max-width: 600px) */
