/* ============================================================
   MapRegion — Adapted stylesheet for PSSR integration
   Light theme by default, matching main SPA palette
   ============================================================ */

/* === CSS Variables === */
:root {
  /* Light theme matching main SPA */
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --bg-hover: #edf0f5;
  --bg-active: #e2e8f0;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #d0d7de;
  --border-light: #e2e8f0;
  --text: #1a202c;
  --text-muted: #4a5568;
  --text-faint: #94a3b8;
  --text-secondary: #4a5568;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;

  /* Group colors */
  --group-a: #C0392B;
  --group-b: #E67E22;
  --group-c: #1A8A7D;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Radius */
  --radius: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* Transitions */
  --transition: 200ms ease;
  --transition-slow: 300ms ease;

  /* Layout */
  --controls-h: 48px;
  --kpi-h: 52px;
  --footer-h: 32px;
  --info-w: 340px;

  /* Panel / overlay backgrounds */
  --panel-bg: rgba(255, 255, 255, 0.97);
  --panel-bg-solid: #ffffff;
  --overlay-bg: rgba(0, 0, 0, 0.3);
  --hover-bg: rgba(0, 0, 0, 0.04);
  --active-bg: rgba(0, 0, 0, 0.06);
  --tooltip-bg: rgba(30, 30, 30, 0.92);
  --tooltip-text: #fff;
}

/* === Dark Mode Variables === */
html.dark {
  --bg: #131211;
  --surface: #1A1918;
  --surface-alt: #1F1E1C;
  --border: #2E2D2B;
  --border-light: #252423;
  --text: #D5D4D0;
  --text-muted: #8A8985;
  --text-faint: #5C5B58;
  --primary: #4DB8A4;
  --primary-hover: #3A9B89;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  --panel-bg: rgba(26, 25, 24, 0.95);
  --panel-bg-solid: #1A1918;
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --hover-bg: rgba(255, 255, 255, 0.06);
  --active-bg: rgba(255, 255, 255, 0.1);
  --tooltip-bg: rgba(40, 38, 36, 0.95);
  --tooltip-text: #D5D4D0;
}

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

body {
  margin: 0;
  font-family: 'Rubik', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* === Focus Visible === */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}


/* === Controls Bar === */
#controls-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--controls-h);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.controls-left,
.controls-center,
.controls-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.controls-center {
  margin-left: auto;
}

.controls-right {
  margin-left: auto;
}

.control-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Custom select */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 13px;
  padding: var(--sp-1) var(--sp-6) var(--sp-1) var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition);
  outline: none;
}

.select-wrapper select:hover {
  border-color: var(--text-muted);
}

.select-wrapper select:focus {
  border-color: var(--primary);
}

.select-wrapper::after {
  content: '\25BE';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  font-size: 11px;
}

/* Group filter checkboxes */
.group-filter {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius);
  transition: background var(--transition);
  user-select: none;
}

.group-filter:hover {
  background: var(--hover-bg);
}

.group-filter input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.filter-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.group-filter input[type="checkbox"]:not(:checked) ~ .filter-dot,
.group-filter:has(input:not(:checked)) .filter-dot {
  opacity: 0.3;
}

/* Export & tile toggle buttons */
#btn-export-png,
#btn-export-csv,
#toggle-tiles {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
  padding: 0;
}

#btn-export-png:hover,
#btn-export-csv:hover,
#toggle-tiles:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

#toggle-tiles.tiles-hidden {
  opacity: 0.5;
}

/* === KPI Summary Strip === */
#kpi-strip {
  position: fixed;
  top: var(--controls-h);
  left: 0;
  right: 0;
  z-index: 999;
  height: var(--kpi-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 var(--sp-4);
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(6px);
}

.kpi-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-1) var(--sp-5);
}

.kpi-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.2;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1.3;
}

.kpi-divider {
  width: 1px;
  height: 28px;
  background: var(--border-light);
  flex-shrink: 0;
}

/* === Main Layout === */
#main-content {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h));
  left: 0;
  right: 0;
  bottom: var(--footer-h);
  display: flex;
}

#map {
  flex: 1;
  min-width: 0;
}

/* Subdued tile layer */
.leaflet-tile-pane {
  filter: saturate(0.3) brightness(1.08);
}

/* Style Leaflet zoom controls */
.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--panel-bg) !important;
  color: var(--text-muted) !important;
  border-bottom: 1px solid var(--border-light) !important;
  width: 30px !important;
  height: 30px !important;
  line-height: 30px !important;
  font-size: 16px !important;
  transition: all var(--transition);
}

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

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

/* Attribution */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: var(--panel-bg) !important;
  padding: 2px 6px !important;
  color: var(--text-faint) !important;
}

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

/* === Info Panel === */
#info {
  width: var(--info-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border-light);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.04);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-5);
  position: relative;
}

.info-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--sp-1) 0;
}

.info-hint {
  font-size: 13px;
  color: var(--text-faint);
  margin: 0 0 var(--sp-5) 0;
}

/* Summary stats cards */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-2);
}

.summary-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.summary-card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums lining-nums;
}

