/**
 * Route Map Component Styles
 * Extracted from map.j2 inline styles for better organization
 */

/* Route map theme tokens */
:root {
  --route-map-hub: #1e40af;
  --route-map-major: #3b82f6;
  --route-map-regional: #eab308;
  --route-map-local: #ef4444;
  --route-map-unserved: #6b7280;
  --route-map-route-default: #f472b6;
  --route-map-route-selected: #3b82f6;
  --route-map-route-muted: #6b7280;
  --route-map-selected-stroke: #3b82f6;
  --route-map-cluster: #1e3a8a;
  --route-map-cluster-text: #ffffff;
  --route-map-cluster-stroke: rgba(255, 255, 255, 0.75);
  --z-route-map-skeleton: 30;
  --z-route-map-overlay-panel: 40;
  --z-route-map-autocomplete: 60;
  --z-route-map-range-thumb: 10;
  --z-route-map-range-lower: 2;
  --z-route-map-range-track: 1;
  --z-route-map-marker-hover: 100;
  --z-route-map-airport-label: 10;
}

[data-theme="2lnr-dark"] {
  --route-map-hub: #60a5fa;
  --route-map-major: #93c5fd;
  --route-map-regional: #facc15;
  --route-map-local: #f87171;
  --route-map-unserved: #94a3b8;
  --route-map-route-default: #f9a8d4;
  --route-map-route-selected: #60a5fa;
  --route-map-route-muted: #9ca3af;
  --route-map-selected-stroke: #60a5fa;
  --route-map-cluster: #93c5fd;
  --route-map-cluster-text: #0f172a;
  --route-map-cluster-stroke: rgba(15, 23, 42, 0.6);
}

/* Route line visibility hierarchy */
:root {
  --route-line-primary-width: 4px;
  --route-line-primary-opacity: 1;
  --route-line-secondary-width: 2px;
  --route-line-secondary-opacity: 0.5;
}

/* Layout */
.route-map-layout {
  min-height: calc(100vh - 4rem);
}

.folded-map {
  padding: 0.75rem;
  background: linear-gradient(135deg, var(--journal-paper), color-mix(in oklab, var(--journal-paper) 70%, #fff));
}

@media (max-width: 640px) {
  .folded-map {
    padding: 0.5rem;
  }
}

/* Viewport Stability - prevent scroll anchoring from causing shifts */
.route-map-layout,
.route-map-header,
#map-pane,
#panel-content {
  overflow-anchor: none;
}

.route-map-header {
  background-color: var(--color-base-100);
}

.route-map-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: var(--z-route-map-overlay-panel);
}

.route-map-list {
  display: grid;
  gap: 0.75rem;
}

body.route-panel-open {
  overflow: hidden;
}

.route-map-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: var(--z-map-overlay);
}

.route-map-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.route-map-sidebar {
  position: relative;
  z-index: var(--z-map-sidebar);
}

/* Map Container */
#map-pane {
  position: relative;
  min-height: 520px;
  contain: layout style;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

/* ==========================================================================
   Inline Tag Input Component
   A text input that displays tags inline before the cursor
   ========================================================================== */

.inline-tag-input {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  height: 1.75rem;
  padding: 0 0.5rem;
  background: color-mix(in oklab, var(--color-base-content) 5%, transparent);
  border-radius: 0.375rem;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.inline-tag-input:focus-within {
  background: color-mix(in oklab, var(--color-base-content) 8%, transparent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--color-primary) 25%, transparent);
}

.inline-tag-input-field {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.inline-tag-input-wrapper {
  position: relative;
  display: inline-flex;
  flex: 1 1 1ch;
  min-width: 1ch;
  max-width: 100%;
}

.inline-tag-container {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.inline-tag-container:not(:empty) {
  margin-right: 0.25rem;
}

/* Individual tag inside the input */
.inline-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-family-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.025em;
  background: var(--color-primary);
  color: var(--color-primary-content, #fff);
  border-radius: 0.25rem;
  white-space: nowrap;
  line-height: 1.25;
}

.inline-tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.875rem;
  height: 0.875rem;
  margin-left: 0.125rem;
  margin-right: -0.125rem;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 0.1s, background 0.1s;
  border: none;
  padding: 0;
  font-size: 0.625rem;
}

.inline-tag-remove:hover {
  opacity: 1;
  background: color-mix(in oklab, var(--color-primary-content, #fff) 20%, transparent);
}

/* The actual text input */
.inline-tag-text-input {
  flex: 1;
  min-width: 3rem;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.875rem;
  font-family: var(--font-family-mono, 'JetBrains Mono', monospace);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-base-content);
  outline: none;
}

.inline-tag-text-input::placeholder {
  color: color-mix(in oklab, var(--color-base-content) 35%, transparent);
  text-transform: none;
  letter-spacing: normal;
}

/* Hide placeholder when tags exist */
.inline-tag-container:not(:empty) + .inline-tag-text-input::placeholder {
  color: transparent;
}

/* Clear button */
.inline-tag-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--color-base-content);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s;
  padding: 0;
  font-size: 0.5rem;
}

