/* ═══════════════════════════════════════════════════
   INDONESIA FLOOD EXPLORER — Design System v3
   Warm neutral · Multi-accent · Sidebar layout · Map-first
   ═══════════════════════════════════════════════════ */

:root {
  /* Surface — warm cream / ivory / sand */
  --bg: #f5f1eb;
  --surface: rgba(250, 249, 246, 0.88);
  --surface-solid: #faf9f6;
  --surface-hover: rgba(250, 249, 246, 0.96);
  --surface-card: #f0ebe4;
  --border: rgba(120, 90, 50, 0.10);
  --border-strong: rgba(120, 90, 50, 0.18);

  /* Text — warm charcoal / brown hierarchy */
  --ink: #2c2418;
  --ink-secondary: #6b5e4f;
  --ink-tertiary: #9a8e7f;
  --ink-inverse: #faf9f6;

  /* Accent — muted blue for interactive UI elements */
  --accent: #4f7ec4;
  --accent-hover: #3d6db3;
  --accent-soft: rgba(79, 126, 196, 0.10);
  --accent-glow: rgba(79, 126, 196, 0.22);
  /* Warm accent — amber for data highlights & title */
  --accent-warm: #b45309;
  --accent-warm-soft: rgba(180, 83, 9, 0.10);
  /* Chart accent — teal for trend charts */
  --accent-chart: #14b8a6;
  --accent-chart-soft: rgba(20, 184, 166, 0.10);

  /* Status */
  --danger: #dc4a3c;
  --success: #2d9c6f;
  --warn: #d4880a;

  /* Shadows — warm-tinted */
  --shadow-sm: 0 1px 3px rgba(120, 90, 50, 0.07), 0 1px 2px rgba(120, 90, 50, 0.05);
  --shadow-md: 0 4px 16px rgba(120, 90, 50, 0.08), 0 2px 4px rgba(120, 90, 50, 0.05);
  --shadow-lg: 0 12px 40px rgba(120, 90, 50, 0.10), 0 4px 12px rgba(120, 90, 50, 0.06);
  --shadow-xl: 0 24px 64px rgba(120, 90, 50, 0.12);

  /* Layout */
  --sidebar-w: 380px;
  --sidebar-collapse: 0px;
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  /* Timing */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration: 280ms;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Map ─── */
#map {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  transition: left var(--duration) var(--ease);
  z-index: 0;
}

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

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 100;
  background: var(--surface);
  backdrop-filter: blur(32px) saturate(1.3);
  -webkit-backdrop-filter: blur(32px) saturate(1.3);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration) var(--ease);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.sidebar-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 20px 16px;
  scroll-padding-bottom: 32px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-inner::-webkit-scrollbar {
  width: 5px;
}

.sidebar-inner::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-inner::-webkit-scrollbar-thumb {
  background: rgba(120, 90, 50, 0.18);
  border-radius: var(--radius-pill);
}

/* ─── Brand ─── */
.sidebar-brand {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 4px;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--ink-tertiary);
  line-height: 1.4;
  max-width: 26ch;
  white-space: pre-line;
}

.sidebar-toggle {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.sidebar-toggle:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* Collapsed state — show expand button on the map side */
.sidebar-expand {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--duration) var(--ease);
}

body.sidebar-collapsed .sidebar-expand {
  display: flex;
}

.sidebar-expand:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: scale(1.05);
}

/* ─── Sidebar Sections ─── */
.sidebar-section {
  position: relative;
  overflow: visible;
  margin-bottom: 20px;
}

.sidebar-section:has(.select-shell.is-open) {
  z-index: 50;
}

.sidebar-section:last-of-type {
  margin-bottom: 8px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.section-head h2 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-secondary);
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0 20px;
}

/* ─── Level Pill ─── */
.level-pill, .period-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.level-pill {
  background: var(--accent-soft);
  color: var(--accent);
}

.period-badge {
  background: var(--accent-warm-soft);
  color: var(--accent-warm);
}

/* ─── Search ─── */
.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-tertiary);
  pointer-events: none;
}

input[type="search"] {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  transition: all var(--duration) var(--ease);
  outline: none;
}

