/**
 * Mobile Optimizations CSS
 * Specific optimizations for mobile and touch devices
 */

/* Import variables */
@import 'variables.css';

/* ===== MOBILE MAP OPTIMIZATIONS ===== */

/* Ensure map doesn't overlap navbar on mobile */
@media (max-width: 768px) {
    #mapid {
        height: calc(100vh - var(--navbar-height-mobile, 60px)) !important;
    }
}

/* ===== MOBILE LOGO OVERLAY OPTIMIZATIONS ===== */

  /* Logo overlay mobile adjustments - moved to bottom-left */
  @media (max-width: 768px) {
      #logo-overlay {
          top: auto;
          right: auto;
          bottom: 15px;
          left: 15px;
      }
      
      .logo-image {
          height: 16px;
          max-width: 80px;
      }
  }

  @media (max-width: 480px) {
      #logo-overlay {
          bottom: 10px;
          left: 10px;
      }
      
      .logo-image {
          height: 14px;
          max-width: 70px;
      }
  }

  @media (max-width: 360px) {
      #logo-overlay {
          bottom: 8px;
          left: 8px;
      }
      
      .logo-image {
          height: 12px;
          max-width: 60px;
      }
  }

/* ===== MOBILE NAVIGATION OPTIMIZATIONS ===== */

/* Mobile Navigation Container */
@media (max-width: 768px) {
    .top-right-button-set {
        /* Ensure buttons don't overlap with other elements */
        position: fixed;
        top: calc(var(--navbar-height) + 10px); /* Push down by navbar height + margin */
        right: 10px;
        z-index: 1002;
        
        /* Horizontal layout for better mobile UX */
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        gap: 8px;
        
        /* Responsive sizing */
        max-width: calc(100vw - 20px);
        height: auto;
        
        /* Better touch targets */
        padding: 4px;
        background: rgba(0, 0, 0, 0.1);
        border-radius: var(--border-radius);
        backdrop-filter: blur(10px);
    }
}

/* Small Mobile Optimizations */
@media (max-width: 480px) {
    .top-right-button-set {
        top: calc(var(--navbar-height) + 5px); /* Push down by navbar height + smaller margin */
        right: 5px;
        gap: 6px;
        max-width: calc(100vw - 10px);
        padding: 3px;
    }
}

/* Extra Small Mobile */
@media (max-width: 360px) {
    .top-right-button-set {
        top: calc(var(--navbar-height) + 3px); /* Push down by navbar height + smallest margin */
        right: 3px;
        gap: 4px;
        max-width: calc(100vw - 6px);
        padding: 2px;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */

/* Touch Device Specific Styles */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .icon-button-stats-toggle:hover,
    .icon-button-show-hide-alert-zones-toggle:hover,
    .icon-button:hover,
    .icon-button-light-dark-toggle:hover {
        transform: none;
        box-shadow: var(--shadow);
    }
    
    /* Enhanced active states for touch feedback */
    .icon-button-stats-toggle:active,
    .icon-button-show-hide-alert-zones-toggle:active,
    .icon-button:active,
    .icon-button-light-dark-toggle:active {
        transform: scale(0.95);
        background: var(--primary-active);
        transition: all 0.1s ease;
    }
    
    /* Better touch targets */
    .icon-button-stats-toggle,
    .icon-button-show-hide-alert-zones-toggle,
    .icon-button,
    .icon-button-light-dark-toggle {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        -webkit-tap-highlight-color: rgba(52, 152, 219, 0.3);
        touch-action: manipulation;
    }
}

/* ===== MOBILE PANEL OPTIMIZATIONS ===== */

/* Mobile Stats Panel */
@media (max-width: 768px) {
    .stats-panel {
        /* Full screen on mobile */
        width: 100%;
        height: calc(100vh - var(--navbar-height)); /* Account for navbar height */
        top: var(--navbar-height); /* Push down by navbar height */
        right: -100%;
        border-radius: 0;
        
        /* Better mobile scrolling */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .stats-panel.open {
        right: 0;
    }
    
    /* Mobile panel content */
    .stats-panel .panel-section {
        margin-bottom: var(--spacing-sm);
        padding: var(--spacing-sm);
    }
    
    .stats-panel h2 {
        font-size: var(--font-size-md);
        margin-bottom: var(--spacing-sm);
    }
    
    .stats-panel p {
        font-size: var(--font-size-sm);
        line-height: 1.4;
    }
}

/* ===== MOBILE SEARCH OPTIMIZATIONS ===== */

/* Mobile Search Container */
@media (max-width: 768px) {
    .search-container {
        margin-bottom: var(--spacing-sm);
    }
    
    .search-box {
        padding: var(--spacing-xs);
        border-radius: var(--border-radius-sm);
    }
    
    .search-box input {
        font-size: var(--font-size-xs);
        padding: var(--spacing-xs);
    }
    
    .search-box i {
        font-size: var(--font-size-xs);
        margin-right: var(--spacing-xs);
    }
    
    /* Floating search on mobile */
    #floating-search-wrapper {
        padding: var(--spacing-sm);
        transform: translateY(-100%);
    }
    
    #floating-search-wrapper.show {
        transform: translateY(0);
    }
}

