/* ========================================================================== */
/* MAP.CSS - Map controls, overlays, popups, and UI components               */
/* Extracted from templates/index.html                                        */
/* ========================================================================== */

/* ========== Global Reset ========== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background: #020814;
  color: #e6f3ff;
}

:root {
  --map-bg: #020814;
  --map-panel: rgba(7, 20, 31, 0.84);
  --map-panel-strong: rgba(8, 24, 38, 0.94);
  --map-panel-soft: rgba(8, 22, 34, 0.7);
  --map-text: #e6f3ff;
  --map-muted: #89a7bb;
  --map-cyan: #7be7ff;
  --map-cyan-strong: #37cfff;
  --map-amber: #ffb24d;
  --map-amber-strong: #ff7b1a;
  --map-red: #ff6464;
  --map-line: rgba(123, 231, 255, 0.2);
  --map-line-strong: rgba(123, 231, 255, 0.42);
  --map-shadow: 0 20px 55px rgba(0, 0, 0, 0.46);
  --map-glow-cyan: 0 0 0 1px rgba(123, 231, 255, 0.18), 0 0 18px rgba(55, 207, 255, 0.18);
  --map-glow-amber: 0 0 0 1px rgba(255, 178, 77, 0.16), 0 0 18px rgba(255, 123, 26, 0.16);
  --focus-x: 50%;
  --focus-y: 50%;
}

/* ========== Map Container ========== */

#mapContainer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 123, 26, 0.12), transparent 18%),
    radial-gradient(circle at 82% 18%, rgba(55, 207, 255, 0.12), transparent 20%),
    radial-gradient(circle at var(--focus-x) var(--focus-y), rgba(88, 74, 142, 0.14), transparent 22%),
    radial-gradient(circle at var(--focus-x) var(--focus-y), rgba(19, 69, 106, 0.18), transparent 42%),
    linear-gradient(180deg, #06101b 0%, #020814 100%);
  transition: background-position 220ms ease;
}

#mapContainer::before,
#mapContainer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

#mapContainer::before {
  background:
    linear-gradient(90deg, transparent 0, rgba(123, 231, 255, 0.2) 42%, rgba(123, 231, 255, 0.2) 58%, transparent 100%),
    linear-gradient(180deg, transparent 0, rgba(123, 231, 255, 0.2) 42%, rgba(123, 231, 255, 0.2) 58%, transparent 100%),
    radial-gradient(circle at 50% 50%, transparent 0 24%, rgba(123, 231, 255, 0.18) 24.2%, transparent 24.7%),
    radial-gradient(circle at 50% 50%, transparent 0 18%, rgba(123, 231, 255, 0.13) 18.2%, transparent 18.7%),
    radial-gradient(circle at 14% 18%, rgba(123, 231, 255, 0.11) 0, transparent 11%),
    radial-gradient(circle at 86% 16%, rgba(255, 178, 77, 0.09) 0, transparent 10%),
    radial-gradient(circle at 88% 82%, rgba(123, 231, 255, 0.08) 0, transparent 12%),
    radial-gradient(circle at 12% 84%, rgba(255, 178, 77, 0.07) 0, transparent 10%);
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat;
  background-position: center center, center center, center center, center center, 14% 18%, 86% 16%, 88% 82%, 12% 84%;
  background-size: 28px 2px, 2px 28px, auto, auto, auto, auto, auto, auto;
  opacity: 0.4;
  mix-blend-mode: screen;
}

#mapContainer::after {
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, transparent 0, rgba(123, 231, 255, 0.035) 50%, transparent 100%);
  background-size: 100% 42px, 42px 100%, 100% 100%;
  opacity: 0.34;
}

#map {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at var(--focus-x) var(--focus-y), #0a1b2b 0%, #040b14 58%, #020814 100%);
}

/* ========== HUD Elements (structural only; visuals in HUD Theme Overrides below) ========== */

#breadcrumb {
  position: absolute;
  z-index: 1000;
  font-size: 14px;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#breadcrumb span { cursor: pointer; }
#breadcrumb span:hover { text-decoration: underline; }
#breadcrumb span.current { cursor: default; }
#breadcrumb span.current:hover { text-decoration: none; }

#zoomLevel {
  position: absolute;
  z-index: 1000;
}

#globeToggle {
  position: absolute;
  z-index: 1000;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#globeToggle label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