input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.search-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink);
  text-align: left;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 160ms var(--ease);
}

.search-result:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateX(2px);
}

.search-result strong {
  display: block;
  font-weight: 600;
}

.search-result span {
  display: block;
  color: var(--ink-tertiary);
  font-size: 0.78rem;
}

/* ─── Stat Grid ─── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  transition: all var(--duration) var(--ease);
}

.stat-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.stat-card--primary {
  background: linear-gradient(135deg, var(--accent-warm-soft), rgba(180, 83, 9, 0.04));
  border-color: rgba(180, 83, 9, 0.15);
  border-left: 3px solid var(--accent-warm);
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-tertiary);
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.stat-card--primary .stat-value {
  color: var(--accent-warm);
}

/* ─── Filter Group ─── */
.filter-group {
  position: relative;
  margin-bottom: 10px;
}

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

.filter-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-tertiary);
  margin-bottom: 6px;
}

.control-help {
  margin-top: 7px;
  font-size: 0.76rem;
  line-height: 1.45;
}

select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23546a7b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  transition: all var(--duration) var(--ease);
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-native {
  display: none;
}

.select-shell {
  position: relative;
}

.select-shell.is-open {
  z-index: 40;
}

.select-trigger {
  position: relative;
  width: 100%;
  padding: 10px 40px 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease),
    background-color var(--duration) var(--ease);
}

.select-trigger::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 14px;
  width: 10px;
  height: 6px;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23546a7b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  transition: transform 160ms var(--ease);
}

.select-shell.is-open .select-trigger,
.select-trigger:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-shell.is-open .select-trigger::after {
  transform: translateY(-50%) rotate(180deg);
}

.select-trigger-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: grid;
  gap: 4px;
  max-height: 216px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: rgba(250, 249, 246, 0.96);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px) scale(0.985);
  transform-origin: top center;
  z-index: 41;
  transition:
    opacity 140ms var(--ease),
    transform 140ms var(--ease);
}

.select-shell.is-open .select-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.select-menu::-webkit-scrollbar {
  width: 6px;
}

.select-menu::-webkit-scrollbar-thumb {
  background: rgba(120, 90, 50, 0.22);
  border-radius: 999px;
}

.select-option {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 140ms var(--ease),
    color 140ms var(--ease);
}

.select-option:hover,
.select-option:focus-visible {
  background: rgba(120, 90, 50, 0.07);
  outline: none;
}

.select-option.is-selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.select-option:disabled {
  cursor: default;
  opacity: 0.55;
}

/* ─── Ghost Button ─── */
.btn-ghost {
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms var(--ease);
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Selection Detail ─── */
.selection-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.selection-header h3 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-grid dt {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-tertiary);
  margin-bottom: 3px;
}

.detail-grid dd {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.detail-grid > div {
  padding: 10px;
  border-radius: var(--radius-xs);
  background: var(--surface-card);
  border: 1px solid var(--border);
}

/* ─── Chart ─── */
.chart-shell {
  position: relative;
  min-height: 180px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  border: 1px solid var(--border);
}

/* ─── Empty State ─── */
.empty-state {
  padding: 20px 0;
  color: var(--ink-tertiary);
  font-size: 0.85rem;
  text-align: center;
}

.is-hidden {
  display: none !important;
}

/* ─── Text Utilities ─── */
.text-muted {
  color: var(--ink-secondary);
  font-size: 0.82rem;
  line-height: 1.5;
}

.method-summary {
  margin-bottom: 8px;
}

.methodology-list {
  padding-left: 16px;
  color: var(--ink-secondary);
  font-size: 0.82rem;
  line-height: 1.7;
}

/* ─── Sidebar Footer ─── */
.sidebar-footer {
  padding: 16px 0 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.sidebar-footer p {
  font-size: 0.72rem;
  color: var(--ink-tertiary);
  line-height: 1.5;
}

.map-attribution-copy {
  margin-top: 6px;
  font-size: 0.68rem;
  line-height: 1.55;
}

.map-attribution-copy a {
  color: inherit;
  text-decoration-color: rgba(120, 90, 50, 0.3);
  text-underline-offset: 2px;
}

.map-attribution-copy a:hover {
  color: var(--ink-secondary);
  text-decoration-color: currentColor;
}

/* ═══════════ MAP OVERLAYS ═══════════ */

/* Top-right controls */
.map-controls-tr {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.language-toggle {
  display: flex;
  border-radius: var(--radius-pill);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-strong);
}

.lang-btn {
  padding: 8px 14px;
  border: none;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 160ms var(--ease);
}

.lang-btn:first-child {
  border-right: 1px solid var(--border);
}

.lang-btn.is-active {
  background: var(--accent);
  color: var(--ink-inverse);
}

.lang-btn:hover:not(.is-active) {
  background: var(--accent-soft);
  color: var(--accent);
}

.basemap-toggle {
  display: flex;
  border-radius: var(--radius-pill);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-strong);
}

.segmented-btn {
  padding: 8px 16px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--ink-secondary);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms var(--ease);
}