/* ===== MOBILE NAVBAR OPTIMIZATIONS ===== */

/* Mobile Navbar */
@media (max-width: 768px) {
    .navbar-top {
        padding: var(--spacing-xs) 0;
        position: relative; /* Ensure it stays relative on mobile too */
        z-index: var(--z-navbar) !important; /* Ensure navbar stays on top on mobile */
        display: block !important; /* Defensive: prevent accidental hiding */
        visibility: visible !important; /* Defensive: ensure always visible */
    }
    
    .navbar-container {
        padding: var(--spacing-xs) var(--spacing-sm);
        flex-wrap: wrap;
        display: flex !important; /* Defensive: ensure flex layout on mobile */
        opacity: 1 !important; /* Defensive: prevent opacity issues */
        position: relative; /* Ensure proper positioning context */
    }
    
    .brand-text {
        font-size: var(--font-size-sm);
    }
    
    .navbar-info {
        display: none; /* Hide on mobile to save space */
    }
    
    /* Mobile navbar collapse */
    .navbar-collapse {
        position: relative; /* Changed from fixed since navbar is now relative */
        top: 0; /* Changed from 100% */
        left: 0;
        right: 0;
        background-color: var(--dark-panel);
        border-top: 1px solid var(--border-color);
        box-shadow: var(--shadow);
        transform: none; /* Removed transform since using relative positioning */
        transition: max-height var(--transition-speed); /* Changed transition property */
        z-index: var(--z-navbar);
        max-height: 0; /* Start collapsed */
        overflow: hidden; /* Hide content when collapsed */
        -webkit-overflow-scrolling: touch;
    }
    
    .navbar-collapse.show {
        max-height: 300px; /* Allow expansion to show content */
    }
    
    .navbar-nav {
        flex-direction: column;
        padding: var(--spacing-md);
    }
    
    .nav-item {
        margin-bottom: var(--spacing-sm);
    }
    
    .nav-link {
        padding: var(--spacing-sm) 0;
        border-bottom: 1px solid var(--border-color);
        color: var(--text-light);
        transition: color var(--transition-speed);
        font-size: var(--font-size-sm);
    }
    
    .nav-link:hover {
        color: var(--primary-color);
        background-color: transparent;
    }
}

/* ===== MOBILE TABLE OPTIMIZATIONS ===== */

/* Mobile Table Responsiveness */
@media (max-width: 768px) {
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--border-radius-sm);
        margin: var(--spacing-sm) 0;
    }
    
    table {
        min-width: 300px; /* Ensure minimum readable width */
    }
    
    th, td {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-xs);
        white-space: nowrap;
    }
    
    /* Stack table on very small screens */
    @media (max-width: 480px) {
        table {
            display: block;
        }
        
        thead {
            display: none;
        }
        
        tbody {
            display: block;
        }
        
        tr {
            display: block;
            margin-bottom: var(--spacing-sm);
            padding: var(--spacing-sm);
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius-sm);
        }
        
        td {
            display: block;
            text-align: left;
            padding: var(--spacing-xs) 0;
            border: none;
            white-space: normal;
        }
        
        td:before {
            content: attr(data-label) ": ";
            font-weight: bold;
            color: var(--primary-color);
        }
    }
}

/* ===== MOBILE FORM OPTIMIZATIONS ===== */