#levelButtons {
  position: absolute;
  z-index: 1000;
  display: flex;
}

#levelButtons button,
#levelLockBtn {
  cursor: pointer;
  transition: all 0.2s;
}

#levelLockBtn { margin-left: 4px; }

#levelLockBtn.locked {
  background: rgba(200, 50, 50, 0.8);
  color: white;
  border-color: #ff4444;
}

/* ========== Overlay Selector ========== */

#overlaySelector {
  position: absolute;
  top: 80px;
  right: 10px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 6px;
  min-width: 140px;
  font-size: 12px;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  color: #ddd;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.overlay-header:hover {
  background: rgba(255,255,255,0.05);
}

.overlay-title {
  font-weight: 500;
}

.overlay-toggle {
  color: #888;
  font-family: monospace;
}

.overlay-list {
  padding: 6px 0;
}

.overlay-item {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  color: #bbb;
  gap: 8px;
}

.overlay-item:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.overlay-item input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.overlay-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  color: #888;
}

.overlay-item input:checked + .overlay-icon {
  background: #0f4c75;
  color: #fff;
}

.overlay-label {
  flex: 1;
}

.overlay-label.placeholder {
  color: #666;
  font-style: italic;
}

/* Category styles */
.overlay-category {
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.overlay-category:last-child {
  border-bottom: none;
}

.overlay-category-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  color: #ccc;
  gap: 8px;
  font-weight: 500;
}

.overlay-category-header:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.overlay-category-header input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.overlay-category-header .overlay-icon {
  background: rgba(255,255,255,0.15);
  color: #aaa;
}

.overlay-category-header input:checked + .overlay-icon {
  background: #0f4c75;
  color: #fff;
}

.category-toggle {
  margin-left: auto;
  color: #666;
  font-family: monospace;
  font-size: 14px;
}

.overlay-sub-list {
  background: rgba(0,0,0,0.2);
}

.overlay-sub-item {
  padding-left: 32px;
  font-size: 11px;
}

.overlay-sub-item .overlay-icon {
  width: 16px;
  height: 16px;
  font-size: 9px;
}

.overlay-sub-item input[type="checkbox"]:disabled + .overlay-icon {
  background: rgba(255,255,255,0.05);
  color: #555;
}

/* ========== Stats Overlay ========== */

#statsOverlay {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(26,26,46,0.9);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: #d0d0d0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* ========== Time Slider ========== */

#timeSliderContainer {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(26,26,46,0.95);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  display: none;
  min-width: 300px;
  max-width: 500px;
}

#timeSliderContainer.visible {
  display: block;
}

.time-slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.time-slider-title {
  font-size: 12px;
  font-weight: 600;
  color: #d0d0d0;
}

.time-slider-year {
  font-size: 18px;
  font-weight: 700;
  color: #5dade2;
  min-width: 50px;
  text-align: center;
}

/* Live mode indicator */
.live-badge {
  display: none;
  background: #e74c3c;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 8px;
  animation: live-pulse 2s infinite;
}

.live-badge.active {
  display: inline-block;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* When in live mode, year label shows clock */
.time-slider-year.live-mode {
  color: #e74c3c;
}

.time-slider-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Slider track container - holds slider and trim handles */
.slider-track-container {
  flex: 1;
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
}

#timeSlider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #3d3d5c;
  border-radius: 3px;
  outline: none;
  position: relative;
  z-index: 6;
}

#timeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  background: #0f4c75;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  position: relative;
  z-index: 5;
}

#timeSlider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  background: #0f4c75;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  position: relative;
  z-index: 5;
}

/* Trim handles - vertical bars for cropping time range */
.trim-handle {
  position: absolute;
  width: 8px;
  height: 20px;
  background: #ff9800;
  border-radius: 2px;
  cursor: ew-resize;
  z-index: 4;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  transition: background 0.15s;
}

.trim-handle:hover {
  background: #ffb74d;
}

.trim-handle:active {
  background: #f57c00;
}

.trim-handle-label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 600;
  color: #ff9800;
  white-space: nowrap;
  pointer-events: none;
}

#lowerTrimHandle {
  left: 0;
}

#upperTrimHandle {
  right: 0;
}

/* Trim overlay - dims the excluded areas */
.trim-overlay {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 1;
  border-radius: 3px;
}

