/* BC Transporter - Modern Web App Styles */

/* ========================================
   THEME SYSTEM
   ======================================== */

/* Declare color-scheme support for browser native UI elements */
:root {
  color-scheme: light dark;
}

html[data-theme="light"],
body[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"],
body[data-theme="dark"] {
  color-scheme: dark;
}

/* ========================================
   COLOR PRESERVATION SYSTEM (DOM-based rendering)
   ======================================== 
   Similar to map_3d.html, this app uses a DOM-based rendering approach
   for map elements (train markers, routes, stops) to prevent Mapbox GL 
   theme changes from altering element colors.
   
   Strategy:
   1. DOM Markers: Train markers are rendered as DOM elements, not GL layers
   2. RGBA Expressions: Route/stop GL layers use explicit rgba() expressions
   3. Force Flags: !important on critical properties to prevent theme override
   4. Reassertion: JS periodically re-applies colors after style changes
   5. Filter Protection: filter:none and mix-blend-mode:normal prevent blending
   
   This ensures elements maintain EXACT colors in both light/dark themes,
   independent of the Mapbox basemap lightPreset setting.
   ======================================== */

:root {
  /* Colors */
  --primary-color: #667eea;
  --primary-dark: #5a67d8;
  --secondary-color: #f093fb;
  --accent-color: #4facfe;
  --success-color: #48bb78;
  --warning-color: #ed8936;
  --error-color: #f56565;
  --info-color: #4299e1;

  /* Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f7fafc;
  --bg-tertiary: #edf2f7;
  --bg-dark: #1a202c;
  --bg-darker: #2d3748;

  /* Text Colors */
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --text-light: #ffffff;

  /* Border Colors */
  --border-color: #e2e8f0;
  --border-dark: #cbd5e0;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;
  --spacing-4xl: 5rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Font Sizes */
  --font-xs: 0.75rem;
  --font-sm: 0.875rem;
  --font-base: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.25rem;
  --font-2xl: 1.5rem;
  --font-3xl: 1.875rem;
  --font-4xl: 2.25rem;

  /* Font Weights */
  --font-light: 300;
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Transitions */
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.3s ease-in-out;
  --transition-slow: 0.5s ease-in-out;
}

/* Dark theme variables */
html[data-theme="dark"],
body[data-theme="dark"] {
  /* Background Colors */
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #3a3a3a;
  --bg-dark: #1a202c;
  --bg-darker: #0f1419;

  /* Text Colors */
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5e0;
  --text-muted: #a0aec0;
  --text-light: #ffffff;

  /* Border Colors */
  --border-color: #4a5568;
  --border-dark: #2d3748;

  /* Shadows - darker for dark theme */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.2), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3), 0 4px 6px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.3), 0 10px 10px rgba(0, 0, 0, 0.2);
}

/* Light theme variables (explicit) */
html[data-theme="light"],
body[data-theme="light"] {
  /* Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f7fafc;
  --bg-tertiary: #edf2f7;
  --bg-dark: #1a202c;
  --bg-darker: #2d3748;

  /* Text Colors */
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --text-light: #ffffff;

  /* Border Colors */
  --border-color: #e2e8f0;
  --border-dark: #cbd5e0;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);
}

/* Force theme backgrounds and text colors */
html[data-theme="light"],
body[data-theme="light"] {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
}

html[data-theme="dark"],
body[data-theme="dark"] {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  /* Use percent-based sizing so children can fill the viewport
     and avoid locking the viewport with `position: fixed`. */
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  position: relative;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  /* Keep the app full-viewport but avoid double-fixed stacking
     that can break Mapbox sizing. */
  position: fixed;
  inset: 0; /* shorthand for top/right/bottom/left:0 */
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

#main-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Ensure any map container fills the viewport. These rules force
   the Mapbox/hero/map containers to use full viewport height so the
   map will occupy the entire page. */
#main-content,
.page-container,
.home-page.fullscreen-map,
.map-fullscreen,
.hero-map-container,
#hero-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
}

/* Mapbox specific containers - reinforce full height/width */
.mapboxgl-map,
.mapboxgl-canvas,
.mapboxgl-canvas-container {
  width: 100% !important;
  height: 100% !important;
}

/* Override layout helpers that later constrain the map to a fixed max-width
   when the map is rendered inside a centered `.page-container`. This rule
   targets `.page-container` only when it's a descendant of `#main-content`.
   Using !important here ensures it wins over the later generic `.page-container` rules. */
#main-content .page-container {
  max-width: none !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* If a map element is inside a page container, ensure its direct map element
   (#hero-map or .map-fullscreen) fills the entire viewport and sits above
   other layout elements. */
#main-content #hero-map,
#main-content .map-fullscreen,
#main-content .hero-map-container {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100vh !important;
  min-height: 100vh !important;
  z-index: 1 !important;
}

/* App header / glass-dark menu */
.app-header {
  position: absolute;
  top: 18px;
  left: 25px;
  /* Ensure header sits above the search-overlay (which uses z-index:10050)
     so header controls (settings, theme toggle) remain clickable on small screens */
  z-index: 11060;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(8, 10, 12, 0.55);
  color: #fff;
  border-radius: 12px;
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.04);
}

.app-header .app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}

/* Mobile header variant: compact, touch-friendly and centered logo */
@media (max-width: 768px) {
  .app-header.app-header-mobile {
    left: 12px !important;
    right: 12px !important;
    top: 12px !important;
    padding: 8px 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: auto;
  }

  .app-header.app-header-mobile .header-left,
  .app-header.app-header-mobile .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .app-header.app-header-mobile .logo {
    margin: 0 8px;
    /* Larger, responsive logo on mobile for improved visibility */
    font-size: clamp(1.6rem, 6vw, 2.4rem);
    /* Slightly increased weight on mobile for visibility */
    font-weight: 900;
  }

  .app-header.app-header-mobile .timetable-btn,
  .app-header.app-header-mobile .settings-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.03);
    box-shadow: none;
    font-size: 16px;
    padding: 0;
  }

  .app-header.app-header-mobile .timetable-btn:hover,
  .app-header.app-header-mobile .settings-btn:hover {
    transform: translateY(-1px);
  }
}

/* When settings modal is open on index (desktop), force header in foreground */
.app-header.settings-modal-open {
  z-index: 12010 !important;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  /* Force fixed positioning to escape any parent stacking context
     and avoid being blurred by backdrop-filter of overlays. */
  position: fixed !important;
  top: 18px !important;
  left: 25px !important;
  right: auto !important;
}
.logo {
  font-family: 'Syne', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 1200;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  line-height: 1.2;
  letter-spacing: 0;
  cursor: pointer;
  transition: transform 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0;
}

/* BC part with orange to green gradient */
.logo-bc {
  background: linear-gradient(90deg,
    #FF6B35 0%,   /* Arancione */
    #F4A261 25%,  /* Arancione chiaro */
    #90BE6D 60%,  /* Verde giallo */
    #43AA8B 100%  /* Verde */
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

/* Blue dot */
.logo-dot {
  color: #00A4EF;
  -webkit-text-fill-color: initial;
  font-weight: 800;
  margin: 0 -0.05em;
}

/* White T */
.logo-t {
  color: #FFFFFF;
  -webkit-text-fill-color: initial;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.logo-transporter {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  -webkit-text-fill-color: initial;
  color: var(--text-light);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

.logo:hover {
  transform: scale(1.05);
}

/* Logo link: no underline and accessible focus style */
.logo-link {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
}
.logo-link:hover,
.logo-link:active {
  text-decoration: none;
}
.logo-link:focus {
  outline: 3px solid rgba(66,153,225,0.6);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Hidden mobile header for fullscreen modal */
.app-header-hidden-mobile {
  display: none !important;
}

/* Download App Button - Positioned outside header box */
.download-app-btn {
  position: absolute;
  top: 18px;
  right: 25px;
  /* Keep aligned with header stacking context */
  z-index: 11060;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(8, 10, 12, 0.55);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.3s ease;
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
  white-space: nowrap;
}

.download-app-btn:hover {
  background: rgba(8, 10, 12, 0.65);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  transform: translateY(-2px);
  box-shadow: 0 10px 35px rgba(0,0,0,0.65);
}

/* Trip stopovers timeline styles */
.trip-stopovers {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 72px; /* space for vertical line and markers */
}

.trip-stopover {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border-radius: 6px;
}

/* Vertical timeline line (spans the whole stopovers container) */
.trip-stopovers::before {
  content: '';
  position: absolute;
  left: 36px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: linear-gradient(to bottom, var(--border-color), rgba(0,0,0,0.06));
  border-radius: 2px;
  z-index: 0;
}

/* Circle marker for each stop */
.trip-stopover::after {
  content: '';
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 3px solid var(--border-color);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  z-index: 2;
}

/* Past stops: smaller/filled */
.trip-stopover.stop-past::after {
  background: var(--text-muted);
  border-color: var(--text-muted);
}

/* Current stop: highlighted circle */
.trip-stopover.stop-current::after {
  background: var(--accent-color);
  border-color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  width: 16px;
  height: 16px;
}

/* Future stops: outline style */
.trip-stopover.stop-future::after {
  background: transparent;
  border-color: var(--border-color);
}

/* Train progress marker (inserted inside the current stop element by JS) */
.trip-stopover .trainposition {
  position: absolute;
  left: 12px; /* align roughly on the vertical line */
  top: var(--progress-px, 0px);
  transform: translateY(-50%);
  width: 28px;
  height: auto;
  z-index: 3;
  transition: top 0.25s ease-out, transform 0.25s ease-out;
}

/* Styling for stop time/info blocks to keep layout tidy */
.trip-stop-time {
  min-width: 96px;
  max-width: 120px;
  color: var(--text-muted);
  font-weight: var(--font-medium);
}

.trip-stop-info {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trip-stop-name {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.trip-platform {
  color: var(--text-muted);
  font-size: 0.9rem;
}


.download-app-btn:active {
  background: rgba(8, 10, 12, 0.45);
  transform: translateY(0);
  box-shadow: 0 6px 25px rgba(0,0,0,0.45);
}

.download-app-btn i {
  font-size: 16px;
  transition: transform 0.3s ease;
}

.download-app-btn:hover i {
  transform: translateY(2px);
}

.download-text {
  font-size: 14px;
  font-weight: 600;
}

/* Responsive: hide text on small screens */
@media (max-width: 768px) {
  .download-text {
    display: none;
  }

  .download-app-btn {
    padding: 10px 12px;
    min-width: 40px;
    justify-content: center;
  }
}

.main-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Header controls wrapper */
.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.9);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.settings-btn:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.settings-btn:active {
  transform: translateY(0);
}

.settings-btn i {
  transition: transform 0.3s ease;
}

.settings-btn:hover i {
  transform: rotate(45deg);
}

/* Light theme settings button - black icon */
body[data-theme="light"] .settings-btn {
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.7);
}

body[data-theme="light"] .settings-btn:hover {
  background: rgba(0,0,0,0.08);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Timetable button mirrors settings-btn but has right margin */
.timetable-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.9);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  margin-left: 0.75rem; /* extra spacing to the right */
}

.timetable-btn:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.timetable-btn:active {
  transform: translateY(0);
}

.timetable-btn i {
  transition: transform 0.3s ease;
}

.timetable-btn:hover i {
  transform: rotate(45deg);
}

/* Light theme timetable button - black icon */
body[data-theme="light"] .timetable-btn {
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.7);
}

body[data-theme="light"] .timetable-btn:hover {
  background: rgba(0,0,0,0.08);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Settings Modal - Modern Glassmorphism Design */
.settings-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9998;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.settings-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 9999;
  width: 90%;
  max-width: 420px;
  opacity: 1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.settings-modal.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  pointer-events: none;
}

.settings-modal-content {
  background: rgba(18, 20, 24, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  overflow: hidden;
}

.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.settings-modal-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-modal-title i {
  font-size: 1.1rem;
  color: var(--primary-color);
}

.settings-modal-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.settings-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
  transform: scale(1.05);
}

.settings-modal-body {
  padding: 24px;
  max-height: calc(80vh - 80px); /* Leave space for header */
  overflow-y: auto; /* Enable vertical scrolling */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Hide scrollbar but keep functionality */
.settings-modal-body::-webkit-scrollbar {
  width: 4px;
}

.settings-modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.settings-modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.settings-modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-section-label i {
  color: var(--primary-color);
  font-size: 1rem;
}

.settings-language-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.language-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.language-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateX(4px);
}

.language-option input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.language-option input[type="radio"]:checked {
  border-color: var(--primary-color);
  background: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.15);
}

.language-option input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

.language-flag {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.language-name {
  font-size: 1rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  flex: 1;
}

.language-option input[type="radio"]:checked ~ .language-name {
  color: rgba(255, 255, 255, 1);
  font-weight: 600;
}

/* Light theme adjustments for modal */
body[data-theme="light"] .settings-modal-content {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .settings-modal-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.02);
}

body[data-theme="light"] .settings-modal-title {
  color: rgba(0, 0, 0, 0.9);
}

body[data-theme="light"] .settings-modal-close {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.7);
}

body[data-theme="light"] .settings-modal-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.95);
}

body[data-theme="light"] .settings-section-label {
  color: rgba(0, 0, 0, 0.85);
}

body[data-theme="light"] .language-option {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] .language-option:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.12);
}

body[data-theme="light"] .language-option input[type="radio"] {
  border-color: rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] .language-name {
  color: rgba(0, 0, 0, 0.85);
}

body[data-theme="light"] .language-option input[type="radio"]:checked ~ .language-name {
  color: rgba(0, 0, 0, 0.95);
}

