/* Re-add missing swarm definitions for radar-view legend */
.radar-view__legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.radar-view__legend-swatch--rain {
  background: linear-gradient(90deg, #4fc3f7, #0288d1);
}

.radar-view__legend-swatch--snow {
  background: linear-gradient(90deg, #e0f7fa, #b3e5fc);
}

.radar-view__legend-swatch--temp {
  background: linear-gradient(90deg, #4fc3f7, #ff7043);
}

.radar-view__legend-swatch--wind {
  background: linear-gradient(90deg, #80cbc4, #004d40);
}

.radar-view__legend-swatch--clouds {
  background: linear-gradient(90deg, #cfd8dc, #90a4ae);
}

/* Updated Layer Button Style */
.radar-view__layer-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px;
  padding: 0 !important;
  background: rgba(10, 16, 32, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.15s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.radar-view__layer-btn span:not(.material-symbols-outlined) {
  display: none !important;
}

.radar-view__layer-btn .material-symbols-outlined {
  font-size: 24px;
  color: #e0e0e0;
  margin: 0 !important;
}

.radar-view__layer-btn:hover,
.radar-view__layer-btn:active {
  background: rgba(30, 41, 59, 0.95);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

/* FIX: Map Height extends to bottom */
.radar-view {
  position: fixed !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1; /* Below UI but above basic content */
}

/* CRITICAL: Ensure radar view doesn't block when hidden */
.radar-view[hidden] {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
  z-index: -9999 !important;
}

.radar-view__map-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* Fix: Move top controls down to avoid notch/rounded corners */
.radar-view__top-controls {
  position: absolute;
  top: max(
    10px,
    env(safe-area-inset-top) + 8px
  ); /* Moves up closer to map ceiling as requested */
  left: 16px;
  right: calc(
    16px + env(safe-area-inset-right)
  ); /* Fix for button being too far right on curved edges */
  display: flex !important;
  justify-content: center !important; /* Center for cleanliness */
  align-items: flex-start !important;
  height: 0; /* height 0 so it doesn't block clicks below, children will have height */
  overflow: visible !important;
  z-index: 1000;
  pointer-events: none; /* Container passes clicks */
}

/* DEPRECATED: Layer Button (Merged into Legend) */
.radar-view__layer-btn,
#map-layer-toggle,
.map-layer-menu {
  display: none !important;
}

/* Adjusted Legend Items for Interactivity */
.radar-view__legend-item {
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
}

.radar-view__legend-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.radar-view__legend-item.active-layer {
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Ensure children are clickable */
.radar-view__top-controls > * {
  pointer-events: auto;
}

/* FIX: Timeline Controls Size & Usability - Pill Shape */
.radar-view__bottom-overlay {
  position: absolute;
  bottom: calc(
    85px + env(safe-area-inset-bottom)
  ); /* Increased base offset to clear bottom nav */
  left: 0;
  right: 0;
  padding: 0;
  z-index: 500;
  pointer-events: none;
  display: flex;
  justify-content: center;
  background: none;
}

.radar-view__timeline {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* Pill Shape */
  border-radius: 100px;
  padding: 6px 16px;
  margin-bottom: 0;

  /* Size & Positioning */
  width: auto;
  max-width: 90%;
  min-width: 280px;

  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.radar-view__timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px; /* Tighter controls */
  flex-shrink: 0;
}

.radar-view__timeline-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05); /* Subtle bg */
  border: 1px solid transparent; /* Cleaner border */
  color: #e0e0e0;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.radar-view__timeline-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.radar-view__timeline-btn--primary {
  background: #4c6fff !important;
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(76, 111, 255, 0.3);
  transform: scale(1.05);
}

.radar-view__timeline-btn .material-symbols-outlined {
  font-size: 20px;
}

.radar-view__timeline-slider-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 4px;
}

.radar-view__timeline-slider {
  width: 100%;
  height: 4px; /* Thinner line */
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.radar-view__timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; /* Daintier thumb */
  height: 12px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 2px rgba(10, 16, 32, 0.5); /* Contrast ring */
}

.radar-view__timeline-label {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  min-width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.radar-view__control-divider-vertical {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 2px;
}

/* Layer Menu Modern Styles */
.map-layer-menu {
  position: absolute;
  top: 70px;
  right: 16px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  width: 220px;
  z-index: 2000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  padding: 8px;
  overflow: hidden;
  animation: menuFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.map-layer-menu-header {
  padding: 8px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.map-layer-menu-title {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.map-layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  color: #b0b8c4;
  user-select: none;
  background: transparent;
}

.map-layer-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

/* Custom Checkbox Design */
.map-layer-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 50%; /* Circle according to new UI style */
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.05);
}

.map-layer-checkbox::after {
  content: "";
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.map-layer-item input[type="checkbox"] {
  display: none;
}

.map-layer-item input[type="checkbox"]:checked + .map-layer-checkbox {
  background: #4c6fff;
  border-color: #4c6fff;
  box-shadow: 0 2px 8px rgba(76, 111, 255, 0.4);
}

.map-layer-item input[type="checkbox"]:checked + .map-layer-checkbox::after {
  opacity: 1;
  transform: scale(1);
}

.map-layer-label {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  margin-left: 12px;
}

/* Mobile Optimization for Timeline logic */
@media (max-width: 480px) {
  .radar-view__timeline {
    width: 96% !important;
    max-width: 96% !important;
    min-width: unset !important;
    padding: 8px 10px !important;
    gap: 6px !important;
    margin-bottom: 4px;
    /* Slightly less rounded on mobile to save vertical space if needed, keeping pill for now */
  }

  .radar-view__timeline-controls {
    gap: 4px !important;
  }

  .radar-view__timeline-btn {
    width: 32px; /* Touch target still decent */
    height: 32px;
  }

  .radar-view__timeline-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* Allow shrinking */
    max-width: 80px; /* Force constraint */
    text-align: right;
    font-size: 10px;
    padding: 2px 6px;
  }

  /* Hide the vertical divider on very small screens to save space */
  .radar-view__control-divider-vertical {
    display: none;
  }
}

/* UI Consistency (Glassmorphism & Style Match) - Consolidated */
.weather-detail-popup .leaflet-popup-content-wrapper,
.map-layer-menu,
.radar-view__timeline,
.radar-view__layer-btn,
#map-layer-selector {
  /* Exact match for .bottom-nav */
  background: linear-gradient(
    135deg,
    rgba(18, 28, 45, 0.65) 0%,
    rgba(8, 15, 28, 0.75) 50%,
    rgba(18, 28, 45, 0.65) 100%
  ) !important;
  backdrop-filter: blur(12px) saturate(1.2) !important;
  -webkit-backdrop-filter: blur(12px) saturate(1.2) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.25),
    0 1px 4px rgba(0, 0, 0, 0.15) !important;
  border-radius: 24px !important;
  color: #fff !important;
}

.map-layer-menu {
  padding: 12px 0 !important;
  width: 240px !important;
}

.map-layer-item {
  margin: 0 8px;
  border-radius: 16px !important;
}

/* Ensure Tip matches the gradient background roughly or is hidden */
.weather-detail-popup .leaflet-popup-tip {
  background: rgba(
    18,
    28,
    45,
    0.75
  ); /* Approximate the dark part of gradient */
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-top: none;
  border-left: none;
  box-shadow: none;
}

/* Close Button REMOVED per user request */
.weather-detail-popup .leaflet-popup-close-button {
  display: none !important;
}

/* Directional Popups */
.weather-detail-popup.popup-below .leaflet-popup-content-wrapper {
  margin-top: 40px !important; /* Push down */
}

/* Hide tip if we are flipping */
.weather-detail-popup.popup-below .leaflet-popup-tip-container {
  display: none;
}

.weather-detail-popup.popup-left .leaflet-popup-content-wrapper {
  /* Standard Leaflet logic handles left/right well usually, but we can tweak margins */
}

.weather-detail-popup .leaflet-popup-content {
  margin: 0;
  width: 200px !important;
}

.weather-popup-content {
  padding: 12px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.popup-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #a7b6c5;
}

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

.popup-item {
  display: flex;
  flex-direction: column;
}

.popup-label {
  font-size: 10px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 2px;
}

.popup-value {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

/* Coordinates Visibility Improvement */
.popup-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  opacity: 0.9;
  font-size: 11px;
  color: #e2e8f0; /* Brighter color */
  font-weight: 500;
  letter-spacing: 0.02em;
}

.weather-popup-loading {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: #aaa;
}

/* Interactive Legend Styles */
.radar-view__legend-item {
  transition: all 0.2s ease;
  padding: 2px 6px;
  border-radius: 12px;
}

.radar-view__legend-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.radar-view__legend-item.active-layer {
  background: rgba(255, 255, 255, 0.2);
  font-weight: 700;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

/* Map Dark Mode for Better Contrast */
.radar-view .leaflet-tile-pane .leaflet-layer:first-child {
  filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

/* Ensure Weather Layers are clear */
.radar-view .leaflet-tile-pane .leaflet-layer:not(:first-child) {
  filter: none;
  opacity: 0.65 !important;
}

/* Hide Leaflet Attribution */
.leaflet-control-attribution {
  display: none !important;
}

/* Enhancing Rain Layer Visibility */
/* Balanced boost for weather tiles - Reduced intensity per user feedback */
.leaflet-layer img[src*="openweathermap.org"],
.leaflet-layer img[src*="rainviewer.com"] {
  filter: saturate(110%) brightness(1.05);
}

/* Ensure map fills entire screen including edges */
.radar-view,
.radar-view__map-wrapper {
  width: 100vw !important;
  height: 100vh !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
}

/* Fix Layer Button Position (User Feedback) */
.radar-view__layer-btn,
#map-layer-toggle {
  position: relative !important;
  top: auto !important;
  right: auto !important;
  margin: 0 !important;
  order: 2; /* Ensure it is on the right */
}

/* Adjust Menu Position since Button moved */
.map-layer-menu {
  top: calc(max(50px, env(safe-area-inset-top) + 20px) + 50px) !important;
  right: 16px !important;
}

.radar-view__legend {
  background: linear-gradient(
    135deg,
    rgba(18, 28, 45, 0.65) 0%,
    rgba(8, 15, 28, 0.75) 50%,
    rgba(18, 28, 45, 0.65) 100%
  ) !important;
  backdrop-filter: blur(12px) saturate(1.2) !important;
  -webkit-backdrop-filter: blur(12px) saturate(1.2) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.25),
    0 1px 4px rgba(0, 0, 0, 0.15) !important;
  border-radius: 24px !important;
  color: #fff !important;
  padding: 8px 18px !important;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 1001;
}
