:root {
  --bg-dark: #080c14;
  --panel-bg: #0d1424;
  --card-bg: #131d33;
  --card-hover: #1c2b4a;
  --border: #1f2e4d;
  --border-focus: #3b82f6;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent: #38bdf8;
  --accent-cyan: #06b6d4;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  
  --font-mono: 'SF Mono', 'Fira Code', 'Courier New', monospace;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar Layout */
#sidebar {
  width: 380px;
  min-width: 380px;
  max-width: 380px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}

.sidebar-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, #101a30 0%, var(--panel-bg) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.radar-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.5));
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.station-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.disconnected { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* Avionics Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

.metric-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  text-align: center;
}

.metric-val {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--font-mono);
}

.metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Emergency Banner */
.emergency-banner {
  background: #7f1d1d;
  color: #fecaca;
  border-bottom: 1px solid #dc2626;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.5px;
  animation: flash 1s infinite alternate;
}

@keyframes flash {
  from { background: #7f1d1d; }
  to { background: #b91c1c; }
}

/* Controls Bar */
.controls-bar {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.85rem;
  opacity: 0.6;
}

.search-box input {
  width: 100%;
  background: #090f1d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1.8rem 0.5rem 2rem;
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
}

.clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 4px;
}

.pill {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  user-select: none;
}

.pill:hover, .pill.active {
  background: var(--accent);
  color: #04101e;
  border-color: var(--accent);
  font-weight: 700;
}

/* Aircraft Scroll List */
.aircraft-scroll-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.25rem;
}

.aircraft-scroll-container::-webkit-scrollbar {
  width: 6px;
}

.aircraft-scroll-container::-webkit-scrollbar-track {
  background: var(--panel-bg);
}

.aircraft-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.aircraft-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.aircraft-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  display: flex;
  gap: 10px;
  align-items: center;
}

.card-photo-thumb {
  width: 48px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  background: #090f1d;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.aircraft-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.aircraft-card:hover {
  background: var(--card-hover);
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateX(2px);
}

.aircraft-card.selected {
  border-color: var(--accent);
  background: #192642;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.2);
}

/* Plane Photo Banner in Detail Panel */
.plane-photo-banner {
  position: relative;
  width: 100%;
  height: 160px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  background: #090f1d;
}

.plane-photo-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-credit {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(8, 12, 20, 0.8);
  backdrop-filter: blur(4px);
  color: var(--text-secondary);
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.photo-credit:hover {
  color: var(--accent);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.callsign-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.callsign {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 800;
  color: #ffffff;
}

.card-kind-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.kind-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.kind-military {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.45);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.2);
}

.kind-heli {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.15);
}

.kind-plane {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.kind-glider {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.kind-balloon {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.3);
}

.kind-drone {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.alt-tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  color: #ffffff;
}

.card-bottom {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.hex-tag {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.speed-tag, .vert-tag {
  font-family: var(--font-mono);
}

.vert-up { color: var(--green); }
.vert-down { color: var(--amber); }

/* Selected Aircraft Detail Panel */
.selected-detail-panel {
  background: #111a30;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.detail-flight {
  font-size: 1.15rem;
  font-weight: 900;
  font-family: var(--font-mono);
  color: #ffffff;
}

.detail-hex {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: 6px;
}

.close-panel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  font-size: 0.78rem;
  margin-bottom: 0.75rem;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.detail-item.full-width {
  grid-column: span 2;
}

.detail-item strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

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

.action-btn {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: #1f3056;
  border-color: var(--accent);
}

.action-btn.active-trail {
  background: rgba(16, 185, 129, 0.18);
  border-color: #10b981;
  color: #34d399;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.25);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 0.85rem 1.25rem;
  background: #0a0f1d;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.footer-row input[type="range"] {
  width: 50%;
  accent-color: var(--accent);
}

.footer-toggles {
  display: flex;
  justify-content: space-between;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Map Container */
#mapContainer {
  flex: 1;
  position: relative;
  height: 100vh;
}

#map {
  width: 100%;
  height: 100%;
  background: #050810;
}

/* Floating Controls */
.map-overlay-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  gap: 8px;
}

.map-layer-selector {
  display: flex;
  background: rgba(13, 20, 36, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.map-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.map-btn.active, .map-btn:hover {
  background: var(--accent);
  color: #04101e;
  font-weight: 700;
}

#btnResetView {
  background: rgba(13, 20, 36, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
}

/* Radar Playback HUD (Bottom Left) */
.radar-playback-hud {
  position: absolute;
  bottom: 24px;
  left: 24px;
  z-index: 1000;
  background: rgba(13, 20, 36, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 380px;
  max-width: calc(100vw - 420px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.radar-hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
}

.live-dot-green {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 6px;
  animation: pulse 1.5s infinite;
}

.radar-title {
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.radar-time {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

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

.radar-action-btn {
  background: var(--accent);
  border: none;
  color: #04101e;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.radar-controls input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.radar-opacity-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

#radarOpacitySlider {
  width: 60px;
}

/* Unified Avionics & Lightning Legend HUD (Bottom Right) */
.map-legend-hud {
  position: absolute;
  bottom: 24px;
  right: 16px;
  z-index: 1000;
  background: rgba(13, 20, 36, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
}

.legend-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-title {
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  font-size: 0.68rem;
}

.legend-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
}

.legend-bar span {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.legend-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.map-btn-telemetry {
  background: rgba(56, 189, 248, 0.15) !important;
  color: #38bdf8 !important;
  border-color: rgba(56, 189, 248, 0.4) !important;
  font-weight: 700 !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
}

.map-btn-telemetry:hover {
  background: #38bdf8 !important;
  color: #04101e !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.map-btn-lightning {
  background: rgba(245, 158, 11, 0.15) !important;
  color: #fbbf24 !important;
  border-color: rgba(245, 158, 11, 0.4) !important;
  font-weight: 700 !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
}

.map-btn-lightning:hover {
  background: #f59e0b !important;
  color: #000000 !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

/* Lightning Strike Markers & Shockwaves */
.lightning-marker-recent {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightning-marker-recent::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2px solid #facc15;
  border-radius: 50%;
  animation: lightningShockwave 1.8s infinite ease-out;
  opacity: 0;
}

@keyframes lightningShockwave {
  0% {
    transform: scale(0.4);
    opacity: 1;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

/* Leaflet Popup Styling */
.leaflet-popup-content-wrapper {
  background: rgba(13, 20, 36, 0.95);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.leaflet-popup-tip {
  background: rgba(13, 20, 36, 0.95);
}

.popup-avionics {
  font-size: 0.8rem;
  line-height: 1.5;
  width: 220px;
}

.popup-photo-thumb {
  width: 100%;
  height: 125px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  background: #090f1d;
  display: block;
}

.popup-flight {
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #ffffff;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 6px;
}
