/* CSS Variables for Dark Theme Only */
:root {
  /* Colors - Dark Theme */
  --primary-bg: #0f1117;
  --secondary-bg: #1a1d29;
  --tertiary-bg: #252a3a;
  --surface-bg: #2d3348;
  
  --text-primary: #ffffff;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  
  --accent-primary: #4299e1;
  --accent-secondary: #38b2ac;
  --accent-success: #48bb78;
  --accent-warning: #ed8936;
  --accent-error: #f56565;
  
  --border-color: #2d3748;
  --border-light: #4a5568;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  
  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s ease;
  
  /* Z-index */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal: 1040;
  --z-popover: 1050;
  --z-tooltip: 1060;
}

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

html {
  font-size: 16px;
  height: 100%;
}

body {
  font-family: var(--font-family);
  font-weight: var(--font-weight-normal);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--primary-bg);
  height: 100%;
  overflow: hidden;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--primary-bg);
}

/* Header Styles */
.app-header {
  background: var(--secondary-bg);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-md) var(--space-xl);
  position: relative;
  z-index: var(--z-sticky);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  transition: all var(--transition-normal);
}

/* When dashboard is active, keep header visible */
.dashboard-active .app-header {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  height: auto !important;
  padding: var(--space-md) var(--space-xl) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 100%;
  gap: var(--space-lg);
}

.logo-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.title-icon {
  font-size: 1.75rem;
}

.app-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: var(--font-weight-normal);
}

/* Header Toggles Container */
.header-toggles {
  display: flex;
  justify-content: center;
  flex: 1;
  max-width: 400px;
  margin: 0 var(--space-lg);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-shrink: 0;
}

/* Remove the old toggle group from sidebar */
.left-sidebar .toggle-group {
  display: none;
}

/* Update toggle group for header */
.header-toggles .toggle-group {
  display: flex;
  gap: var(--space-sm);
  background: var(--tertiary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-sm);
}

.header-toggles .toggle-btn {
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  justify-content: center;
  font-size: 0.875rem;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.header-toggles .toggle-btn:hover {
  background: var(--surface-bg);
  color: var(--text-primary);
}

.header-toggles .toggle-btn.active {
  background: var(--accent-primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.header-toggles .toggle-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: white;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.header-toggles .toggle-icon {
  font-size: 1.125rem;
}

/* Theme toggle removed */
.theme-toggle {
  display: none;
}

.last-updated {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-xs);
}

.update-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: var(--font-weight-medium);
}

.update-time {
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
}

/* Main Content Layout */
.main-content {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  height: 100%;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ==================== DASHBOARD FIXED STYLES ==================== */
/* Dashboard container - MUST BE VISIBLE WHEN ACTIVE */
#dashboard-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background: var(--primary-bg) !important;
  z-index: var(--z-modal) !important;
  overflow: hidden !important;
  display: none !important; /* Hidden by default */
  opacity: 0 !important;
  visibility: hidden !important;
  transition: opacity var(--transition-normal) !important;
}

/* CRITICAL: When dashboard is active, show it */
.dashboard-active #dashboard-container {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* When dashboard is active, hide other content */
.dashboard-active .sidebar,
.dashboard-active .map-container {
  display: none !important;
}

.dashboard-active .main-content {
  grid-template-columns: 1fr !important;
  position: relative !important;
}

#dashboard-frame {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  background: var(--primary-bg) !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 1 !important;
}

/* Dashboard loading state */
.dashboard-loading {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  text-align: center !important;
  color: var(--text-secondary) !important;
  z-index: 2 !important;
  background: var(--primary-bg) !important;
  padding: var(--space-xl) !important;
  border-radius: var(--radius-lg) !important;
  border: 1px solid var(--border-color) !important;
}

.dashboard-loading-spinner {
  width: 48px !important;
  height: 48px !important;
  border: 4px solid var(--border-color) !important;
  border-top: 4px solid var(--accent-primary) !important;
  border-radius: 50% !important;
  animation: spin 1s linear infinite !important;
  margin: 0 auto 1rem !important;
}

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

/* Sidebar Base Styles */
.sidebar {
  background: var(--secondary-bg);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  height: 100%;
  position: relative;
  z-index: var(--z-fixed);
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
}

.right-sidebar {
  border-right: none;
  border-left: 1px solid var(--border-color);
}