.summary-card-value .summary-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Detail view */
#info-close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  border: none;
  background: none;
  font-size: 22px;
  color: var(--text-faint);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: all var(--transition);
  padding: 0;
  line-height: 1;
}

#info-close:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.detail-oblast {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 2px 0;
  padding-right: 28px;
}

.detail-district {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 var(--sp-3) 0;
}

.group-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  margin-bottom: var(--sp-4);
}

/* Metric rows */
.metric-row {
  display: flex;
  align-items: center;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border-light);
}

.metric-row:last-child {
  border-bottom: none;
}

.metric-icon {
  width: 20px;
  flex-shrink: 0;
  font-size: 14px;
  text-align: center;
  color: var(--text-faint);
}

.metric-body {
  flex: 1;
  margin-left: var(--sp-2);
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums lining-nums;
}

.metric-value-sm {
  font-size: 14px;
  font-weight: 500;
}

/* Progress bar with national average marker */
.progress-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  margin-top: 4px;
  overflow: visible;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition-slow);
}

.progress-fill--urban {
  background: var(--primary);
}

.progress-fill--poverty {
  background: #A13544;
}

.progress-fill--grp {
  background: #1A8A7D;
}

.progress-fill--income {
  background: #2E86AB;
}

.progress-fill--unemployment {
  background: #E67E22;
}

.avg-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 12px;
  background: var(--text);
  border-radius: 1px;
  transform: translateX(-1px);
}

.avg-marker-label {
  position: absolute;
  top: -16px;
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transform: translateX(-50%);
}

/* Population rank bar */
.rank-bar-container {
  margin-top: 4px;
}

.rank-bar-track {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
  transition: width var(--transition-slow);
}

.rank-bar-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.metric-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-top: var(--sp-3);
  margin-bottom: var(--sp-1);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-light);
}

.metric-source {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-light);
  font-style: italic;
}

.sparkline-container {
  margin: var(--sp-2) 0;
  min-height: 40px;
}
.sparkline-loading, .sparkline-empty {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
}
.sparkline-chart {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--sp-2);
  border: 1px solid var(--border-light);
}
.sparkline-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.sparkline-year {
  font-size: 10px;
  fill: var(--text-faint);
}

/* Inline spark bars for economic section */
.spark-inline {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 20px;
  vertical-align: middle;
  margin-left: 4px;
}
.spark-bar {
  display: inline-block;
  width: 6px;
  min-height: 2px;
  border-radius: 1px;
}
.spark-bar-red { background: #EF4444; }
.spark-bar-teal { background: #14B8A6; }
.delta-up { color: #DC2626; font-size: 0.85em; margin-left: 2px; }
.delta-down { color: #059669; font-size: 0.85em; margin-left: 2px; }
.delta-zero { color: var(--text-muted); font-size: 0.85em; margin-left: 2px; }

.info-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--sp-4) 0;
}

.detail-name-row {
  margin-bottom: var(--sp-2);
}

.detail-name-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-name-value {
  font-size: 13px;
  color: var(--text-muted);
}

/* === Info Panel Tabs === */

#info-tabs {
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
}
#info-tabs::-webkit-scrollbar { display: none; }

.nav-tabs-sm {
  border-bottom: 2px solid var(--border-light);
  gap: 0;
  flex-wrap: nowrap;
}
.nav-tabs-sm .nav-link {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  color: var(--text-faint);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.nav-tabs-sm .nav-link:hover {
  color: var(--text-secondary);
}
.nav-tabs-sm .nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.info-tab-pane {
  padding-top: var(--sp-2);
}

/* === Strata Tab === */
.strata-total {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
  padding: var(--sp-2);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}
.strata-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-top: var(--sp-3);
  margin-bottom: var(--sp-1);
}
.strata-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.strata-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.strata-bar-label {
  width: 28px;
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: right;
}
.strata-bar-track {
  flex: 1;
  height: 14px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.strata-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.strata-bar-value {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 80px;
}
.strata-bar-value small {
  color: var(--text-faint);
}

/* Matrix heatmap */
.strata-matrix {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--sp-1);
}
.strata-matrix-row {
  display: flex;
  gap: 2px;
}
.strata-matrix-cell {
  width: 36px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border-radius: 3px;
}
.strata-matrix-corner {
  background: none;
}
.strata-matrix-col-header,
.strata-matrix-row-header {
  font-weight: 600;
  color: var(--text-faint);
  font-size: 10px;
  background: none;
}
.strata-matrix-data {
  border-radius: 3px;
  cursor: default;
}

/* Top strata list */
.strata-top-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.strata-top-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 6px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}
.strata-top-rank {
  font-weight: 700;
  color: var(--primary);
  width: 18px;
  text-align: center;
}
.strata-top-code {
  font-weight: 600;
  color: var(--text-secondary);
  font-family: monospace;
}
.strata-top-pop {
  margin-left: auto;
  color: var(--text-muted);
}
.strata-top-ei {
  font-size: 11px;
  color: var(--text-faint);
}

