/**
 * Map View Styles
 */

/* === Views === */
.view {
  width: 100%;
  height: 100%;
}

.view--map {
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Sidebar + map container share a flex row, below the chips bar */
.map-row {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  z-index: 0;
}

.view[hidden],
.map-loading[hidden],
.detail-panel[hidden] {
  display: none !important;
}

/* === Map Container === */
.map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* === Map Loading Overlay === */
.map-loading {
  position: absolute;
  inset: 0;
  background: rgba(247,249,252,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
}

/* On desktop, offset spinner to center in the visible (unobscured) map area */
@media (min-width: 640px) {
  .map-loading {
    left: var(--sidebar-width);
  }
}

.map-loading__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--gray-700);
  font-size: 0.875rem;
}

/* === Takeoff Animation (search spinner) === */
.takeoff-animation {
  width: 200px;
  height: 70px;
  position: relative;
}

.takeoff-plane {
  position: absolute;
  left: 15%;
  bottom: 5px;
  color: var(--horizon-teal);
  animation: takeoff 2.4s ease-in-out infinite;
}

.takeoff-plane img {
  width: 80px;
  height: 30px;
  transform: scaleX(-1);
}

/* Fade between 3 positions: low-left → mid-center → high-right.
   Uses transform instead of left/bottom so position changes are GPU-composited. */
@keyframes takeoff {
  0%   { transform: translateX(0)     translateY(0)     rotate(-2deg); opacity: 1; }
  8%   { transform: translateX(0)     translateY(0)     rotate(-2deg); opacity: 1; }
  25%  { transform: translateX(0)     translateY(0)     rotate(-2deg); opacity: 1; }
  33%  { transform: translateX(0)     translateY(0)     rotate(-2deg); opacity: 0; }
  34%  { transform: translateX(50px)  translateY(-17px) rotate(-5deg); opacity: 1; }
  42%  { transform: translateX(50px)  translateY(-17px) rotate(-5deg); opacity: 1; }
  58%  { transform: translateX(50px)  translateY(-17px) rotate(-5deg); opacity: 1; }
  66%  { transform: translateX(50px)  translateY(-17px) rotate(-5deg); opacity: 0; }
  67%  { transform: translateX(100px) translateY(-37px) rotate(-8deg); opacity: 1; }
  75%  { transform: translateX(100px) translateY(-37px) rotate(-8deg); opacity: 1; }
  91%  { transform: translateX(100px) translateY(-37px) rotate(-8deg); opacity: 1; }
  100% { transform: translateX(100px) translateY(-37px) rotate(-8deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .takeoff-plane {
    animation: none;
    transform: translateX(50px) translateY(-17px) rotate(-5deg);
    opacity: 1;
  }
}

/* === Map Timestamp === */
.map-timestamp {
  position: absolute;
  bottom: 28px;
  right: var(--space-3);
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: var(--radius-pill);
  padding: 0 var(--space-3);
  height: 28px;
  font-size: 0.6875rem;
  color: rgba(255,255,255,1.0);
  text-shadow: 0 0 6px rgba(255,255,255,0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  backdrop-filter: blur(4px);
}

.map-refresh-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,1.0);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0 2px;
  min-width: 20px;
  min-height: 20px;
  transition: color 120ms;
}

.map-refresh-btn:hover { color: rgba(255,255,255,0.9); }

.map-timestamp--stale {
  background: rgba(217,119,6,0.15);
  border-color: rgba(217,119,6,0.4);
  color: rgba(253,230,138,0.9);
}

/* === No Results Overlay === */
.no-results-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 600;
  pointer-events: all;
}

/* On mobile, always center in viewport (no side panels) */
@media (max-width: 639px) {
  .no-results-overlay {
    left: 50% !important;
  }
}

.no-results-card {
  position: relative;
  text-align: center;
  padding: var(--space-6) var(--space-8);
  max-width: 340px;
}

