/* Map viewer — FAO Uganda + ICPAC layout */

.map-app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--chrome-h));
}

.map-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left filter sidebar (FAO blue) ── */
.filter-sidebar {
  flex: 0 0 var(--sidebar-w);
  background: var(--fao-blue);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: visible;
  -webkit-overflow-scrolling: touch;
  transition: margin-left 0.3s ease;
  z-index: 600;
  position: relative;
}

.filter-sidebar.collapsed {
  flex: 0 0 42px;
  width: 42px;
  overflow: hidden;
}

.sidebar-title-short { display: none; }

.filter-sidebar.collapsed .sidebar-header {
  flex-direction: column;
  justify-content: flex-start;
  gap: 14px;
  height: 100%;
  padding: 12px 0;
  border-bottom: none;
  cursor: pointer;
}

.filter-sidebar.collapsed .sidebar-title-full { display: none; }

.filter-sidebar.collapsed .sidebar-title-short {
  display: block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
}

.filter-sidebar.collapsed .filter-section,
.filter-sidebar.collapsed .btn-clear-filters,
.filter-sidebar.collapsed .btn-mobile-show-map,
.filter-sidebar.collapsed .layer-lag-note { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-header h2 {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar-collapse-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.15);
  border: none; border-radius: 50%;
  color: #fff; cursor: pointer;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.25); }

.filter-section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.filter-section h3 {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.7);
  margin-bottom: 10px;
}

.filter-group { margin-bottom: 10px; }
.filter-group:last-child { margin-bottom: 0; }

.filter-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: rgba(255,255,255,0.9);
}

.filter-group select {
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.82rem;
  background: #fff;
  color: var(--text-primary);
  cursor: pointer;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-clear-filters {
  margin: 12px 16px 16px;
  padding: 9px;
  background: #fff;
  color: var(--fao-blue-dark);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-clear-filters:hover { background: var(--fao-blue-light); }

/* Layer toggles (ICPAC style) */
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  font-size: 0.78rem;
}

.layer-toggle {
  position: relative;
  width: 36px; height: 20px;
  flex-shrink: 0;
}
.layer-toggle input { opacity: 0; width: 0; height: 0; }
.layer-toggle .slider {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition);
}
.layer-toggle .slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}
.layer-toggle input:checked + .slider { background: var(--final-green); }
.layer-toggle input:checked + .slider::before { transform: translateX(16px); }

.layer-item.layer-unavailable {
  opacity: 0.55;
}
.layer-item.layer-unavailable .layer-name::after {
  content: ' (no data)';
  font-weight: 400;
  color: rgba(255, 255, 255, 0.65);
}
.layer-item.layer-unavailable .layer-toggle .slider {
  cursor: not-allowed;
}

.layer-name { flex: 1; font-weight: 500; }

.layer-lag-note {
  margin: 0 0 8px 44px;
  font-size: 0.68rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.78);
}

.layer-sub-filters {
  padding: 6px 0 6px 44px;
  display: none;
}
.layer-sub-filters.open { display: block; }
.layer-sub-filters select {
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-bottom: 4px;
}
.layer-opacity-row {
  margin-top: 8px;
}
.layer-opacity-row label {
  display: block;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 4px;
}
.layer-opacity-row input[type="range"] {
  width: 100%;
}

/* ── Center map area — flexes between sidebar and data panel (no gap on the right) ── */
.map-center {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
}

.map-title-bar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.map-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.exposure-info-tip[hidden] { display: none !important; }

.map-title-actions .info-tip-icon {
  width: 22px;
  height: 22px;
  font-size: 0.72rem;
}