.sidebar-section {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 1rem;
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.metric-card {
  background: var(--tertiary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  transition: all var(--transition-normal);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-primary);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.metric-card:hover::before {
  opacity: 1;
}

.metric-icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
}

.metric-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.metric-value {
  font-size: 1.5rem;
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Search Container */
.search-container {
  position: relative;
  flex-shrink: 0;
}

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

.search-input {
  width: 100%;
  background: var(--tertiary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  padding-right: 3rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all var(--transition-normal);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-btn {
  position: absolute;
  right: var(--space-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.search-btn:hover {
  color: var(--text-primary);
  background: var(--surface-bg);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-lg);
  display: none;
}

/* Map Container */
.map-container {
  position: relative;
  background: var(--tertiary-bg);
  overflow: hidden;
  height: 100%;
  width: 100%;
  flex: 1;
  transition: all var(--transition-normal);
}

.map {
  width: 100%;
  height: 100%;
  background: var(--tertiary-bg);
  cursor: default !important;
  touch-action: manipulation;
}

/* Map Controls */
.map-controls {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  z-index: var(--z-fixed);
}

.map-control-btn {
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

.map-control-btn:hover {
  background: var(--surface-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.control-icon {
  font-size: 1.125rem;
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: var(--space-lg);
  left: var(--space-lg);
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  z-index: var(--z-fixed);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  display: none;
}

/* Routes List */
.routes-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
  flex: 1;
}

.route-item {
  background: var(--tertiary-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.route-item:hover {
  background: var(--surface-bg);
  border-color: var(--accent-primary);
  transform: translateX(2px);
}

.route-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xs);
}

.route-name {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  font-size: 0.875rem;
}

.route-delay {
  font-weight: var(--font-weight-bold);
  font-size: 0.875rem;
}

.delay-high {
  color: var(--accent-error);
}

.delay-medium {
  color: var(--accent-warning);
}

.delay-low {
  color: var(--accent-success);
}

.route-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Viewport Insights */
.viewport-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  flex: 1;
}

.hint-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

.viewport-routes {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex: 1;
}

/* Analytics Chart */
.analytics-chart {
  width: 100%;
  height: 200px;
  background: var(--tertiary-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  flex-shrink: 0;
}

/* Data Summary */
.data-summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-light);
}

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

.summary-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
}

.summary-value {
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
}

/* Footer */
.app-footer {
  background: var(--secondary-bg);
  border-top: 1px solid var(--border-color);
  padding: var(--space-md) var(--space-xl);
  position: relative;
  z-index: var(--z-sticky);
  flex-shrink: 0;
  transition: all var(--transition-normal);
}

/* When dashboard is active, keep footer visible */
.dashboard-active .app-footer {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  height: auto !important;
  padding: var(--space-md) var(--space-xl) !important;
  border-top: 1px solid var(--border-color) !important;
}

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

.footer-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.footer-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-separator {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.footer-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color var(--transition-fast);
}

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

/* Footer analytics removed */
.footer-analytics {
  display: none;
}

/* Loading States */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xl);
  color: var(--text-muted);
  text-align: center;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--tertiary-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
  justify-content: center;
}

.empty-state span {
  font-size: 2rem;
  display: block;
  margin-bottom: var(--space-md);
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: var(--space-xs);
}

/* Fix for Leaflet auto-zooming issues */
.leaflet-container {
  cursor: default !important;
  outline: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

.leaflet-tile {
  pointer-events: auto !important;
}

/* Prevent unwanted zoom on mobile */
.leaflet-touch .leaflet-control-zoom,
.leaflet-touch .leaflet-control-layers {
  touch-action: manipulation;
}

/* ==================== DASHBOARD LOADING FIX ==================== */
/* Ensure loading spinner is properly hidden when not needed */
#dashboard-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    z-index: 1001;
    background: rgba(15, 17, 23, 0.9);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: none; /* Start hidden */
    transition: opacity 0.3s ease;
}

/* When loading, show it */
#dashboard-loading.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Dashboard frame - ensure it's on top when loaded */
#dashboard-frame.loaded {
    z-index: 1000 !important;
    opacity: 1 !important;
}

/* Make sure iframe content is clickable */
#dashboard-frame {
    pointer-events: auto !important;
}

/* When dashboard is active but iframe hasn't loaded yet */
.dashboard-active:not(.dashboard-loaded) #dashboard-container {
    background: var(--primary-bg);
}

/* Force the iframe to be interactive */
iframe {
    border: none;
    background: transparent;
}

/* Debug border for iframe (remove in production) */
#dashboard-frame.debug {
    border: 2px solid #00ff00 !important;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 280px 1fr 280px;
  }
  
  .metrics-grid {
    grid-template-columns: 1fr;
  }
  
  .header-toggles .toggle-btn {
    padding: var(--space-md);
  }
}