.segmented-btn:last-child {
  border-right: none;
}

.segmented-btn.is-active {
  background: var(--accent);
  color: var(--ink-inverse);
}

.segmented-btn:hover:not(.is-active) {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ─── Legend ─── */
.legend-panel {
  position: fixed;
  bottom: 68px;
  left: calc(var(--sidebar-w) + 16px);
  z-index: 50;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  min-width: 0;
  transition: left var(--duration) var(--ease);
}

body.sidebar-collapsed .legend-panel {
  left: 16px;
}

.legend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.legend-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-tertiary);
}

.legend-head strong {
  font-size: 0.82rem;
  font-weight: 700;
}

.legend-bar {
  display: flex;
  gap: 3px;
  height: 8px;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.legend-swatch {
  flex: 1;
  border-radius: var(--radius-pill);
  transition: transform 160ms var(--ease);
}

.legend-swatch:hover {
  transform: scaleY(1.6);
}

.legend-note {
  margin-top: 6px;
  font-size: 0.7rem;
  line-height: 1.4;
}

/* ─── Timeline Bar ─── */
.timeline-bar {
  position: fixed;
  bottom: 10px;
  left: calc(var(--sidebar-w) + 10px);
  width: calc(100vw - var(--sidebar-w) - 20px);
  max-width: calc(100vw - var(--sidebar-w) - 20px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: left var(--duration) var(--ease);
}

body.sidebar-collapsed .timeline-bar {
  left: 10px;
  width: calc(100vw - 20px);
  max-width: calc(100vw - 20px);
}

.timeline-value {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 60px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Single-track dual-thumb container */
.timeline-track-wrap {
  position: relative;
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
}

/* Both range inputs sit on the same track */
.timeline-range {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: transparent;
  outline: none;
  pointer-events: none;
  z-index: 2;
  margin: 0;
}

/* The 'from' slider renders the base track */
.timeline-range--from {
  z-index: 2;
  background: var(--border);
  border-radius: var(--radius-pill);
}

/* The 'to' slider is fully transparent (stacked on top) */
.timeline-range--to {
  z-index: 3;
  background: transparent;
}

/* Coloured fill between the two thumbs */
.timeline-track-fill {
  position: absolute;
  height: 6px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent-warm), #78350f);
  pointer-events: none;
  z-index: 1;
  transition: left 60ms, right 60ms;
}

/* Thumb styling — both visible and draggable */
.timeline-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-warm);
  border: 3px solid var(--surface-solid);
  box-shadow: var(--shadow-md), 0 0 0 2px var(--accent-warm-soft);
  cursor: grab;
  pointer-events: auto;
  transition: transform 160ms var(--ease-spring), box-shadow 160ms var(--ease);
  position: relative;
  z-index: 5;
}

.timeline-range--to::-webkit-slider-thumb {
  background: #78350f;
  box-shadow: var(--shadow-md), 0 0 0 2px rgba(120, 53, 15, 0.2);
}

.timeline-range::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--accent-glow);
}

.timeline-range::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

.timeline-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-warm);
  border: 3px solid var(--surface-solid);
  box-shadow: var(--shadow-md);
  cursor: grab;
  pointer-events: auto;
}

.timeline-range--to::-moz-range-thumb {
  background: #78350f;
}