.inline-tag-input:hover .inline-tag-clear,
.inline-tag-input:focus-within .inline-tag-clear {
  opacity: 0.4;
}

.inline-tag-clear:hover {
  opacity: 1 !important;
  color: var(--color-error);
}

/* Hide clear button when empty */
.inline-tag-container:empty ~ .inline-tag-clear {
  visibility: hidden;
}

/* Dark mode adjustments */
[data-theme*="dark"] .inline-tag-input {
  background: color-mix(in oklab, var(--color-base-content) 8%, transparent);
}

[data-theme*="dark"] .inline-tag-input:focus-within {
  background: color-mix(in oklab, var(--color-base-content) 12%, transparent);
}

/* Map Skeleton Loading State */
.map-skeleton {
  position: absolute;
  inset: 0;
  z-index: var(--z-route-map-skeleton);
  background-color: color-mix(in oklab, var(--color-base-100) 84%, var(--journal-paper) 16%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  transition: opacity 300ms ease-in-out;
}

.map-skeleton.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.map-skeleton-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.map-skeleton-icon {
  font-size: 3rem;
  color: var(--color-primary);
  opacity: 0.7;
  animation: pulse 2s ease-in-out infinite;
}

.map-skeleton-text {
  color: color-mix(in oklab, var(--color-base-content) 70%, transparent);
  font-size: 0.875rem;
}

@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.4; }
}

/* Map Overlay Panels */
.map-overlay-panel {
  position: absolute;
  z-index: var(--z-route-map-overlay-panel);
  pointer-events: none;
}

.map-overlay-panel > * {
  pointer-events: auto;
}

.map-legend {
  min-width: 220px;
}

#map-legend .collapse-title {
  position: relative;
  padding-right: 1.75rem;
}

#map-legend .collapse-title::after {
  content: '';
  position: absolute;
  right: 0.75rem;
  top: 50%;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-50%) rotate(-135deg);
  transition: transform 0.2s ease;
}

#map-legend input[type="checkbox"]:checked ~ .collapse-title::after {
  transform: translateY(-50%) rotate(45deg);
}

.map-legend-highlight {
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--color-primary) 45%, transparent),
    0 12px 30px rgba(15, 23, 42, 0.2);
}

/* Autocomplete Panel - Minimal styling */
.autocomplete-panel {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow-y: auto;
  border: 1px solid color-mix(in oklab, var(--color-base-content) 10%, transparent);
  border-radius: 0.25rem;
  background: var(--color-base-100);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  padding: 0.25rem 0;
  z-index: var(--z-route-map-autocomplete);
}

.autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  transition: background-color 0.15s ease;
}

.autocomplete-item:hover,
.autocomplete-item.is-active {
  background: color-mix(in oklab, var(--color-primary) 12%, transparent);
}

.autocomplete-item .code {
  font-weight: 700;
  font-family: var(--font-family-mono, 'JetBrains Mono', monospace);
}

.autocomplete-empty {
  padding: 0.75rem 0.75rem;
  font-size: 0.75rem;
  color: color-mix(in oklab, var(--color-base-content) 60%, transparent);
}

/* Dual Range Slider */
.dual-range {
  position: relative;
  height: 1.75rem;
}

.dual-range::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  height: 0.35rem;
  border-radius: 9999px;
  background: color-mix(in oklab, var(--color-base-300) 70%, transparent);
  pointer-events: none;
}

.dual-range::before {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: var(--range-start, 0%);
  width: calc(var(--range-end, 100%) - var(--range-start, 0%));
  height: 0.35rem;
  border-radius: 9999px;
  background: var(--color-primary);
  opacity: 0.4;
  pointer-events: none;
}

.dual-range input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
}

.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
}

.dual-range .range-lower {
  z-index: var(--z-route-map-range-lower);
}

/* Dual range slider - compact inline (matching dashboard) */
.dual-range-slider.compact {
  height: 1rem;
  position: relative;
}
.dual-range-slider.compact .range-min,
.dual-range-slider.compact .range-max {
  pointer-events: none;
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  -webkit-appearance: none;
  background: none;
  z-index: var(--z-route-map-range-thumb);
}
.dual-range-slider.compact input::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-base-100);
  border: 1.5px solid var(--color-base-content);
  margin-top: -4px;
  cursor: pointer;
}
.dual-range-slider.compact input::-moz-range-thumb {
  pointer-events: auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-base-100);
  border: 1.5px solid var(--color-base-content);
  cursor: pointer;
}
.dual-range-slider.compact .range-track {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
}
.dual-range-slider.compact .range-progress {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-route-map-range-track);
}