/* Theme options styling */
.settings-theme-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.theme-option input[type="radio"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.theme-option input[type="radio"]:checked {
  border-color: var(--accent-color, #0070e0);
  background: var(--accent-color, #0070e0);
}

.theme-option input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

/* Cache options styling */
.settings-cache-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.clear-cache-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255, 100, 100, 0.1);
  border: 1px solid rgba(255, 100, 100, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #ff6464;
  font-size: 1rem;
  font-weight: 500;
}

.clear-cache-btn:hover {
  background: rgba(255, 100, 100, 0.15);
  border-color: rgba(255, 100, 100, 0.3);
  transform: translateY(-1px);
}

/* Mobile fullscreen modal styles */
.settings-modal-mobile {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  transform: none !important;
  border-radius: 0 !important;
  z-index: 10000;
}

.settings-modal-mobile .settings-modal-content {
  height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.settings-modal-mobile .settings-modal-header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

.settings-modal-mobile .settings-modal-back {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.settings-modal-mobile .settings-modal-back:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
}

.settings-modal-mobile .settings-modal-title {
  margin: 0 auto;
  font-size: 1.1rem;
}

.settings-modal-mobile .settings-modal-close {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.settings-modal-mobile .settings-modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  max-height: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .settings-modal:not(.settings-modal-mobile) {
    width: 95vw;
    max-width: none;
  }

  .settings-modal:not(.settings-modal-mobile) .settings-modal-body {
    max-height: calc(85vh - 80px);
  }
}

@media (min-width: 769px) {
  .settings-modal:not(.settings-modal-mobile) {
    width: 480px;
    max-width: 480px;
  }
}

.clear-cache-btn i {
  font-size: 1.1rem;
}

.theme-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.theme-name {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  transition: color 0.2s ease;
}

.theme-option input[type="radio"]:checked ~ .theme-name {
  color: white;
  font-weight: 600;
}

/* Light theme overrides for theme options */
body[data-theme="light"] .theme-option {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .theme-option:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .theme-option input[type="radio"] {
  border-color: rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] .theme-name {
  color: rgba(0, 0, 0, 0.85);
}

body[data-theme="light"] .theme-option input[type="radio"]:checked ~ .theme-name {
  color: rgba(0, 0, 0, 0.95);
}

/* Remove old popover styles (no longer needed) */
.settings-popover { display: none !important; }



.menu-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}

.menu-btn:hover {
  background: rgba(255,255,255,0.10);
  transform: translateY(-1px);
}

/* Optional: make the search-panel blend with the dark glass header when visible */
.search-overlay .search-panel {
  background: rgba(10,12,14,0.6);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.04);
  backdrop-filter: blur(8px) saturate(120%);
}

.search-overlay .panel-header {
  background: transparent;
  color: #fff;
}

.search-overlay .panel-body {
  color: #e6eefc;
}

.search-overlay .search-input-container .search-input {
  color: #fff;
  border: 1px solid rgba(255,255,255,0.08);
}

.search-overlay .search-btn {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: var(--text-light);
}

/* Fullscreen Map Home Page */
.page-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.home-page.fullscreen-map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.map-fullscreen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  z-index: 1;
}

/*
=====================================================
--- STILI PANNELLO DI RICERCA PROFESSIONALE ---
=====================================================
*/

/* Overlay di Ricerca - Posizionamento */
.search-overlay {
  position: absolute;
  z-index: 10050; /* ensure overlay is above map controls */
  pointer-events: none;
}

/* NUOVO: Barra di ricerca centrata in alto */
.search-overlay.top-left {
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  right: auto;
  width: auto;
  max-width: calc(100vw - 40px);
}

/* Make sure the panel inside overlay is positioned so it stacks above map */
.search-overlay .search-panel {
  position: relative;
}

.search-overlay * {
  pointer-events: auto;
}

/* Visibilità (collegata a .menu-open) */
.search-overlay {
  display: block; /* Sempre visibile */
  opacity: 1;
  transition: opacity 200ms ease, transform 200ms ease;
}

/* --- Pannello Principale - Stile Barra Compatta con Menu a Tendina --- 
Nuovo design: barra orizzontale centrata in alto che si espande verso il basso.
*/
.search-panel {
  /* Stile "Dark Glass" come l'app-header */
  background: rgba(10, 12, 14, 0.85); /* Sfondo più opaco per leggibilità */
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  
  /* Layout barra orizzontale */
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
  overflow: visible; /* Permette al menu di espandersi */
  
  /* Dimensioni barra compatta */
  width: clamp(600px, 70vw, 900px); /* Barra orizzontale larga */
  min-height: 60px; /* Altezza barra compatta */
  
  /* Layout flessibile */
  display: flex;
  flex-direction: column;
  
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: top center;
}

/* Stato collassato - mostra solo la barra di ricerca SENZA sfondo blur */
.search-panel.collapsed {
  min-height: auto;
  max-height: auto;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: none;
  box-shadow: none;
}

/* Stato espanso - mostra il menu a tendina */
.search-panel:not(.collapsed) {
  max-height: 80vh; /* Può espandersi fino all'80% dell'altezza */
}

/* Supporto per schermi molto larghi (> 1920px) */
@media (min-width: 1920px) {
  .search-panel {
    width: clamp(700px, 60vw, 1100px);
  }
}

/* Stili per pannello collassato - rimosso duplicato */
.search-panel.collapsed .panel-body {
  opacity: 0;
  transform: scaleY(0);
  transform-origin: top;
  pointer-events: none;
  height: 0;
  padding: 0;
  overflow: hidden;
  margin-top: 0;
}

/* Header del Pannello - Layout Orizzontale Compatto */
.panel-header {
  display: flex;
  justify-content: center; /* centra la barra di ricerca */
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  min-height: auto;
  flex-shrink: 0;
  backdrop-filter: none;
  border: none;
  position: relative; /* per posizionare la freccia */
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.panel-title i {
  font-size: 1.2rem;
}

.panel-toggle {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  cursor: pointer;
  padding: var(--spacing-xs);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-md);
}

.panel-toggle:hover {
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.1);
}

/* Centra l'input di ricerca e limita la larghezza */
.search-input-container {
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  width: 100%;
  max-width: 720px;
}

.search-input {
  width: 100%;
  max-width: 520px;
  min-width: 140px;
}

/* Posiziona la freccia di toggle a destra, centrata verticalmente */
.panel-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.search-panel.collapsed .panel-toggle {
  transform: rotate(180deg);
}

/* Corpo del Pannello - Menu a Tendina */
.panel-body {
  padding: 0 var(--spacing-lg) var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: #e6eefc;
  overflow-y: auto;
  overflow-x: hidden;
  
  /* Altezza adattiva */
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(80vh - 80px); /* Sottrae altezza header */
  
  /* Animazione tendina */
  transform-origin: top;
  transform: scaleY(1);
  opacity: 1;
}

/* Scrollbar personalizzata per panel-body */
.panel-body::-webkit-scrollbar {
  width: 8px;
}

.panel-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
}

.panel-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.panel-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --- Selettori Modalità (Treno/Stazione, Partenza/Arrivo) --- 
Stile professionale con supporto per icone.
Layout orizzontale nella barra compatta.
*/
.mode-toggle,
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-full);
  padding: 4px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Layout orizzontale per header compatto */
.panel-header .controls-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  flex: 1;
  margin-left: var(--spacing-lg);
}

.panel-header .mode-toggle,
.panel-header .type-toggle {
  flex: 0 0 auto;
  min-width: 180px;
}

/* "Pillola" scorrevole per la selezione attiva */
.mode-toggle::before,
.type-toggle::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  border-radius: var(--radius-full);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

/* Logica di movimento della pillola */
.mode-toggle.train-active::before,
.type-toggle.arrival-active::before {
  transform: translateX(100%);
}

/* ============================================
   THEME-AWARE STYLING: Search Panel Light Theme
   ============================================
   All search panel elements adapt to body[data-theme="light"]
   App.setTheme('light') triggers this via data-theme attribute.
*/

/* === PANEL BACKGROUNDS & CONTAINERS === */
body[data-theme="light"] .search-panel,
body[data-theme="light"] .search-overlay .search-panel {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
}

body[data-theme="light"] .search-panel.collapsed {
  border-color: rgba(0,0,0,0.06);
}

/* Ensure collapsed panel in light theme behaves like dark: compact, no white "pill" */
body[data-theme="light"] .search-panel.collapsed {
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* === PANEL HEADER === */
body[data-theme="light"] .panel-header {
  color: var(--text-primary);
  background: transparent;
}

/* Light theme: make search icon, input text and toggle arrow darker to contrast the light frosted background */
body[data-theme="light"] .search-input-container .search-icon {
  color: rgba(26,32,44,0.55);
}

body[data-theme="light"] .search-input-container .search-input {
  color: var(--text-primary);
}

body[data-theme="light"] .panel-toggle {
  color: rgba(26,32,44,0.7);
}

body[data-theme="light"] .panel-toggle:hover {
  color: var(--text-primary);
  background: rgba(15, 23, 42, 0.04);
}

/* Ensure search button stays visible on light theme (primary gradient) */
body[data-theme="light"] .search-input-container .search-btn {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
}

/* Dark theme explicit rules to ensure good contrast */
body[data-theme="dark"] .search-input-container .search-icon,
body[data-theme="dark"] .panel-toggle {
  color: rgba(255,255,255,0.78);
}

body[data-theme="dark"] .panel-toggle:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text-light);
}

body[data-theme="light"] .panel-title {
  color: var(--text-primary);
}

body[data-theme="light"] .panel-title i {
  color: var(--primary-color);
}

body[data-theme="light"] .panel-toggle {
  color: rgba(0,0,0,0.65);
  background: transparent;
  border: none;
}

body[data-theme="light"] .panel-toggle:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text-primary);
}

/* === PANEL BODY === */
body[data-theme="light"] .panel-body {
  color: var(--text-primary);
  background: transparent;
}

/* Scrollbar styling for light theme */
body[data-theme="light"] .panel-body::-webkit-scrollbar {
  width: 8px;
}

body[data-theme="light"] .panel-body::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.02);
  border-radius: var(--radius-sm);
}

body[data-theme="light"] .panel-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: var(--radius-sm);
}

body[data-theme="light"] .panel-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.25);
}

/* === MODE & TYPE TOGGLES === */
body[data-theme="light"] .mode-toggle,
body[data-theme="light"] .type-toggle {
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.08);
}

body[data-theme="light"] .mode-toggle::before,
body[data-theme="light"] .type-toggle::before {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}

body[data-theme="light"] .mode-btn,
body[data-theme="light"] .type-btn {
  color: rgba(0,0,0,0.65);
  background: transparent;
  border: none;
}

body[data-theme="light"] .mode-btn.active,
body[data-theme="light"] .type-btn.active {
  color: var(--text-light);
}

body[data-theme="light"] .mode-btn i,
body[data-theme="light"] .type-btn i {
  color: inherit;
}

body[data-theme="light"] .mode-btn:hover,
body[data-theme="light"] .type-btn:hover {
  color: var(--text-primary);
}

/* === SEARCH INPUT & ICON === */
body[data-theme="light"] .search-input-container {
  background: transparent;
}

body[data-theme="light"] .search-input-container .search-icon {
  color: rgba(26,32,44,0.55);
}

body[data-theme="light"] .search-input-container .search-input {
  /* Sfondo OPACO quando non è in focus - tema light */
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  color: var(--text-primary);
  /* No visible borders */
  border: none;
  padding: var(--spacing-sm) 50px var(--spacing-sm) 40px;
}

body[data-theme="light"] .search-input-container .search-input::placeholder {
  color: rgba(26,32,44,0.55);
}

body[data-theme="light"] .search-input-container .search-input:focus {
  outline: none;
  /* Quando è in FOCUS, diventa leggermente più trasparente con effetto frosted glass */
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

/* === SEARCH BUTTON === */
body[data-theme="light"] .search-input-container .search-btn {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(102,126,234,0.15);
}

body[data-theme="light"] .search-input-container .search-btn:hover {
  box-shadow: 0 6px 16px rgba(102,126,234,0.25);
}

body[data-theme="light"] .search-input-container .search-btn i {
  color: #fff;
}

/* === RECENT SEARCHES === */
body[data-theme="light"] .recent-searches {
  background: transparent;
}

body[data-theme="light"] .recent-searches-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(0,0,0,0.55);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

body[data-theme="light"] .recent-search-item {
  background: rgba(0,0,0,0.04);
  color: rgba(0,0,0,0.65);
  border: 1px solid rgba(0,0,0,0.08);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
}

body[data-theme="light"] .recent-search-item:hover {
  background: rgba(0,0,0,0.08);
  color: var(--text-primary);
  border-color: rgba(0,0,0,0.12);
}

/* === SEARCH RESULTS PANEL === */
body[data-theme="light"] .search-results {
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  max-height: 400px;
}

body[data-theme="light"] .search-results-panel {
  background: rgba(255,255,255,0.98);
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body[data-theme="light"] .search-results-panel.visible {
  opacity: 1;
  pointer-events: auto;
}

/* === RESULT ITEM === */
body[data-theme="light"] .result-item {
  padding: var(--spacing-md);
  color: var(--text-primary);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

body[data-theme="light"] .result-item:hover {
  background: rgba(102,126,234,0.08);
}

body[data-theme="light"] .result-item:last-child {
  border-bottom: none;
}

/* === RESULTS HEADER === */
body[data-theme="light"] .results-header {
  background: transparent;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  color: rgba(0,0,0,0.55);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

body[data-theme="light"] .result-count {
  color: rgba(0,0,0,0.55);
}

body[data-theme="light"] .results-header h4 {
  display: none;
}

body[data-theme="light"] .results-header p {
  display: none;
}

/* === RESULTS LIST & SCROLLING === */
body[data-theme="light"] .results-list {
  scrollbar-color: rgba(102,126,234,0.3) rgba(0,0,0,0.02);
  background: transparent;
}

body[data-theme="light"] .results-list::before {
  background: linear-gradient(to bottom, rgba(255,255,255,0.98), transparent);
}

body[data-theme="light"] .results-list::after {
  background: linear-gradient(to top, rgba(255,255,255,0.98), transparent);
}

/* === TRAINS TABLE THEME LIGHT === */
body[data-theme="light"] .trains-results-container {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

body[data-theme="light"] .trains-table {
  background: rgba(255, 255, 255, 0.95);
}

body[data-theme="light"] .trains-table thead {
  background: rgba(255, 255, 255, 0.75);
  /* blur the underlying content for a frosted glass header effect */
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  transition: background-color 220ms ease, backdrop-filter 220ms ease;
}

body[data-theme="light"] .trains-table th {
  color: rgba(0, 0, 0, 0.7);
  border-bottom: 2px solid rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] .trains-table td {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

body[data-theme="light"] .trains-table tbody tr:hover {
  background: rgba(102, 126, 234, 0.15);
  box-shadow: inset 0 0 8px rgba(102, 126, 234, 0.3);
}

body[data-theme="light"] .trains-table tbody tr.delayed {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.25) 0%, rgba(239, 68, 68, 0.35) 100%);
  border-left-color: #dc2626;
  border-left-width: 5px;
}

/* Early row - green highlight for trains that are early (anticipo) */
body[data-theme="light"] .trains-table tbody tr.early {
  background: linear-gradient(90deg, rgba(34,197,94,0.10) 0%, rgba(34,197,94,0.14) 100%);
  border-left-color: #16a34a; /* green-600 */
  border-left-width: 5px;
}
body[data-theme="light"] .trains-table tbody tr.early:hover {
  background: linear-gradient(90deg, rgba(34,197,94,0.14) 0%, rgba(34,197,94,0.18) 100%);
}
body[data-theme="light"] .trains-table td.early {
  color: #16a34a;
}

body[data-theme="light"] .trains-table tbody tr.delayed:hover {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.35) 0%, rgba(239, 68, 68, 0.45) 100%);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.5), inset 0 0 8px rgba(239, 68, 68, 0.3);
}

body[data-theme="light"] .trains-table td.delayed {
  color: #dc2626;
}

/* Numero treno mobile - tema light */
body[data-theme="light"] .train-number-mobile {
  color: #1a202c; /* Colore scuro per buona leggibilità */
}

body[data-theme="light"] .trains-table-wrapper::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.02);
}