/* === Roads Tab === */
.roads-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.road-card {
  padding: var(--sp-2);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
}
.road-card-header {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.road-ref {
  font-size: 11px;
  color: var(--text-faint);
}
.road-card-status {
  margin-bottom: 4px;
}
.road-status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
}
.road-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.road-detail {
  white-space: nowrap;
}
.road-card-desc {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
  line-height: 1.4;
}

/* === Legend === */
#legend {
  position: fixed;
  bottom: calc(var(--footer-h) + var(--sp-3));
  right: calc(var(--info-w) + var(--sp-3));
  z-index: 800;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
  transition: all var(--transition);
}

#legend-toggle {
  padding: var(--sp-1) var(--sp-2);
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
  user-select: none;
}

#legend-toggle:hover {
  color: var(--text);
}

#legend-content {
  padding: 0 var(--sp-3) var(--sp-3);
}

.legend-collapsed #legend-content {
  display: none;
}

.legend-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--sp-2);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 12px;
  color: var(--text);
  padding: 2px 0;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Heatmap gradient bar */
.legend-gradient {
  height: 10px;
  border-radius: 3px;
  margin-bottom: 4px;
  width: 150px;
}

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

.legend-gradient-labels span {
  min-width: 0;
}

/* === Hover Tooltip === */
#map-tooltip {
  position: fixed;
  z-index: 1100;
  pointer-events: none;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 220px;
  opacity: 0;
  transition: opacity 150ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  font-family: 'Rubik', sans-serif;
}

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

.tooltip-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.tooltip-oblast {
  font-weight: 400;
  font-size: 11px;
  opacity: 0.75;
  margin-top: 1px;
}

.tooltip-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
}

.tooltip-metric {
  font-size: 12px;
  color: var(--tooltip-text);
}

.tooltip-metric strong {
  color: #fff;
  font-weight: 600;
}

/* === Ranking Panel === */
#ranking-panel {
  position: fixed;
  bottom: var(--footer-h);
  left: 0;
  right: var(--info-w);
  z-index: 850;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(6px);
  transition: max-height var(--transition-slow);
}

#ranking-toggle {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
  text-align: center;
  transition: color var(--transition), background var(--transition);
  border-top: 2px solid var(--accent, #3b82f6);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}

#ranking-toggle:hover {
  color: var(--text);
  background: rgba(59, 130, 246, 0.06);
}

#ranking-content {
  max-height: 250px;
  overflow-y: auto;
  padding: 0 var(--sp-4) var(--sp-3);
}

.ranking-collapsed #ranking-content {
  display: none;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 3px 0;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition);
}

.rank-row:hover {
  background: var(--hover-bg);
}

.rank-row.rank-row--active {
  background: var(--active-bg);
}

.rank-position {
  width: 22px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-align: right;
  flex-shrink: 0;
}

.rank-name {
  width: 130px;
  font-size: 12px;
  color: var(--text);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-bar-outer {
  flex: 1;
  height: 16px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.rank-bar-inner {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition-slow);
  min-width: 2px;
}

.rank-value {
  width: 60px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums lining-nums;
}

/* === Colorblind Group Markers === */
.group-marker {
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 2px solid currentColor;
  font-family: 'Rubik', sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity var(--transition);
}

.group-marker.visible {
  opacity: 1;
}

/* === Region Labels on Map === */
.region-label {
  pointer-events: none;
  white-space: normal;
  line-height: 1.25;
  background: none;
  border: none;
  text-align: center;
  font-family: 'Rubik', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-shadow:
    0 0 4px rgba(255, 255, 255, 0.9),
    0 0 8px rgba(255, 255, 255, 0.7),
    1px 1px 2px rgba(255, 255, 255, 0.8);
  padding: 2px 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.region-label.visible {
  opacity: 1;
}

/* === Footer === */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--bg);
  border-top: 1px solid var(--border-light);
  font-size: 11px;
  color: var(--text-faint);
  z-index: 900;
}

/* === Air Quality Badges === */
.aq-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.aq-1 { background: #1A8A7D; }
.aq-2 { background: #4A9A6B; }
.aq-3 { background: #B0B040; }
.aq-4 { background: #C07840; }
.aq-5 { background: #C0392B; }

/* === Transport Layer Controls === */
#transport-panel {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h) + var(--sp-3));
  left: var(--sp-3);
  z-index: 800;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
  min-width: 160px;
}

#transport-toggle {
  padding: var(--sp-1) var(--sp-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

#transport-toggle:hover {
  color: var(--text);
}

.transport-chevron {
  margin-left: auto;
  font-size: 10px;
  transition: transform var(--transition);
}

#transport-body {
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
}

#transport-body.transport-collapsed {
  display: none;
}

.transport-check {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px 0;
}

.transport-check input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.transport-check label {
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.transport-loading {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  padding: 2px 0;
}

/* === POI Layer Panel === */
#poi-panel {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h) + var(--sp-3) + 180px);
  left: var(--sp-3);
  z-index: 800;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
  min-width: 160px;
}

#poi-toggle {
  padding: var(--sp-1) var(--sp-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

#poi-toggle:hover {
  color: var(--text);
}

.poi-chevron {
  margin-left: auto;
  font-size: 10px;
  transition: transform var(--transition);
}

#poi-body {
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
}

#poi-body.poi-collapsed {
  display: none;
}