.btn-exposure-report {
  flex-shrink: 0;
  padding: 7px 14px;
  background: var(--fao-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.btn-exposure-report:hover { background: var(--fao-blue-hover); }
.btn-exposure-report[hidden] { display: none !important; }

.map-title-bar h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.map-title-bar .map-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.map-viewport {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map, .comparison-grid .quad-map {
  width: 100%;
  height: 100%;
  background: #e8edf2;
}

/* Map toolbar — zoom then comparison */
.map-zoom-toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  transition: top 0.2s, bottom 0.2s, left 0.2s, right 0.2s;
}

.map-app.comparison-active .map-zoom-toolbar {
  top: auto;
  left: auto;
  right: 12px;
  bottom: 12px;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
  gap: 6px;
}

.map-app.comparison-active .map-zoom-toolbar .map-tool-btn {
  order: 1;
  pointer-events: auto;
}

.map-app.comparison-active .map-zoom-toolbar .map-zoom-group {
  order: 2;
  pointer-events: auto;
}

.map-zoom-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.map-tool-btn {
  width: 34px; height: 34px;
  background: var(--fao-blue);
  border: 2px solid #f0a030;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition);
}
.map-tool-btn:hover { background: var(--fao-blue-dark); }
.map-tool-btn.active { background: var(--fao-blue-darker); }

.map-tool-btn .icon-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 14px; height: 14px;
}
.map-tool-btn .icon-grid span {
  background: #fff;
  border-radius: 1px;
}

.map-compare-btn {
  width: auto;
  gap: 7px;
  padding: 0 11px 0 9px;
  border-radius: 17px;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.map-compare-btn .icon-grid { flex-shrink: 0; }
.map-compare-btn.attention { animation: compare-pulse 1.8s ease-out 0.8s 3; }

@keyframes compare-pulse {
  0% { box-shadow: 0 0 0 0 rgba(240, 160, 48, 0.65); }
  70% { box-shadow: 0 0 0 10px rgba(240, 160, 48, 0); }
  100% { box-shadow: 0 0 0 0 rgba(240, 160, 48, 0); }
}

.map-ctrl-btn {
  width: 32px; height: 32px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.map-ctrl-btn:hover { background: var(--page-bg); }

/* Legend */
.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 500;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.72rem;
  box-shadow: var(--shadow-sm);
}
.map-legend h4 {
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; color: var(--text-secondary);
  margin-bottom: 4px;
}
.legend-item { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.legend-swatch { width: 16px; height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.08); }

.map-downloads {
  position: absolute; bottom: 12px; right: 12px;
  z-index: 500; display: flex; gap: 4px;
}
.download-btn {
  padding: 5px 10px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 4px; font-size: 0.7rem; font-weight: 600;
  color: var(--fao-blue-dark); cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* Comparison mode — 4 quadrants */
.comparison-grid {
  display: none;
  width: 100%;
  height: 100%;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--border);
}
.comparison-grid.active { display: grid; }

.comparison-grid .quad {
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  overflow: hidden;
  min-height: 0;
}
.comparison-grid .quad-controls {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  background: var(--fao-blue-light);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.comparison-grid .quad-field label {
  display: block;
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.comparison-grid .quad-field select {
  width: 100%;
  padding: 4px 6px;
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
  color: var(--text-primary);
}
.comparison-grid .quad-body {
  flex: 1;
  position: relative;
  min-height: 0;
}
.comparison-grid .quad-legend {
  position: absolute;
  left: 12%;
  top: 50%;
  transform: translateY(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  line-height: 1.25;
  background: rgba(255,255,255,0.94);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 0.62rem;
  border: 1px solid var(--border);
  width: max-content;
  max-width: 46%;
  height: auto;
  max-height: 72%;
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
.quad-legend-item { white-space: nowrap; }
.comparison-grid .quad-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.quad-graph-toggle {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 520;
  padding: 4px 10px;
  font-size: 0.62rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.92);
  color: var(--fao-blue-dark);
  cursor: pointer;
  font-family: var(--font);
  box-shadow: var(--shadow-sm);
}
.quad-graph-toggle:hover { background: var(--fao-blue-light); }
.quad-graph-toggle.active { background: var(--fao-blue); color: #fff; border-color: var(--fao-blue); }

.quad-graph-panel {
  position: absolute;
  top: 32px;
  left: 6px;
  right: 6px;
  bottom: 28px;
  z-index: 510;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.quad-graph-panel[hidden] { display: none !important; }

.quad-graph-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--fao-blue-dark);
  flex-shrink: 0;
}
.quad-graph-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 2px 4px;
}
.quad-graph-canvas {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  padding: 4px 6px 6px;
}
.quad-graph-canvas canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
}
.quad-graph-empty {
  margin: 0;
  padding: 16px 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

/* Comparison lock overlays */
.comparison-locked { position: relative; }
.comparison-lock-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 800;
  background: rgba(0,0,0,0.18);
  cursor: not-allowed;
}
.comparison-locked .comparison-lock-overlay { display: block; }

.comparison-locked .filter-section,
.comparison-locked .btn-clear-filters,
.comparison-locked .sidebar-header {
  opacity: 0.55;
  filter: grayscale(0.3);
}

.comparison-locked .panel-stack,
.comparison-locked .chart-actions,
.comparison-locked .situation-csv-btn {
  opacity: 0.45;
  pointer-events: none;
}

.comparison-locked .timeline-label,
.comparison-locked .timeline-slider,
.comparison-locked .timeline-range {
  opacity: 0.55;
}

.single-map-view { width: 100%; height: 100%; }
.single-map-view.hidden { display: none; }

/* ── Right panel — wider fixed column, flush to viewport right edge ── */
.data-panel {
  flex: 0 0 500px;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

.panel-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fao-blue-dark);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--fao-blue);
}

.panel-graphs { flex-shrink: 0; }
.panel-graphs .panel-section-title { margin-bottom: 6px; }

.panel-situation {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 8px;
}

.panel-legend {
  flex-shrink: 0;
  padding: 8px 12px 10px;
  overflow: visible;
}

.situation-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--fao-blue);
  flex-shrink: 0;
}