#trimOverlayLeft {
  left: 0;
  width: 0;
  border-radius: 3px 0 0 3px;
}

#trimOverlayRight {
  right: 0;
  width: 0;
  border-radius: 0 3px 3px 0;
}

.time-slider-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

/* Time slider buttons */
.time-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: #2d2d44;
  color: #d0d0d0;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  flex-shrink: 0;
}

.time-btn:hover {
  background: #3d3d5c;
}

.time-btn.play {
  width: 32px;
  height: 32px;
  background: #0f4c75;
  border-radius: 50%;
  font-size: 12px;
}

.time-btn.play:hover {
  background: #1a6a9e;
}

.time-btn.active {
  background: #ff6600;
  color: white;
}

/* Time slider tabs (multi-scale) */
.time-slider-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #3d3d5c;
}

.time-slider-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #2d2d44;
  border: 1px solid #3d3d5c;
  border-radius: 4px;
  color: #a0a0a0;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}

.time-slider-tab:hover {
  background: #3d3d5c;
  color: #d0d0d0;
}

.time-slider-tab.active {
  background: #0f4c75;
  border-color: #1a6a9e;
  color: #ffffff;
}

.time-slider-tab .tab-label {
  font-weight: 500;
}

.time-slider-tab .tab-granularity {
  font-size: 9px;
  padding: 1px 4px;
  background: rgba(0,0,0,0.3);
  border-radius: 2px;
  color: #888;
}

.time-slider-tab.active .tab-granularity {
  background: rgba(255,255,255,0.15);
  color: #b0d0e8;
}

.time-slider-tab .tab-close {
  margin-left: 4px;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  font-size: 10px;
  color: #666;
}

/* Metric tabs (above time slider) - scrollable row */
.metric-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #3d3d5c;
  overflow-x: hidden;
  position: relative;
  align-items: center;
}

.metric-tabs-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  scroll-behavior: smooth;
}

.metric-tabs-scroll::-webkit-scrollbar {
  display: none;
}

.metric-tabs-arrow {
  background: #2d2d44;
  border: 1px solid #3d3d5c;
  color: #a0a0a0;
  font-size: 14px;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 3px;
  flex-shrink: 0;
}

.metric-tabs-arrow:hover {
  background: #3d3d5c;
  color: #d0d0d0;
}

.metric-tabs-arrow.hidden {
  visibility: hidden;
}

.metric-tab {
  padding: 5px 12px;
  background: #2d2d44;
  border: 1px solid #3d3d5c;
  border-radius: 4px;
  color: #a0a0a0;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.metric-tab:hover {
  background: #3d3d5c;
  color: #d0d0d0;
}

.metric-tab.active {
  background: #0f4c75;
  border-color: #1a6a9e;
  color: #ffffff;
}

.time-slider-tab .tab-close:hover {
  background: rgba(255,100,100,0.3);
  color: #ff6666;
}

/* Speed Control - Unified Speed Slider */
.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #3d3d5c;
}

.speed-label-left,
.speed-label-right {
  font-size: 10px;
  color: #888;
  min-width: 28px;
}

.speed-label-right {
  text-align: right;
}

.speed-step-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 3px;
  background: #2a2a4a;
  color: #aaa;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-step-btn:hover {
  background: #3a3a5a;
  color: #fff;
  border-color: #777;
}

.speed-step-btn:active {
  background: #4a4a6a;
}

#speedSlider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #2d5a87, #ff6600);
  border-radius: 2px;
  outline: none;
}

#speedSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: #5dade2;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

#speedSlider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #5dade2;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.speed-value {
  font-size: 11px;
  font-weight: 600;
  color: #5dade2;
  min-width: 70px;
  text-align: right;
}

.loop-control {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  cursor: pointer;
  font-size: 11px;
  color: #888;
}

.loop-control:hover {
  color: #5dade2;
}

.loop-control input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #5dade2;
}

/* Reset trim button */
.bounds-clear-btn {
  padding: 2px 8px;
  font-size: 9px;
  background: #2d2d44;
  color: #888;
  border: 1px solid #3d3d5c;
  border-radius: 3px;
  cursor: pointer;
}

.bounds-clear-btn:hover {
  background: #3d3d5c;
  color: #d0d0d0;
}

/* Live button - jumps to and locks at current time */
.live-btn {
  padding: 2px 8px;
  font-size: 9px;
  font-weight: 700;
  background: #2d2d44;
  color: #888;
  border: 1px solid #3d3d5c;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 8px;
  transition: all 0.2s ease;
}