.poi-badge {
  font-size: 10px;
  color: var(--text-faint);
  margin-left: 2px;
}

/* === Region Transitions (SVG paths) === */
.leaflet-interactive {
  transition: fill-opacity 200ms ease, stroke-width 150ms ease;
}

/* === Sheet Handle (hidden on desktop) === */
.sheet-handle {
  display: none;
}

/* === Mobile Nav (hidden on desktop) === */
.mobile-nav {
  display: none;
}

/* === Tablet Layout (768px - 991px) === */
@media (min-width: 768px) and (max-width: 991.98px) {
  :root {
    --info-w: 280px;
  }

  #controls-bar {
    gap: var(--sp-2);
    padding: 0 var(--sp-2);
  }

  .control-label {
    font-size: 11px;
  }

  .select-wrapper select {
    font-size: 12px;
    padding: var(--sp-1) var(--sp-5) var(--sp-1) var(--sp-2);
  }

  #btn-compare {
    font-size: 11px;
    padding: 3px 8px;
  }

  .kpi-card {
    padding: var(--sp-1) var(--sp-3);
  }

  .kpi-value {
    font-size: 17px;
  }

  .kpi-label {
    font-size: 9px;
  }

  #compare-panel {
    width: 500px;
    max-width: 55vw;
  }
}

/* === Mobile Layout (< 768px) === */
@media (max-width: 767.98px) {
  /* -- Mobile Nav Bar -- */
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface);
    display: flex;
    border-top: 1px solid var(--border);
    z-index: 1001;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    padding: var(--sp-1) 0;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-nav-item.active {
    color: var(--primary);
  }

  .mobile-nav-icon {
    font-size: 20px;
    line-height: 1;
    margin-bottom: 2px;
  }

  .mobile-nav-item small {
    font-size: 10px;
    line-height: 1.2;
  }

  /* -- Hide desktop controls, KPI strip, footer on mobile -- */
  #controls-bar {
    display: none !important;
  }

  #kpi-strip {
    display: none !important;
  }

  footer {
    display: none !important;
  }

  /* -- Main layout: full-screen map -- */
  #main-content {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 56px;
    display: block;
  }

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

  /* -- Remove zoom controls on mobile (use gestures) -- */
  .leaflet-control-zoom {
    display: none !important;
  }

  /* -- Sidebar → Bottom Sheet -- */
  #info {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(calc(100% - 60px));
    transition: transform 0.3s ease;
    background: var(--surface);
    padding-top: 0;
  }

  #info.sheet-half {
    transform: translateY(50%);
  }

  #info.sheet-full {
    transform: translateY(0);
  }

  /* -- Sheet Handle -- */
  .sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto;
    flex-shrink: 0;
  }

  /* -- KPI strip inside bottom sheet for collapsed state -- */
  .mobile-kpi-strip {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 var(--sp-2) var(--sp-2);
    gap: var(--sp-1);
  }

  .mobile-kpi-strip .kpi-card {
    padding: 2px var(--sp-1);
  }

  .mobile-kpi-strip .kpi-label {
    font-size: 8px;
  }

  .mobile-kpi-strip .kpi-value {
    font-size: 14px;
  }

  /* -- Hide ranking panel on mobile -- */
  #ranking-panel {
    display: none !important;
  }

  /* -- Legend repositioned above bottom nav -- */
  #legend {
    right: var(--sp-3);
    bottom: calc(56px + 68px);
    left: auto;
    max-width: 180px;
  }

  /* -- Transport panel repositioned -- */
  #transport-panel {
    top: var(--sp-3);
    left: var(--sp-3);
  }

  /* -- POI panel hidden on mobile (too crowded) -- */
  #poi-panel {
    display: none;
  }

  /* -- Comparison panel on mobile -- */
  #compare-panel {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    max-height: 60vh;
    border-radius: 16px 16px 0 0;
    z-index: 1050;
    animation: none;
  }

  #compare-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compare-table {
    min-width: 500px;
  }

  /* -- Compare hint repositioned -- */
  #compare-hint {
    top: var(--sp-3);
    font-size: 12px;
    padding: 6px 14px;
  }

  /* -- Tooltip hidden on mobile (use tap popups) -- */
  #map-tooltip {
    display: none !important;
  }

  /* -- Touch-optimized: larger tap targets -- */
  .search-input {
    font-size: 16px;
    padding: 10px 0;
    min-height: 44px;
  }

  .search-item {
    padding: 10px;
    min-height: 44px;
  }

  .filter-header {
    padding: 10px var(--sp-2);
    min-height: 44px;
  }

  .filter-select {
    padding: 8px 6px;
    font-size: 14px;
    min-height: 44px;
  }

  .filter-num {
    padding: 8px 6px;
    font-size: 14px;
    min-height: 44px;
  }

  #info-close {
    width: 44px;
    height: 44px;
    font-size: 24px;
  }

  /* -- Transport: full-width toggle switches on mobile -- */
  .transport-check {
    padding: 8px 0;
    min-height: 44px;
  }

  .transport-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  .transport-check label {
    font-size: 14px;
  }

  /* -- "Ещё" (more) panel for transport/filters on mobile -- */
  .mobile-more-panel {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    max-height: 60vh;
    background: var(--panel-bg-solid);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1002;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--sp-4);
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .mobile-more-panel.open {
    transform: translateY(0);
  }

  .mobile-more-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-2);
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    min-height: 48px;
    font-size: 14px;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-more-item:last-child {
    border-bottom: none;
  }

  .mobile-more-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
  }

  /* -- Mobile overlay backdrop -- */
  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .mobile-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ========== Comparison Feature ========== */

