/**
 * Mobile Responsiveness Optimization
 * Perfect mobile layout for map, forms, navigation, and all components
 */

/* ==========================================================================
   MOBILE-FIRST RESPONSIVE DESIGN
   ========================================================================== */

/* Base mobile styles (320px and up) */
@media (max-width: 480px) {
  /* Container adjustments */
  .container {
    padding: 0 var(--space-3);
    max-width: 100%;
  }

  /* Typography scaling */
  h1 {
    font-size: var(--font-size-3xl);
  }
  h2 {
    font-size: var(--font-size-2xl);
  }
  h3 {
    font-size: var(--font-size-xl);
  }
  h4 {
    font-size: var(--font-size-lg);
  }

  /* Button adjustments */
  .btn {
    width: 100%;
    justify-content: center;
    padding: var(--space-4) var(--space-3);
    font-size: var(--font-size-base);
  }

  /* Form improvements */
  .form-input,
  .form-textarea,
  .form-select {
    font-size: var(--font-size-base);
    padding: var(--space-4);
  }

  /* Card adjustments */
  .card {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
  }

  /* Grid system mobile-first */
  .grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  /* Spacing adjustments */
  .p-8 {
    padding: var(--space-4);
  }
  .p-6 {
    padding: var(--space-4);
  }
  .m-8 {
    margin: var(--space-4);
  }
  .m-6 {
    margin: var(--space-4);
  }

  /* Navigation improvements */
  nav {
    flex-direction: column;
    gap: var(--space-3);
  }

  nav a {
    width: 100%;
    text-align: center;
    padding: var(--space-3) var(--space-4);
  }
}

/* ==========================================================================
   MAP MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  /* Map container mobile adjustments */
  .map-container {
    height: 50vh;
    min-height: 400px;
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
  }

  /* Map statistics overlay mobile */
  .map-stats {
    top: var(--space-2);
    left: var(--space-2);
    right: var(--space-2);
  }

  .stat-card {
    padding: var(--space-3) var(--space-4);
    min-width: auto;
    width: 100%;
    font-size: var(--font-size-sm);
  }

  .stat-value {
    font-size: var(--font-size-xl);
  }

  .stat-label {
    font-size: var(--font-size-xs);
  }

  /* Map legend mobile */
  .map-legend {
    bottom: var(--space-2);
    left: var(--space-2);
    right: var(--space-2);
    padding: var(--space-3);
    font-size: var(--font-size-xs);
  }

  .legend-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }

  /* Statistics panels mobile */
  .stats-panels {
    bottom: var(--space-2);
    right: var(--space-2);
    left: auto;
    max-width: 120px;
  }

  .stat-panel {
    padding: var(--space-2) var(--space-3);
    min-width: auto;
    font-size: var(--font-size-xs);
  }

  .stat-panel .stat-value {
    font-size: var(--font-size-lg);
  }

  .stat-panel .stat-label {
    font-size: var(--font-size-xs);
  }

  /* Map actions mobile */
  .map-actions {
    top: var(--space-2);
    right: var(--space-2);
    left: auto;
  }

  .action-btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
    min-width: 100px;
  }

  /* Map popup visuals are handled by MapLibre vendor CSS and the project's map bundle. */
}

/* ==========================================================================
   FORM MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  /* Form container */
  .form-container {
    padding: var(--space-4);
    margin: var(--space-4) 0;
  }

  /* Form groups */
  .form-group {
    margin-bottom: var(--space-4);
  }

  /* Form labels */
  .form-label {
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-2);
    font-weight: var(--font-weight-semibold);
  }

  /* Form inputs */
  .form-input,
  .form-textarea,
  .form-select {
    padding: var(--space-4);
    font-size: var(--font-size-base);
    border-radius: var(--radius-md);
    line-height: var(--line-height-normal);
  }

  /* Form textarea */
  .form-textarea {
    min-height: 120px;
    resize: vertical;
  }

  /* Form buttons */
  .form-submit {
    width: 100%;
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-4);
  }

  /* Form validation messages */
  .form-error,
  .form-help {
    font-size: var(--font-size-sm);
    margin-top: var(--space-2);
    line-height: var(--line-height-normal);
  }

  /* Form success state */
  .form-success {
    padding: var(--space-4);
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    text-align: center;
  }
}

/* ==========================================================================
   NAVIGATION MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  /* Header mobile */
  header {
    padding: var(--space-6) var(--space-4);
    min-height: 90vh;
  }

  /* Main title mobile */
  header h1 {
    font-size: clamp(2.5rem, 12vw, 5rem);
    margin-bottom: var(--space-6);
    line-height: 0.9;
  }

  /* Navigation mobile */
  header nav {
    flex-direction: column;
    gap: var(--space-4);
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
  }

  header nav a {
    width: 100%;
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-size-lg);
    text-align: center;
    border-radius: var(--radius-lg);
    /* Remove light-pink background on mobile while keeping spacing —
       we preserve an accessible focus outline instead of filling the
       entire link with a background color. */
    background: transparent;
    transition:
      transform var(--transition-fast),
      opacity var(--transition-fast);
  }

  header nav a:hover,
  header nav a:focus {
    /* Don't fill the link on hover/focus to avoid large colored boxes.
       Use a visible outline + subtle shadow for pointer and keyboard
       users to indicate interaction without changing background. */
    background: transparent;
    color: var(--accent-color);
    transform: none;
    box-shadow: var(--shadow-lg);
    outline: 3px solid rgba(0,0,0,0);
    outline-offset: 3px;
  }
}