.live-btn:hover {
  background: #3d3d5c;
  color: #d0d0d0;
}

.live-btn.active {
  background: #c0392b;
  color: white;
  border-color: #e74c3c;
  box-shadow: 0 0 8px rgba(231, 76, 60, 0.5);
}

.live-btn.active:hover {
  background: #e74c3c;
}

/* Dot indicator for live button */
.live-btn::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #666;
  margin-right: 4px;
  vertical-align: middle;
}

.live-btn.active::before {
  background: white;
  animation: live-dot-pulse 1.5s infinite;
}

@keyframes live-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ========== Choropleth Legend (nested inside timeSliderContainer) ========== */

#choroplethLegend {
  display: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 6px -20px -12px;
  padding: 8px 20px 10px;
}

#choroplethLegend.visible {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.legend-title {
  font-size: 10px;
  font-weight: 500;
  color: #aaa;
  margin-bottom: 4px;
  text-align: center;
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-gradient {
  height: 10px;
  width: 100%;
  border-radius: 2px;
  margin-bottom: 2px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 10px;
  color: #888;
}

/* ========== MapLibre Popup Styling ========== */

.maplibregl-popup-content {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
}

.maplibregl-popup-content strong {
  font-size: 14px;
  display: block;
  margin-bottom: 5px;
  color: #333;
}

.maplibregl-popup-close-button {
  font-size: 16px;
  padding: 4px 6px;
}

/* ========== Selection Mode (Disambiguation) ========== */

#map.selection-mode {
  cursor: crosshair;
}

.selection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.selection-overlay.visible {
  opacity: 1;
}

.selection-overlay-content {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 26, 46, 0.95);
  border: 1px solid #ff8800;
  border-radius: 8px;
  padding: 16px 24px;
  color: white;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  max-width: 400px;
}

.selection-overlay-title {
  font-size: 18px;
  font-weight: 600;
  color: #ffaa00;
  margin-bottom: 8px;
}

.selection-overlay-subtitle {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 12px;
}

.selection-options-list {
  text-align: left;
  margin-bottom: 12px;
}

.selection-option-label {
  font-size: 13px;
  color: #ddd;
  padding: 4px 0;
}

.selection-overlay-hint {
  font-size: 12px;
  color: #888;
  font-style: italic;
}

/* Selection mode numbered markers */
.selection-marker {
  width: 32px;
  height: 32px;
  background: #ff8800;
  border: 3px solid #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  transition: transform 0.15s ease, background 0.15s ease;
}

.selection-marker:hover {
  transform: scale(1.15);
  background: #ffaa00;
}