/* ═══════════ MAPLIBRE OVERRIDES ═══════════ */
.maplibregl-popup {
  max-width: 260px;
}

.maplibregl-popup-content {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  border: 1px solid var(--border-strong);
}

.maplibregl-popup-content strong {
  display: block;
  margin-bottom: 2px;
  font-weight: 700;
}

.maplibregl-ctrl-group {
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
  box-shadow: var(--shadow-md) !important;
  border: 1px solid var(--border-strong) !important;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
}

.maplibregl-ctrl-attrib {
  background: var(--surface) !important;
  backdrop-filter: blur(12px) !important;
  border-radius: var(--radius-xs) !important;
  padding: 4px 8px !important;
  font-size: 0.65rem !important;
}

.maplibregl-ctrl-bottom-right {
  bottom: 64px !important;
}

.maplibregl-ctrl-bottom-left {
  bottom: 64px !important;
  left: 8px !important;
}

/* ═══════════ RESPONSIVE ═══════════ */

@media (max-width: 1024px) {
  :root {
    --sidebar-w: 340px;
  }
}

@media (min-width: 769px) {
  .map-controls-tr {
    max-width: calc(100vw - var(--sidebar-w) - 20px);
  }

  body.sidebar-collapsed .map-controls-tr {
    max-width: calc(100vw - 20px);
  }

  .legend-panel {
    width: min(220px, calc(100vw - var(--sidebar-w) - 32px));
    max-width: calc(100vw - var(--sidebar-w) - 32px);
  }

  body.sidebar-collapsed .legend-panel {
    width: min(220px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
  }
}

@media (max-height: 860px) and (min-width: 769px) {
  .map-controls-tr {
    top: 12px;
    right: 12px;
    gap: 6px;
  }

  .lang-btn,
  .segmented-btn {
    padding: 7px 12px;
    font-size: 0.74rem;
  }

  .legend-panel {
    bottom: 74px;
    left: calc(var(--sidebar-w) + 12px);
    width: min(220px, calc(100vw - var(--sidebar-w) - 24px));
    max-width: calc(100vw - var(--sidebar-w) - 24px);
    padding: 10px 14px;
  }

  body.sidebar-collapsed .legend-panel {
    left: 12px;
    width: min(220px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }

  .timeline-bar {
    bottom: 12px;
    left: calc(var(--sidebar-w) + 12px);
    width: calc(100vw - var(--sidebar-w) - 24px);
    max-width: calc(100vw - var(--sidebar-w) - 24px);
    gap: 10px;
    padding: 10px 18px;
  }

  body.sidebar-collapsed .timeline-bar {
    left: 12px;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }

  .maplibregl-ctrl-bottom-right {
    bottom: 78px !important;
  }

  .maplibregl-ctrl-bottom-left {
    bottom: 78px !important;
    left: 8px !important;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: min(340px, 85vw);
  }

  #map {
    left: 0;
    bottom: 0;
  }

  /* Left slide-out drawer instead of bottom sheet */
  .sidebar {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: var(--sidebar-w);
    height: 100%;
    max-height: none;
    border-right: 1px solid var(--border);
    border-top: none;
    border-radius: 0;
    transform: translateX(0);
    z-index: 200;
  }

  body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

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

  .sidebar-inner {
    padding: 16px 16px 20px;
    scroll-padding-bottom: 72px;
  }

  .sidebar-brand {
    position: sticky;
    top: -16px;
    z-index: 5;
    margin: -16px -16px 14px;
    padding: 16px 16px 12px;
    background:
      linear-gradient(180deg, rgba(250, 249, 246, 0.97) 0%, rgba(250, 249, 246, 0.92) 72%, rgba(250, 249, 246, 0.8) 100%);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
  }

  .sidebar-toggle svg {
    transform: none;
  }

  body.sidebar-collapsed .sidebar-toggle svg {
    transform: none;
  }

  .sidebar-expand {
    display: none;
    top: 12px;
    left: 12px;
    z-index: 200;
  }

  body.sidebar-collapsed .sidebar-expand {
    display: flex !important;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .brand-sub {
    max-width: none;
    font-size: 0.74rem;
    line-height: 1.35;
  }

  .sidebar-section {
    margin-bottom: 16px;
  }

  .sidebar-divider {
    margin: 2px 0 16px;
  }

  .section-head {
    margin-bottom: 8px;
  }

  .section-head h2 {
    font-size: 0.76rem;
  }

  .stat-card,
  .detail-grid > div {
    padding: 10px;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .filter-group {
    margin-bottom: 8px;
  }

  .select-trigger,
  .select-option,
  input[type="search"] {
    font-size: 0.84rem;
  }

  .selection-header {
    margin-bottom: 10px;
  }

  .selection-header h3 {
    font-size: 1.16rem;
  }

  .chart-shell {
    min-height: 144px;
    padding: 6px;
  }

  #trend-chart {
    height: 132px !important;
  }

  .method-summary,
  .methodology-list,
  .text-muted {
    font-size: 0.78rem;
  }

  .sidebar-footer {
    padding-top: 12px;
  }

  .legend-panel {
    left: 12px;
    bottom: 78px;
    width: min(180px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    min-width: 0;
    padding: 10px 12px;
  }

  .timeline-bar {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    bottom: 12px;
    align-items: center;
    column-gap: 8px;
    row-gap: 4px;
    padding: 10px 12px;
  }

  .timeline-play-btn {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
  }

  .timeline-value {
    min-width: 0;
    font-size: 0.68rem;
  }

  #timeline-from-label {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    text-align: left;
  }

  #timeline-to-label {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    text-align: right;
  }

  .timeline-track-wrap {
    grid-column: 2 / 4;
    grid-row: 1;
    height: 24px;
  }

  .timeline-range::-webkit-slider-thumb,
  .timeline-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
  }

  .legend-note {
    display: none;
  }

  .map-controls-tr {
    top: 12px;
    left: 12px;
    right: 12px;
    gap: 6px;
    justify-content: flex-end;
    align-items: stretch;
  }

  .language-toggle,
  .basemap-toggle {
    box-shadow: var(--shadow-sm);
  }

  .lang-btn {
    min-width: 42px;
    padding: 7px 10px;
    font-size: 0.72rem;
  }

  .segmented-btn {
    padding: 7px 12px;
    font-size: 0.72rem;
  }

  .maplibregl-ctrl-bottom-right,
  .maplibregl-ctrl-bottom-left {
    bottom: 68px !important;
  }

  .maplibregl-ctrl-attrib {
    max-width: min(62vw, 220px);
    font-size: 0.62rem !important;
  }
}