body[data-theme="light"] .trains-table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
}

body[data-theme="light"] .trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

body[data-theme="light"] .timetable-trains-table-wrapper::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.02);
}

body[data-theme="light"] .timetable-trains-table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
}

body[data-theme="light"] .timetable-trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

/* === TRAINS TABLE THEME DARK === */
body[data-theme="dark"] .trains-results-container {
  background: rgba(2,6,23,0.65);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 6px 18px rgba(0,0,0,0.6);
}

body[data-theme="dark"] .trains-table {
  background: rgba(6,10,15,0.6);
}

body[data-theme="dark"] .trains-table thead {
  background: rgba(12,16,24,0.55);
  /* frosted glass blur for dark theme */
  backdrop-filter: blur(6px) saturate(110%);
  -webkit-backdrop-filter: blur(6px) saturate(110%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.6);
  transition: background-color 220ms ease, backdrop-filter 220ms ease;
}

body[data-theme="dark"] .trains-table th {
  color: rgba(255, 255, 255, 0.72);
  border-bottom: 2px solid rgba(255,255,255,0.04);
}

body[data-theme="dark"] .trains-table td {
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.92); /* stronger text for readability on dark background */
  font-size: 0.95rem;
  line-height: 1.25;
  font-weight: 500;
}

body[data-theme="dark"] .trains-table tbody tr:hover {
  background: rgba(102, 126, 234, 0.25);
  box-shadow: inset 0 0 8px rgba(102, 126, 234, 0.4);
}

body[data-theme="dark"] .trains-table tbody tr.delayed {
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.30) 0%, rgba(220, 38, 38, 0.40) 100%);
  border-left-color: #ff6b6b;
  border-left-width: 5px;
}

body[data-theme="dark"] .trains-table tbody tr.delayed:hover {
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.40) 0%, rgba(220, 38, 38, 0.50) 100%);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.6), inset 0 0 8px rgba(220, 38, 38, 0.4);
}

body[data-theme="dark"] .trains-table td.delayed {
  color: #ff7b7b;
}

/* Numero treno mobile - tema dark */
body[data-theme="dark"] .train-number-mobile {
  color: #e2e8f0; /* Colore chiaro per buona leggibilità */
}

body[data-theme="dark"] .trains-table-wrapper::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.12);
}

body[data-theme="dark"] .trains-table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.06);
}

body[data-theme="dark"] .trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.12);
}

body[data-theme="dark"] .timetable-trains-table-wrapper::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.12);
}

body[data-theme="dark"] .timetable-trains-table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.06);
}

body[data-theme="dark"] .timetable-trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.12);
}

/* Badge adjustments for dark theme */
body[data-theme="dark"] .train-category-badge {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.88);
}

/* Mobile: Hide table headers */
@media (max-width: 768px) {
  .trains-table thead {
    display: none;
  }
  
  .results-table thead {
    display: none;
  }
}


/* Bottoni delle modalità (con spazio per icone) */
.mode-btn,
.type-btn {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  z-index: 2;
  position: relative;
  white-space: nowrap;
}

/* Stile per le icone (es. <i class="fas fa-train"></i>) */
.mode-btn i,
.type-btn i {
  font-size: 0.95rem;
  line-height: 1;
  width: 1.1em;
  text-align: center;
  transition: transform 0.3s ease;
}

/* Stile attivo e hover */
.mode-btn.active,
.type-btn.active {
  color: var(--text-light); /* Testo bianco e nitido */
}

.mode-btn:not(.active):hover,
.type-btn:not(.active):hover {
  color: var(--text-light); /* Effetto hover per bottoni non attivi */
}

/* --- Input di Ricerca - Layout Orizzontale nella Barra --- 
*/
.search-input-container {
  position: relative;
  flex: 1; /* Prende tutto lo spazio disponibile */
  max-width: 400px; /* Limita la larghezza massima */
}

.search-input-container .search-icon {
  position: absolute;
  top: 50%;
  left: var(--spacing-md);
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 1rem;
  pointer-events: none;
}

.search-input-container .search-input {
  width: 100%;
  padding: var(--spacing-sm) 50px var(--spacing-sm) 40px; /* Aggiunto padding-right per il pulsante */
  /* Sfondo OPACO (non trasparente) quando non è in focus - tema dark */
  background: rgba(15, 23, 35, 0.95); /* Quasi completamente opaco */
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
  color: #fff;
  border: 2px solid;
  border-color: black;
  /* No visual border; keep original rounded shape and spacing */
  border: none;
  border-radius: var(--radius-full); /* Più arrotondato per stile barra */
  font-size: 0.95rem;
  transition: all 0.2s ease;
  height: 42px; /* Altezza fissa compatta */
  min-width: 260px; /* ensure visible on wide layouts */
  z-index: 1; /* below button */
}

.search-input-container .search-input::placeholder {
  color: rgba(255, 255, 255, 0.78);
}

.search-input-container .search-input:focus {
  outline: none;
  /* Quando è in FOCUS, diventa leggermente più trasparente con effetto blur */
  background: rgba(2, 6, 10, 0.75);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Bottone di ricerca - visibile nella barra */
.search-input-container .search-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  border: none;
  border-radius: var(--radius-full);
  padding: var(--spacing-xs) var(--spacing-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  height: 34px;
  width: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  z-index: 2; /* above input field */
}

.search-input-container .search-btn:hover {
  transform: translateY(-50%) scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.search-input-container .search-btn i {
  font-size: 0.9rem;
}

/* --- Ricerche Recenti (nel Menu a Tendina) --- 
*/
.recent-searches {
  margin-top: var(--spacing-sm);
}

.recent-searches-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6); /* Colore secondario chiaro */
  margin-bottom: var(--spacing-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recent-searches-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
}

.recent-search-item {
  background: rgba(255, 255, 255, 0.08); /* Sfondo scuro e traslucido */
  color: rgba(255, 255, 255, 0.6);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.recent-search-item:hover {
  background: rgba(255, 255, 255, 0.15); /* Hover più luminoso */
  color: var(--text-light);
}

/* --- Pannello Risultati di Ricerca (Stile "Dark Glass") --- 
*/
.search-results {
  margin-top: var(--spacing-md);
  background: rgba(26, 26, 46, 0.9); /* Sfondo molto scuro */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1); /* Bordo vetro */
  overflow-y: auto; /* Abilita lo scroll verticale */
  max-height: 400px; /* Altezza massima per lo scroll */
  display: flex;
  flex-direction: column;
}

.search-results-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  /* Stile "Dark Glass" per i risultati */
  background: rgba(26, 26, 46, 0.9); /* Sfondo molto scuro */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1); /* Bordo vetro */
  z-index: 10;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.search-results-panel.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.result-item {
  padding: var(--spacing-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* Separatore scuro */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
}

.result-item:last-child {
  border-bottom: none;
}

.result-item:hover {
  /* Hover che usa un bagliore primario */
  background: rgba(102, 126, 234, 0.15);
}

.results-header {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-count {
  display: inline-block;
  color: rgba(255, 255, 255, 0.5);
}

.results-header h4 {
  display: none;
}

.results-header p {
  display: none;
}

.results-list {
  max-height: 320px; /* Altezza massima lista scrollabile */
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(102, 126, 234, 0.5) rgba(255, 255, 255, 0.05); /* Firefox */
  scroll-behavior: smooth; /* Scroll fluido */
  position: relative;
}

/* Indicatore scroll - ombra sfumata in alto */
.results-list::before {
  content: '';
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(to bottom, rgba(26, 26, 46, 0.9), transparent);
  pointer-events: none;
  z-index: 1;
  display: block;
}

/* Indicatore scroll - ombra sfumata in basso */
.results-list::after {
  content: '';
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(to top, rgba(26, 26, 46, 0.9), transparent);
  pointer-events: none;
  z-index: 1;
  display: block;
}

/* Scrollbar personalizzata per WebKit (Chrome, Safari, Edge) */
.results-list::-webkit-scrollbar {
  width: 8px;
}

.results-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  margin: 4px 0; /* Margine sopra e sotto */
}

.results-list::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.5);
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
  border: 2px solid transparent;
  background-clip: content-box;
}

.results-list::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.7);
  background-clip: content-box;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-info strong {
  display: block;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
}

.result-direction {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 2px;
}

.result-operator {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
}

.result-button {
  flex-shrink: 0;
  background: rgba(102, 126, 234, 0.2);
  border: 1px solid rgba(102, 126, 234, 0.3);
  color: var(--text-light);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
}

.result-button:hover {
  background: rgba(102, 126, 234, 0.3);
  border-color: rgba(102, 126, 234, 0.5);
  transform: scale(1.05);
}

.result-button i {
  font-size: 1rem;
}

.result-item-name {
  font-weight: 600;
  color: var(--text-light); /* Testo risultato chiaro */
}

.result-item-details {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6); /* Dettagli chiari ma secondari */
}


/* Stats Overlay - Bottom Right */
.stats-overlay {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.stats-overlay.bottom-right {
  bottom: 80px;
  right: 20px;
}

.stats-overlay * {
  pointer-events: auto;
}

.stats-panel {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  padding: var(--spacing-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 200px;
  overflow: hidden;
}

.stats-panel.collapsed {
  max-height: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.stats-content {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.stat-item-inline {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.stat-item-inline .stat-icon {
  font-size: 1.5rem;
}

.stat-item-inline .stat-info {
  display: flex;
  flex-direction: column;
}

.stat-item-inline .stat-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary-color);
  line-height: 1.2;
}

.stat-item-inline .stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Mapbox Overrides */
.mapboxgl-canvas {
  outline: none;
  width: 100% !important;
  height: 100% !important;
}

.mapboxgl-canvas-container {
  width: 100% !important;
  height: 100% !important;
}

.mapboxgl-map {
  width: 100% !important;
  height: 100% !important;
}

.mapboxgl-ctrl-attrib {
  background: rgba(255, 255, 255, 0.8) !important;
  font-size: 0.7rem !important;
}

.mapboxgl-popup-content {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0;
}

.mapboxgl-popup-close-button {
  font-size: 1.5rem;
  padding: var(--spacing-xs);
  color: var(--text-secondary);
}

.mapboxgl-popup-close-button:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Main Content */
#main-content {
  flex: 1;
  padding-bottom: 80px; /* Space for bottom nav */
  min-height: calc(100vh - 80px);
}

/* Page Container */
.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

/* Loading */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Material-style circular progress (indeterminate) */
.material-spinner { display:inline-block; width:40px; height:40px; }
.material-circular { animation: rotate 2s linear infinite; width:40px; height:40px; }
.material-path {
  stroke: var(--md-primary);
  stroke-linecap: round;
  animation: dash 1.5s ease-in-out infinite;
  stroke-width: 4;
}

@keyframes rotate {
  100% { transform: rotate(360deg); }
}

@keyframes dash {
  0% { stroke-dasharray: 1, 200; stroke-dashoffset: 0; }
  50% { stroke-dasharray: 100, 200; stroke-dashoffset: -15px; }
  100% { stroke-dasharray: 100, 200; stroke-dashoffset: -125px; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-lg);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  font-weight: var(--font-medium);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-fast);
  gap: var(--spacing-sm);
}

.btn-primary {
  background: var(--primary-color);
  color: var(--text-light);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-success {
  background: var(--success-color);
  color: var(--text-light);
}

.btn-danger {
  background: var(--error-color);
  color: var(--text-light);
}

/* Hero Section */
.hero-section {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  padding: var(--spacing-3xl) var(--spacing-xl);
  text-align: center;
  color: var(--text-light);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  box-shadow: var(--shadow-xl);
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="rgba(255,255,255,0.1)" d="M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,112C672,96,768,96,864,112C960,128,1056,160,1152,160C1248,160,1344,128,1392,112L1440,96L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom;
  background-size: cover;
  opacity: 0.5;
  pointer-events: none;
}

/* Hero with Map */
.hero-with-map {
  position: relative;
  height: 600px;
  padding: 0;
  background: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  overflow: hidden;
}

.hero-with-map::before {
  display: none;
}

.hero-map-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#hero-map {
  width: 100%;
  height: 100%;
}

.map-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.95) 0%, 
    rgba(102, 126, 234, 0.8) 50%,
    rgba(102, 126, 234, 0.4) 100%
  );
  backdrop-filter: blur(2px);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl);
  pointer-events: none;
}

.map-overlay .hero-content {
  pointer-events: auto;
  text-align: center;
  color: var(--text-light);
  max-width: 800px;
  margin: 0 auto;
}

.hero-content {
  position: relative;
  z-index: 3;
  max-width: 800px;
  margin: 0 auto;
}

.hero-title {
  font-size: 3.5rem;
  font-weight: 900;
  margin: 0 0 var(--spacing-lg) 0;
  line-height: 1.2;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.02em;
}

.gradient-text {
  background: linear-gradient(135deg, #fff 0%, #e0e7ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1.5rem;
  font-weight: 400;
  margin: 0 0 var(--spacing-2xl) 0;
  opacity: 0.95;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  letter-spacing: 0.01em;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--spacing-lg);
  margin-top: var(--spacing-2xl);
}

.stat-item {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.3s ease, background 0.3s ease;
}

.stat-item:hover {
  transform: translateY(-5px);
  background: rgba(255, 255, 255, 0.25);
}

.stat-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: var(--spacing-sm);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  display: block;
  margin-bottom: var(--spacing-xs);
  color: var(--text-light);
}

.stat-label {
  font-size: 0.9rem;
  opacity: 0.9;
  font-weight: 500;
  display: block;
  color: var(--text-light);
}

/* ===================================================================
   TRAIN MARKER STYLES - WebGL Layers with Icon Inside Circle
   =================================================================== 
   
   Train markers are now rendered as Mapbox GL layers:
   - trains-layer: Colored circle background (type: 'circle')
   - trains-icons-layer: White train icon on top (type: 'symbol')
   
   The icon (SVG) is displayed inside the colored circle.
   All styling is done via Mapbox paint/layout properties in map.js.
   No CSS classes needed for the markers themselves.
   
   ================================================================ */

/* Pulse animation keyframes (used for reference/future DOM markers) */
@keyframes pulse-marker {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(255, 255, 255, 0.7);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 10px rgba(255, 255, 255, 0);
  }
}

/* Train Popup Styles */
.train-popup {
  padding: var(--spacing-sm);
  min-width: 200px;
}