.selection-marker-number {
  color: white;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ========== Disaster Popup Styles ========== */

.disaster-popup {
  min-width: 280px;
  max-width: 340px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.popup-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #e0e0e0;
  padding-left: 8px;
}

.popup-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.popup-title-group {
  flex: 1;
  min-width: 0;
}

.popup-title {
  font-size: 15px;
  font-weight: 600;
  color: #222;
  line-height: 1.3;
}

.popup-subtitle {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.popup-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  flex: 1;
  background: #f5f5f5;
  border-radius: 6px;
  padding: 8px;
  text-align: center;
  min-width: 0;
}

.stat-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-detail {
  font-size: 10px;
  color: #666;
  margin-top: 2px;
}

.popup-actions {
  display: flex;
  gap: 6px;
}

.popup-btn {
  flex: 1;
  padding: 8px 10px;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.popup-btn.btn-details {
  background: #0f4c75;
  color: white;
}

.popup-btn.btn-details:hover {
  background: #1a6a9e;
}

.popup-btn.btn-sequence {
  background: #4caf50;
  color: white;
}

.popup-btn.btn-sequence:hover {
  background: #388e3c;
}

.popup-btn.btn-related {
  background: #ff9800;
  color: white;
}

.popup-btn.btn-related:hover {
  background: #f57c00;
}

.popup-btn.disabled {
  background: #e0e0e0;
  color: #999;
  cursor: not-allowed;
}

.popup-btn.disabled:hover {
  background: #e0e0e0;
}

/* ========== Detail View Styles ========== */

.popup-header-detail {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #e0e0e0;
  padding-left: 8px;
}

.popup-back {
  background: none;
  border: none;
  color: #0f4c75;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: -8px;
}

.popup-back:hover {
  text-decoration: underline;
}

.popup-title-detail {
  font-size: 14px;
  font-weight: 600;
  color: #222;
}

.popup-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.tab-btn {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #ddd;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  color: #666;
}

.tab-btn.active {
  background: #0f4c75;
  border-color: #0f4c75;
  color: white;
}

.tab-btn:hover:not(.active) {
  background: #e8e8e8;
}

.tab-content {
  display: none;
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.tab-content.active {
  display: block;
}

/* Demographic popup tabs (data mode) */
.popup-tab {
  padding: 3px 8px;
  font-size: 10px;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.popup-tab.active {
  color: #5dade2;
  border-bottom-color: #5dade2;
}

.popup-tab:hover:not(.active) {
  color: #bbb;
}

.popup-tab-content {
  display: none;
  font-size: 12px;
  line-height: 1.6;
}

.popup-tab-content.active {
  display: block;
}

/* Chat action buttons (metric warning yes/no) */
.metric-warning-buttons {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.chat-action-btn {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border: none;
}

.chat-action-btn.confirm {
  background: #0f4c75;
  color: #fff;
}

.chat-action-btn.confirm:hover {
  background: #1a6a9e;
}

.chat-action-btn.cancel {
  background: #3d3d5c;
  color: #ccc;
}

.chat-action-btn.cancel:hover {
  background: #4d4d6c;
}

.detail-row {
  padding: 4px 0;
  font-size: 12px;
  color: #333;
  border-bottom: 1px solid #f0f0f0;
}

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

.detail-separator {
  height: 1px;
  background: #ddd;
  margin: 8px 0;
}

.impact-deaths {
  color: #c62828;
  font-weight: 500;
}

.detail-label {
  font-weight: 500;
  color: #666;
}

.detail-empty {
  font-size: 12px;
  color: #999;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

.source-link {
  color: #1976d2;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
  color: #0d47a1;
}

/* ========== Disaster Hover Styles ========== */

.disaster-hover {
  background: #fff;
  padding: 8px 10px;
  border-radius: 4px;
  min-width: 160px;
  max-width: 240px;
}

.hover-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.hover-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: white;
  flex-shrink: 0;
}

.hover-title {
  font-weight: 600;
  font-size: 13px;
  color: #333;
  line-height: 1.2;
}

.hover-date {
  font-size: 11px;
  color: #666;
  margin-bottom: 2px;
}

.hover-intensity {
  font-size: 12px;
  color: #444;
  font-weight: 500;
}

.hover-detail {
  font-weight: 400;
  color: #888;
  font-size: 11px;
}

.hover-hint {
  font-size: 10px;
  color: #0f4c75;
  margin-top: 6px;
  font-style: italic;
}

/* ========== Sequence View Styles ========== */

.sequence-summary {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.sequence-summary strong {
  font-size: 13px;
  color: #333;
}

.seq-count {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
}

.sequence-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.sequence-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.sequence-item:hover {
  background: #f5f5f5;
}

.seq-marker {
  width: 16px;
  font-size: 14px;
  font-weight: 700;
  color: #0f4c75;
}

.seq-label {
  flex: 1;
  font-size: 12px;
  color: #333;
}

.seq-sublabel {
  font-size: 10px;
  color: #888;
}

.sequence-more {
  font-size: 11px;
  color: #666;
  font-style: italic;
  text-align: center;
  padding: 8px;
}

.sequence-loading {
  font-size: 12px;
  color: #666;
  text-align: center;
  padding: 20px;
}

/* ========== Related View Styles ========== */

.related-primary {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f5f5f5;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.related-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.related-info {
  flex: 1;
  min-width: 0;
}

.related-title {
  font-size: 13px;
  font-weight: 600;
  color: #333;
}

.related-subtitle,
.related-link-type {
  font-size: 11px;
  color: #666;
}

.related-chain-label {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.related-list {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.related-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
}

.related-item:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

.related-empty {
  font-size: 12px;
  color: #999;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

.popup-footer {
  font-size: 11px;
  color: #888;
  text-align: center;
  padding-top: 8px;
  border-top: 1px solid #e0e0e0;
}

/* ========== Geometry Popup Styles ========== */

.geometry-popup {
  background: #fff;
  padding: 12px;
  border-radius: 6px;
  min-width: 200px;
  max-width: 280px;
}

.geometry-popup-header {
  margin-bottom: 10px;
}

.geometry-popup-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 2px;
}

.geometry-popup-type {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
}

.geometry-popup-body {
  border-top: 1px solid #e0e0e0;
  padding-top: 8px;
}

.geometry-popup-row {
  font-size: 12px;
  color: #444;
  padding: 3px 0;
}

.geometry-label {
  font-weight: 500;
  color: #666;
}

/* Geometry Hover Styles */

.geometry-hover {
  background: #fff;
  padding: 8px 10px;
  border-radius: 4px;
  min-width: 140px;
  max-width: 220px;
}

.geometry-hover-title {
  font-weight: 600;
  font-size: 13px;
  color: #333;
  margin-bottom: 2px;
}

.geometry-hover-code {
  font-size: 12px;
  color: #444;
  font-weight: 500;
}

.geometry-hover-type {
  font-size: 11px;
  color: #666;
  margin-top: 2px;
}

.geometry-hover-hint {
  font-size: 10px;
  color: #0f4c75;
  margin-top: 6px;
  font-style: italic;
}

/* ==========================================================================
   HUD Theme Overrides
   Spatial field styling for the map app. This intentionally differs from
   the .com site: same palette family, more blue/cyan, less amber, more map.
   ========================================================================== */

#breadcrumb,
#zoomLevel,
#globeToggle,
#overlaySelector,
#statsOverlay,
#timeSliderContainer,
#choroplethLegend,
.selection-overlay-content {
  background: linear-gradient(180deg, rgba(8, 24, 38, 0.92), rgba(4, 12, 20, 0.88));
  border: 1px solid var(--map-line);
  box-shadow: var(--map-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  color: var(--map-text);
  backdrop-filter: blur(10px);
}

#breadcrumb,
#zoomLevel,
#globeToggle,
#statsOverlay {
  border-radius: 14px;
}

#breadcrumb {
  top: 14px;
  right: 257px;
  padding: 8px 12px;
  color: var(--map-muted);
  font-size: 13px;
  max-width: 900px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: right;
}

#breadcrumb span {
  direction: ltr;
  unicode-bidi: embed;
}

#breadcrumb span.current {
  color: var(--map-amber);
}

#zoomLevel {
  top: 14px;
  right: 14px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: monospace;
  color: var(--map-cyan);
  letter-spacing: 0.08em;
}

#globeToggle {
  top: 14px;
  right: 127px;
  padding: 8px 12px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--map-muted);
  border-radius: 14px;
}

#globeToggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border: 1px solid rgba(127, 231, 255, 0.35);
  border-radius: 3px;
  background: rgba(7, 20, 31, 0.9);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

#globeToggle input[type="checkbox"]:checked {
  background: rgba(127, 231, 255, 0.18);
  border-color: rgba(127, 231, 255, 0.6);
}

#globeToggle input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 4px;
  height: 8px;
  border: 1.5px solid #7fe7ff;
  border-left: none;
  border-top: none;
  transform: rotate(45deg);
}

