/* =================================
   MOBILE-FIRST RESPONSIVE FIXES
   SYD Platform - Complete Mobile Optimization
   ================================= */

/* =================================
   PREVENT HORIZONTAL SCROLL
   ================================= */
html {
  overflow-x: hidden;
  width: 100%;
}

body {
  overflow-x: hidden;
  width: 100%;
  min-width: 320px; /* Minimum supported width */
  position: relative;
}

/* Ensure nothing overflows */
* {
  max-width: 100%;
  box-sizing: border-box;
}

/* =================================
   BASE MOBILE (<= 480px)
   ================================= */
@media (max-width: 480px) {
  /* Global container fixes */
  .container,
  [class*="-container"] {
    padding-left: 16px !important;
    padding-right: 16px !important;
    max-width: 100% !important;
  }

  /* Section padding reduction */
  section {
    padding: 60px 0 !important;
  }

  /* Fix all grid layouts to single column */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }

  /* Fix flex layouts */
  [style*="display: flex"] {
    flex-wrap: wrap;
  }

  /* Fix horizontal flex to vertical on mobile */
  [style*="flex-direction: row"] {
    flex-direction: column !important;
  }

  /* Fix large gaps */
  [style*="gap: 60px"],
  [style*="gap: 40px"],
  [style*="gap: var(--space-3xl)"],
  [style*="gap: var(--space-2xl)"] {
    gap: 20px !important;
  }

  /* Fix large padding */
  [style*="padding: 60px"],
  [style*="padding: 90px"] {
    padding: 30px 16px !important;
  }

  /* Typography scaling */
  h1 {
    font-size: 2rem !important;
    line-height: 1.2 !important;
  }

  h2 {
    font-size: 1.5rem !important;
    line-height: 1.3 !important;
  }

  h3 {
    font-size: 1.2rem !important;
    line-height: 1.4 !important;
  }

  p {
    font-size: 0.95rem !important;
    line-height: 1.6 !important;
  }

  /* Button adjustments */
  .btn,
  button {
    width: 100%;
    justify-content: center;
    padding: 14px 20px !important;
    font-size: 1rem !important;
  }

  /* Header CTA must stay compact (it sits in a horizontal flex with logo + menu).
     Override the mobile full-width default. */
  .header .btn-get-started,
  .nav-right .btn-get-started {
    width: auto !important;
    padding: 8px 14px !important;
    font-size: 0.8125rem !important;
    min-height: 36px !important;
    flex-shrink: 0;
  }
  .nav-right { gap: 8px !important; }

  /* Multiple buttons in row */
  .btn-group,
  [style*="display: flex"] > .btn {
    width: auto;
    flex: 1;
    min-width: 0;
  }

  /* Card grids to single column */
  .card-grid,
  .benefits-grid,
  .products-grid,
  .pricing-grid {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }

  /* Modal full screen on mobile */
  .modal,
  .modal-content {
    width: 100% !important;
    height: 100vh !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 20px !important;
  }

  /* Navigation mobile */
  nav ul {
    flex-direction: column;
    gap: 10px !important;
  }

  nav a {
    padding: 12px 16px;
    width: 100%;
    text-align: left;
  }

  /* Footer adjustments */
  footer .footer-content {
    flex-direction: column !important;
    gap: 30px !important;
    text-align: center;
  }

  .footer-links {
    flex-direction: column !important;
    gap: 15px !important;
  }

  /* Hero section */
  .hero {
    padding: 60px 0 !important;
  }

  .hero h1 {
    font-size: 2rem !important;
    margin-bottom: 20px !important;
  }

  .hero .subtitle {
    font-size: 1rem !important;
  }

  /* Demo section */
  .demo-container {
    padding: 20px !important;
  }

  .demo-iframe {
    height: 400px !important;
  }

  /* Network stats */
  .network-stats {
    flex-direction: column !important;
    gap: 20px !important;
  }

  /* Comparison section */
  .comparison-grid {
    grid-template-columns: 1fr !important;
  }

  /* CTA section */
  .cta-content {
    padding: 30px 20px !important;
  }

  /* Products cards */
  .product-card {
    padding: 20px !important;
  }

  /* Price display */
  .price {
    font-size: 2rem !important;
  }

  /* Form inputs (exclude checkbox/radio — they should keep their natural 16px size) */
  input:not([type="checkbox"]):not([type="radio"]),
  textarea,
  select {
    width: 100% !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
  }
}