.train-popup-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 var(--spacing-sm) 0;
  color: var(--text-primary);
}

.train-popup-direction {
  font-size: 0.9rem;
  margin: 0 0 var(--spacing-md) 0;
  color: var(--text-secondary);
}

.train-popup-button {
  background: var(--primary-color);
  color: var(--text-light);
  border: none;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  width: 100%;
  transition: background 0.2s ease;
}

.train-popup-button:hover {
  background: var(--primary-dark);
}

/* Train Hover Popup Styles */
.train-hover-popup-container .mapboxgl-popup-content {
  padding: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.train-hover-popup {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  min-width: 150px;
}

.train-hover-info {
  flex: 1;
  color: white;
  font-size: 13px;
  line-height: 1.4;
}

.train-hover-info strong {
  font-weight: 600;
  font-size: 14px;
}

.train-hover-info small {
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
}

.train-hover-button {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.train-hover-button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.train-hover-button:active {
  transform: scale(0.95);
}

/* Remove default popup arrow for hover popup */
.train-hover-popup-container .mapboxgl-popup-tip {
  display: none;
}

/* Light theme hover popup */
body[data-theme="light"] .train-hover-popup-container .mapboxgl-popup-content {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .train-hover-info {
  color: #000;
}

body[data-theme="light"] .train-hover-info small {
  color: rgba(0, 0, 0, 0.6);
}

body[data-theme="light"] .train-hover-button {
  background: rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: #000;
}

body[data-theme="light"] .train-hover-button:hover {
  background: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.2);
}

/* Leaflet Popup Adjustments */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.leaflet-popup-tip {
  box-shadow: var(--shadow-md);
}

/* Hero Section */
.hero-section {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: var(--text-light);
  padding: var(--spacing-4xl) 0;
  text-align: center;
}

.hero-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
}

.hero-title {
  font-size: var(--font-4xl);
  font-weight: var(--font-bold);
  margin-bottom: var(--spacing-md);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.hero-subtitle {
  font-size: var(--font-lg);
  opacity: 0.9;
  margin-bottom: var(--spacing-xl);
}

/* Search Section */
.search-section {
  padding: var(--spacing-4xl) 0;
  background: var(--bg-secondary);
}

.search-card {
  max-width: 600px;
  margin: 0 auto;
}

.search-form {
  display: grid;
  gap: var(--spacing-lg);
}

.search-field-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.search-field-group label {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.date-time-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-md);
}

.search-btn {
  width: 100%;
  padding: var(--spacing-lg);
  font-size: var(--font-lg);
  font-weight: var(--font-semibold);
}

/* Search Controls */
.search-controls {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
  box-shadow: var(--shadow-sm);
}

.country-selector {
  margin-bottom: var(--spacing-lg);
}

.country-selector label {
  display: block;
  margin-bottom: var(--spacing-sm);
  font-weight: var(--font-semibold);
}

.country-selector select {
  width: 100%;
  max-width: 200px;
}

/* Search Tabs */
.search-tabs {
  display: flex;
  margin-bottom: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
}

.tab-button {
  background: none;
  border: none;
  padding: var(--spacing-md) var(--spacing-lg);
  cursor: pointer;
  font-weight: var(--font-medium);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: var(--transition-fast);
}

.tab-button.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.tab-button:hover {
  color: var(--primary-color);
}

/* Sections */
.featured-section,
.news-section {
  padding: var(--spacing-4xl) 0;
}

.section-title {
  text-align: center;
  font-size: var(--font-3xl);
  font-weight: var(--font-bold);
  margin-bottom: var(--spacing-2xl);
  color: var(--text-primary);
}

.featured-trains-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--spacing-lg);
  max-width: 1200px;
  margin: 0 auto;
}

.news-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: var(--spacing-lg);
  max-width: 1200px;
  margin: 0 auto;
}

.news-list {
  display: grid;
  gap: var(--spacing-lg);
}

/* Cards */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.news-card {
  cursor: pointer;
  transition: var(--transition-normal);
}

.news-card:hover {
  transform: translateY(-2px);
}

.news-card h3 {
  margin-bottom: var(--spacing-sm);
  color: var(--text-primary);
}

.news-card p {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-md);
  line-height: 1.6;
}

.news-card small {
  color: var(--text-muted);
  font-size: var(--font-sm);
}

/* Form Elements */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--spacing-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: var(--spacing-md);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  transition: var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Modal Enhancements */
.modal-overlay {
  display: none;
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  margin: 0;
  font-size: var(--font-xl);
  font-weight: var(--font-semibold);
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--font-xl);
  cursor: pointer;
  padding: var(--spacing-sm);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--spacing-lg);
}

/* Train Details */
.train-details {
  max-width: 500px;
}

.train-header h2 {
  margin-bottom: var(--spacing-lg);
  color: var(--text-primary);
}

.train-route {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--spacing-lg) 0;
  padding: var(--spacing-lg);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
}

.route-station {
  flex: 1;
  text-align: center;
}

.route-station h3 {
  margin-bottom: var(--spacing-xs);
  font-size: var(--font-lg);
  color: var(--text-primary);
}

.route-station p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.route-arrow {
  font-size: var(--font-xl);
  color: var(--text-muted);
  margin: 0 var(--spacing-md);
}

.delay-info {
  background: #fee;
  color: #c33;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  text-align: center;
  margin: var(--spacing-md) 0;
  font-weight: var(--font-semibold);
}

.train-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-md);
  margin-top: var(--spacing-lg);
}

.train-info p {
  margin: 0;
  padding: var(--spacing-sm);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  text-align: center;
}

/* News Details */
.news-details {
  max-width: 700px;
}

.news-header {
  margin-bottom: var(--spacing-lg);
}

.news-header h2 {
  margin-bottom: var(--spacing-sm);
  color: var(--text-primary);
}

.news-meta {
  display: flex;
  gap: var(--spacing-md);
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.news-content {
  line-height: 1.7;
  color: var(--text-primary);
}

/* Notification Styles */
.notification {
  position: fixed;
  top: var(--spacing-lg);
  right: var(--spacing-lg);
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  z-index: 10000;
  max-width: 400px;
  animation: slideIn 0.3s ease-out;
}

.notification.success {
  border-left: 4px solid var(--success-color);
}

.notification.error {
  border-left: 4px solid var(--error-color);
}

.notification.warning {
  border-left: 4px solid var(--warning-color);
}

.notification.info {
  border-left: 4px solid var(--info-color);
}

.notification-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--spacing-xs);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  margin-left: auto;
}

.notification-close:hover {
  background: var(--bg-tertiary);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .page-container {
    padding: var(--spacing-md);
  }

  .bottom-nav {
    padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom));
  }

  #main-content {
    padding-bottom: 100px;
  }

  .hero-title {
    font-size: var(--font-3xl);
  }

  .search-card {
    margin: 0 var(--spacing-md);
  }

  .date-time-group {
    grid-template-columns: 1fr;
  }

  .featured-trains-container,
  .news-container {
    grid-template-columns: 1fr;
  }

  .train-route {
    flex-direction: column;
    gap: var(--spacing-md);
  }

  .route-arrow {
    transform: rotate(90deg);
  }

  .train-info {
    grid-template-columns: 1fr;
  }

  .notification {
    left: var(--spacing-md);
    right: var(--spacing-md);
    max-width: none;
  }

  /* Search Controls */
  .search-controls {
    padding: var(--spacing-md);
  }

  .search-tabs {
    flex-direction: column;
  }

  .tab-button {
    text-align: center;
  }

  .mode-toggle {
    flex-direction: column;
  }

  .view-toggle {
    flex-direction: column;
    align-items: center;
  }

  .trains-table {
    font-size: var(--font-sm);
  }

  .trains-table th,
  .trains-table td {
    padding: var(--spacing-sm);
  }
}

@media (max-width: 480px) {
  .page-container {
    padding: var(--spacing-sm);
  }

  .trains-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .trains-table th,
  .trains-table td {
    min-width: 120px;
  }
}

/* Trains Page Styles */
.trains-page {
  padding: var(--spacing-lg);
  max-width: 1200px;
  margin: 0 auto;
}

.trains-search-section {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  margin-bottom: var(--spacing-xl);
  box-shadow: var(--shadow-md);
}

