/* ==========================================================================
   Live Map Section - SWISS Virtual
   Displays real-time flight positions when pilots are flying
   ========================================================================== */

/* Live Map Section Container */
.live-map-section {
  --color-background-rgb: 255, 255, 255;
  padding: var(--space-xl) 0;
  background-color: var(--color-surface);
}

@media (prefers-color-scheme: dark) {
  .live-map-section {
    --color-background-rgb: 26, 26, 26;
  }
}

/* Header with title */
.live-map-header {
  text-align: center;
  margin-bottom: var(--space-lg);
}

/* --------------------------------------------------------------------------
   Stage Layout - Full-width map with floating overlay card
   -------------------------------------------------------------------------- */

.live-map-stage {
  position: relative;
  width: 100%;
  min-height: 500px;
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* Live status indicator - top right corner */
.live-map-status {
  position: absolute;
  top: var(--space-sm, 8px);
  right: var(--space-sm, 8px);
  z-index: 1000;
}

/* --------------------------------------------------------------------------
   LIVE Badge - Red pill with pulsing white dot
   -------------------------------------------------------------------------- */

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-primary);
  color: white;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.live-badge-dot {
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: badge-pulse 1.5s ease-in-out infinite;
}

.live-badge-separator {
  margin: 0 2px;
}

@keyframes badge-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(0.9);
  }
}

/* Reduced motion preference for badge */
@media (prefers-reduced-motion: reduce) {
  .live-badge-dot {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   Flight Info Panel - Floating overlay card
   -------------------------------------------------------------------------- */

.flight-info-panel {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  bottom: var(--space-sm);
  width: 400px;
  background-color: var(--color-background);
  color: var(--color-text);
  padding: var(--space-md) var(--space-md);
  border-radius: var(--radius-lg, 12px);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.06),
    inset 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  z-index: 1000;  /* Must be higher than Leaflet's panes (up to 700) */
  opacity: 0;
  transition: opacity 0.8s ease;  /* Faster panel fade (was 1.5s) */
  will-change: opacity;
}

.flight-info-panel.visible {
  opacity: 1;
}

/* Panel crossfade - content fades while container persists */
.flight-info-panel.crossfading .flight-header,
.flight-info-panel.crossfading .flight-narrative,
.flight-info-panel.crossfading .flight-data-grid {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.flight-info-panel:not(.crossfading) .flight-header,
.flight-info-panel:not(.crossfading) .flight-narrative,
.flight-info-panel:not(.crossfading) .flight-data-grid {
  opacity: 1;
  transition: opacity 0.6s ease 0.1s;
}

/* Flight header - aircraft type and registration */
.flight-header {
  margin-bottom: var(--space-md);
}

.flight-aircraft-type {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold, 700);
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.flight-registration {
  font-size: var(--font-size-2xl, 1.75rem);
  font-weight: var(--font-weight-bold, 700);
  color: var(--color-primary);
  line-height: 1.2;
}

/* Narrative sentence - bold black */
.flight-narrative {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold, 700);
  color: var(--color-text);
  margin: 0 0 var(--space-md) 0;
  line-height: 1.4;
}

/* Split-flap display animation (airport departure board style) */
.flight-narrative .split-flap-char {
  display: inline;
  position: relative;
}

.flight-narrative .split-flap-char .flap {
  display: inline;
  transform-origin: center center;
}

.flight-narrative .split-flap-char .flap.flipping {
  animation: splitFlapFlip 0.12s ease-in-out forwards;
}

@keyframes splitFlapFlip {
  0% {
    opacity: 1;
    transform: scaleY(1);
  }
  50% {
    opacity: 0;
    transform: scaleY(0);
  }
  100% {
    opacity: 1;
    transform: scaleY(1);
  }
}

/* Flight data grid - two columns */
.flight-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
  margin-top: auto;
}

.flight-data-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.flight-data-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.flight-data-icon {
  flex-shrink: 0;
  width: 20px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flight-data-icon svg {
  display: block;
}

.flight-data-value {
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-mono, monospace);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

/* Marquee effect for long text that overflows */
.flight-data-value.is-overflowing {
  text-overflow: clip;
}

.flight-data-value.is-overflowing::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(to right, transparent, var(--color-background));
  pointer-events: none;
}

.flight-data-value.is-overflowing .marquee-content {
  display: inline-block;
  animation: marquee-scroll 8s linear infinite;
  padding-right: 2em;
}

@keyframes marquee-scroll {
  0%, 20% {
    transform: translateX(0);
  }
  80%, 100% {
    transform: translateX(-50%);
  }
}

/* Reduced motion preference for marquee */
@media (prefers-reduced-motion: reduce) {
  .flight-data-value.is-overflowing .marquee-content {
    animation: none;
  }
  .flight-data-value.is-overflowing {
    text-overflow: ellipsis;
  }
}

/* --------------------------------------------------------------------------
   Map Container - Full width, fills stage
   -------------------------------------------------------------------------- */