#levelButtons {
  top: 54px;
  right: 14px;
  gap: 6px;
  display: flex;
}

#levelButtons button,
#levelLockBtn,
.time-btn,
.time-slider-tab,
.metric-tab,
.metric-tabs-arrow,
.speed-step-btn,
.bounds-clear-btn,
.live-btn,
.tab-btn {
  background: linear-gradient(180deg, rgba(9, 22, 35, 0.96), rgba(5, 12, 20, 0.92));
  border: 1px solid rgba(123, 231, 255, 0.18);
  color: var(--map-muted);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

#levelButtons button,
#levelLockBtn {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#levelButtons button:hover,
#levelLockBtn:hover,
.time-btn:hover,
.time-slider-tab:hover,
.metric-tab:hover,
.metric-tabs-arrow:hover,
.speed-step-btn:hover,
.bounds-clear-btn:hover,
.live-btn:hover,
.tab-btn:hover:not(.active) {
  color: var(--map-text);
  border-color: var(--map-line-strong);
  box-shadow: var(--map-glow-cyan);
}

#levelButtons button.active,
.time-btn.active,
.time-btn.play,
.time-slider-tab.active,
.metric-tab.active,
.tab-btn.active {
  background: linear-gradient(180deg, rgba(17, 64, 84, 0.96), rgba(7, 30, 43, 0.92));
  border-color: rgba(123, 231, 255, 0.4);
  color: var(--map-text);
  box-shadow: var(--map-glow-cyan);
}

#levelLockBtn.locked,
.live-btn.active {
  background: linear-gradient(180deg, rgba(90, 31, 20, 0.96), rgba(44, 15, 14, 0.92));
  border-color: rgba(255, 100, 100, 0.45);
  color: #fff0f0;
  box-shadow: 0 0 0 1px rgba(255, 100, 100, 0.16), 0 0 18px rgba(255, 100, 100, 0.16);
}

#overlaySelector {
  top: 92px;
  right: 14px;
  min-width: 176px;
  border-radius: 18px;
  overflow: hidden;
}