.search-controls {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

.search-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.search-label {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 150px;
}

.search-input-group {
  flex: 1;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: var(--spacing-md);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-button {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: var(--text-light);
  border: none;
  padding: var(--spacing-md) var(--spacing-xl);
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-width: 120px;
}

.search-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.search-button:active {
  transform: translateY(0);
}

.toggle-group {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: var(--spacing-xs);
  gap: var(--spacing-xs);
}

.toggle-button {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.toggle-button.active {
  background: var(--primary-color);
  color: var(--text-light);
  box-shadow: var(--shadow-sm);
}

.toggle-button:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.results-section {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  box-shadow: var(--shadow-md);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  flex-wrap: wrap;
  gap: var(--spacing-md);
}

.results-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.view-toggle {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: var(--spacing-xs);
  gap: var(--spacing-xs);
}

.view-toggle-button {
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.view-toggle-button.active {
  background: var(--primary-color);
  color: var(--text-light);
  box-shadow: var(--shadow-sm);
}

.view-toggle-button:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.loading-indicator {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--spacing-3xl);
  color: var(--text-secondary);
}

.loading-spinner {
  /* Container to center the material spinner inside the content area */
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: var(--spacing-3xl);
  box-sizing: border-box;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--spacing-lg);
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.results-table th {
  background: var(--bg-dark);
  color: var(--text-light);
  padding: var(--spacing-md);
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.results-table td {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.results-table tbody tr:hover {
  background: var(--bg-secondary);
}

.results-table tbody tr:last-child td {
  border-bottom: none;
}

.results-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--spacing-lg);
  margin-top: var(--spacing-lg);
}

.result-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.result-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 2px solid var(--primary-color);
}

.train-number {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
}

.station-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
}

.destination {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

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

.card-row .label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.card-row .value {
  font-weight: 500;
  color: var(--text-primary);
}

.no-results,
.error-message {
  text-align: center;
  padding: var(--spacing-3xl);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.error-message {
  color: var(--error-color);
  background: rgba(245, 101, 101, 0.1);
  border-radius: var(--radius-md);
  border: 1px solid rgba(245, 101, 101, 0.2);
}

/* ===== RESPONSIVE BREAKPOINTS FOR SEARCH PANEL ===== 
Sistema di breakpoint multi-livello per adattamento ottimale a tutte le risoluzioni.

BREAKPOINT STRUCTURE:
- 4K+ (>2560px): width 18vw (420-560px), max-height calc(100vh - 60px)
- Desktop Large (1920-2559px): width 22vw (380-480px), max-height calc(100vh - 50px)
- Desktop Standard (1441-1919px): width 26vw (360-440px), max-height calc(100vh - 40px)
- Laptop (1025-1440px): width 30vw (340-400px), max-height calc(100vh - 35px)
- Tablet Landscape (769-1024px): width 40vw (320-380px), max-height calc(100vh - 25px)
- Tablet Portrait (481-768px): width calc(100vw - 20px), max-width 500px
- Mobile Large (375-480px): width calc(100vw - 20px), max-height calc(100vh - 15px)
- Mobile Small (<375px): width calc(100vw - 10px), max-height calc(100vh - 10px)

HEIGHT-BASED:
- Landscape (<600px height): max-height calc(100vh - 10px), compact padding
- Very Short (<500px height): max-height calc(100vh - 5px), minimal padding

ADAPTIVE FEATURES:
✓ Fluid width using clamp() con min/ideal/max
✓ Altezza dinamica basata su viewport height (vh)
✓ Padding e gap adattivi per risoluzioni diverse
✓ Font-size responsive per leggibilità ottimale
✓ Scrollbar personalizzata su tutti i breakpoint
*/

/* Supporto per schermi ad alta risoluzione (4K e oltre - > 2560px) */
@media (min-width: 2560px) {
  .search-panel {
    width: clamp(420px, 18vw, 560px);
    max-height: calc(100vh - 60px);
  }
  
  .panel-body {
    max-height: calc(100vh - 160px);
  }
  
  .panel-title {
    font-size: 1.4rem;
  }
  
  .trains-table th,
  .trains-table td {
    font-size: var(--font-lg);
    padding: var(--spacing-lg) var(--spacing-md);
  }
}

/* Desktop grandi (1920px - 2559px) */
@media (min-width: 1920px) and (max-width: 2559px) {
  .search-panel {
    width: clamp(700px, 60vw, 1100px);
  }
}

/* Desktop standard (1441px - 1919px) */
@media (min-width: 1441px) and (max-width: 1919px) {
  .search-panel {
    width: clamp(650px, 65vw, 1000px);
  }
}

/* Laptop standard (1025px - 1440px) */
@media (min-width: 1025px) and (max-width: 1440px) {
  .search-panel {
    width: clamp(600px, 70vw, 900px);
  }
  
  .panel-body {
    max-height: calc(100vh - 130px);
  }
}

/* Tablet landscape (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .search-panel {
    width: clamp(500px, 80vw, 750px);
  }
  
  .panel-header .controls-row {
    gap: var(--spacing-md);
  }
  
  .mode-btn,
  .type-btn {
    font-size: 0.8rem;
    padding: var(--spacing-xs) var(--spacing-sm);
  }
}

/* Responsive Design for Trains Page */
@media (max-width: 768px) {
  .search-overlay.top-left {
    top: 100px; /* Margine maggiore dal titolo della pagina */
    left: 10px;
    right: 10px;
    transform: none;
    max-width: none;
  }

  .search-panel {
    width: 100%;
    max-height: calc(100vh - 20px);
    border-radius: var(--radius-lg); /* Bordi meno arrotondati su mobile */
  }

  /* Header più compatto su mobile */
  .panel-header {
    flex-direction: row; /* Mantieni orizzontale */
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    gap: var(--spacing-xs);
    min-height: 50px; /* Più basso */
  }

  .panel-title {
    font-size: 0.85rem;
    order: 1;
    flex-shrink: 0;
    margin-right: auto;
  }
  
  .panel-title i {
    font-size: 1rem;
  }

  .panel-toggle {
    position: relative; /* Non più assoluto */
    right: auto;
    top: auto;
    background: rgba(102, 126, 234, 0.25);
    color: #fff;
    font-size: 1.1rem;
    padding: var(--spacing-xs);
    z-index: 10;
    order: 3;
    border-radius: var(--radius-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  
  .panel-toggle:hover {
    background: rgba(102, 126, 234, 0.4);
  }

  /* Input di ricerca più compatto */
  .search-input-container {
    max-width: none;
    flex: 1;
    order: 2;
  }
  
  .search-input-container .search-input {
    height: 36px;
    font-size: 0.85rem;
    padding: var(--spacing-xs) 42px var(--spacing-xs) 32px;
    min-width: 0;
  }
  
  .search-input-container .search-icon {
    font-size: 0.9rem;
    left: var(--spacing-sm);
  }
  
  .search-input-container .search-btn {
    height: 28px;
    width: 28px;
    font-size: 0.75rem;
    padding: 0;
  }

  .panel-header .controls-row {
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-left: 0;
    order: 2;
  }

  .panel-header .mode-toggle,
  .panel-header .type-toggle {
    width: 100%;
    min-width: auto;
  }

  /* Panel body compatto */
  .panel-body {
    max-height: calc(100vh - 200px);
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
  }
  
  /* Toggle più compatti su mobile */
  .mode-toggle,
  .type-toggle {
    padding: 2px;
  }
  
  .mode-btn,
  .type-btn {
    font-size: 0.8rem;
    padding: var(--spacing-xs) var(--spacing-sm);
    gap: 4px;
  }
  
  .mode-btn i,
  .type-btn i {
    font-size: 0.85rem;
  }
  
  /* Assicura transizione fluida del collapse anche su mobile */
  .search-panel {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .search-panel.collapsed {
    max-height: 50px; /* Altezza ridotta per header compatto */
    overflow: hidden;
  }
  
  .search-panel:not(.collapsed) {
    max-height: calc(100vh - 30px);
  }

  .stats-overlay.bottom-right {
    bottom: 70px;
    right: 10px;
    left: 10px;
  }

  .stats-panel {
    width: 100%;
  }

  .stats-content {
    flex-direction: row;
    justify-content: space-around;
  }

  .hero-with-map {
    height: 500px;
  }

  .hero-title {
    font-size: 2.5rem;
  }

  .hero-subtitle {
    font-size: 1.2rem;
  }

  .hero-stats {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }

  .stat-item {
    padding: var(--spacing-md);
  }

  .stat-icon {
    font-size: 2rem;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .trains-page {
    padding: var(--spacing-md);
  }

  .trains-search-section {
    padding: var(--spacing-lg);
  }
}

/* Tablet portrait (481px - 768px) */
@media (max-width: 768px) and (min-width: 481px) {
  .search-panel {
    width: 100%;
  }
}

/* Mobile portrait (max 480px) */
@media (max-width: 480px) {
  .search-panel {
    width: 100%;
    min-height: 60px;
  }
  
  .panel-header {
    padding: var(--spacing-xs);
  }
  
  .panel-title {
    font-size: 0.85rem;
  }
  
  .panel-title i {
    font-size: 1rem;
  }

  .mode-btn,
  .type-btn {
    font-size: 0.75rem;
    padding: var(--spacing-xs);
  }

  .search-input-container .search-input {
    font-size: 0.85rem;
    padding-left: 35px;
  }

  .search-input-container .search-btn {
    font-size: 0.75rem;
    padding: var(--spacing-xs) var(--spacing-sm);
  }
}

/* Mobile molto piccoli (< 375px) */
@media (max-width: 374px) {
  .search-panel {
    width: 100%;
  }
  
  .panel-header .controls-row {
    gap: var(--spacing-xs);
  }
  
  .mode-btn i,
  .type-btn i {
    display: none; /* Nasconde icone per risparmiare spazio */
  }
}

/* Landscape orientation optimization */
@media (max-height: 600px) and (orientation: landscape) {
  .search-panel {
    max-height: calc(100vh - 10px);
  }
  
  .panel-body {
    max-height: calc(100vh - 70px);
    gap: var(--spacing-sm);
  }
  
  .panel-header {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

/* Very short screens (height < 500px) */
@media (max-height: 500px) {
  .search-panel {
    max-height: calc(100vh - 5px);
  }
  
  .panel-body {
    max-height: calc(100vh - 60px);
    padding: 0 var(--spacing-sm) var(--spacing-sm);
  }
  
  .trains-results-header {
    padding: var(--spacing-sm);
  }
  
  .trains-table-wrapper {
    max-height: 40vh;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-label {
    min-width: auto;
    margin-bottom: var(--spacing-xs);
  }

  .search-input-group {
    min-width: auto;
  }

  .toggle-group {
    flex-direction: column;
  }

  .toggle-button {
    width: 100%;
  }

  .results-header {
    flex-direction: column;
    align-items: stretch;
  }

  .view-toggle {
    align-self: center;
  }

  .results-table {
    font-size: 0.9rem;
  }

  .results-table th,
  .results-table td {
    padding: var(--spacing-sm);
    min-width: 80px;
  }

  .results-cards {
    grid-template-columns: 1fr;
  }

  .result-card {
    padding: var(--spacing-md);
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }

  .train-number,
  .station-name {
    font-size: 1.1rem;
  }

  .destination {
    font-size: 0.9rem;
  }
}

/* Mobile molto piccoli - estensione regole */
@media (max-width: 480px) {
  .search-overlay.top-left {
    top: 100px; /* Margine adeguato per schermi piccoli */
    left: 8px;
    right: 8px;
  }
  
  /* Pannello ancora più compatto */
  .search-panel {
    max-height: calc(100vh - 16px);
    border-radius: var(--radius-md);
  }
  
  .panel-header {
    padding: 6px var(--spacing-xs);
    min-height: 44px;
  }
  
  .panel-title {
    font-size: 0.8rem;
  }
  
  .panel-title i {
    font-size: 0.9rem;
  }
  
  .panel-toggle {
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }
  
  .search-input-container .search-input {
    height: 32px;
    font-size: 0.8rem;
    padding: 6px 38px 6px 28px;
  }
  
  .search-input-container .search-icon {
    font-size: 0.85rem;
    left: 8px;
  }
  
  .search-input-container .search-btn {
    height: 24px;
    width: 24px;
    font-size: 0.7rem;
    right: 4px;
  }
  
  .search-panel.collapsed {
    max-height: 44px;
  }
  
  .search-panel:not(.collapsed) {
    max-height: calc(100vh - 20px);
  }
  .search-panel {
    max-height: calc(100vh - 80px);
  }
  
  /* Rimuovi l'override forzato - lascia funzionare il toggle normalmente */

  .panel-body {
    padding: var(--spacing-sm);
    max-height: calc(100vh - 160px);
  }

  .mode-btn,
  .type-btn {
    font-size: 0.8rem;
    padding: var(--spacing-xs) var(--spacing-sm);
  }

  .search-input-container .search-input {
    font-size: 0.9rem;
    padding: var(--spacing-sm);
  }

  .search-btn {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .stats-overlay.bottom-right {
    bottom: 65px;
    right: 5px;
    left: 5px;
  }

  .stats-panel {
    padding: var(--spacing-sm);
  }

  .stat-item-inline .stat-icon {
    font-size: 1.2rem;
  }

  .stat-item-inline .stat-value {
    font-size: 1rem;
  }

  .stat-item-inline .stat-label {
    font-size: 0.65rem;
  }

  .hero-with-map {
    height: 400px;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
  }

  .map-overlay {
    padding: var(--spacing-md);
  }

  .hero-stats {
    margin-top: var(--spacing-lg);
  }

  .stat-item {
    padding: var(--spacing-sm);
  }

  .stat-icon {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-xs);
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .stat-label {
    font-size: 0.8rem;
  }

  .trains-page {
    padding: var(--spacing-sm);
  }

  .trains-search-section {
    padding: var(--spacing-md);
  }

  .results-section {
    padding: var(--spacing-md);
  }

  .results-table {
    font-size: 0.8rem;
  }

  .results-table th,
  .results-table td {
    padding: var(--spacing-xs);
    min-width: 60px;
  }

  .result-card {
    padding: var(--spacing-sm);
  }

  .card-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }

  .card-row .label {
    font-size: 0.8rem;
  }

  .card-row .value {
    font-size: 0.9rem;
  }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--spacing-xs); }
.mb-2 { margin-bottom: var(--spacing-sm); }
.mb-3 { margin-bottom: var(--spacing-md); }
.mb-4 { margin-bottom: var(--spacing-lg); }
.mb-5 { margin-bottom: var(--spacing-xl); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--spacing-xs); }
.mt-2 { margin-top: var(--spacing-sm); }
.mt-3 { margin-top: var(--spacing-md); }
.mt-4 { margin-top: var(--spacing-lg); }
.mt-5 { margin-top: var(--spacing-xl); }

.hidden { display: none !important; }
.flex { display: flex; }
.flex-column { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--spacing-sm); }
.gap-3 { gap: var(--spacing-md); }
.gap-4 { gap: var(--spacing-lg); }

/* Journey Details Panel */
.journey-panel {
    position: fixed;
    left: 20px;
    top: 100px;
    width: 400px;
    max-width: 90vw;
    max-height: calc(100vh - 120px);
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 1001;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: none;
}

.journey-panel:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 24px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.journey-header {
    padding: 20px;
    padding-top: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.journey-header h2 {
    margin: 0 0 10px 0;
    font-size: 20px;
    font-weight: 600;
    color: white;
}

.journey-header p {
    margin: 5px 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

.journey-info {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
}

.info-section {
    margin-bottom: 12px;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-section strong {
    font-weight: 600;
    color: white;
}

.delay-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.delay-badge.on-time {
    background: #4caf50;
    color: white;
}

.delay-badge.delayed {
    background: #ff5722;
    color: white;
}

/* Early: anticipo (green) for Italian trains only */
.delay-badge.early {
  background: #2e7d32; /* green-800 */
  color: white;
}

.stops-timeline {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Custom Scrollbar for Stops Timeline - Dark Theme */
.stops-timeline::-webkit-scrollbar {
    width: 8px;
}

.stops-timeline::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin: 10px 0;
}

.stops-timeline::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    transition: background 0.3s ease;
}

.stops-timeline::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.stops-timeline::-webkit-scrollbar-thumb:active {
    background: rgba(255, 255, 255, 0.5);
}

/* Firefox Scrollbar */
.stops-timeline {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.05);
}

.stop-item {
    display: flex;
    padding: 15px 0;
    position: relative;
    transition: background-color 0.2s ease;
}

.stop-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.stop-item:last-child .stop-line {
    display: none;
}

.stop-timeline {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 15px;
    position: relative;
    width: 20px;
}

.stop-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    border: 3px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    transition: all 0.3s ease;
}

/* Fermate passate: azzurro pieno */
.stop-past .stop-dot {
    background: #4facfe;
    border-color: #4facfe;
}

/* Fermata corrente: azzurro con anello */
.stop-current .stop-dot {
    background: white;
    border-color: #4facfe;
    box-shadow: 0 0 0 4px rgba(79, 172, 254, 0.3);
}

/* Fermate future: grigio */
.stop-future .stop-dot {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.3);
}

.stop-line {
    width: 2px;
    background: linear-gradient(to bottom, 
        #4facfe 0%, 
        #4facfe var(--progress-percentage, 0%), 
        rgba(255, 255, 255, 0.2) var(--progress-percentage, 0%), 
        rgba(255, 255, 255, 0.2) 100%);
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    height: calc(100% + 15px);
    z-index: 1;
    transition: background 0.3s ease;
}

/* Detection dot (orange) shown on the segment where the train was last detected.
   The dot is positioned along the vertical .stop-line using inline top % set by JS. */
.stop-line .stop-detection-dot {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #FF6B00;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 4;
  transition: top 0.25s ease;
}

.stop-details {
    flex: 1;
}

.stop-item:last-child .stop-details {
    margin-bottom: 40px;
}

.stop-name {
    font-weight: 600;
    color: white;
    margin-bottom: 4px;
}

.stop-times {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}

.stop-delay {
    font-size: 12px;
    margin-top: 4px;
}

/* ===================================================================
   MOBILE BOTTOM SHEET - Swipeable Panel for Journey Details
   =================================================================== */

.mobile-bottom-sheet {
    display: none; /* Hidden on desktop, shown on mobile via media query */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(26, 26, 46, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    max-height: 85vh;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    touch-action: pan-y;
}

.mobile-bottom-sheet:not(.hidden) {
    transform: translateY(0);
}

.mobile-bottom-sheet.collapsed {
    transform: translateY(calc(100% - 80px)) !important;
}

.mobile-bottom-sheet.expanded {
    transform: translateY(0) !important;
}

/* Handle Area - Swipe to expand/collapse */
.bottom-sheet-handle-area {
    padding: 12px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
}

.bottom-sheet-handle-area:active {
    cursor: grabbing;
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    transition: background 0.2s ease;
}

.bottom-sheet-handle-area:hover .bottom-sheet-handle {
    background: rgba(255, 255, 255, 0.5);
}

/* Bottom Sheet Header */
.bottom-sheet-header {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
}

.bottom-sheet-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: white;
    flex: 1;
}

.bottom-sheet-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 18px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.bottom-sheet-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Bottom Sheet Content */
.bottom-sheet-content {
    padding: 16px 20px;
    overflow-y: auto;
    max-height: calc(85vh - 140px);
}

.bottom-sheet-content p {
    margin: 8px 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* Custom Scrollbar for Bottom Sheet */
.bottom-sheet-content::-webkit-scrollbar {
    width: 6px;
}

.bottom-sheet-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.bottom-sheet-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.bottom-sheet-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Mobile Responsive: Hide desktop panel, show bottom sheet */
@media (max-width: 768px) {
    .journey-panel {
        display: none !important;
    }

    .mobile-bottom-sheet {
        display: block;
    }
}

/* Light Theme Overrides */
body[data-theme="light"] .app-header {
    background: rgba(255, 255, 255, 0.85);
    color: #000;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    border: 1px solid rgba(0,0,0,0.08);
}

body[data-theme="light"] .logo-t {
    color: #000;
    text-shadow: 0 2px 8px rgba(255,255,255,0.6);
}

body[data-theme="light"] .download-app-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    box-shadow: 0 10px 35px rgba(0,0,0,0.25);
}

body[data-theme="light"] .journey-panel {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .close-btn {
    background: rgba(0, 0, 0, 0.1);
    color: #000;
}

body[data-theme="light"] .close-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .journey-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.03);
}

/* Light Theme - Mobile Bottom Sheet */
body[data-theme="light"] .mobile-bottom-sheet {
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .bottom-sheet-handle {
    background: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .bottom-sheet-handle-area:hover .bottom-sheet-handle {
    background: rgba(0, 0, 0, 0.4);
}

body[data-theme="light"] .bottom-sheet-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.03);
}

body[data-theme="light"] .bottom-sheet-header h2 {
    color: #000;
}

body[data-theme="light"] .bottom-sheet-close-btn {
    background: rgba(0, 0, 0, 0.1);
    color: #000;
}

body[data-theme="light"] .bottom-sheet-close-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .bottom-sheet-content p {
    color: rgba(0, 0, 0, 0.7);
}

body[data-theme="light"] .bottom-sheet-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .bottom-sheet-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

body[data-theme="light"] .journey-header h2 {
    color: #000;
}

body[data-theme="light"] .journey-header p {
    color: rgba(0, 0, 0, 0.7);
}

body[data-theme="light"] .journey-info {
    background: rgba(0, 0, 0, 0.03);
}

body[data-theme="light"] .info-section strong {
    color: #000;
}

body[data-theme="light"] .stop-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] .stop-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

body[data-theme="light"] .stop-line {
    background: rgba(0, 0, 0, 0.15);
}

body[data-theme="light"] .stop-name {
    color: #000;
}

body[data-theme="light"] .stop-times {
    color: rgba(0, 0, 0, 0.6);
}

/* Custom Scrollbar for Stops Timeline - Light Theme */
body[data-theme="light"] .stops-timeline::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

body[data-theme="light"] .stops-timeline::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .stops-timeline::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

body[data-theme="light"] .stops-timeline::-webkit-scrollbar-thumb:active {
    background: rgba(0, 0, 0, 0.5);
}

/* Firefox Scrollbar - Light Theme */
body[data-theme="light"] .stops-timeline {
    scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.05);
}

/* Search suggestions styling */
.search-results {
  position: relative;
  z-index: 60;
}

.suggestions-list {
  display: flex;
  flex-direction: column;
}

.suggestion-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  transition: background-color 0.2s ease;
  gap: 12px;
}

.suggestion-item:hover {
  background: rgba(102, 126, 234, 0.1);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-flag {
  flex-shrink: 0;
}

.suggestion-body {
  flex: 1;
  min-width: 0;
}

.suggestion-name {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 2px;
  word-break: break-word;
}

.suggestion-meta {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
}

.suggestion-code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 4px;
}

.suggestion-select-btn {
  background: rgba(102, 126, 234, 0.2);
  border: 1px solid rgba(102, 126, 234, 0.3);
  color: rgba(255, 255, 255, 0.9);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.suggestion-select-btn:hover {
  background: rgba(102, 126, 234, 0.3);
  border-color: rgba(102, 126, 234, 0.5);
  transform: translateY(-1px);
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease;
  background: rgba(0,0,0,0.25);
}

.suggestion-item:hover {
  background: rgba(0,0,0,0.35);
}

.suggestion-flag {
  font-size: 1.1rem;
  width: 34px;
  text-align: center;
}

.flag-img {
  width: 28px;
  height: 20px;
  object-fit: contain;
  display: block;
}

.flag-emoji {
  font-size: 1.1rem;
}

.suggestion-body {
  display: flex;
  flex-direction: column;
}

.suggestion-name {
  font-weight: 600;
}

/* Small badge for station code inside suggestion name */
.suggestion-code {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 6px;
  font-size: 0.75rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.12);
  color: var(--text-primary);
  font-weight: 600;
}

.suggestion-meta {
  font-size: 0.85rem;
  opacity: 0.8;
}

/* Scrollbar styling for search results */
.search-results::-webkit-scrollbar {
  width: 8px;
}

.search-results::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.search-results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

.search-results::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

body[data-theme="light"] .search-results::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
}

body[data-theme="light"] .search-results::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] .search-results::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