#btn-compare {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
#btn-compare:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
#btn-compare.compare-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

#compare-hint {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  z-index: 1100;
  pointer-events: none;
  animation: compareHintFade 0.3s ease;
}
@keyframes compareHintFade {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#compare-panel {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h));
  right: 0;
  width: 620px;
  max-width: 45vw;
  bottom: var(--footer-h);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: comparePanelSlide 0.3s ease;
}
@keyframes comparePanelSlide {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

#compare-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.compare-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
#compare-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
#compare-close:hover {
  color: var(--text);
}

#compare-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* Comparison table */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.compare-table th,
.compare-table td {
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
}
.compare-table thead th {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.compare-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  min-width: 120px;
}
.compare-table thead th:first-child {
  z-index: 3;
}
.compare-table tbody tr:hover {
  background: var(--surface-alt);
}

/* Group badge in header */
.compare-group-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

/* Region header column */
.compare-region-col {
  text-align: center;
  min-width: 100px;
}
.compare-region-name {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 2px;
}
.compare-region-border {
  width: 100%;
  height: 3px;
  border-radius: 2px;
  margin-top: 4px;
}

/* Indicator label column */
.compare-indicator {
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Cell with bar */
.compare-cell {
  position: relative;
}
.compare-cell-value {
  position: relative;
  z-index: 1;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.compare-cell-bar {
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  border-radius: 2px;
  opacity: 0.15;
}
.compare-cell--best .compare-cell-value {
  font-weight: 700;
  color: var(--primary);
}

/* Sparkline section */
.compare-sparklines {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.compare-sparklines h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px 0;
}
.compare-spark-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.compare-spark-label {
  width: 100px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding-top: 4px;
}
.compare-spark-charts {
  display: flex;
  gap: 6px;
  flex: 1;
  flex-wrap: wrap;
}
.compare-spark-item {
  text-align: center;
}
.compare-spark-item svg {
  display: block;
}
.compare-spark-region-name {
  font-size: 9px;
  color: var(--text-faint);
  margin-top: 1px;
}

/* Map cursor in comparison mode */
.compare-cursor {
  cursor: crosshair !important;
}
.compare-cursor .leaflet-interactive {
  cursor: crosshair !important;
}

/* === Search & Filter === */
.search-container {
  position: relative;
  padding: var(--sp-2) var(--sp-3);
  padding-bottom: 0;
}
.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 var(--sp-2);
  gap: 4px;
}
.search-icon { font-size: 14px; flex-shrink: 0; }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  padding: 6px 0;
  color: var(--text);
}
.search-input::placeholder { color: var(--text-faint); }
.search-clear {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 0 2px;
  line-height: 1;
}
.search-clear:hover { color: var(--text); }
.search-dropdown {
  position: absolute;
  z-index: 1000;
  width: calc(100% - var(--sp-3) * 2);
  left: var(--sp-3);
  background: var(--panel-bg-solid);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 200px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.search-item {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-item:hover, .search-item.active { background: var(--hover-bg); }
.search-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--active-bg);
  color: var(--text-muted);
  flex-shrink: 0;
}
.search-item .search-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .search-oblast { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

/* Filter panel */
.filter-panel {
  margin: var(--sp-2) var(--sp-3) 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--surface-alt);
}
.filter-header {
  padding: 6px var(--sp-2);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.filter-header:hover { background: var(--surface); border-radius: var(--radius); }
.filter-body { padding: var(--sp-2); padding-top: 0; }
.filter-row { margin-bottom: var(--sp-2); }
.filter-select {
  width: 100%;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.filter-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--sp-1);
}
.filter-num {
  flex: 1;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 0;
}
.filter-num::-webkit-inner-spin-button { -webkit-appearance: none; }
.filter-dash { color: var(--text-muted); font-size: 12px; }
.filter-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.filter-clear-btn {
  border: none;
  background: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}
.filter-clear-btn:hover { text-decoration: underline; }
.mb-2 { margin-bottom: 8px; }
.float-end { float: right; }
.text-muted { color: var(--text-muted); font-size: 12px; }

