/*
 * Mobile Usability Enhancements - Tropacirca Theme 2025
 * Specific optimizations for small screen devices and touch interfaces
 */

/* ============================================
   Viewport and Base Mobile Optimizations
   ============================================ */

/* Prevent horizontal scroll on mobile */
html, body {
  overflow-x: hidden;
}

/* Better touch scrolling performance */
-webkit-touch-callout: none;
-webkit-text-size-adjust: 100%;

/* ============================================
   Extra Small Phones (< 375px / iPhone SE)
   ============================================ */

@media (max-width: 374px) {
  :root {
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.75rem;
  }

  body {
    font-size: 15px;
  }

  h1 { font-size: clamp(1.75rem, 5vw, 2.25rem); }
  h2 { font-size: clamp(1.5rem, 4vw, 1.875rem); }
  h3 { font-size: clamp(1.25rem, 3vw, 1.5rem); }

  .container {
    padding-inline: 0.75rem;
  }

  .container-wide {
    padding-inline: 0.75rem;
  }

  /* Reduce padding for tight spaces */
  section, .site-main {
    padding: 1rem 0;
  }
}

/* ============================================
   Small Phones (375px - 479px)
   ============================================ */

@media (max-width: 479px) {
  /* Stack buttons instead of row on very small screens */
  .button-group, 
  .actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .button-group button,
  .button-group a,
  .actions button,
  .actions a {
    width: 100%;
  }

  /* Improve form field spacing on small phones */
  .form-group {
    margin-bottom: 1rem;
  }

  label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    width: 100%;
    max-width: 100%;
  }

  /* Improve readability of cards on small screens */
  .card,
  [class*="card"],
  [role="article"] {
    padding: 1rem;
  }

  /* Reduce image sizes */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Make tables scrollable on small screens */
  table {
    font-size: 0.875rem;
  }

  /* Improve modal/overlay sizing */
  .modal,
  .overlay {
    padding: 1rem;
  }
}

/* ============================================
   Medium Phones (480px - 768px)
   ============================================ */

@media (min-width: 480px) and (max-width: 768px) {
  /* Better spacing for medium screens */
  .container {
    padding-inline: 1rem;
  }

  /* Two-column layouts when beneficial */
  .grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  /* Improve footer on medium phones */
  .site-footer .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }
}

/* ============================================
   Touch Interface Optimizations
   ============================================ */

@media (pointer: coarse) {
  /* Increase spacing between clickable elements */
  a, button, [role="button"], input[type="submit"],
  input[type="button"], .nav-toggle, .search-toggle,
  .cart-toggle, .social-link {
    min-height: 48px;
    min-width: 48px;
  }

  /* Add extra padding for easier tapping */
  .menu a,
  .footer-menu a {
    padding: 0.75rem 0;
  }

  /* Remove hover-only content on touch devices */
  .tooltip {
    display: none;
  }

  /* Improve form field touch targets */
  select,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Reduce double-tap delay on touch devices */
  a, button, input {
    touch-action: manipulation;
  }
}

/* ============================================
   Landscape Orientation Adjustments
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce header height in landscape */
  .site-header {
    position: relative;
  }

  /* Minimize hero section in landscape */
  .slide {
    min-height: clamp(200px, 80vh, 400px) !important;
  }

  /* Reduce padding to save vertical space */
  section, .container {
    padding: 0.75rem 0;
  }

  /* Make tables more compact */
  table {
    font-size: 0.8rem;
  }
}

/* ============================================
   Tablet Optimization (769px - 1023px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1023px) {
  /* Optimize spacing for tablet */
  .container {
    max-width: 720px;
  }

  .container-wide {
    max-width: 920px;
  }

  /* Three-column to two-column on tablets */
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   Safe Area Support (Notch/Dynamic Island)
   ============================================ */

@supports (padding: max(0px)) {
  .site-header {
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }

  .site-footer {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* ============================================
   Reduced Motion Support
   ============================================ */

@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;
  }

  .slide {
    min-height: clamp(300px, 50vh, 600px) !important;
  }
}

/* ============================================
   High Contrast Mode Support
   ============================================ */

@media (prefers-contrast: more) {
  body {
    color: #000;
    background: #fff;
  }

  .site-header {
    border-bottom-width: 2px;
  }

  a {
    text-decoration: underline;
  }

  button {
    border-width: 2px;
  }
}

/* ============================================
   Dark Mode Support
   ============================================ */

@media (prefers-color-scheme: dark) {
  /* This is intentionally minimal - respect existing dark styles */
}

/* ============================================
   Performance: Lazy Loading Images
   ============================================ */

img[loading="lazy"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   Print Styles (Mobile-Friendly Printing)
   ============================================ */

@media print {
  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  .site-header,
  .site-footer,
  .nav-toggle,
  .search-toggle,
  .cart-toggle,
  .sidebar,
  .newsletter-signup {
    display: none !important;
  }

  main {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  img {
    max-width: 100%;
    page-break-inside: avoid;
  }
}