.situation-section-header .panel-section-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
  flex: 1;
}

.situation-csv-btn {
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--fao-blue-dark);
  cursor: pointer;
  font-family: var(--font);
}

/* Graphs pane */
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chart-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chart-action-btn {
  padding: 4px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--fao-blue-dark);
  cursor: pointer;
  font-family: var(--font);
}
.chart-action-btn:hover { background: var(--fao-blue-light); }
.chart-action-btn .icon-expand { display: block; }

.has-action-tip { position: relative; }

.chart-expand-box { max-width: 900px; width: 100%; }
.chart-expand-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.chart-expand-header h3 { font-size: 1rem; color: var(--fao-blue-dark); }
.chart-expand-header p { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}
.chart-zoom-hint {
  margin: 0 0 8px;
  font-size: 0.74rem;
  color: var(--text-secondary);
}
.chart-zoom-band {
  position: absolute;
  background: rgba(46, 139, 199, 0.18);
  border: 1px solid rgba(36, 120, 176, 0.75);
  pointer-events: none;
  z-index: 4;
}
.chart-zoom-band[hidden] { display: none !important; }
.quad-zoom-hint {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
}
.chart-zoom-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: 0 0 8px;
}
.quad-graph-panel .chart-zoom-controls { margin: 4px 8px 0; }
.chart-zoom-controls button {
  min-width: 28px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--fao-blue-dark);
  font-weight: 700;
  cursor: pointer;
}
.chart-zoom-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}
.chart-expand-wrapper { height: 420px; margin-bottom: 14px; position: relative; }
.chart-expand-actions { display: flex; gap: 8px; justify-content: flex-end; }

.chart-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--fao-blue-dark);
}
.chart-subtitle { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 6px; }

.chart-series-toggles {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.chart-series-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--fao-blue-dark);
  cursor: pointer;
  user-select: none;
}

.chart-series-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--fao-blue);
  cursor: pointer;
}

.chart-series-toggle.is-off { opacity: 0.5; }

.chart-series-toggles-expanded {
  margin-bottom: 12px;
}

.chart-spi-note {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 0.66rem; color: var(--text-muted);
}
.chart-spi-note-swatch { width: 14px; height: 3px; border-radius: 2px; flex: none; }

.chart-empty-note {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; text-align: center; font-size: 0.75rem; color: var(--text-muted);
  background: rgba(255,255,255,0.75); pointer-events: none;
}

.chart-wrapper {
  position: relative;
  height: 200px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 0;
}

/* Tall windows keep a larger graph; the list already has room there. */
@media (min-height: 980px) {
  .chart-wrapper { height: 240px; }
}