.no-results-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--gray-500);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.no-results-close:hover {
  color: var(--gray-600);
  background: var(--gray-100);
}

/* === Custom Map Pins === */
.airport-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 100ms var(--ease-out);
}

.airport-pin:hover {
  transform: scale(1.15);
}

.airport-pin--home {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.airport-pin--qualifying {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.airport-pin--nonqualifying {
  opacity: 0.8;
}

/* === Selected Pin Pulse === */
.airport-pin--selected {
  border-radius: 50%;
  animation: pinPulse 1.8s ease-out infinite;
}

.airport-pin--selected.airport-pin--qualifying {
  --pin-glow: rgba(26,127,75,0.85);
  --pin-glow-fade: rgba(26,127,75,0);
}
.airport-pin--selected.airport-pin--marginal {
  --pin-glow: rgba(146,112,0,0.85);
  --pin-glow-fade: rgba(146,112,0,0);
}
.airport-pin--selected.airport-pin--home {
  --pin-glow: rgba(0,147,215,0.85);
  --pin-glow-fade: rgba(0,147,215,0);
}
.airport-pin--selected.airport-pin--nonqualifying {
  --pin-glow: rgba(185,28,28,0.85);
  --pin-glow-fade: rgba(185,28,28,0);
}
.airport-pin--selected.airport-pin--noweather {
  --pin-glow: rgba(148,163,184,0.85);
  --pin-glow-fade: rgba(148,163,184,0);
}

@keyframes pinPulse {
  0%   { box-shadow: 0 0 0 0 var(--pin-glow), 0 0 0 0 rgba(255,255,255,0.45); }
  100% { box-shadow: 0 0 0 13px var(--pin-glow-fade), 0 0 0 15px rgba(255,255,255,0); }
}

@media (prefers-reduced-motion: reduce) {
  .airport-pin--selected { animation: none; }
}
.reduce-motion .airport-pin--selected { animation: none; }

/* Ghost pins — beyond-cap airports: tooltip-only, no popup */
.airport-pin--ghost {
  opacity: 0.7;
  pointer-events: auto; /* still hoverable for tooltip */
}
.airport-pin--ghost:hover {
  transform: none; /* no scale on hover — these are not interactive pins */
}

/* === Cluster Icons === */
.marker-cluster-runwy {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--deep-navy);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
}

/* === Map Popup Styling === */
.leaflet-popup-content-wrapper {
  background: var(--surface-bg) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
  border: 1px solid var(--gray-100) !important;
}

.leaflet-popup-tip {
  background: var(--surface-bg) !important;
}

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

.map-popup {
  padding: var(--space-3) var(--space-4);
}

.map-popup__status {
  margin-bottom: var(--space-1);
}

.map-popup__identifier {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--gray-900);
  margin-bottom: 2px;
}

.map-popup__note {
  font-size: 0.6875rem;
  color: var(--gray-500);
  padding: var(--space-1) 0;
}

.map-popup__name {
  font-size: 0.8125rem;
  color: var(--gray-700);
  margin-bottom: var(--space-1);
}

.map-popup__crosswind {
  font-size: 0.8125rem;
  color: var(--gray-500);
  margin-bottom: var(--space-2);
}

.map-popup__action {
  text-align: center;
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.popup-search-from {
  margin-top: 0;
}

/* === Error Page === */
.view--error {
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-page {
  text-align: center;
  max-width: 400px;
  padding: var(--space-8);
}

.error-icon {
  margin: 0 auto var(--space-6);
}

.error-page h2 { margin-bottom: var(--space-2); }

.error-page .btn {
  margin-top: var(--space-6);
}

/* === Leaflet tile seam fix (retina / fractional zoom) === */
.leaflet-tile-pane {
  will-change: transform;
}

/* Mute street tiles — softens brightness contrast vs. dark home page */

.leaflet-tile {
  image-rendering: -webkit-optimize-contrast;
  outline: 1px solid transparent;
}

/* === Leaflet overrides === */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: var(--radius-md) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: #fff !important;
  color: var(--gray-700) !important;
  border-color: var(--gray-100) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--gray-50) !important;
  text-decoration: none !important;
}