.overlay-header,
.overlay-category-header,
.overlay-item {
  color: var(--map-muted);
}

.overlay-header,
.overlay-category-header {
  border-bottom-color: rgba(255, 255, 255, 0.05);
}

.overlay-header:hover,
.overlay-category-header:hover,
.overlay-item:hover {
  background: rgba(123, 231, 255, 0.06);
  color: var(--map-text);
}

.overlay-icon,
.overlay-category-header .overlay-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(123, 231, 255, 0.08);
  color: #8aa1b4;
}

.overlay-item input:checked + .overlay-icon,
.overlay-category-header input:checked + .overlay-icon {
  background: linear-gradient(180deg, rgba(17, 64, 84, 0.96), rgba(8, 30, 43, 0.92));
  color: #fff;
  border-color: rgba(123, 231, 255, 0.42);
  box-shadow: var(--map-glow-cyan);
}

.overlay-sub-list {
  background: rgba(0, 0, 0, 0.14);
}

#statsOverlay {
  bottom: 14px;
  right: 14px;
  color: var(--map-cyan);
  letter-spacing: 0.08em;
}

#timeSliderContainer {
  bottom: 54px;
  border-radius: 20px;
  min-width: 360px;
}

.time-slider-title,
.legend-title,
.time-slider-labels,
.speed-label-left,
.speed-label-right,
.loop-control,
.popup-subtitle,
.stat-label,
.stat-detail,
.related-subtitle,
.related-link-type,
.seq-sublabel,
.hover-detail,
.geometry-hover-type,
.geometry-popup-type,
.popup-footer {
  color: var(--map-muted);
}

.time-slider-year,
.speed-value {
  color: var(--map-cyan);
}

.live-badge {
  background: linear-gradient(90deg, #a6322b, #ff6a4d);
  box-shadow: 0 0 16px rgba(255, 100, 100, 0.24);
}

#timeSlider {
  background: linear-gradient(90deg, rgba(34, 67, 91, 0.9), rgba(52, 145, 182, 0.9));
}

#timeSlider::-webkit-slider-thumb,
#timeSlider::-moz-range-thumb,
#speedSlider::-webkit-slider-thumb,
#speedSlider::-moz-range-thumb {
  background: radial-gradient(circle at 30% 30%, #c8f8ff, var(--map-cyan-strong));
  box-shadow: 0 0 0 2px rgba(7, 20, 31, 0.9), 0 0 14px rgba(55, 207, 255, 0.28);
}

.trim-handle,
.popup-btn.btn-related,
.selection-marker {
  background: linear-gradient(180deg, var(--map-amber), var(--map-amber-strong));
  box-shadow: var(--map-glow-amber);
}

.trim-handle-label,
.selection-overlay-title {
  color: var(--map-amber);
}

#speedSlider {
  background: linear-gradient(90deg, #264f69, var(--map-cyan-strong), var(--map-amber-strong));
}

#choroplethLegend {
  bottom: 8px;
  min-width: 280px;
  border-radius: 16px;
}

.maplibregl-popup-content,
.disaster-popup,
.geometry-popup,
.geometry-hover {
  background: linear-gradient(180deg, rgba(10, 24, 37, 0.98), rgba(6, 14, 22, 0.96));
  color: var(--map-text);
  border: 1px solid rgba(123, 231, 255, 0.18);
  border-radius: 16px;
  box-shadow: var(--map-shadow);
}

.maplibregl-popup-tip {
  border-top-color: rgba(6, 14, 22, 0.96) !important;
  border-bottom-color: rgba(6, 14, 22, 0.96) !important;
}