/* ========== Demographics Tab ========== */
.demo-section { padding: 8px 0; border-bottom: 1px solid var(--border); }
.demo-section:last-child { border-bottom: none; }
.demo-section-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.demo-total { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.demo-gender-row { display: flex; gap: 12px; margin-bottom: 8px; font-size: 12px; }
.demo-male { color: #3b82f6; }
.demo-female { color: #ec4899; }
.demo-ratio { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* Population Pyramid */
.pyramid { margin: 8px 0; }
.pyramid-header { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-muted); margin-bottom: 4px; padding: 0 2px; }
.pyramid-side-label { flex: 1; }
.pyramid-side-label:last-child { text-align: right; }
.pyramid-age-label { width: 54px; text-align: center; }
.pyramid-row { display: flex; align-items: center; margin-bottom: 3px; }
.pyramid-bar-left { flex: 1; display: flex; flex-direction: row-reverse; align-items: center; gap: 4px; }
.pyramid-bar-right { flex: 1; display: flex; align-items: center; gap: 4px; }
.pyramid-age { width: 54px; text-align: center; font-size: 11px; font-weight: 500; line-height: 1.2; flex-shrink: 0; }
.pyramid-fill { height: 18px; border-radius: 2px; min-width: 2px; transition: width .3s ease; }
.pyramid-fill-male { background: #93c5fd; }
.pyramid-fill-female { background: #f9a8d4; }
.pyramid-val { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

/* Ethnicity Bars */
.eth-bars { margin: 6px 0; }
.eth-bar-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.eth-bar-label { width: 80px; font-size: 11px; color: var(--text); text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eth-bar-track { flex: 1; height: 14px; background: var(--surface); border-radius: 2px; overflow: hidden; }
.eth-bar-fill { height: 100%; border-radius: 2px; min-width: 1px; transition: width .3s ease; }
.eth-bar-value { width: 44px; font-size: 11px; color: var(--text-muted); text-align: right; flex-shrink: 0; }

/* === Strata Matrix Floating Panel === */
#strata-matrix-panel {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  min-width: 380px;
  max-width: 520px;
}
#strata-matrix-panel.hidden { display: none; }
#strata-matrix-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.strata-matrix-title { font-weight: 600; font-size: 14px; }
.strata-matrix-controls { display: flex; align-items: center; gap: 8px; }
#strata-matrix-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-muted); padding: 0 4px;
}
#settlement-toggle .btn { font-size: 11px; padding: 2px 8px; }
#settlement-toggle .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Matrix grid inside floating panel */
.smp-grid { display: grid; gap: 3px; }
.smp-grid-header { font-size: 10px; font-weight: 600; text-align: center; color: var(--text-muted); padding: 2px; }
.smp-grid-row-header { font-size: 11px; font-weight: 600; color: var(--text); padding: 4px 2px; text-align: right; }
.smp-cell {
  border-radius: 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  padding: 6px 2px;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.smp-cell:hover { transform: scale(1.08); box-shadow: 0 2px 6px rgba(0,0,0,.15); z-index: 1; }
.smp-cell.smp-selected { outline: 2px solid var(--text); outline-offset: -1px; }
#strata-matrix-legend { font-size: 11px; text-align: center; }

/* === ROL Document Viewer === */
.rol-section {
  margin-bottom: 12px;
  padding: 10px;
  background: var(--surface-alt);
  border-radius: 6px;
  border: 1px solid var(--border-light);
}
.rol-section-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 6px;
  cursor: pointer;
}
.rol-section-title::before { content: '\25B6 '; font-size: 9px; }
.rol-section-title.expanded::before { content: '\25BC '; }
.rol-section-body { display: none; }
.rol-section-body.expanded { display: block; }
.rol-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.rol-doc-title { font-weight: 600; font-size: 13px; }
.rol-doc-version { font-size: 11px; color: var(--text-muted); }
.rol-channel-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.rol-channel-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 11px;
  font-weight: 500;
}
.rol-tactics-table { width: 100%; font-size: 11px; border-collapse: collapse; margin: 6px 0; }
.rol-tactics-table th { background: var(--surface); padding: 4px 6px; text-align: left; font-weight: 600; border-bottom: 1px solid var(--border-light); }
.rol-tactics-table td { padding: 4px 6px; border-bottom: 1px solid var(--border-light); }
.rol-kpi-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 6px; margin: 6px 0; }
.rol-kpi-card {
  background: var(--surface);
  border-radius: 6px;
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border-light);
}
.rol-kpi-name { font-size: 10px; color: var(--text-muted); }
.rol-kpi-target { font-size: 13px; font-weight: 600; color: var(--primary); }
.rol-md-content { font-size: 12px; line-height: 1.5; color: var(--text); }
.rol-md-content h1, .rol-md-content h2, .rol-md-content h3 { font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.rol-md-content ul, .rol-md-content ol { padding-left: 16px; margin: 4px 0; }
.rol-md-content li { margin-bottom: 2px; }
.rol-empty { color: var(--text-muted); font-size: 12px; padding: 8px; }

/* EI color scale */
.ei-high { color: #166534; }
.ei-mid { color: #854d0e; }
.ei-low { color: #991b1b; }

/* === Analytics Panel === */
#analytics-panel {
  position: fixed;
  top: calc(var(--controls-h) + var(--kpi-h));
  left: 0;
  right: 0;
  bottom: var(--footer-h);
  z-index: 900;
  background: var(--surface);
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.analytics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  position: sticky;
  top: 0;
  z-index: 2;
}

.analytics-tabs {
  display: flex;
  gap: var(--sp-2);
}

.analytics-tab {
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.analytics-tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

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

.analytics-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 var(--sp-2);
  line-height: 1;
}

.analytics-close-btn:hover {
  color: var(--text);
}

.analytics-view {
  flex: 1;
  padding: var(--sp-4);
  display: none;
}

.analytics-view.active {
  display: block;
}

/* Dead Loop Summary */
.analytics-summary {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.dl-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-alt);
  border: 1px solid var(--border-light);
}

.dl-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Analytics Chart Container */
.analytics-chart-container {
  position: relative;
  background: var(--panel-bg-solid);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--sp-3);
  margin-bottom: var(--sp-4);
  min-height: 360px;
}

.analytics-svg {
  width: 100%;
  height: 360px;
}

/* Analytics Tooltip */
.analytics-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
  max-width: 260px;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

/* Dead Loop Details Table */
.dl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.dl-table th {
  text-align: left;
  padding: var(--sp-2) var(--sp-2);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dl-table td {
  padding: var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.dl-table tr:hover td {
  background: var(--surface-alt);
}

.dl-quadrant-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dl-quadrant-tag.dead_loop { background: #fee2e2; color: #991b1b; }
.dl-quadrant-tag.efficient { background: #dcfce7; color: #166534; }
.dl-quadrant-tag.underserved { background: #fef9c3; color: #854d0e; }
.dl-quadrant-tag.dormant { background: #e0e7ff; color: #3730a3; }

/* Strata gap mini bars */
.dl-strata-gaps {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 18px;
}

.dl-strata-bar {
  width: 4px;
  border-radius: 1px;
  background: #ef4444;
  opacity: 0.7;
}

/* Saturation Controls */
.analytics-saturation-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

/* Saturation Insights */
.analytics-insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-3);
}

.sat-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--sp-3);
  background: var(--panel-bg-solid);
}

.sat-card-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.sat-card-title .color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.sat-card-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 0;
}

.sat-card-row .value {
  font-weight: 600;
  color: var(--text);
}

.sat-headroom-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border-light);
  margin-top: var(--sp-2);
  overflow: hidden;
}

.sat-headroom-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition-slow);
}


