/* Responsive styles for mobile and tablet devices */

/* Enhanced Touch Interactions - Minimum 48px touch targets */
/* Apply globally for better touch accessibility */
@media (hover: none) and (pointer: coarse) {
  .header-btn, .btn, .city-option, .radio-option, .report-option-btn {
    min-height: 48px;
    min-width: 48px;
  }

  .header-btn {
    padding: 0.875rem 1.125rem;
  }

  .btn {
    padding: 1rem 1.75rem;
  }

  .city-option {
    padding: 1.5rem 1.75rem;
  }

  .radio-option {
    padding: 1.125rem 1rem;
  }

  /* Ensure stat cards and interactive elements have good touch areas */
  .stat-card {
    min-height: 48px;
    padding: 1.25rem;
  }

  .activity-item {
    min-height: 56px;
    padding: 1rem;
  }
}

/* Tablet styles */
@media (max-width: 1024px) {
  .dashboard-header {
    padding: 1rem 1.5rem;
  }
  
  .dashboard-main {
    padding: 1.5rem;
  }
  
  .quick-stats {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
  }
  
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
  }
  
  /* Better spacing for cards */
  .stat-card {
    padding: 1.5rem;
    gap: 1.25rem;
  }
  
  .dashboard-card {
    min-height: 300px;
  }
}