/* Legend table (FAO Uganda style) */
.legend-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.legend-table thead th {
  background: var(--fao-blue);
  color: #fff;
  padding: 6px 8px;
  text-align: left;
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
}
.legend-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.legend-table .lt-color { width: 36px; padding: 6px 8px !important; }
.legend-table .lt-swatch {
  display: block;
  width: 24px;
  height: 18px;
  min-width: 24px;
  min-height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
}

.map-legend-section {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.map-legend-section h5 {
  font-size: 0.62rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

/* Drought situation pane (Observatory style) */
.situation-search {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.76rem;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.situation-search:focus { outline: none; border-color: var(--fao-blue); }

.situation-list-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.district-situation-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: var(--fao-blue) transparent;
  scrollbar-width: thin;
}
.district-situation-list::-webkit-scrollbar { width: 8px; }
.district-situation-list::-webkit-scrollbar-thumb {
  background: var(--fao-blue);
  border-radius: 4px;
}

.situation-scroll-fade {
  position: absolute;
  left: 0;
  right: 8px;
  bottom: 0;
  height: 42px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  background: linear-gradient(to bottom, rgba(255,255,255,0), var(--panel-bg) 62%);
  color: var(--fao-blue-dark);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  pointer-events: none;
}
.situation-scroll-fade[hidden] { display: none !important; }

.district-situation-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.district-situation-item.is-open { background: var(--fao-blue-light); margin: 0 -6px; padding: 8px 6px; border-radius: 4px; }
.district-situation-item:last-child { border-bottom: none; }

.dsit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.dsit-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}
.dsit-actions {
  display: flex;
  gap: 8px;
  font-size: 0.68rem;
}
.dsit-actions a,
.dsit-actions .detail-toggle { color: var(--fao-blue); font-weight: 600; text-decoration: none; }
.dsit-actions a:hover,
.dsit-actions .detail-toggle:hover { text-decoration: underline; }

.dsit-bar {
  height: 10px;
  background: #e8e8e8;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
}
.dsit-bar-seg { height: 100%; transition: width 0.3s; }

.dsit-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Timeline slider (bottom) */
.timeline-bar {
  flex-shrink: 0;
  background: var(--fao-blue);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
}

.timeline-label {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 100px;
}

.timeline-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  background: rgba(255,255,255,0.3);
  border-radius: 3px;
  outline: none;
}
.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.timeline-range {
  font-size: 0.72rem;
  opacity: 0.85;
  white-space: nowrap;
}

.leaflet-control-zoom { display: none !important; }
.district-tooltip {
  background: rgba(36,120,176,0.92) !important;
  color: #fff !important; border: none !important;
  border-radius: 4px !important;
  padding: 6px 10px !important;
  font-size: 0.78rem !important;
}

/* Responsive */
@media (max-width: 1100px) {
  .data-panel { flex: 0 0 420px; }
  .chart-wrapper { height: 188px; }
}

/* Shorter desktop windows: keep a readable chart, fold the classification into
   one colour key, and leave the district list tall enough to show several rows. */
@media (max-height: 860px) and (min-width: 901px) {
  .panel-graphs {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: 8px;
    padding-bottom: 6px;
  }
  .chart-series-toggles { margin-bottom: 4px; }
  .chart-wrapper {
    height: auto;
    flex: 1 1 auto;
    min-height: 120px;
    max-height: 200px;
  }
  .panel-situation {
    flex: 1 0 188px;
    min-height: 188px;
  }
  .panel-legend { padding: 6px 10px 8px; }
  .panel-legend .panel-section-title { margin-bottom: 4px; }
  .legend-table thead { display: none; }
  .legend-table,
  .legend-table tbody {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
  }
  .legend-table tr { display: inline-flex; align-items: center; gap: 4px; }
  .legend-table td { border: none; padding: 0; font-size: 0.68rem; }
  .legend-table .lt-color { width: auto; padding: 0 !important; }
  .legend-table td:nth-child(4) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
}

.mobile-view-tabs,
.btn-mobile-show-map,
.map-legend-toggle { display: none; }