/* === Small Mobile (≤375px) === */
@media (max-width: 375px) {
  .mobile-nav-item small { font-size: 9px; }
  .mobile-nav-icon { font-size: 18px; }
  .mobile-kpi-strip .kpi-value { font-size: 12px; }
  .mobile-kpi-strip .kpi-label { font-size: 7px; }
  #legend { max-width: 150px; font-size: 10px; }
  .sheet-handle { width: 32px; }
  #info .nav-tabs-sm .nav-link { font-size: 10px; padding: 4px 6px; }
}

/* Responsive adjustments */
@media (max-width: 767.98px) {
  #analytics-panel {
    top: 0;
    bottom: 56px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 0;
  }

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

  .analytics-svg {
    height: 280px;
  }

  .analytics-insights {
    grid-template-columns: 1fr;
  }
}

/* === Report / Passport Tab === */
.report-passport-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background 0.15s;
}
.report-passport-btn:hover { background: var(--primary-hover); }
.report-passport-btn:disabled { opacity: 0.6; cursor: wait; }

.report-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin: 14px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-light);
}

.swot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.swot-cell {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}
.swot-cell h4 {
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 4px;
}
.swot-cell ul {
  margin: 0;
  padding-left: 16px;
}
.swot-strengths  { background: #e8f5e9; }
.swot-weaknesses { background: #fce4ec; }
.swot-opportunities { background: #e3f2fd; }
.swot-risks      { background: var(--panel-bg-solid)3e0; }

.report-findings {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.report-findings li {
  font-size: 12px;
  padding: 3px 0;
  line-height: 1.5;
}
.finding-up   { color: #2e7d32; }
.finding-down { color: #c62828; }
.finding-neutral { color: var(--text-muted); }

.report-actions {
  padding-left: 18px;
  margin: 0 0 12px;
}
.report-actions li {
  font-size: 12px;
  padding: 2px 0;
  line-height: 1.5;
}

/* === Large Desktop (≥1440px) === */
@media (min-width: 1440px) {
  :root {
    --info-w: 400px;
  }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 11px; }
  #controls-bar { padding: 0 var(--sp-4); }
}

/* === Ultra-wide / 4K (≥2560px) === */
@media (min-width: 2560px) {
  :root {
    --info-w: 480px;
    --controls-h: 56px;
    --kpi-h: 60px;
  }
  body { font-size: 16px; }
  .kpi-value { font-size: 26px; }
  .kpi-label { font-size: 12px; letter-spacing: 0.12em; }
  .select-wrapper select { font-size: 15px; }
  .control-label { font-size: 12px; }
  #ranking-panel { width: 320px; }
}


/* === Dark Mode Component Overrides === */
html.dark .leaflet-tile-pane {
  filter: saturate(0.3) brightness(0.85);
}

html.dark .region-label {
  text-shadow:
    0 0 4px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(0, 0, 0, 0.7),
    1px 1px 2px rgba(0, 0, 0, 0.8);
}

html.dark .leaflet-control-zoom a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
html.dark .leaflet-control-zoom a:hover {
  background: var(--surface-alt);
}

html.dark .swot-strengths  { background: rgba(34, 197, 94, 0.12); }
html.dark .swot-weaknesses { background: rgba(244, 63, 94, 0.12); }
html.dark .swot-opportunities { background: rgba(59, 130, 246, 0.12); }
html.dark .swot-risks      { background: rgba(251, 146, 60, 0.12); }

html.dark .dl-quadrant-tag.dead_loop { background: rgba(220, 38, 38, 0.15); color: #fca5a5; }
html.dark .dl-quadrant-tag.efficient { background: rgba(34, 197, 94, 0.15); color: #86efac; }
html.dark .dl-quadrant-tag.underserved { background: rgba(234, 179, 8, 0.15); color: #fde68a; }
html.dark .dl-quadrant-tag.dormant { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }

html.dark .info-badge { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }

html.dark .modal-content { background: var(--surface); color: var(--text); border-color: var(--border); }
html.dark .modal-header { border-color: var(--border); }
html.dark .modal-footer { border-color: var(--border); }
html.dark .btn-close { filter: invert(1); }

html.dark .alert-success { background: rgba(34, 197, 94, 0.15); color: #86efac; border-color: rgba(34, 197, 94, 0.3); }
html.dark .alert-warning { background: rgba(234, 179, 8, 0.15); color: #fde68a; border-color: rgba(234, 179, 8, 0.3); }
html.dark .alert-danger { background: rgba(220, 38, 38, 0.15); color: #fca5a5; border-color: rgba(220, 38, 38, 0.3); }

html.dark #settlement-toggle .btn { color: var(--text); border-color: var(--border); }

html.dark .mobile-more-panel { background: var(--surface); }
html.dark .mobile-more-item:active { background: var(--active-bg); }

/* Theme Toggle Button */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.theme-toggle-btn:hover {
  background: var(--hover-bg);
  border-color: var(--text-faint);
  color: var(--text);
}
html:not(.dark) .theme-icon-dark { display: none; }
html.dark .theme-icon-light { display: 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;
  }
}


/* ============================================================
   Bootstrap Replacement Classes
   ============================================================ */

/* --- Dropdown --- */
.mr-dropdown {
  position: relative;
  display: inline-block;
}
.mr-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: 'Rubik', sans-serif;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.mr-dropdown-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}
.mr-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1100;
  min-width: 180px;
  margin-top: 4px;
  padding: 4px 0;
  background: var(--panel-bg-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.mr-dropdown-menu.show {
  display: block;
}
.mr-dropdown-item {
  display: block;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
}
.mr-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--primary);
}
.mr-dropdown-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--border-light);
}

/* --- Dialog (modal replacement) --- */
.mr-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  width: 420px;
  max-width: 90vw;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-bg-solid);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.mr-dialog::backdrop {
  background: rgba(0,0,0,0.35);
}
.mr-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
}
.mr-dialog-header h6 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.mr-dialog-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.mr-dialog-close:hover { color: var(--danger); }
.mr-dialog-body {
  padding: 16px 18px;
}
.mr-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
}

/* --- Buttons --- */
.mr-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  font-size: 12px;
  font-family: 'Rubik', sans-serif;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.mr-btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.mr-btn-primary:hover {
  background: var(--primary-hover);
}
.mr-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.mr-btn-secondary {
  background: var(--surface);
  color: var(--text);
}
.mr-btn-secondary:hover {
  background: var(--bg-hover);
}

/* --- Analytics button --- */
.mr-btn-analytics {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: 'Rubik', sans-serif;
  font-weight: 500;
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.mr-btn-analytics:hover {
  background: var(--primary);
  color: #fff;
}

/* --- Tabs (replacing Bootstrap nav-tabs) --- */
.mr-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-light);
  margin-top: 8px;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  white-space: nowrap;
}
.mr-tabs::-webkit-scrollbar { display: none; }
.mr-tab-item {
  flex-shrink: 0;
}
.mr-tab {
  display: inline-block;
  padding: 6px 10px;
  font-size: 12px;
  font-family: 'Rubik', sans-serif;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.mr-tab:hover {
  color: var(--text);
}
.mr-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* --- Button group (toggle) --- */
.mr-btn-group {
  display: inline-flex;
  gap: 0;
}
.mr-btn-group .mr-btn-toggle {
  padding: 4px 10px;
  font-size: 11px;
  font-family: 'Rubik', sans-serif;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}
.mr-btn-group .mr-btn-toggle:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}
.mr-btn-group .mr-btn-toggle:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}
.mr-btn-group .mr-btn-toggle.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Select (replacing form-select) --- */
.mr-select {
  padding: 4px 8px;
  font-size: 12px;
  font-family: 'Rubik', sans-serif;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}
.mr-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* --- Utility classes (replacing Bootstrap utilities) --- */
.hint-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