/* === Layer Switcher === */
.leaflet-control-layers {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-primary) !important;
  font-size: 0.8125rem !important;
  padding: 0 !important;
}

.leaflet-control-layers-expanded {
  padding: var(--space-2) var(--space-3) !important;
}

.leaflet-control-layers-toggle {
  width: 32px !important;
  height: 32px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2 2 7l10 5 10-5-10-5z'/%3E%3Cpath d='m2 17 10 5 10-5'/%3E%3Cpath d='m2 12 10 5 10-5'/%3E%3C/svg%3E") !important;
  background-size: 18px 18px !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}

.leaflet-control-layers-base label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
  cursor: pointer;
  color: var(--gray-700);
}

.leaflet-control-layers-base label:hover {
  color: var(--gray-900);
}

.leaflet-control-layers-separator {
  border-color: var(--gray-100) !important;
}

/* === Search radius circle === */
.search-radius-circle {
  stroke: rgba(0,147,215,0.2);
  stroke-dasharray: 6 4;
  fill: rgba(0,147,215,0.06);
}

.search-radius-inner {
  fill: rgba(0,0,0,0.04);
}

@media (max-width: 639px) {
  .map-container {
    position: absolute;
    inset: 0;
    bottom: 54px;
  }

  /* Keep Leaflet controls below the detail panel (z-index: 900) */
  .leaflet-top.leaflet-right {
    z-index: 800;
  }

  /* Keep attribution fully above the mobile results bar */
  .leaflet-bottom.leaflet-right {
    bottom: 10px;
  }

  /* Hide attribution when detail panel is open on mobile — it peeks through */
  .map-container:has(.detail-panel.open) .leaflet-bottom.leaflet-right {
    display: none;
  }

  .map-timestamp {
    bottom: 34px;
    right: var(--space-2);
  }
}

/* === Dark theme — slate-navy popup === */
.leaflet-popup {
  --surface-bg:           #131F2E;
  --surface-card:         #1B2C40;
  --gray-100:             rgba(255,255,255,0.07);
  --gray-200:             rgba(255,255,255,0.09);
  --gray-500:             rgba(150,199,232,0.6);
  --gray-700:             rgba(200,220,235,0.75);
  --gray-900:             #E8F0F8;
  --qualify-green:        #45f0d0;
  --qualify-green-light:  rgba(69,240,208,0.1);
  --marginal-amber:       #F59E0B;
  --marginal-amber-light: rgba(245,158,11,0.12);
  --exceed-red:           #EF4444;
  --exceed-red-light:     rgba(239,68,68,0.12);
  /* Re-establish text color for all inherited popup text */
  color: #E8F0F8;
}
.leaflet-popup-content-wrapper {
  border: 1px solid rgba(255,255,255,0.09) !important;
}
/* Hardcoded source badge backgrounds */
.leaflet-popup .source-badge--metar { background: rgba(37,99,235,0.18);  color: #93C5FD; }
.leaflet-popup .source-badge--taf   { background: rgba(124,58,237,0.18); color: #C4B5FD; }
.leaflet-popup .source-badge--nws   { background: rgba(234,88,12,0.18);  color: #FCA47A; }

/* Home-pin badge — default (light context) and dark popup override */
.badge--home-pin {
  background: var(--gray-100);
  color: var(--deep-navy);
}
.leaflet-popup .badge--home-pin {
  background: rgba(0, 147, 215, 0.2);
  color: #57B9FF;
}

/* View Details button inside dark popup */
.leaflet-popup .btn--primary {
  background: var(--horizon-teal);
  color: #fff;
}
.leaflet-popup .btn--primary:hover {
  background: var(--horizon-teal-active);
}