.maplibregl-popup-content strong,
.popup-title,
.popup-title-detail,
.related-title,
.geometry-popup-title,
.geometry-hover-title,
.seq-label,
.stat-value,
.hover-intensity,
.geometry-hover-code {
  color: var(--map-text);
}

.maplibregl-popup-close-button {
  color: var(--map-muted);
}

.popup-header,
.popup-header-detail,
.popup-footer,
.geometry-popup-body {
  border-color: rgba(123, 231, 255, 0.12);
}

.stat-card,
.sequence-summary,
.related-primary,
.related-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(123, 231, 255, 0.08);
}

.related-item:hover,
.sequence-item:hover {
  background: rgba(123, 231, 255, 0.06);
  border-color: rgba(123, 231, 255, 0.18);
}

.popup-btn {
  border: 1px solid transparent;
  border-radius: 999px;
}

.popup-btn.btn-details,
.popup-btn.btn-sequence {
  background: linear-gradient(180deg, rgba(17, 64, 84, 0.96), rgba(7, 30, 43, 0.92));
  box-shadow: var(--map-glow-cyan);
}

.popup-btn.btn-sequence {
  background: linear-gradient(180deg, rgba(25, 81, 92, 0.96), rgba(8, 43, 45, 0.92));
}

.popup-btn.btn-details:hover,
.popup-btn.btn-sequence:hover,
.popup-btn.btn-related:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.popup-btn.disabled,
.popup-btn.disabled:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #6f8493;
  border-color: rgba(255, 255, 255, 0.06);
}

.selection-overlay-content {
  border-radius: 20px;
}

.selection-marker {
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.selection-marker:hover {
  transform: scale(1.15);
  filter: brightness(1.08);
}

#map.selection-mode {
  cursor: crosshair;
  box-shadow: inset 0 0 0 1px rgba(255, 178, 77, 0.22);
}

/* ========== Feedback Bubble ========== */

.feedback-btn {
  position: fixed;
  bottom: 55px;
  right: 20px;
  z-index: 1200;
  background: rgba(255, 120, 40, 0.15);
  color: #ff8c42;
  border: 1px solid rgba(255, 120, 40, 0.5);
  border-radius: 20px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.feedback-btn:hover,
.feedback-btn.active {
  color: #ffaa66;
  border-color: rgba(255, 120, 40, 0.75);
  background: rgba(255, 120, 40, 0.25);
}

.feedback-panel {
  position: fixed;
  bottom: 105px;
  right: 20px;
  z-index: 1200;
  width: 320px;
  background: var(--map-panel-strong);
  border: 1px solid var(--map-line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--map-shadow);
  display: none;
  flex-direction: column;
  gap: 10px;
}

.feedback-panel.open {
  display: flex;
}

.feedback-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.feedback-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--map-text);
}

.feedback-close {
  background: none;
  border: none;
  color: var(--map-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.feedback-close:hover {
  color: var(--map-text);
}

.feedback-panel-copy {
  font-size: 12px;
  color: var(--map-muted);
  line-height: 1.5;
}

.feedback-textarea {
  width: 100%;
  min-height: 100px;
  max-height: 220px;
  background: rgba(7, 20, 31, 0.7);
  border: 1px solid var(--map-line);
  border-radius: 6px;
  color: var(--map-text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.feedback-textarea:focus {
  border-color: rgba(123, 231, 255, 0.4);
  box-shadow: 0 0 0 2px rgba(123, 231, 255, 0.08);
}

.feedback-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.feedback-char-count {
  font-size: 11px;
  color: var(--map-muted);
  white-space: nowrap;
}

.feedback-char-warn {
  color: var(--map-amber);
}

.feedback-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feedback-status {
  font-size: 11px;
  color: var(--map-muted);
}

.feedback-status.success {
  color: #5eead4;
}

.feedback-status.error {
  color: var(--map-red);
}

.feedback-submit {
  background: rgba(123, 231, 255, 0.12);
  border: 1px solid rgba(123, 231, 255, 0.3);
  color: var(--map-cyan);
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.feedback-submit:hover:not(:disabled) {
  background: rgba(123, 231, 255, 0.2);
  border-color: rgba(123, 231, 255, 0.5);
}

.feedback-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .feedback-panel {
    width: calc(100vw - 40px);
    right: 20px;
  }
}