.live-map-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 500px;
  background-color: var(--color-surface);
  overflow: hidden;
}

/* Bounce animation for elastic effect */
@keyframes map-bounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.01); }
  100% { transform: scale(1); }
}

.live-map-container.map-bounce {
  animation: map-bounce 0.3s ease-out;
}

/* --------------------------------------------------------------------------
   Responsive: stack vertically on mobile/tablet
   -------------------------------------------------------------------------- */

@media (max-width: 991px) {
  .live-map-stage {
    min-height: 450px;
  }

  .flight-info-panel {
    position: relative;
    top: unset;
    left: unset;
    bottom: unset;
    width: 100%;
    padding: var(--space-md);
    margin-top: -80px;
    border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
    box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.06);
    z-index: 1000;
  }

  .live-map-container {
    position: relative;
    height: 350px;
    min-height: 350px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }
}

/* --------------------------------------------------------------------------
   Aircraft Markers - Focused and Unfocused States
   -------------------------------------------------------------------------- */

.aircraft-marker {
  color: var(--color-primary);
}

/* Unfocused aircraft - small with subtle shadow */
.aircraft-unfocused {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.aircraft-unfocused svg {
  width: 24px;
  height: 24px;
}

/* Focused aircraft - large with radar rings, staggered entrance */
.aircraft-focused {
  position: relative;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

/* SVG grows from small to large after radar starts fading in
   Sequence: 0.1s wait, 0.5s radar fade, then 1s grow = 0.6s delay */
.aircraft-focused svg {
  width: 72px;
  height: 72px;
  position: relative;
  z-index: 2;
  transform: scale(0.333);
  transform-origin: center center;
  animation: icon-grow 1s ease-out 0.6s forwards;
}

/* Radar container fades in after 0.1s delay */
.aircraft-focused .radar-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  animation: radar-fade-in 0.5s ease-out 0.1s forwards;
}

/* Unfocusing state - reverse the animations */
.aircraft-focused.unfocusing svg {
  transform: scale(1);
  animation: icon-shrink 1s ease-in forwards;
}

.aircraft-focused.unfocusing .radar-container {
  opacity: 1;
  animation: radar-fade-out 0.5s ease-in 1s forwards;
}

@keyframes icon-grow {
  from { transform: scale(0.333); }
  to { transform: scale(1); }
}

@keyframes icon-shrink {
  from { transform: scale(1); }
  to { transform: scale(0.333); }
}

@keyframes radar-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes radar-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Radar rings - expanding outward, start after container fades in */
.aircraft-focused .radar-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100px;
  height: 100px;
  margin: -50px 0 0 -50px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  opacity: 0;
  animation: radar-pulse 3s ease-out infinite;
}

.aircraft-focused .radar-ring:nth-child(2) {
  animation-delay: -1s;
}

.aircraft-focused .radar-ring:nth-child(3) {
  animation-delay: -2s;
}

@keyframes radar-pulse {
  0% {
    transform: scale(0.3);
    opacity: 0.8;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* Reduced motion preference for radar */
@media (prefers-reduced-motion: reduce) {
  .aircraft-focused .radar-ring {
    animation: none;
    opacity: 0.3;
    transform: scale(1);
  }
  .aircraft-focused .radar-container {
    animation: none;
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Leaflet Overrides - Tile and Marker Rendering
   -------------------------------------------------------------------------- */

/* Prevent tile flicker during zoom transitions */
.leaflet-tile-container {
  will-change: transform;
}

.leaflet-zoom-animated {
  will-change: transform;
}

/* Ensure smooth tile loading */
.leaflet-tile {
  will-change: opacity;
}

/* Prevent marker jumps during transforms */
.leaflet-marker-pane {
  will-change: transform;
}

/* Smooth marker position/rotation updates */
.aircraft-marker {
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

/* Ensure radar rings don't cause layout thrashing */
.radar-container {
  contain: layout style;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-tip {
  box-shadow: none;
}

/* Ensure proper popup text color in dark mode */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background-color: var(--color-background);
}

.leaflet-popup-content {
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Dark Mode Adjustments
   -------------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  .aircraft-unfocused {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  }

  .aircraft-focused {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6));
  }

  .leaflet-popup-content-wrapper {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  }

  .flight-info-panel {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.08),
      inset 0 2px 8px rgba(0, 0, 0, 0.25);
  }
}

/* --------------------------------------------------------------------------
   Swiss Flag Easter Egg - Flat square flag for Zürich/Genève
   -------------------------------------------------------------------------- */

.swiss-flag {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  background-color: #da291c;
  position: relative;
  vertical-align: middle;
  margin-left: 0.15em;
  transform: translateY(-0.1em);
  border-radius: 1px;
}

.swiss-flag::before,
.swiss-flag::after {
  content: '';
  position: absolute;
  background-color: white;
}

/* Horizontal bar of the cross */
.swiss-flag::before {
  width: 55%;
  height: 18%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Vertical bar of the cross */
.swiss-flag::after {
  width: 18%;
  height: 55%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