/* Mobile Form Elements */
@media (max-width: 768px) {
    .form-group {
        flex-direction: column;
        align-items: flex-start;
        margin-bottom: var(--spacing-sm);
    }
    
    .form-group label {
        width: auto;
        margin-bottom: var(--spacing-xs);
        font-size: var(--font-size-sm);
    }
    
    .form-control {
        width: 100%;
        padding: var(--spacing-sm);
        font-size: var(--font-size-sm);
        border-radius: var(--border-radius-sm);
    }
    
    .btn {
        width: 100%;
        min-height: var(--touch-target-min);
        font-size: var(--font-size-sm);
        padding: var(--spacing-sm);
    }
}

/* ===== MOBILE MODAL OPTIMIZATIONS ===== */

/* Mobile Modal */
@media (max-width: 768px) {
    .modal-content {
        margin: var(--spacing-sm);
        border-radius: var(--border-radius);
        max-height: calc(100vh - 2 * var(--spacing-sm));
        overflow-y: auto;
    }
    
    .modal-header {
        padding: var(--spacing-sm);
    }
    
    .modal-body {
        padding: var(--spacing-sm);
    }
    
    .modal-footer {
        padding: var(--spacing-sm);
        flex-direction: column;
        gap: var(--spacing-xs);
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ===== MOBILE UTILITY CLASSES ===== */

/* Mobile-specific utility classes */
@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-visible {
        display: block !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-text-small {
        font-size: var(--font-size-xs) !important;
    }
    
    .mobile-padding-sm {
        padding: var(--spacing-xs) !important;
    }
    
    .mobile-margin-sm {
        margin: var(--spacing-xs) !important;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATIONS ===== */

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .top-right-button-set {
        top: calc(var(--navbar-height) + 5px); /* Push down by navbar height + margin */
        right: 5px;
        gap: 6px;
        flex-wrap: nowrap;
    }

    .navbar-container {
        padding: var(--spacing-xs);
    }

    .stats-panel {
        top: var(--navbar-height); /* Push down by navbar height */
        height: calc(100vh - var(--navbar-height)); /* Account for navbar height */
    }
    
    /* Reduce vertical spacing in landscape */
    .panel-section {
        padding: var(--spacing-xs);
        margin-bottom: var(--spacing-xs);
    }
    
    .search-container {
        margin-bottom: var(--spacing-xs);
    }
}

/* ===== HIGH DPI DISPLAY OPTIMIZATIONS ===== */

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .icon-button-stats-toggle,
    .icon-button-show-hide-alert-zones-toggle,
    .icon-button,
    .icon-button-light-dark-toggle {
        border: 0.5px solid rgba(255, 255, 255, 0.1);
    }
    
    .search-box {
        border: 0.5px solid var(--border-color);
    }
    
    .modal-content {
        border: 0.5px solid var(--border-color);
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus indicators for mobile */
@media (max-width: 768px) {
    .icon-button-stats-toggle:focus,
    .icon-button-show-hide-alert-zones-toggle:focus,
    .icon-button:focus,
    .icon-button-light-dark-toggle:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    .btn:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    .form-control:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
    .icon-button-stats-toggle,
    .icon-button-show-hide-alert-zones-toggle,
    .icon-button,
    .icon-button-light-dark-toggle {
        transition: background-color 0.15s ease, transform 0.1s ease;
    }
    
    .btn {
        transition: background-color 0.15s ease, transform 0.1s ease;
    }
    
    .stats-panel {
        transition: right 0.2s ease;
    }
    
    .navbar-collapse {
        transition: transform 0.2s ease;
    }
}

/* ===== SAFE AREA SUPPORT ===== */

/* Support for devices with notches and safe areas */
@supports (padding: max(0px)) {
    .top-right-button-set {
        top: max(calc(var(--navbar-height) + 10px), calc(var(--navbar-height) + env(safe-area-inset-top))); /* Account for navbar + safe area */
        right: max(10px, env(safe-area-inset-right));
    }
    
    .navbar-top {
        padding-top: max(var(--spacing-sm), env(safe-area-inset-top));
    }
    
    .navbar-bottom {
        padding-bottom: max(var(--spacing-sm), env(safe-area-inset-bottom));
    }
    
    .stats-panel {
        top: max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))); /* Account for navbar + safe area */
        height: calc(100vh - max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    /* Ensure left sidebar accounts for safe areas */
    .left-sidebar {
        top: max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))); /* Account for navbar + safe area */
        height: calc(100vh - max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    /* Ensure secondary menu accounts for safe areas */
    .secondary-menu {
        top: max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))); /* Account for navbar + safe area */
        height: calc(100vh - max(var(--navbar-height), calc(var(--navbar-height) + env(safe-area-inset-top))));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
} 