/* Mobile styles */
@media (max-width: 768px) {
  .dashboard-header {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    /* Add safe area for top notch */
    padding-top: calc(1rem + env(safe-area-inset-top));
  }

  .header-left {
    width: 100%;
  }

  .dashboard-logo {
    font-size: 1.5rem;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    width: 100%;
  }

  .logo-text {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .location-info {
    flex: 1;
    justify-content: flex-end;
    text-align: right;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .location-info::before {
    content: '◉';
    font-size: 1rem;
    color: var(--success-green);
    animation: status-pulse 2s ease-in-out infinite;
    flex-shrink: 0;
  }

  .header-right {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
  }

  /* Buttons container on the left */
  .header-right > button {
    flex: 0 0 auto;
  }

  /* View toggle on the right */
  .view-toggle-container {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0.4rem 0.75rem;
  }

  .view-label {
    font-size: 0.65rem;
  }

  .view-toggle-switch {
    width: 44px;
    height: 22px;
  }

  .view-slider:before {
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
  }

  .view-toggle-switch input:checked + .view-slider:before {
    transform: translateX(22px);
  }

  .dashboard-main {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    gap: 1.5rem;
  }
  
  /* Quick stats mobile layout */
  .quick-stats {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .stat-card {
    padding: 1rem;
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }
  
  .stat-icon {
    font-size: 2rem;
  }
  
  .stat-value {
    font-size: 1.5rem;
  }
  
  .stat-label {
    font-size: 0.75rem;
  }
  
  /* Dashboard grid mobile layout */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  /* Card adjustments for mobile */
  .dashboard-card {
    min-height: 250px;
  }
  
  .card-header {
    padding: 1rem;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
  
  .card-period {
    order: -1;
  }
  
  .card-content {
    padding: 1rem;
  }
  
  /* Activity list mobile */
  .activity-item {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .activity-time {
    min-width: auto;
    text-align: left;
    order: -1;
  }
  
  /* Service chart mobile */
  .service-item {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }
  
  .service-info {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  /* Hourly chart mobile */
  .hourly-bars {
    height: 80px;
  }
  
  .hourly-labels {
    font-size: 0.625rem;
  }
  
  /* Map card mobile - larger for better interaction */
  .map-card {
    min-height: 350px;
  }

  .mini-map-container {
    min-height: 280px;
  }

  /* Add touch handling hint for maps */
  .mini-map-container {
    touch-action: pan-x pan-y;
  }
}

/* Small mobile styles */
@media (max-width: 480px) {
  body {
    font-size: 15px;
  }

  .dashboard-header {
    padding: 0.75rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    gap: 0.5rem;
  }

  .dashboard-logo {
    font-size: 1.25rem;
    line-height: 1.2;
    gap: 0.75rem;
  }

  .location-info {
    font-size: 0.65rem;
    gap: 0.375rem;
  }

  .location-info::before {
    font-size: 0.85rem;
  }

  .header-right {
    gap: 0.375rem;
  }

  /* Ensure touch targets remain accessible */
  .header-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0.75rem;
    font-size: 0.85rem;
  }

  .header-btn.icon-only {
    width: 44px;
    height: 44px;
    padding: 0.75rem;
  }

  .btn-icon {
    font-size: 0.95rem;
  }

  .view-toggle-container {
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
  }

  .view-label {
    font-size: 0.65rem;
  }

  .view-toggle-switch {
    width: 44px;
    height: 22px;
  }

  .view-slider:before {
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
  }

  .view-toggle-switch input:checked + .view-slider:before {
    transform: translateX(22px);
  }
  
  .dashboard-main {
    padding: 1rem 0.75rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    gap: 1.5rem;
  }
  
  /* Single column stats on small screens - better proportions */
  .quick-stats {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .stat-card {
    padding: 1.25rem 1rem;
    min-height: 140px;
  }
  
  .stat-value {
    font-size: 1.5rem;
  }
  
  .stat-label {
    font-size: 0.85rem;
  }

  .stat-icon {
    font-size: 1.75rem;
  }

  /* Combined Stats small mobile adjustments */
  .stats-grid {
    gap: 0.75rem;
  }

  .stat-item {
    padding: 0.75rem;
  }

  .stat-item .stat-value {
    font-size: 1.125rem;
  }

  .stat-item .stat-label {
    font-size: 0.75rem;
  }
  
  /* Card adjustments for small screens */
  .dashboard-card {
    min-height: 200px;
  }
  
  .card-header {
    padding: 0.75rem;
  }
  
  .card-header h3 {
    font-size: 1.125rem;
  }

  .card-period {
    font-size: 0.75rem;
    padding: 0.375rem 0.5rem;
  }

  .card-content {
    padding: 1rem;
  }

  /* Event type items more readable */
  .event-type-item {
    padding: 0.75rem 0;
    font-size: 0.9rem;
  }

  .event-type-bar {
    width: 50px;
  }

  /* Activity items more readable */
  .activity-item {
    padding: 0.75rem;
  }

  .activity-type {
    font-size: 0.875rem;
  }

  .activity-location {
    font-size: 0.75rem;
  }
  
  /* Status items more readable */
  .status-item {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  .status-indicator {
    font-size: 0.8rem;
  }

  /* Empty states more readable */
  .empty-state {
    padding: 1.5rem;
  }

  .empty-state-icon {
    font-size: 2.5rem;
  }

  .empty-state-text {
    font-size: 0.875rem;
  }

  .empty-state-subtext {
    font-size: 0.75rem;
  }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
  .dashboard-header {
    flex-direction: row;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
  }

  .header-left {
    align-items: flex-start;
    width: auto;
  }

  .header-right {
    justify-content: flex-end;
    width: auto;
    flex-wrap: nowrap;
  }

  .dashboard-logo {
    flex-direction: row;
    gap: 0.75rem;
  }

  .quick-stats {
    grid-template-columns: 1.5fr 0.8fr 1fr;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Optimize modals for landscape */
  .setup-modal {
    max-height: 85vh;
  }

  .modal-content {
    max-height: 85vh;
  }

  /* Better map height in landscape */
  .setup-map {
    height: 280px;
  }
}

/* High DPI/Retina display adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .stat-icon,
  .empty-state-icon,
  .service-icon {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Print styles */
@media print {
  .dashboard-header .header-right,
  .modal-overlay,
  .setup-wizard {
    display: none !important;
  }
  
  .dashboard-main {
    padding: 1rem;
  }
  
  .dashboard-card {
    break-inside: avoid;
    border: 1px solid #333;
    margin-bottom: 1rem;
  }
  
  .stat-card {
    border: 1px solid #333;
  }
}

/* Enhanced Accessibility Features */

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--emergency-red);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 10001;
  border-radius: 4px;
  font-weight: 600;
}

.skip-link:focus {
  top: 6px;
}

/* Screen reader only text */
.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;
}

/* Enhanced focus states for keyboard navigation */
.btn:focus-visible,
.header-btn:focus-visible,
.city-option:focus-visible,
.radio-option:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--electric-blue);
  outline-offset: 2px;
  border-color: var(--electric-blue);
  box-shadow: 0 0 0 1px var(--electric-blue-glow);
}

.dashboard-card:focus-visible,
.stat-card:focus-visible {
  outline: 2px solid var(--electric-blue);
  outline-offset: 4px;
  box-shadow: 
    0 0 0 2px var(--electric-blue-glow),
    var(--glow-md) var(--electric-blue-glow);
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  /* Keep essential loading animations */
  .loading-spinner,
  .card-loading-spinner {
    animation-duration: 1s !important;
  }
}

/* Dark mode support (already dark by default) */
@media (prefers-color-scheme: light) {
  /* Keep dark theme even if user prefers light mode */
  /* This app is designed for emergency monitoring and dark theme is better for visibility */
}

/* Enhanced high contrast mode support */
@media (prefers-contrast: high) {
  .dashboard-card,
  .stat-card {
    border-width: 3px;
    border-color: var(--text-primary);
  }
  
  .btn-primary {
    border: 3px solid var(--electric-blue);
    background: var(--emergency-red);
  }
  
  .btn-secondary {
    border: 3px solid var(--text-primary);
    background: var(--steel-dark);
  }
  
  .status-dot.online,
  .status-dot.warning,
  .status-dot.offline {
    box-shadow: 0 0 0 3px white;
    border: 2px solid black;
  }
  
  /* Enhanced text contrast */
  h1, h2, h3, h4, h5, h6 {
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 1);
  }
  
  .text-secondary {
    color: #e0e0e0;
  }
}

/* Mobile Performance Optimizations */
@media (max-width: 768px) {
  /* Reduce complexity of expensive effects */
  body::before {
    opacity: 0.15; /* Reduce grid opacity for performance */
  }

  /* Disable entrance animations on mobile for faster initial load */
  .animate-fade-in,
  .animate-slide-in {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .stat-card,
  .dashboard-card {
    animation: none;
  }

  /* Simplified transitions for better mobile performance */
  .stat-card,
  .dashboard-card,
  .city-option,
  .btn {
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  }

  /* Reduce backdrop-filter blur for performance */
  .dashboard-header,
  .modal-content,
  .stat-card,
  .dashboard-card {
    backdrop-filter: blur(5px); /* Reduced from 10-20px */
  }

  /* Optimize animation durations */
  .tactical-fade-in,
  .slide-in-left,
  .number-count-up,
  .card-slide-in {
    animation-duration: 0.2s !important;
  }

  /* Keep essential brand animations but optimize */
  .logo-r {
    animation-duration: 4s !important; /* Slightly slower to reduce repaints */
  }

  .status-pulse {
    animation-duration: 3s !important; /* Reduce animation frequency */
  }

  /* Reduce shadow complexity on mobile */
  .stat-card:hover,
  .dashboard-card:hover {
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.3);
  }
}

/* Touch device adjustments */
@media (hover: none) and (pointer: coarse) {
  /* Disable hover effects that don't work on touch */
  .stat-card:hover,
  .dashboard-card:hover,
  .city-option:hover {
    transform: none;
    box-shadow: none;
  }
  
  /* Improved touch interactions with active states */
  .stat-card:active,
  .dashboard-card:active {
    transform: scale(0.98);
  }
  
  .btn:active {
    transform: scale(0.96);
  }
  
  .city-option:active {
    transform: scale(0.98);
  }
  
  /* Increase touch targets */
  .header-btn {
    min-height: 48px;
    padding: 0.875rem 1.125rem;
  }

  .btn {
    min-height: 48px;
    padding: 1rem 1.5rem;
  }

  .city-option {
    min-height: 64px;
    padding: 1.5rem;
  }

  .radio-option {
    min-height: 48px;
    padding: 1rem;
  }

  /* Make report buttons easier to tap */
  .report-option-btn {
    min-height: 56px;
    padding: 1rem;
  }
}

/* Enhanced loading states for mobile */
@media (max-width: 768px) {
  .loading-overlay {
    background: #000000; /* Solid background for better performance */
  }

  .loading-spinner {
    width: 32px;
    height: 32px; /* Slightly smaller for mobile */
    border-width: 2px;
    /* Hint for GPU acceleration */
    will-change: transform;
  }

  .card-loading-spinner {
    width: 20px;
    height: 20px; /* Smaller card loaders */
    border-width: 2px;
    will-change: transform;
  }

  /* Optimized empty states */
  .empty-state-icon {
    font-size: 2.5rem; /* Smaller icons */
  }

  .empty-state-text {
    font-size: 0.9rem;
    line-height: 1.4;
  }

  /* GPU acceleration hints for animated elements */
  .logo-r,
  .view-slider:before,
  .status-dot {
    will-change: transform;
    transform: translateZ(0); /* Force GPU acceleration */
  }

  /* Optimize scroll performance */
  .activity-list,
  #recent-activity,
  #event-types-chart {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
}

/* ========================================
   MOBILE TAB NAVIGATION (Mobile Only)
   ======================================== */

/* Hide mobile tab navigation on desktop */
.mobile-tab-nav {
  display: none;
}

/* Mobile Tab Navigation - Show only on mobile */
@media (max-width: 768px) {
  .mobile-tab-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--tactical-bg);
    backdrop-filter: blur(15px);
    border-top: 2px solid var(--emergency-red);
    padding: 0.5rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 90;
    box-shadow:
      0 -4px 20px rgba(0, 0, 0, 0.5),
      0 0 0 1px var(--steel-dark);
    gap: 0.5rem;
  }

  .mobile-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: rgba(31, 41, 55, 0.6);
    border: 1px solid var(--steel-medium);
    clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
    color: var(--text-muted);
    font-family: 'Roboto', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 56px;
  }

  .mobile-tab-btn .tab-icon {
    font-size: 1.5rem;
    transition: transform 0.3s ease;
  }

  .mobile-tab-btn .tab-label {
    font-size: 0.7rem;
  }

  .mobile-tab-btn:active {
    transform: scale(0.96);
  }

  .mobile-tab-btn.active {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.3), rgba(14, 165, 233, 0.3));
    border-color: var(--emergency-red);
    color: var(--text-primary);
    box-shadow:
      var(--glow-sm) var(--emergency-red-glow),
      inset 0 0 20px rgba(220, 38, 38, 0.1);
  }

  .mobile-tab-btn.active .tab-icon {
    transform: scale(1.1);
  }

  /* Add bottom padding to dashboard to account for tab bar */
  .dashboard-main {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  /* Tab content is controlled by JavaScript adding/removing display: none */
  /* This ensures smooth transitions and proper grid reflow */
  .mobile-tab-hidden {
    display: none !important;
  }

  /* Ensure grid adjusts when items are hidden */
  .dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Show extra cards on mobile within visible tabs */
  [data-mobile-tab]:not(.mobile-tab-hidden) .extra-card.hidden {
    display: flex !important;
  }
}

/* Small mobile tab adjustments */
@media (max-width: 480px) {
  .mobile-tab-nav {
    padding: 0.375rem;
    padding-bottom: calc(0.375rem + env(safe-area-inset-bottom));
  }

  .mobile-tab-btn {
    padding: 0.625rem 0.75rem;
    gap: 0.125rem;
  }

  .mobile-tab-btn .tab-icon {
    font-size: 1.25rem;
  }

  .mobile-tab-btn .tab-label {
    font-size: 0.625rem;
  }

  .dashboard-main {
    padding-bottom: calc(75px + env(safe-area-inset-bottom));
  }
}

/* Landscape adjustments for mobile tabs */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-tab-nav {
    padding-left: calc(0.5rem + env(safe-area-inset-left));
    padding-right: calc(0.5rem + env(safe-area-inset-right));
  }

  .mobile-tab-btn {
    flex-direction: row;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
  }

  .mobile-tab-btn .tab-icon {
    font-size: 1.25rem;
  }
}