/* ==========================================================================
   CONTENT SECTIONS MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  /* Section spacing */
  section {
    padding: 0;
  }

  /* Section headings */
  section h2 {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--space-6);
    text-align: center;
  }

  section h3 {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-4);
  }

  /* Section content */
  section p {
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--space-4);
  }

  /* Lists */
  section ul,
  section ol {
    padding-left: var(--space-6);
    margin-bottom: var(--space-4);
  }

  section li {
    margin-bottom: var(--space-2);
    line-height: var(--line-height-relaxed);
  }
}

/* ==========================================================================
   PRODUCT CARDS MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  /* Product grid */
  .products-grid {
    grid-template-columns: 1fr;
    gap: var(--space-6);
    padding: var(--space-4);
  }

  /* Product card */
  .product-card {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    text-align: center;
  }

  /* Product image */
  .product-image {
    width: 100%;
    max-width: 300px;
    height: auto;
    margin: 0 auto var(--space-4);
    border-radius: var(--radius-md);
  }

  /* Product title */
  .product-title {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-3);
  }

  /* Product description */
  .product-description {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--space-4);
  }

  /* Product price */
  .product-price {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--accent-color);
    margin-bottom: var(--space-4);
  }

  /* Product button */
  .product-button {
    width: 100%;
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
  }
}

/* ==========================================================================
   FOOTER MOBILE OPTIMIZATION
   ========================================================================== */

@media (max-width: 768px) {
  footer {
    padding: var(--space-8) var(--space-4);
    text-align: center;
  }

  footer .footer-content {
    flex-direction: column;
    gap: var(--space-6);
  }

  footer .footer-section {
    width: 100%;
    text-align: center;
  }

  footer .footer-title {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-3);
  }

  footer .footer-links {
    flex-direction: column;
    gap: var(--space-3);
  }

  footer .footer-link {
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-base);
  }
}

/* ==========================================================================
   TOUCH AND GESTURE OPTIMIZATION
   ========================================================================== */

/* Touch-friendly targets */
@media (pointer: coarse) {
  /* Minimum touch target size (44x44px) */
  a,
  button,
  input[type='submit'],
  input[type='button'],
  .btn,
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 44px;
    min-width: 44px;
  }

  /* Button padding for touch */
  .btn {
    padding: var(--space-3) var(--space-6);
  }

  /* Form input padding for touch */
  .form-input,
  .form-textarea,
  .form-select {
    padding: var(--space-4);
  }

  /* Navigation link padding for touch */
  nav a {
    padding: var(--space-3) var(--space-4);
  }
}

/* ==========================================================================
   SCROLL OPTIMIZATION
   ========================================================================== */

/* Smooth scrolling enhancements */
html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}

/* iOS momentum scrolling */
body {
  -webkit-overflow-scrolling: touch;
}

/* Scroll snap for sections */
@media (max-width: 768px) {
  main {
    scroll-snap-type: y proximity;
  }

  section {
    scroll-snap-align: start;
  }
}

/* ==========================================================================
   ORIENTATION CHANGE HANDLING
   ========================================================================== */

/* Landscape mobile adjustments */
@media (max-width: 768px) and (orientation: landscape) {
  header {
    min-height: auto;
    padding: var(--space-4);
  }

  header h1 {
    font-size: var(--font-size-3xl);
    margin-bottom: var(--space-4);
  }

  header nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  header nav a {
    width: auto;
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-base);
  }

  .map-container {
    height: 70vh;
    min-height: 300px;
  }
}

/* ==========================================================================
   ACCESSIBILITY ENHANCEMENTS
   ========================================================================== */

/* Focus indicators */
@media (max-width: 768px) {
  /* Avoid forcing outlines for all elements on mobile; prefer :focus-visible with brand ring */
  *:focus {
    outline: none !important;
    box-shadow: none !important;
  }

  *:focus-visible {
    outline: none !important;
    box-shadow: var(--brand-focus-ring) !important;
    outline-offset: 2px;
  }

  /* Skip links */
  .sr-only:focus {
    position: absolute !important;
    top: var(--space-4) !important;
    left: var(--space-4) !important;
    right: var(--space-4) !important;
    width: auto !important;
    height: auto !important;
    padding: var(--space-4) !important;
    font-size: var(--font-size-lg) !important;
    z-index: var(--z-toast) !important;
  }
}

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

/* Reduce motion for mobile if preferred */
@media (prefers-reduced-motion: reduce) and (max-width: 768px) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .map-container {
    transform: none !important;
  }
}

/* Battery optimization */
@media (prefers-reduced-transparency) and (max-width: 768px) {
  .map-stats,
  .map-legend,
  .stats-panels {
    backdrop-filter: none;
    background: var(--surface-bg);
  }
}

/* ==========================================================================
   VERY SMALL SCREENS (320px and below)
   ========================================================================== */

@media (max-width: 320px) {
  .container {
    padding: 0 var(--space-2);
  }

  header h1 {
    font-size: clamp(2rem, 10vw, 4rem);
  }

  .btn {
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .map-container {
    height: 40vh;
    min-height: 300px;
  }

  .stat-card,
  .stat-panel {
    padding: var(--space-2);
    font-size: var(--font-size-xs);
  }

  .action-btn {
    padding: var(--space-2);
    font-size: var(--font-size-xs);
  }
}
