/**
 * FloodArk AI - Mobile Responsiveness Optimization
 * Natural Disaster Early Warning System
 *
 * This file contains responsive CSS fixes for mobile devices
 * Maintains Fast Panel V2 premium minimal neutral dark styling
 */

/* ========================================
   MOBILE BREAKPOINTS
   ======================================== */

/* Mobile Small: 320px - 374px (iPhone SE) */
@media (max-width: 374px) {
  /* P-Wave Camera Popup - Stage 1 (Camera Selection) */
  #pwave-camera-popup {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    min-width: unset !important;
    max-width: unset !important;
    width: calc(100vw - 20px) !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
  }

  /* P-Wave Camera Viewer - Stage 2 (Video Player) */
  #pwave-camera-viewer {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 10px !important;
    bottom: 10px !important;
    width: calc(100vw - 20px) !important;
    height: calc(100vh - 20px) !important;
    transform: none !important;
    max-height: calc(100vh - 20px) !important;
  }

  /* Header Navigation - Stack tabs vertically on very small screens */
  .header-tabs {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  .header-tabs > div {
    font-size: 10px !important;
    padding: 4px 6px !important;
  }

  /* Hamburger Menu Panel */
  #hamburger-menu-panel {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }

  /* Global Disaster Panel */
  #seismic-watchlist-panel {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }

  /* Camera Panel */
  #camera-panel {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }

  /* Flight Drawer */
  #flight-drawer {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }

  /* Fast Panel V2 */
  #fast-panel-v2 {
    width: calc(100vw - 20px) !important;
    left: 10px !important;
    right: 10px !important;
  }

  /* Touch Target Minimum Size (WCAG 2.1) */
  button, .clickable, [onclick] {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Font Size Minimum (Readability) */
  body {
    font-size: 14px !important;
  }

  /* Announcement Bar */
  #announcement-bar {
    font-size: 12px !important;
    padding: 8px !important;
  }
}

/* Mobile Medium: 375px - 413px (iPhone 12/13) */
@media (min-width: 375px) and (max-width: 413px) {
  #pwave-camera-popup {
    position: fixed !important;
    left: 15px !important;
    right: 15px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    min-width: unset !important;
    max-width: unset !important;
    width: calc(100vw - 30px) !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
  }

  #pwave-camera-viewer {
    position: fixed !important;
    left: 15px !important;
    right: 15px !important;
    top: 15px !important;
    bottom: 15px !important;
    width: calc(100vw - 30px) !important;
    height: calc(100vh - 30px) !important;
    transform: none !important;
  }

  /* Touch targets */
  button, .clickable, [onclick] {
    min-height: 44px !important;
    min-width: 44px !important;
  }
}

/* Mobile Large: 414px - 767px (iPhone 12 Pro Max, Android) */
@media (min-width: 414px) and (max-width: 767px) {
  #pwave-camera-popup {
    position: fixed !important;
    left: 20px !important;
    right: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    min-width: unset !important;
    max-width: unset !important;
    width: calc(100vw - 40px) !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
  }

  #pwave-camera-viewer {
    position: fixed !important;
    left: 20px !important;
    right: 20px !important;
    top: 20px !important;
    bottom: 20px !important;
    width: calc(100vw - 40px) !important;
    height: calc(100vh - 40px) !important;
    transform: none !important;
  }

  /* Touch targets */
  button, .clickable, [onclick] {
    min-height: 44px !important;
    min-width: 44px !important;
  }
}

/* Tablet Portrait: 768px - 1023px (iPad) */
@media (min-width: 768px) and (max-width: 1023px) {
  #pwave-camera-popup {
    min-width: 400px !important;
    max-width: 500px !important;
  }

  #pwave-camera-viewer {
    width: 600px !important;
    height: 500px !important;
  }
}

/* Tablet Landscape: 1024px - 1279px (iPad Pro) */
@media (min-width: 1024px) and (max-width: 1279px) {
  #pwave-camera-popup {
    min-width: 400px !important;
    max-width: 500px !important;
  }

  #pwave-camera-viewer {
    width: 700px !important;
    height: 550px !important;
  }
}

/* ========================================
   DESKTOP: Hide mobile-only elements
   ======================================== */
@media (min-width: 768px) {
  /* Hide hamburger button on desktop */
  #hamburger-toggle {
    display: none !important;
  }

  /* Hide mobile logo on desktop */
  #mobile-logo {
    display: none !important;
  }

  /* Hide mobile search icon on desktop */
  #mobile-search-icon {
    display: none !important;
  }

  /* Show desktop header elements */
  .header-left {
    display: flex !important;
  }

  .header-right {
    display: flex !important;
  }

  /* Desktop search bar - grid-based centering */
  #disaster-search-container {
    display: flex !important;
    position: relative;
    width: 100%;
    max-width: none;
    min-width: 400px;
    grid-column: 2;
    justify-self: center;
    z-index: 3001;
  }
}