@media (max-width: 480px) {
  .brand-row {
    gap: 10px;
  }

  .stat-grid {
    gap: 8px;
  }

  .detail-grid {
    gap: 8px;
  }

  .timeline-bar {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    column-gap: 6px;
    row-gap: 3px;
    padding: 9px 10px;
  }

  .timeline-value {
    font-size: 0.64rem;
  }

  .selection-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .map-controls-tr {
    justify-content: flex-end;
  }
}

@media (max-width: 360px) {
  .stat-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════ PLAY BUTTON ═══════════ */

.timeline-play-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--accent);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 180ms var(--ease);
}

.timeline-play-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
}

.timeline-play-btn.is-playing {
  background: var(--accent);
  color: var(--ink-inverse);
  border-color: var(--accent);
}

.timeline-play-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ═══════════ TITLE HIGHLIGHT ═══════════ */

.brand-highlight {
  color: var(--accent-warm);
}

/* ═══════════ ANIMATIONS ═══════════ */

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

.sidebar-section {
  animation: fadeSlideIn 400ms var(--ease) both;
}

.sidebar-section:nth-child(1) { animation-delay: 0ms; }
.sidebar-section:nth-child(2) { animation-delay: 50ms; }
.sidebar-section:nth-child(3) { animation-delay: 100ms; }
.sidebar-section:nth-child(4) { animation-delay: 150ms; }
.sidebar-section:nth-child(5) { animation-delay: 200ms; }
.sidebar-section:nth-child(6) { animation-delay: 250ms; }
.sidebar-section:nth-child(7) { animation-delay: 300ms; }

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