/* Light theme overrides */
body[data-theme="light"] .suggestion-item {
  background: rgba(255,255,255,0.7);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
body[data-theme="light"] .suggestion-item:hover {
  background: rgba(255,255,255,0.85);
}

body[data-theme="light"] .suggestion-name {
  color: var(--text-primary);
}

body[data-theme="light"] .suggestion-meta {
  color: var(--text-secondary);
}

body[data-theme="light"] .suggestion-code {
  background: rgba(0, 0, 0, 0.1);
  color: var(--text-secondary);
}

body[data-theme="dark"] .suggestion-code {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

body[data-theme="light"] .suggestion-select-btn {
  background: var(--accent-color);
  color: white;
  border: 1px solid var(--accent-color);
}

body[data-theme="light"] .suggestion-select-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ===== TRAINS RESULTS DISPLAY (PANEL INTEGRATED) ===== */
.trains-results-container {
  margin-top: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.trains-results-header {
  padding: var(--spacing-lg);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.trains-results-header .results-info {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.trains-results-header h4 {
  margin: 0;
  font-size: var(--font-xl);
  font-weight: var(--font-bold);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.trains-results-header .station-name {
  margin: 0;
  font-size: var(--font-base);
  opacity: 0.95;
  font-weight: var(--font-medium);
}

.trains-results-header .results-count {
  display: inline-block;
  margin-top: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  font-size: var(--font-sm);
  font-weight: var(--font-semibold);
}

.trains-table-wrapper {
  overflow-y: auto;
  overflow-x: hidden;
}

.trains-table-wrapper::-webkit-scrollbar {
  width: 8px;
}

.trains-table-wrapper::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.trains-table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: var(--radius-sm);
}

.trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.timetable-trains-table-wrapper {
  overflow-y: auto;
  overflow-x: hidden;
}

.timetable-trains-table-wrapper::-webkit-scrollbar {
  width: 8px;
}

.timetable-trains-table-wrapper::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.timetable-trains-table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: var(--radius-sm);
}

.timetable-trains-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.trains-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.trains-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.trains-table th {
  padding: var(--spacing-md) var(--spacing-sm);
  text-align: left;
  font-weight: var(--font-semibold);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border-color);
}

/* Column widths for optimal display */
.trains-table th.col-category { width: 10%; }
.trains-table th.col-train { width: 15%; }
.trains-table th.col-destination { width: 35%; }
.trains-table th.col-time { width: 15%; }
.trains-table th.col-delay { width: 15%; }
.trains-table th.col-platform { width: 10%; }

.trains-table td {
  padding: var(--spacing-md) var(--spacing-sm);
  border-bottom: 1px solid var(--border-color);
  font-size: var(--font-base);
  color: var(--text-primary);
  vertical-align: middle;
}

/* Container per categoria + numero treno */
.train-category-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Numero treno inline (visibile solo su mobile) */
.train-number-mobile {
  display: none; /* Nascosto di default su desktop */
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.trains-table tbody tr {
  transition: all var(--transition-fast);
  cursor: pointer;
}

.trains-table tbody tr:hover {
  background: var(--bg-highlight, rgba(102, 126, 234, 0.2));
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.4), inset 0 0 8px rgba(102, 126, 234, 0.2);
  transform: scale(1.01);
}

.trains-table tbody tr:last-child td {
  border-bottom: none;
}

/* Category styling (first column) */
.trains-table td:first-child {
  font-weight: var(--font-bold);
  text-transform: uppercase;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

/* Train logo styling */
.trains-table .train-logo {
  display: inline-block;
  vertical-align: middle;
  height: 20px;
  width: auto;
}

/* Fallback category badge when logo not available */
.train-category-badge {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  font-weight: var(--font-bold);
  text-transform: uppercase;
  color: var(--text-secondary);
  vertical-align: middle;
}

body[data-theme="light"] .train-category-badge {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.7);
}

/* EC logo theme adaptation */
body[data-theme="dark"] img[src*="ec.svg"] {
  filter: invert(1); /* Make EC logo white on dark theme */
}

body[data-theme="light"] img[src*="ec.svg"] {
  filter: none; /* Keep EC logo black on light theme */
}

/* RJ logo theme adaptation */
body[data-theme="dark"] img[src*="rj.svg"] {
  filter: invert(1); /* Make RJ logo white on dark theme */
}

body[data-theme="light"] img[src*="rj.svg"] {
  filter: none; /* Keep RJ logo black on light theme */
}

/* NJ logo theme adaptation (Nightjet / NJ) */
body[data-theme="dark"] img[src*="nj.svg"] {
  filter: invert(1); /* Make NJ logo white on dark theme */
}

body[data-theme="light"] img[src*="nj.svg"] {
  filter: none; /* Keep NJ logo black on light theme */
}

/* ICE logo theme adaptation */
body[data-theme="light"] img[src*="ice.svg"] {
  filter: brightness(0.7); /* Make ICE logo darker on light theme */
}

/* Train number styling (second column) */
.trains-table td:nth-child(2) {
  font-weight: var(--font-semibold);
  color: var(--primary-color);
}

/* Delayed train highlight */
.trains-table tbody tr.delayed {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.25) 0%, rgba(239, 68, 68, 0.35) 100%);
  border-left: 5px solid #dc2626;
}

.trains-table tbody tr.delayed:hover {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.35) 0%, rgba(239, 68, 68, 0.45) 100%);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.5), inset 0 0 8px rgba(239, 68, 68, 0.3);
}

.trains-table td.delayed {
  color: var(--error-color);
  font-weight: var(--font-bold);
}

/* Platform changes */
.trains-table td.platform-changed {
  color: var(--warning-color);
  font-weight: var(--font-semibold);
}

/* Status indicators */
.train-status {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
}

.train-status.on-time {
  background: #e6f4ea;
  color: var(--success-color);
}

.train-status.delayed {
  background: #fce8e6;
  color: var(--error-color);
}

.train-status.cancelled {
  background: #f5f5f5;
  color: var(--text-muted);
  text-decoration: line-through;
}

/* Station links in timetable */
.station-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease;
}

.station-link:hover {
  color: var(--primary-color);
}

.station-text {
  color: inherit;
}

/* Delayed trains section */
.delayed-trains-section {
  margin-top: 20px;
  border-top: 2px solid #ddd;
}

.delayed-trains-header {
  padding: 16px 20px;
  background: #fff3e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.delayed-trains-header h4 {
  margin: 0;
  font-size: 1.1rem;
  color: #ff6b35;
}

.delayed-trains-header .toggle-btn {
  background: none;
  border: none;
  color: #ff6b35;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.3s;
}

.delayed-trains-section.expanded .toggle-btn {
  transform: rotate(180deg);
}

.delayed-trains-section .delayed-table {
  display: none;
  max-height: 300px;
  overflow-y: auto;
}

.delayed-trains-section.expanded .delayed-table {
  display: table;
}

/* Mobile responsive - phones only */
@media (max-width: 480px) {
  .trains-results-container {
    margin-top: var(--spacing-md);
  }

  .trains-results-header {
    padding: var(--spacing-md);
  }

  .trains-results-header h4 {
    font-size: var(--font-lg);
  }

  .trains-results-header .station-name {
    font-size: var(--font-sm);
  }

  .trains-table-wrapper {
    max-height: 50vh;
  }

  .trains-table th,
  .trains-table td {
    padding: var(--spacing-sm) var(--spacing-xs);
    font-size: var(--font-sm);
  }

  /* Hide category column on phones only for more space */
  .trains-table th.col-category,
  .trains-table td:nth-child(2) {
    display: none;
  }

  /* Adjust column widths for mobile */
  .trains-table th.col-train { width: 18%; }
  .trains-table th.col-destination { width: 42%; }
  .trains-table th.col-time { width: 18%; }
  .trains-table th.col-delay { width: 12%; }
  .trains-table th.col-platform { width: 10%; }
  
  /* Panel body scroll adjustment for mobile */
  .panel-body {
    max-height: calc(100vh - 100px);
  }
}

/* ============================================
   📱 OTTIMIZZAZIONE COMPLETA SMARTPHONE
   ============================================ */