/* ========================================
   GENERAL MOBILE OPTIMIZATIONS
   ======================================== */

/* Prevent horizontal scrolling */
@media (max-width: 767px) {
  body {
    overflow-x: hidden !important;
  }

  /* Ensure Cesium globe container is responsive */
  #cesiumContainer {
    width: 100vw !important;
    height: calc(100vh - 60px) !important;
  }

  /* Mobile announcement bar layout */
  #announcement-bar {
    top: 56px !important;
    padding: 8px 12px !important;
    height: auto !important;
  }

  #announcement-bar.show {
    height: auto !important;
    min-height: 64px !important;
  }

  #announcement-bar .announcement-content {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }

  #announcement-bar .announcement-icon {
    font-size: 18px;
  }

  #announcement-bar .announcement-title {
    font-size: 13px;
  }

  #announcement-bar .announcement-message {
    font-size: 12px;
    line-height: 1.4;
  }

  #announcement-bar .announcement-close {
    padding: 4px 8px;
    font-size: 11px;
    align-self: flex-start;
  }

  /* Header adjustments */
  header {
    flex-wrap: wrap !important;
  }

  /* ========================================
     MOBILE HEADER REDESIGN (Amazon-style)
     - Left: Hamburger menu (≡)
     - Center: FloodArk AI logo
     - Right: Search icon (🔍)
     ======================================== */

  .header {
    position: relative !important;
    height: 56px !important;
    min-height: 56px !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 var(--space-2) !important;
    gap: var(--space-2) !important;
  }

  /* Hide header-left container (Submit Camera tab) */
  .header-left {
    display: none !important;
  }

  /* Hide all header-right tabs on mobile */
  .header-right {
    display: none !important;
  }

  /* Hamburger button - LEFT side (Amazon pattern) - integrated in header */
  #hamburger-toggle {
    position: static !important;
    width: 44px !important;
    height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    border-radius: 4px !important;
    color: #e2e8f0 !important;
    cursor: pointer !important;
    font-size: 24px !important;
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    order: 1 !important;
  }

  /* Mobile Logo - CENTER (Amazon pattern) - absolutely centered */
  #mobile-logo {
    display: block !important;
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #e2e8f0 !important;
    white-space: nowrap !important;
    pointer-events: none !important;
    order: 2 !important;
  }

  /* Mobile Search Icon - RIGHT side (Amazon pattern) */
  #mobile-search-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 20px !important;
    background: transparent !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    order: 3 !important;
    margin-left: auto !important;
  }

  #mobile-search-icon:hover {
    background: rgba(51, 65, 85, 0.5) !important;
  }

  /* Hide desktop search container on mobile (by default - JS will show it when clicked) */
  #disaster-search-container {
    display: none;
  }

  /* Search bar responsive */
  input[type="text"], input[type="search"] {
    max-width: 100% !important;
  }

  /* Panel close buttons - larger touch targets */
  .panel-close-btn, [class*="close"] {
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 24px !important;
  }

  /* Grid layouts - stack on mobile */
  .grid-2-col {
    grid-template-columns: 1fr !important;
  }

  /* Flex layouts - wrap on mobile */
  .flex-row {
    flex-wrap: wrap !important;
  }
}

  /* Header-right horizontal scroll to prevent overflow */
  .header-right {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    gap: var(--space-2) !important;
    max-width: 100vw !important;
    scrollbar-width: none !important;
  }
  .header-right::-webkit-scrollbar { display: none !important; }
  .header-right > * {
    flex: 0 0 auto !important;
    min-width: max-content !important;
  }


/* ========================================
   ACCESSIBILITY - WCAG 2.1 COMPLIANCE
   ======================================== */

/* Minimum touch target size: 44px × 44px */
@media (max-width: 767px) {
  a, button, input, select, textarea, [role="button"], [onclick], .clickable {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Exception for inline text links */
  p a, span a {
    min-height: unset;
    min-width: unset;
    display: inline;
  }
}

/* Minimum font size for readability */
@media (max-width: 767px) {
  body, p, div, span {
    font-size: 14px !important;
  }

  h1 { font-size: 24px !important; }
  h2 { font-size: 20px !important; }
  h3 { font-size: 18px !important; }
  h4 { font-size: 16px !important; }
  h5 { font-size: 14px !important; }
  h6 { font-size: 14px !important; }
}

/* ========================================
   COMPONENT-SPECIFIC FIXES
   ======================================== */

/* Seismic Waves Panel */
@media (max-width: 767px) {
  #seismic-waves-panel {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
}

/* Accuracy Dashboard */
@media (max-width: 767px) {
  #accuracy-dashboard {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }
}

/* Data Panel Manager */
@media (max-width: 767px) {
  .data-panel {
    width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }
}