/* Phones & small tablets: one section at a time — Map | Filters & layers | Charts & districts */
@media (max-width: 900px) {
  .map-app { height: calc(100vh - var(--chrome-h)); height: calc(100dvh - var(--chrome-h)); }

  .mobile-view-tabs {
    display: flex;
    flex-shrink: 0;
    background: var(--fao-blue-darker);
    padding: 6px 8px;
    gap: 6px;
  }
  .mobile-view-tabs button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 6px;
    border: none;
    border-radius: 18px;
    background: transparent;
    color: rgba(255,255,255,0.85);
    font-family: var(--font);
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.15;
    cursor: pointer;
  }
  .mobile-view-tabs button svg {
    width: 16px; height: 16px; flex-shrink: 0;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  }
  .mobile-view-tabs button[aria-selected="true"] {
    background: #fff;
    color: var(--fao-blue-darker);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  }

  .map-workspace { flex-direction: column; }
  .filter-sidebar,
  .map-center,
  .data-panel {
    display: none;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin-left: 0 !important;
    border: none;
  }
  .map-app[data-mview="filters"] .filter-sidebar { display: flex; }
  .map-app[data-mview="map"] .map-center { display: flex; }
  .map-app[data-mview="data"] .data-panel { display: flex; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  .filter-sidebar.collapsed {
    flex: 1 1 auto;
    width: 100%;
    overflow: visible;
  }
  .filter-sidebar.collapsed .sidebar-header {
    flex-direction: row;
    height: auto;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    cursor: default;
  }
  .filter-sidebar.collapsed .sidebar-title-full { display: inline; }
  .filter-sidebar.collapsed .sidebar-title-short { display: none; }
  .filter-sidebar.collapsed .filter-section,
  .filter-sidebar.collapsed .btn-clear-filters,
  .filter-sidebar.collapsed .btn-mobile-show-map,
  .filter-sidebar.collapsed .layer-lag-note { display: revert; }
  .sidebar-collapse-btn { display: none; }
  .btn-mobile-show-map {
    display: block;
    margin: 4px 16px 18px;
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    background: #fff;
    color: var(--fao-blue-darker);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
  }

  .map-title-bar { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  .map-title-bar h2 { font-size: 0.92rem; }

  /* Legend collapses behind a button so it does not hide the map */
  .map-legend-toggle {
    display: block;
    position: absolute;
    left: 10px;
    bottom: 24px;
    z-index: 520;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--fao-blue-dark);
    cursor: pointer;
  }
  .map-legend {
    display: none;
    left: 10px;
    bottom: 58px;
    max-height: calc(100% - 120px);
    max-width: calc(100% - 20px);
    overflow-y: auto;
  }
  .map-legend.open { display: block; }
  .map-downloads { bottom: 24px; right: 8px; }
  .download-btn { padding: 5px 8px; }
  .leaflet-control-attribution { font-size: 8px !important; max-width: 70%; }

  /* Charts & districts panel scrolls as one page */
  .panel-stack { flex: none; overflow: visible; }
  .panel-situation { flex: none; overflow: visible; }
  .district-situation-list { max-height: 55vh; }
  .chart-wrapper { height: 240px; }

  /* Comparison maps stack vertically */
  .comparison-grid.active {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: minmax(320px, 60vh);
    overflow-y: auto;
  }
  .map-app.comparison-active .map-zoom-toolbar { bottom: 10px; right: 10px; }

  .timeline-bar { padding: 8px 12px; gap: 10px; }
  .timeline-label { min-width: 0; }
  .timeline-range { display: none; }
}

.district-label-icon { background: transparent !important; border: none !important; }
.district-label-text {
  font-size: 9px;
  font-weight: 700;
  color: #222;
  text-shadow:
    -1px -1px 0 #fff, 1px -1px 0 #fff,
    -1px 1px 0 #fff, 1px 1px 0 #fff,
    0 0 3px #fff;
  white-space: nowrap;
  pointer-events: none;
}

.map-no-data-banner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.82);
  z-index: 500;
  font-weight: 600;
  color: var(--text-secondary);
  pointer-events: none;
}

.overlay-opacity-wrap { margin-top: 10px; }
.overlay-opacity-wrap input[type="range"] { width: 100%; }
.filter-sidebar .overlay-opacity-wrap label { color: rgba(255,255,255,0.85); font-size: 0.72rem; }