/* === MOBILE GENERALE (max 768px - Tablet & Phone) === */
@media (max-width: 768px) {
  /* Root font size più piccolo per schermi mobili */
  :root {
    font-size: 15px;
  }

  /* Container principale full screen */
  .app-container {
    padding: 0;
  }

  /* Pannello di ricerca responsive */
  .search-panel {
    width: 100% !important;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* Header pannello più compatto */
  .panel-header {
    padding: var(--spacing-sm) var(--spacing-md);
    min-height: 50px;
  }

  .panel-title {
    font-size: 1rem;
  }

  /* Input di ricerca mobile-friendly */
  .search-input-container .search-input {
    font-size: 16px; /* Previene zoom automatico su iOS */
    min-height: 44px; /* Dimensione minima touch target iOS */
    padding: var(--spacing-sm) 55px var(--spacing-sm) 42px;
  }

  .search-input-container .search-icon {
    font-size: 1.1rem;
    left: 14px;
  }

  .search-input-container .search-btn {
    min-width: 44px;
    min-height: 34px;
    font-size: 0.85rem;
  }

  /* Bottoni modalità e tipo più grandi per touch */
  .mode-btn,
  .type-btn {
    min-height: 42px;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.9rem;
  }

  /* Tabella treni responsive */
  .trains-table {
    font-size: 0.85rem;
  }

  .trains-table th,
  .trains-table td {
    padding: var(--spacing-sm);
  }

  /* Navigazione bottom più compatta */
  .bottom-nav {
    height: 60px;
    padding: 0 var(--spacing-sm);
  }

  .nav-item {
    min-width: 50px;
    font-size: 0.7rem;
  }

  .nav-item i {
    font-size: 1.3rem;
  }

  /* Suggerimenti autocomplete */
  .suggestion-item {
    padding: var(--spacing-md);
    min-height: 56px;
  }

  /* Risultati treni nel pannello */
  .result-item {
    padding: var(--spacing-md);
    min-height: 60px;
  }
}

/* === SMARTPHONE PORTRAIT (max 480px) === */
@media (max-width: 480px) {
  body.timetable-page /* Font ancora più piccolo */
  :root {
    font-size: 14px;
  }

  body.timetable-page /* Mostra righe come cards su mobile */
  .trains-table tbody tr {
    display: block !important;
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    padding: 8px;
    background: var(--md-surface-container);
  }

  body.timetable-page /* Mostra colonne come card rows su mobile */
  .trains-table tbody td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    visibility: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 4px 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    border: none !important;
  }

  body.timetable-page .trains-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-right: auto;
  }

  body.timetable-page .trains-table tbody td .value {
    font-weight: 500;
    color: var(--text-primary);
  }

  body.timetable-page /* Nascondi numero nella categoria su mobile dato che ora è nella colonna separata */
  .train-number-mobile {
    display: none !important;
  }

  body.timetable-page /* Forza modalità desktop per Fire TV */
  .desktop-mode .trains-table tbody tr {
    display: table-row !important;
    border: none !important;
    border-radius: 0 !important;
    margin-bottom: 0 !important;
    padding: 0 !important;
    background: transparent !important;
  }

  body.timetable-page .desktop-mode .trains-table tbody td {
    display: table-cell !important;
    justify-content: initial !important;
    align-items: initial !important;
    width: auto !important;
    max-width: none !important;
    padding: 8px !important;
    margin: 0 !important;
    overflow: visible !important;
    border: none !important;
  }

  body.timetable-page .desktop-mode .trains-table tbody td::before {
    content: none !important;
  }

  body.timetable-page .desktop-mode .trains-table tbody td .value {
    display: contents !important;
  }

  body.timetable-page /* Safe area per barre di navigazione sistema */
  body {
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  }

  body.timetable-page .app-container {
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
  }

  /* Pannello ricerca ottimizzato */
  .search-panel {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }

  .search-panel.collapsed {
    min-height: 48px;
  }

  .panel-header {
    padding: var(--spacing-xs) var(--spacing-sm);
    min-height: 48px;
  }

  .panel-title {
    font-size: 0.9rem;
    gap: var(--spacing-xs);
  }

  .panel-title i {
    font-size: 1rem;
  }

  /* Freccia toggle più grande */
  .panel-toggle {
    min-width: 36px;
    min-height: 36px;
    padding: var(--spacing-xs);
  }

  .panel-toggle i {
    font-size: 1.1rem;
  }

  /* Input ricerca mobile */
  .search-input-container {
    gap: 0;
  }

  .search-input-container .search-input {
    font-size: 16px; /* iOS zoom prevention */
    min-height: 42px;
    padding: var(--spacing-xs) 52px var(--spacing-xs) 38px;
    border-radius: 21px;
  }

  .search-input-container .search-icon {
    left: 12px;
    font-size: 1rem;
  }

  .search-input-container .search-btn {
    right: 3px;
    min-width: 42px;
    min-height: 32px;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
  }

  .search-input-container .search-btn i {
    font-size: 0.9rem;
  }

  /* Controlli inline più compatti */
  .controls-row {
    gap: var(--spacing-xs);
  }

  /* Toggle modalità/tipo */
  .mode-toggle,
  .type-toggle {
    gap: var(--spacing-xs);
  }

  .mode-btn,
  .type-btn {
    min-height: 38px;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
    gap: 4px;
  }

  .mode-btn i,
  .type-btn i {
    font-size: 0.95rem;
  }

  /* Corpo pannello */
  .panel-body {
    padding: 0 var(--spacing-sm) var(--spacing-sm);
    gap: var(--spacing-sm);
    max-height: calc(100vh - 120px);
  }

  /* Tabella treni mobile */
  .trains-table-wrapper {
    margin: 0 calc(-1 * var(--spacing-sm));
    padding: 0 var(--spacing-sm);
  }

  .timetable-trains-table-wrapper {
    margin: 0 calc(-1 * var(--spacing-sm));
    padding: 0 var(--spacing-sm);
  }

  .trains-table {
    font-size: 0.75rem;
  }

  .trains-table th,
  .trains-table td {
    padding: var(--spacing-xs) 4px;
  }

  .trains-table th {
    font-size: 0.7rem;
  }

  /* Colonne treni ottimizzate */
  .col-category {
    width: 20%; /* Più larga per contenere logo + numero */
    min-width: 60px;
  }

  .col-destination {
    width: 38%;
  }

  .col-time {
    width: 16%;
    min-width: 45px;
  }

  .col-delay {
    width: 14%;
    min-width: 40px;
  }

  .col-platform {
    width: 12%;
    min-width: 35px;
  }

  /* Container per categoria + numero */
  .train-category-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
  }

  /* Numero treno mostrato in mobile */
  .train-number-mobile {
    display: inline-block;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary);
    white-space: nowrap;
  }

  /* Nascondi numero mobile su desktop (verrà mostrato solo su mobile) */
  @media (min-width: 481px) {
    .train-number-mobile {
      display: none;
    }
    
    /* Ripristina colonna numero treno su desktop */
    .trains-table .col-train,
    .trains-table th.col-train,
    .trains-table td.col-train {
      display: table-cell !important;
      width: auto !important;
      padding: var(--spacing-md) var(--spacing-sm) !important;
    }
    
    .col-category {
      width: 10%;
      min-width: 35px;
    }
  }

  /* Badge categoria treno */
  .train-category-badge {
    font-size: 0.6rem;
    padding: 2px 4px;
    min-width: 28px;
  }

  /* Logo treno */
  .train-logo {
    max-width: 30px;
    max-height: 20px;
  }

  /* Suggerimenti autocomplete */
  .autocomplete-suggestions {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .suggestions-list {
    max-height: calc(100vh - 200px);
  }

  .suggestion-item {
    padding: var(--spacing-sm);
    min-height: 52px;
  }

  .flag-container {
    width: 32px;
    height: 32px;
  }

  .flag-emoji {
    font-size: 1.3rem;
  }

  .suggestion-name {
    font-size: 0.9rem;
  }

  .suggestion-meta {
    font-size: 0.75rem;
  }

  /* Risultati ricerca treni */
  .results-list {
    gap: var(--spacing-xs);
  }

  .result-item {
    padding: var(--spacing-sm);
    min-height: 56px;
  }

  .result-info strong {
    font-size: 0.9rem;
  }

  .result-direction {
    font-size: 0.75rem;
  }

  .result-button {
    min-width: 40px;
    min-height: 40px;
    padding: var(--spacing-xs);
  }

  /* Bottom navigation */
  .bottom-nav {
    height: 56px;
    padding: 0 4px;
  }

  .nav-item {
    min-width: 48px;
    font-size: 0.65rem;
    gap: 2px;
  }

  .nav-item i {
    font-size: 1.2rem;
  }

  /* Icona impostazioni */
  .settings-icon {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
}

/* === SMARTPHONE PICCOLI (max 375px - iPhone SE, etc) === */
@media (max-width: 375px) {
  :root {
    font-size: 13px;
  }

  .panel-title {
    font-size: 0.85rem;
  }

  .panel-title i {
    font-size: 0.95rem;
  }

  /* Input ancora più compatto */
  .search-input-container .search-input {
    font-size: 15px;
    padding: var(--spacing-xs) 48px var(--spacing-xs) 36px;
    min-height: 40px;
  }

  .search-input-container .search-btn {
    min-width: 38px;
    min-height: 30px;
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  /* Bottoni più piccoli */
  .mode-btn,
  .type-btn {
    font-size: 0.75rem;
    padding: 6px 10px;
    min-height: 36px;
  }

  /* Nascondi testo su bottoni molto piccoli, solo icone */
  .mode-btn span,
  .type-btn span {
    display: none;
  }

  .mode-btn i,
  .type-btn i {
    margin: 0;
    font-size: 1.1rem;
  }

  /* Tabella ancora più compatta */
  .trains-table {
    font-size: 0.7rem;
  }

  .trains-table th,
  .trains-table td {
    padding: 4px 2px;
  }

  .train-category-badge {
    font-size: 0.55rem;
    padding: 1px 3px;
    min-width: 24px;
  }

  /* Categoria + numero ancora più compatti */
  .train-category-cell {
    gap: 3px;
  }

  .train-number-mobile {
    font-size: 0.7rem;
  }

  /* Logo treno più piccolo */
  .train-logo {
    max-width: 26px;
    max-height: 16px;
  }

  /* Bottom nav compatto */
  .bottom-nav {
    height: 52px;
  }

  .nav-item {
    min-width: 44px;
    font-size: 0.6rem;
  }

  .nav-item i {
    font-size: 1.1rem;
  }
}

/* === LANDSCAPE MODE (Orizzontale) === */
@media (max-height: 600px) and (orientation: landscape) {
  .search-panel {
    max-height: calc(100vh - 8px);
  }

  .panel-header {
    padding: 6px var(--spacing-md);
    min-height: 44px;
  }

  .panel-body {
    max-height: calc(100vh - 52px);
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-md);
  }

  /* Riduci altezza input */
  .search-input-container .search-input {
    min-height: 38px;
  }

  .mode-btn,
  .type-btn {
    min-height: 36px;
    padding: 4px var(--spacing-sm);
  }

  /* Tabella più compatta */
  .trains-table th,
  .trains-table td {
    padding: 4px 6px;
  }

  /* Bottom nav più sottile */
  .bottom-nav {
    height: 48px;
  }

  .nav-item {
    font-size: 0.6rem;
  }

  .nav-item i {
    font-size: 1.1rem;
  }
}

/* === SCHERMI MOLTO BASSI (height < 500px) === */
@media (max-height: 500px) {
  .search-panel {
    max-height: calc(100vh - 5px);
  }

  .panel-header {
    padding: 4px var(--spacing-sm);
    min-height: 40px;
  }

  .panel-body {
    max-height: calc(100vh - 48px);
    padding: var(--spacing-xs);
  }

  .trains-table th,
  .trains-table td {
    padding: 2px 4px;
  }

  .bottom-nav {
    height: 44px;
  }
}

/* === TOUCH OPTIMIZATIONS === */
@media (pointer: coarse) {
  /* Aumenta dimensioni touch target */
  button,
  .btn,
  .nav-item,
  .mode-btn,
  .type-btn,
  .panel-toggle,
  .result-button {
    min-width: 44px;
    min-height: 44px;
  }

  /* Feedback touch più evidente */
  button:active,
  .btn:active {
    transform: scale(0.96);
    opacity: 0.9;
  }
}

/* === SAFE AREA INSETS (iPhone X+, Android con notch) === */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
    height: calc(60px + env(safe-area-inset-bottom));
  }

  .search-panel {
    padding-top: env(safe-area-inset-top);
  }
}

/* === DARK MODE ADJUSTMENTS PER MOBILE === */
@media (max-width: 480px) {
  body[data-theme="dark"] .search-panel {
    background: rgba(15, 23, 42, 0.97);
  }

  body[data-theme="light"] .search-panel {
    background: rgba(255, 255, 255, 0.97);
  }
}

/* Fast Page Transitions */
.page-transitioning {
  position: relative;
  overflow: hidden;
}

.page-entering {
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s ease-out;
}

.page-entered {
  opacity: 1;
  transform: translateX(0);
}

/* Optimize for performance */
.page-container {
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .page-entering {
    transition: none;
  }
  
  .page-entered {
    transition: none;
  }
}

/* ===========================================
   HEIGHT-BASED RESPONSIVE DESIGN
   =========================================== */

/* Very short screens (small phones in landscape, foldables) */
@media (max-height: 400px) {
  /* Reduce modal size */
  .settings-modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .settings-modal-body {
    padding: 15px;
    max-height: calc(90vh - 60px);
    overflow-y: auto;
  }
  
  /* Reduce journey panel height */
  #journeyPanel {
    max-height: 80vh;
    overflow-y: auto;
  }
  
  .journey-panel-content {
    padding: 15px;
  }
  
  /* Compact stop items */
  .stop-item {
    padding: 8px 0;
  }
  
  .stop-timeline {
    width: 16px;
  }
  
  .stop-dot {
    width: 10px;
    height: 10px;
  }
  
  .stop-line {
    width: 1px;
  }
  
  /* Reduce mobile bottom sheet */
  #mobileBottomSheet {
    max-height: 75vh;
  }
  
  .mobile-sheet-content {
    padding: 15px;
  }
  
  /* Compact search results */
  .search-result-item {
    padding: 8px 12px;
  }
  
  /* Reduce header height */
  .app-header {
    height: 50px;
    padding: 0 15px;
  }
  
  .header-content {
    height: 50px;
  }
}

/* Short screens (most phones in landscape) */
@media (max-height: 500px) and (min-height: 401px) {
  /* Modal adjustments */
  .settings-modal-content {
    max-height: 85vh;
    overflow-y: auto;
  }
  
  .settings-modal-body {
    max-height: calc(85vh - 60px);
    overflow-y: auto;
  }
  
  /* Journey panel */
  #journeyPanel {
    max-height: 85vh;
  }
  
  /* Mobile bottom sheet */
  #mobileBottomSheet {
    max-height: 80vh;
  }
  
  /* Reduce padding */
  .journey-panel-content,
  .mobile-sheet-content {
    padding: 20px;
  }
  
  /* Compact timeline */
  .stop-item {
    padding: 10px 0;
  }
}

/* Medium height screens (tablets, some phones) */
@media (max-height: 700px) and (min-height: 501px) {
  /* Modal fine-tuning */
  .settings-modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .settings-modal-body {
    max-height: calc(90vh - 60px);
    overflow-y: auto;
  }
  
  /* Journey panel */
  #journeyPanel {
    max-height: 90vh;
  }
  
  /* Mobile bottom sheet */
  #mobileBottomSheet {
    max-height: 85vh;
  }
}

/* Tall screens - ensure we don't waste space */
@media (min-height: 900px) {
  /* Allow more content on tall screens */
  .settings-modal-content {
    max-height: 80vh;
  }
  
  #journeyPanel {
    max-height: 85vh;
  }
  
  #mobileBottomSheet {
    max-height: 80vh;
  }
  
  /* Increase padding on tall screens */
  .journey-panel-content,
  .mobile-sheet-content {
    padding: 30px;
  }
  
  .settings-modal-body {
    padding: 25px;
  }
}

/* Landscape orientation specific adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  /* Hide or minimize non-essential elements */
  .app-header .header-actions {
    display: none;
  }
  
  /* Compact search bar */
  .search-container {
    margin: 5px 0;
  }
  
  .search-input-group {
    margin-bottom: 5px;
  }
  
  /* Reduce map controls */
  .mapboxgl-ctrl {
    font-size: 12px;
  }
  
  /* Compact notifications */
  .notification {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* Portrait orientation specific adjustments */
@media (orientation: portrait) and (max-height: 600px) {
  /* Ensure mobile bottom sheet takes appropriate space */
  #mobileBottomSheet {
    max-height: 70vh;
  }
  
  /* Compact mobile UI */
  .mobile-controls {
    padding: 10px;
  }
  
  .mobile-toggle-btn {
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* Ultra-wide but short screens (ultrawide monitors) */
@media (min-width: 1920px) and (max-height: 800px) {
  /* Center content better */
  .container {
    max-width: 1600px;
    margin: 0 auto;
  }
  
  /* Allow journey panel to be wider on short ultrawide screens */
  #journeyPanel {
    width: 450px;
  }
}

/* Extreme aspect ratios (very wide, very tall) */
@media (min-aspect-ratio: 21/9) {
  /* Ultra-wide screens */
  #journeyPanel {
    width: 400px;
  }
  
  .main-content {
    padding: 0 20px;
  }
}

@media (max-aspect-ratio: 9/21) {
  /* Ultra-tall screens (some foldables) */
  #journeyPanel {
    width: 100vw;
    max-height: 60vh;
  }
  
  #mobileBottomSheet {
    max-height: 50vh;
  }
}

/* Small touch targets for very small screens */
@media (max-height: 400px) {
  .settings-modal-close,
  .clear-cache-btn,
  .language-option,
  .theme-option {
    min-height: 44px;
  }
  
  .stop-name {
    cursor: default; /* Disable click on very small screens */
  }
  
  /* Stack settings sections vertically with less spacing */
  .settings-section {
    margin-bottom: 15px;
  }
  
  .settings-section-label {
    margin-bottom: 10px;
    font-size: 14px;
  }
  
  /* Ensure scrolling works on very small screens */
  .settings-modal-body {
    padding: 15px;
    max-height: calc(85vh - 50px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Dynamic viewport height handling for mobile browsers */
@media (max-height: 600px) and (orientation: landscape) {
  /* Adjust for mobile browsers that hide/show address bar */
  .app-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
  }
  
  .main-map {
    height: calc(100vh - 50px);
    height: calc(100dvh - 50px);
  }
  
  #journeyPanel {
    max-height: calc(100vh - 50px);
    max-height: calc(100dvh - 50px);
  }
  
  #mobileBottomSheet {
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
  }
}

