/* Mobile-Specific Enhancements for EpiAtlasz */

/* ============================================================================
   Mobile Touch Optimizations
   ============================================================================ */

/* Remove tap highlight on mobile */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Disable native long-press menu only on interactive elements */
button, a, input, select, textarea, [role="button"] {
  -webkit-touch-callout: none;
}

/* Prevent body scroll when drawer is open */
body.drawer-open {
  overflow: hidden !important;
  /* position:fixed, top, and width are managed by JS (mobileFilterDrawer.js)
     to preserve scroll position on iOS Safari */
}

/* ============================================================================
   Mobile Filter Improvements
   ============================================================================ */

/* Hide desktop filters on tablet/mobile */
@media (max-width: 968px) {
  /* Hide all filter columns on mobile - only show charts */
  #filtersColumn,
  #gridLayout > div:first-child,
  #gridLayout > div:nth-child(2) {
    display: none !important;
  }
  
  /* Make grid show only the charts column (third child) */
  #gridLayout {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }
  
  /* Ensure charts container takes full width */
  #gridLayout > div:nth-child(3),
  #gridLayout > div:last-child {
    display: block !important;
    width: 100% !important;
  }
}

/* Button groups - make them full width on mobile */
@media (max-width: 640px) {
  #diseaseGroupButtons,
  #sexButtons {
    flex-direction: column !important;
  }

  #diseaseGroupButtons button,
  #sexButtons button {
    width: 100% !important;
    min-height: 48px;
    font-size: 1rem;
  }

  #indicatorRadios {
    flex-direction: column !important;
  }

  #indicatorRadios label {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 1rem;
  }
}

/* ============================================================================
   Mobile Charts Enhancements
   ============================================================================ */

@media (max-width: 768px) {
  /* Chart containers */
  #chartsContainer {
    min-height: 300px !important;
    margin-bottom: 1rem !important;
  }

  /* SVG responsiveness */
  svg {
    max-width: 100%;
    height: auto;
  }
}

/* ============================================================================
   Mobile Dashboard Layout
   ============================================================================ */

@media (max-width: 768px) {
  /* Single column layout */
  #gridLayout {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Reduce padding on small screens */
  .dashboard-container {
    padding: 0 1rem !important;
  }

  section.dashboard {
    padding: 1rem 0 !important;
  }
}

/* ============================================================================
   Pull-to-Refresh Indicator
   ============================================================================ */

.pull-to-refresh {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  background: white;
  padding: 12px 20px;
  border-radius: 50px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  transition: transform 0.3s ease;
  pointer-events: none;
}

.pull-to-refresh.active {
  transform: translateX(-50%) scale(1);
}

.pull-to-refresh .spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border-subtle);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================================
   Toast Notifications for Mobile
   ============================================================================ */

.mobile-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-primary);
  color: white;
  padding: 14px 20px;
  border-radius: 50px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: transform 0.3s ease;
  max-width: 90%;
}

.mobile-toast.show {
  transform: translateX(-50%) translateY(0);
}

.mobile-toast.success {
  background: #10b981;
}

.mobile-toast.error {
  background: #ef4444;
}

.mobile-toast.warning {
  background: #f59e0b;
}

/* ============================================================================
   Landscape Mode Optimizations
   ============================================================================ */

@media (max-width: 926px) and (orientation: landscape) {
  /* Reduce header height in landscape */
  .navbar {
    padding: 0.5rem 0;
  }

  .navbar-title {
    font-size: 1.25rem;
  }

  /* Make charts use full height */
  #chartsContainer {
    min-height: calc(100vh - 180px) !important;
  }

  /* Adjust modal heights */
  .mobile-filter-drawer {
    max-height: 95vh !important;
  }
}

/* ============================================================================
   Accessibility Improvements for Touch
   ============================================================================ */

/* Focus indicators are now sitewide, not just mobile — see shared/css/styles.css */

/* Increase text size for readability on mobile, and prevent iOS auto-zoom on form focus */
@media (max-width: 768px) {
  body {
    font-size: 16px; /* Prevent zoom on iOS */
  }

  input,
  select,
  textarea {
    font-size: 16px; /* Prevent zoom on iOS form focus */
  }
}

/* ============================================================================
   Safe Area Insets (for notched devices)
   ============================================================================ */

@supports (padding: max(0px)) {
  .mobile-filter-drawer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ============================================================================
   Reduced Motion Support
   ============================================================================ */

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

/* ─── In-chart period slider — mobile overrides ──────────────────────────── */
@media (max-width: 768px) {
  .icp-slider-row {
    justify-content: stretch;
  }

  .icp-widget {
    min-width: 0;
    width: 100%;
  }

  .icp-range {
    min-width: 0;
  }

  .icp-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1rem;
  }

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