/* =================================
   SMALL MOBILE (< 375px)
   iPhone SE, Galaxy Fold
   ================================= */
@media (max-width: 375px) {
  /* Ultra compact spacing */
  :root {
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 24px;
    --space-3xl: 32px;
    --space-4xl: 40px;
  }

  /* Even smaller typography */
  h1 { font-size: 1.75rem !important; }
  h2 { font-size: 1.35rem !important; }
  h3 { font-size: 1.1rem !important; }
  p { font-size: 0.9rem !important; }

  /* Minimum container padding */
  .container {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Compact sections */
  section {
    padding: 40px 0 !important;
  }

  /* Smaller buttons but maintain touch target */
  .btn,
  button {
    min-height: 44px; /* iOS minimum touch target */
    padding: 12px 16px !important;
    font-size: 0.95rem !important;
  }

  /* Compact cards */
  .card,
  [class*="-card"] {
    padding: 16px !important;
  }
}

/* =================================
   LANDSCAPE MOBILE
   ================================= */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  section {
    padding-top: 40px !important;
    padding-bottom: 40px !important;
  }

  .hero {
    min-height: auto !important;
    padding: 40px 0 !important;
  }

  /* Side-by-side layout for landscape */
  .hero-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: center;
  }

  /* Reduce modal height in landscape */
  .modal-content {
    height: auto !important;
    max-height: 90vh !important;
    overflow-y: auto;
  }

  /* Hide decorative elements in landscape mobile */
  .decorative,
  .bg-gradient,
  .particle-bg {
    display: none !important;
  }
}

/* =================================
   TABLET ADJUSTMENTS (768px - 1024px)
   ================================= */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding-left: 30px;
    padding-right: 30px;
  }

  /* 2 column grid on tablet */
  .card-grid,
  .benefits-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Pricing stays 3 columns on tablet */
  .pricing-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* =================================
   SPECIFIC COMPONENT FIXES
   ================================= */

/* Fix images and media */
img, svg, video, canvas, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Fix pre/code blocks */
pre, code {
  overflow-x: auto;
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Fix tables for mobile */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* Make table responsive */
  table thead {
    display: none;
  }

  table tr {
    display: block;
    margin-bottom: 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 10px;
  }

  table td {
    display: block;
    text-align: left !important;
    padding: 10px !important;
    position: relative;
    padding-left: 50%;
  }

  table td:before {
    content: attr(data-label);
    position: absolute;
    left: 10px;
    width: 45%;
    font-weight: bold;
    color: var(--color-text-secondary);
  }
}

/* =================================
   ANIMATION PERFORMANCE
   ================================= */
@media (max-width: 768px) {
  /* Disable complex animations on mobile for performance */
  *,
  *::before,
  *::after {
    animation-duration: 0.3s !important;
    transition-duration: 0.3s !important;
  }

  /* Disable parallax on mobile */
  .parallax {
    transform: none !important;
  }

  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .btn:hover,
    a:hover {
      transform: none !important;
      box-shadow: none !important;
    }
  }
}

/* =================================
   ACCESSIBILITY IMPROVEMENTS
   ================================= */
@media (max-width: 768px) {
  /* Ensure touch targets are large enough */
  a, button, input, textarea, select {
    min-height: 44px;
    min-width: 44px;
  }

  /* Increase tap target spacing */
  .nav-link,
  .menu-item {
    padding: 12px 16px;
    margin: 2px 0;
  }

  /* Focus visible for keyboard navigation */
  *:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }
}

/* =================================
   UTILITY CLASSES
   ================================= */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: block !important; }
  .text-center-mobile { text-align: center !important; }
  .stack-mobile {
    display: block !important;
    width: 100% !important;
  }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
  .show-desktop { display: block !important; }
}

/* =================================
   DEBUG MODE (remove in production)
   ================================= */
.debug-responsive * {
  outline: 1px solid rgba(255, 0, 0, 0.2);
}

.debug-responsive *:hover {
  outline: 2px solid rgba(255, 0, 0, 0.5);
}

/* =================================
   PRINT STYLES
   ================================= */
@media print {
  .no-print,
  nav,
  .modal,
  .btn,
  button,
  .footer {
    display: none !important;
  }
}