@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  
  .sidebar {
    position: absolute;
    z-index: var(--z-modal);
    height: auto;
    max-height: 50vh;
    overflow-y: auto;
    width: 100%;
  }
  
  .left-sidebar {
    top: 0;
    left: 0;
    right: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  
  .right-sidebar {
    bottom: 0;
    left: 0;
    right: 0;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
  
  .map-container {
    grid-row: 2;
  }
  
  .header-content {
    flex-direction: column;
    gap: var(--space-md);
  }
  
  .header-toggles {
    max-width: 100%;
    margin: var(--space-sm) 0;
  }
  
  .header-toggles .toggle-group {
    width: 100%;
  }
  
  .header-toggles .toggle-btn {
    flex: 1;
    padding: var(--space-sm);
    font-size: 0.8rem;
  }
  
  .header-controls {
    width: 100%;
    justify-content: space-between;
  }
  
  .last-updated {
    align-items: flex-start;
  }
  
  .footer-content {
    flex-direction: column;
    gap: var(--space-sm);
    align-items: flex-start;
  }
  
  .footer-links {
    margin-top: var(--space-sm);
  }
  
  /* Dashboard on mobile - CRITICAL FIX */
  .dashboard-active #dashboard-container {
    position: fixed !important;
    top: 60px !important; /* Below header */
    left: 0 !important;
    right: 0 !important;
    bottom: 60px !important; /* Above footer */
    height: calc(100vh - 120px) !important;
    z-index: var(--z-modal) !important;
  }
  
  .dashboard-active #dashboard-frame {
    height: 100% !important;
    width: 100% !important;
  }
  
  .dashboard-loading {
    padding: var(--space-lg) !important;
  }
  
  .dashboard-loading-spinner {
    width: 36px !important;
    height: 36px !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --border-light: #333333;
  }
  
  .metric-card {
    border-width: 2px;
  }
  
  .toggle-btn.active {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  .sidebar,
  .map-controls,
  .app-footer {
    display: none !important;
  }
  
  .main-content {
    grid-template-columns: 1fr !important;
    height: auto !important;
  }
  
  .map-container {
    height: 80vh !important;
  }
}

/* Accessibility improvements */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  z-index: 10000;
  text-decoration: none;
}

.skip-link:focus {
  top: 6px;
}

/* Dark theme specific enhancements for maps */
.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.8) !important;
  color: #fff !important;
}

/* ==================== MOBILE DETECTION & RESPONSIVE ==================== */
@media (max-width: 768px) and (orientation: portrait) {
    /* Hide all desktop elements when mobile container is active */
    body.mobile-active .app-container {
        display: none !important;
    }
    
    body.mobile-active .mobile-container {
        display: flex !important;
    }
}

/* Ensure proper tap targets on mobile */
@media (max-width: 768px) {
    button, 
    .toggle-btn, 
    .map-control-btn,
    .route-item,
    .search-result-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Improve touch scrolling */
    .sidebar,
    .routes-list,
    .viewport-routes {
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent horizontal scroll on mobile */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        position: relative;
    }
    
    .main-content {
        overflow-x: hidden;
    }
}

/* Print styles for SEO content */
@media print {
    .mobile-container,
    .map-controls,
    .sidebar,
    .toggle-group,
    .header-controls {
        display: none !important;
    }
    
    .app-container {
        display: block !important;
        height: auto !important;
    }
    
    .main-content {
        grid-template-columns: 1fr !important;
        height: auto !important;
    }
    
    .map-container {
        height: 600px !important;
        page-break-inside: avoid;
    }
    
    /* Ensure content is visible for search engines */
    .about-container.active {
        display: block !important;
        position: static !important;
        height: auto !important;
        overflow: visible !important;
    }
}

/* Toggle Button Legend Styles */
.legend-toggle-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-toggle-btn {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
    z-index: 1000;
}

.legend-toggle-btn:hover,
.legend-toggle-btn:focus {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.legend-toggle-btn.active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.legend-toggle-btn.active:hover {
    background: linear-gradient(135deg, #b91c1c, #991b1b);
}

.legend-container {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-xl);
    min-width: 200px;
    z-index: 999;
}

.legend-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

.legend-title span {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.legend-title i {
    color: var(--accent-primary);
}

.legend-scale {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.legend-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Mobile-specific legend toggle (override for mobile) */
@media (max-width: 768px) {
    .legend-toggle-container {
        position: fixed !important;
        bottom: 20px;
        left: 20px;
        z-index: 1000;
    }
    
    .legend-toggle-btn {
        width: 44px;
        height: 44px;
        background: linear-gradient(135deg, #dc2626, #b91c1c);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    }
    
    .legend-container {
        position: fixed;
        bottom: 70px;
        left: 20px;
        right: 20px;
        background: rgba(22, 27, 34, 0.95);
        backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.15);
        min-width: auto;
        max-width: 300px;
    }
    
    .legend-title span {
        color: #ffffff;
    }
    
    .legend-label {
        color: rgba(255, 255, 255, 0.8);
    }
}