/* Tall screens - expand content to use available space */
@media (min-height: 900px) {
  .settings-modal {
    max-height: 80vh;
    height: auto;
  }
  
  #journeyPanel {
    max-height: 70vh;
  }
  
  #mobileBottomSheet {
    max-height: 75vh;
  }
  
  /* Larger touch targets for tall screens */
  .settings-modal-close,
  .clear-cache-btn,
  .language-option,
  .theme-option {
    min-height: 48px;
    padding: 12px;
  }
  
  /* More spacing for tall screens */
  .settings-section {
    margin-bottom: 25px;
  }
  
  .stop-item {
    padding: 12px;
  }
}

/* Ultra-wide short screens (aspect ratio > 21:9) */
@media (max-height: 500px) and (aspect-ratio: 21/9) {
  .settings-modal {
    width: 90vw;
    max-width: 600px;
  }
  
  .journey-info {
    flex-direction: row;
    align-items: center;
  }
  
  .journey-info h3 {
    margin-bottom: 0;
    margin-right: 15px;
  }
  
  .journey-details {
    flex: 1;
  }
}

/* Ultra-tall narrow screens (aspect ratio < 9:21) */
@media (min-height: 900px) and (aspect-ratio: 9/21) {
  .settings-modal {
    width: 95vw;
    max-width: 400px;
  }
  
  #journeyPanel {
    width: 95vw;
    max-width: 450px;
  }
  
  #mobileBottomSheet {
    width: 95vw;
    max-width: 450px;
  }
}

/* Riduci dimensioni per schermi bassi (desktop con overflow) */
@media (max-height: 700px) {
  body.timetable-page :root {
    font-size: 13px;
  }

  body.timetable-page .app-container {
    padding: 0.5rem;
  }

  body.timetable-page .search-panel {
    padding: 0.75rem;
  }

  body.timetable-page .trains-table th,
  body.timetable-page .trains-table td {
    padding: 0.5rem;
  }

  body.timetable-page .result-item {
    padding: 0.75rem;
    min-height: 48px;
  }

  body.timetable-page .filter-module {
    margin-bottom: 0.5rem;
    margin-bottom: 6vw;
  }

  body.timetable-page .filter-options {
    gap: 1rem;
  }
}

/* ========================================
   SETTINGS MODAL STYLES
   ======================================== */

/* Backdrop */
.settings-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.settings-backdrop:not(.hidden) {
  opacity: 1;
}

/* Modal Base */
.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: 9999;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  opacity: 0;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.settings-modal:not(.hidden) {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Modal Content */
.settings-modal-content {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

/* Modal Header */
.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.settings-modal-title {
  margin: 0;
  font-size: var(--font-xl);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.settings-modal-title i {
  color: var(--primary-color);
}

/* Modal Buttons */
.settings-modal-close,
.settings-modal-back {
  background: none;
  border: none;
  padding: var(--spacing-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: var(--font-lg);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-modal-close:hover,
.settings-modal-back:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.settings-modal-close {
  margin-left: var(--spacing-md);
}

.settings-modal-back {
  margin-right: var(--spacing-md);
}

/* Modal Body */
.settings-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Desktop Layout - Two Columns */
.settings-body-container {
  display: flex;
  min-height: 400px;
}

.settings-categories-column {
  width: 200px;
  border-right: 1px solid var(--border-color);
  background: var(--bg-secondary);
  padding: var(--spacing-lg) 0;
}

.settings-categories-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.settings-category-item {
  margin: 0;
}

.settings-category-item a {
  display: block;
  padding: var(--spacing-md) var(--spacing-lg);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.settings-category-item:hover a,
.settings-category-item.active a {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border-left-color: var(--primary-color);
}

.settings-category-item i {
  margin-right: var(--spacing-sm);
  width: 16px;
}

.settings-options-column {
  flex: 1;
  padding: var(--spacing-lg);
}

/* Settings Panels */
.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

/* Settings Sections (Mobile) */
.settings-section {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section-label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-md);
  font-size: var(--font-lg);
}

.settings-section-label i {
  margin-right: var(--spacing-sm);
  color: var(--primary-color);
}

/* Language Options */
.settings-language-options,
.settings-theme-options {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.language-option,
.theme-option {
  display: flex;
  align-items: center;
  padding: var(--spacing-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.language-option:hover,
.theme-option:hover {
  background-color: var(--bg-secondary);
}

.language-option input[type="radio"],
.theme-option input[type="radio"] {
  margin-right: var(--spacing-md);
  accent-color: var(--primary-color);
}

.language-flag,
.theme-icon {
  font-size: var(--font-xl);
  margin-right: var(--spacing-md);
}

.language-name,
.theme-name {
  font-weight: 500;
  color: var(--text-primary);
}

/* Cache Options */
.settings-cache-options {
  display: flex;
  justify-content: center;
}

.clear-cache-btn {
  background: var(--error-color);
  color: white;
  border: none;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.clear-cache-btn:hover {
  background: #e53e3e;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.clear-cache-btn:active {
  transform: translateY(0);
}

/* Mobile Styles */
.settings-modal-mobile {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  transform: none !important;
  border-radius: 0 !important;
}

.settings-modal-mobile .settings-modal-content {
  height: 100%;
}

.settings-modal-mobile .settings-modal-body {
  flex: 1;
  max-height: calc(100vh - 80px);
}

/* Responsive Design */
@media (max-width: 767px) {
  .settings-modal {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    top: 0;
    left: 0;
    transform: none;
  }

  .settings-modal-content {
    height: 100%;
  }

  .settings-modal-body {
    max-height: calc(100vh - 80px);
  }

  .settings-body-container {
    flex-direction: column;
  }

  .settings-categories-column {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .settings-options-column {
    padding: var(--spacing-md);
  }
}

/* Dark Theme Support */
html[data-theme="dark"] .settings-modal {
  background: var(--bg-dark);
  border-color: var(--border-dark);
}

html[data-theme="dark"] .settings-modal-header {
  background: var(--bg-darker);
  border-color: var(--border-dark);
}

html[data-theme="dark"] .settings-categories-column {
  background: var(--bg-darker);
}

html[data-theme="dark"] .settings-category-item:hover a,
html[data-theme="dark"] .settings-category-item.active a {
  background-color: var(--bg-dark);
}

html[data-theme="dark"] .language-option:hover,
html[data-theme="dark"] .theme-option:hover {
  background-color: var(--bg-darker);
}

html[data-theme="dark"] .clear-cache-btn {
  background: var(--error-color);
}

html[data-theme="dark"] .clear-cache-btn:hover {
  background: #e53e3e;
}

/* View Toggle Switch */
.view-toggle-switch {
  position: relative;
  display: inline-block;
}

.view-toggle-input {
  /* Visually hide but keep accessible/focusable */
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.view-toggle-label {
  display: block;
  cursor: pointer;
  user-select: none;
}

.view-toggle-slider {
  position: relative;
  display: flex;
  align-items: center;
  width: 140px;
  height: 40px;
  background: var(--md-surface-container);
  border-radius: 20px;
  border: 1px solid var(--md-outline-variant);
  transition: all 0.3s ease;
  overflow: hidden;
}

.view-toggle-slider:before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 68px;
  height: 36px;
  background: var(--md-primary);
  border-radius: 18px;
  transition: transform 0.28s cubic-bezier(.2,.9,.3,1);
  transform: translateX(0);
  z-index: 1;
}

.view-toggle-input:checked + .view-toggle-label .view-toggle-slider:before {
  transform: translateX(68px);
}

.view-toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  height: 100%;
  color: var(--md-on-surface-variant);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.3s ease;
  position: relative;
  z-index: 2;
}

.view-toggle-option i {
  font-size: 16px;
}

.toggle-text {
  display: none;
}

@media (min-width: 480px) {
  .view-toggle-slider {
    width: 160px;
  }
  
  .view-toggle-slider:before {
    width: 76px;
  }
  
  .view-toggle-input:checked + .view-toggle-label .view-toggle-slider:before {
    transform: translateX(76px);
  }
  
  .toggle-text {
    display: inline;
  }
}

.view-toggle-input:checked + .view-toggle-label .card-option {
  color: var(--md-on-primary);
}

.view-toggle-input:not(:checked) + .view-toggle-label .table-option {
  color: var(--md-on-primary);
}

.view-toggle-label:hover .view-toggle-slider {
  border-color: var(--md-outline);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

html[data-theme="dark"] .view-toggle-slider {
  background: var(--md-surface-container);
  border-color: var(--md-outline-variant);
}

html[data-theme="dark"] .view-toggle-slider:before {
  background: var(--md-primary);
}

html[data-theme="dark"] .view-toggle-option {
  color: var(--md-on-surface-variant);
}

html[data-theme="dark"] .view-toggle-input:checked + .view-toggle-label .card-option {
  color: var(--md-on-primary);
}

html[data-theme="dark"] .view-toggle-input:not(:checked) + .view-toggle-label .table-option {
  color: var(--md-on-primary);
}

/* Option pill selects - themed to match MD variables */
.option-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  z-index: 1; /* keep below suggestions */
}

.option-pill select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: var(--md-surface-container);
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
  padding: 6px 36px 6px 8px;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1;
  height: 36px;
}

.option-pill select:focus {
  outline: none;
  border-color: var(--md-primary);
  box-shadow: 0 0 0 4px rgba(102,126,234,0.12);
}

.option-pill::after {
  /* simple chevron using rotated borders */
  content: '';
  position: absolute;
  right: 12px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--md-on-surface-variant);
  border-bottom: 2px solid var(--md-on-surface-variant);
  transform: rotate(45deg);
  pointer-events: none;
  z-index: 2; /* small z-index but lower than suggestions */
}

html[data-theme="dark"] .option-pill select {
  background: var(--md-surface-container);
  color: var(--md-on-surface);
  border-color: var(--md-outline-variant);
}

/* OpenRailwayMap toggle button (placed under download button) */
.openrailwaymap-toggle-btn {
  position: absolute;
  top: 72px; /* placed under the download button (which is at 18px) */
  right: 25px;
  z-index: 11060;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(8, 10, 12, 0.55);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
}

.openrailwaymap-toggle-btn[aria-pressed="true"] {
  border-color: rgba(34,197,94,0.25);
}

.openrailwaymap-toggle-btn:hover {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .openrailwaymap-toggle-btn {
    /* Floating circular button bottom-right on mobile */
    position: fixed;
    bottom: 18px;
    right: 12px;
    top: auto;
    padding: 0;
    width: 56px;
    height: 56px;
    font-size: 14px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  }

  /* hide textual label on very small screens, keep icon visible */
  .openrailwaymap-toggle-btn .orm-label {
    display: none;
  }

  .openrailwaymap-toggle-btn i {
    font-size: 18px;
  }
}

/* ========================================
   LANDING PAGE STYLES
   ======================================== */

.landing-hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
  color: white;
  overflow: hidden;
}

.landing-hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="50" cy="50" r="2" fill="rgba(255,255,255,0.05)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
  opacity: 0.3;
  pointer-events: none;
}

.landing-inner {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  width: 100%;
  padding: var(--spacing-xl);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-4xl);
  align-items: center;
}

.hero-copy {
  animation: fadeInUp 1s ease-out;
}

.hero-title {
  font-size: clamp(var(--font-3xl), 5vw, var(--font-4xl));
  font-weight: var(--font-bold);
  margin-bottom: var(--spacing-md);
  line-height: 1.2;
  font-family: 'Syne', sans-serif;
}

.hero-subtitle {
  font-size: var(--font-xl);
  margin-bottom: var(--spacing-2xl);
  opacity: 0.9;
  font-weight: var(--font-normal);
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  max-width: 500px;
}

.hero-search-form {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: var(--spacing-sm);
  transition: all var(--transition-normal);
}

.hero-search-form:focus-within {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.hero-input {
  flex: 1;
  background: transparent;
  border: none;
  color: white;
  font-size: var(--font-lg);
  padding: var(--spacing-sm);
  outline: none;
}

.hero-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: var(--font-lg);
  font-weight: var(--font-medium);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: all var(--transition-normal);
  cursor: pointer;
  border: none;
  gap: var(--spacing-sm);
}

.btn-primary {
  background: white;
  color: var(--primary-color);
  box-shadow: var(--shadow-lg);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.btn-outline {
  background: transparent;
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}

.hero-visual {
  animation: fadeInRight 1.2s ease-out 0.3s both;
  display: flex;
  justify-content: center;
}

.hero-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-xl);
  padding: var(--spacing-2xl);
  box-shadow: var(--shadow-xl);
  border: 1px solid rgba(255, 255, 255, 0.2);
  max-width: 400px;
  color: var(--text-primary);
}

.hero-card h4 {
  font-size: var(--font-xl);
  font-weight: var(--font-semibold);
  margin-bottom: var(--spacing-md);
  color: var(--primary-color);
}

.hero-card p {
  margin-bottom: var(--spacing-lg);
  color: var(--text-secondary);
}

.mini-stats {
  display: flex;
  gap: var(--spacing-lg);
  font-size: var(--font-sm);
}

.mini-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.mini-stats strong {
  font-size: var(--font-2xl);
  font-weight: var(--font-bold);
  color: var(--primary-color);
}

.mini-stats span {
  color: var(--text-muted);
  margin-top: var(--spacing-xs);
}

.page-container {
  padding: var(--spacing-4xl) var(--spacing-xl);
  max-width: 1200px;
  margin: 0 auto;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--spacing-2xl);
  margin-top: var(--spacing-4xl);
}

.feature {
  text-align: center;
  padding: var(--spacing-2xl);
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-normal);
  border: 1px solid var(--border-color);
}

.feature:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.feature i {
  color: var(--primary-color);
  margin-bottom: var(--spacing-lg);
}

.feature h3 {
  font-size: var(--font-xl);
  font-weight: var(--font-semibold);
  margin-bottom: var(--spacing-md);
  color: var(--text-primary);
}

.feature p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .landing-inner {
    grid-template-columns: 1fr;
    gap: var(--spacing-2xl);
    text-align: center;
  }

  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-search-form {
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  .hero-input {
    text-align: center;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .hero-visual {
    order: -1;
  }

  .hero-card {
    max-width: 100%;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-xl);
  }

  .page-container {
    padding: var(--spacing-2xl) var(--spacing-md);
  }
}