/* Responsive adjustments */
@media (max-width: 1023px) {
  .route-map-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(90vw, 360px);
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: 12px 0 30px rgba(15, 23, 42, 0.15);
  }

  .route-map-sidebar.is-open {
    transform: translateX(0);
  }

  #map-pane {
    min-height: 420px;
  }

  #map {
    min-height: 420px;
  }
}

@media (max-width: 768px) {
  .dual-range-slider.compact input::-webkit-slider-thumb {
    width: 14px;
    height: 14px;
    margin-top: -6px;
  }

  .dual-range-slider.compact input::-moz-range-thumb {
    width: 14px;
    height: 14px;
  }
}

/* MapLibre Popup Theme Override - follows light/dark mode */
.maplibregl-popup-content {
  background-color: var(--color-base-100);
  color: var(--color-base-content);
  border: 1px solid var(--color-base-300);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0.75rem;
}

/* Popup arrow/tip styling to match content background */
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
  border-bottom-color: var(--color-base-100);
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: var(--color-base-100);
}

.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--color-base-100);
}

.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--color-base-100);
}

/* Close button styling */
.maplibregl-popup-close-button {
  color: var(--color-base-content);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
}

.maplibregl-popup-close-button:hover {
  background-color: color-mix(in oklab, var(--color-base-content) 10%, transparent);
  border-radius: 0.25rem;
}

/* Sidebar Insights Card - Top Airlines section */
.sidebar-insights-card {
  padding: 0.875rem 1rem;
  background: linear-gradient(
    135deg,
    color-mix(in oklab, var(--color-base-100) 100%, transparent),
    color-mix(in oklab, var(--color-base-200) 60%, transparent)
  );
  border: 1px solid var(--color-base-300);
  border-radius: 0.75rem;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 2px 4px rgba(0, 0, 0, 0.02);
}

.sidebar-insights-card .label-caps {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: color-mix(in oklab, var(--color-base-content) 55%, transparent);
}

/* Hide empty state when insights are visible */
#sidebar-insights:not(:empty) + #panel-empty-state {
  display: none;
}

/* ==========================================================================
   Dark Mode Theme Support
   ========================================================================== */

/* Dark mode popup shadow enhancement */
[data-theme*="dark"] .maplibregl-popup-content {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Airport tooltip styling for both themes */
.airport-tooltip .maplibregl-popup-content {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
}

/* Map loading overlay theme support */
.map-loading-overlay {
  background: color-mix(in oklab, var(--color-base-100) 80%, transparent);
  backdrop-filter: blur(4px);
}

.map-loading-spinner {
  color: var(--color-primary);
}

/* Map legend theme support */
.map-legend {
  background: color-mix(in oklab, var(--color-base-100) 95%, transparent);
  backdrop-filter: blur(4px);
  border: 1px solid var(--color-base-300);
  color: var(--color-base-content);
}

[data-theme*="dark"] .map-legend {
  background: color-mix(in oklab, var(--color-base-100) 90%, transparent);
}

/* Route marker base styles */
.route-marker {
  background: var(--color-primary);
  border: 2px solid var(--color-base-100);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.route-marker:hover {
  transform: scale(1.3);
  z-index: var(--z-route-map-marker-hover);
}

/* Dark mode marker adjustments */
[data-theme*="dark"] .route-marker {
  border-color: var(--color-base-200);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Selected marker state */
.route-marker.selected {
  background: var(--color-success);
  transform: scale(1.2);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-success) 40%, transparent);
}

/* Airport label pill styling - FlightConnections-style persistent labels per spec */
.airport-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-base-200);
  color: var(--color-base-content);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: auto;
  z-index: var(--z-route-map-airport-label);
}

[data-theme*="dark"] .airport-label {
  background: #1f2937;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.airport-label .iata {
  font-family: 'B612 Mono', 'JetBrains Mono', monospace;
  background: var(--color-base-300);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

[data-theme*="dark"] .airport-label .iata {
  background: #374151;
}

.airport-label .close {
  margin-left: 8px;
  opacity: 0.6;
  cursor: pointer;
}

.airport-label .close:hover {
  opacity: 1;
}

/* Reduced motion support for theme transitions */
@media (prefers-reduced-motion: reduce) {
  .route-marker,
  .route-line,
  .maplibregl-popup-content,
  .map-legend {
    transition: none;
  }
}

/* Legend collapse arrow: UP when collapsed, DOWN when expanded */
#map-legend.collapse-arrow > .collapse-title::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid currentColor;
  border-top: 0;
  transform: none !important;
  transition: border-color 0.2s ease-out;
}

#map-legend.collapse-arrow > input:checked ~ .collapse-title::after {
  border-bottom: 0;
  border-top: 6px solid currentColor;
}
