/* Mobile-only optimizations for Magnolia Diagnostics */

/* Base guard: never affect desktop */
@media (max-width: 768px) {
  /* Layout and containers */
  html { 
    box-sizing: border-box; 
    font-size: 15px; /* Scale down from default 16px */
  }
  *, *::before, *::after { box-sizing: inherit; }

  body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
  }

  /* Global container shrink */
  .container, .wrapper, .content, [class*="container"] {
    max-width: 100%;
    width: 100%;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* Typography: scale down oversized text, improve line length */
  h1 { 
    font-size: clamp(22px, 6vw, 28px) !important; 
    line-height: 1.2 !important; 
  }
  h2 { 
    font-size: clamp(20px, 5.5vw, 24px) !important; 
    line-height: 1.25 !important; 
  }
  h3 { 
    font-size: clamp(18px, 5vw, 20px) !important; 
    line-height: 1.3 !important; 
  }
  h4 {
    font-size: clamp(16px, 4.5vw, 18px) !important;
    line-height: 1.35 !important;
  }
  p, li { 
    font-size: 15px !important; 
    line-height: 1.55 !important; 
  }

  /* Spacing: tighten vertical rhythm */
  :root {
    --space-xxl: 32px;
    --space-xl: 24px;
    --space-lg: 20px;
    --space-md: 16px;
    --space-sm: 12px;
    --space-xs: 8px;
  }

  /* Reduce excessive padding on sections */
  section, .section { 
    padding-top: var(--space-xl) !important; 
    padding-bottom: var(--space-xl) !important; 
  }
  
  /* Hero sections get a bit more space but still reduced */
  .hero { 
    padding-top: var(--space-xxl) !important; 
    padding-bottom: var(--space-xxl) !important; 
  }

  /* Images and media */
  img, svg, canvas, video, iframe {
    max-width: 100% !important;
    height: auto !important;
  }
  
  /* Keep media from touching edges */
  .media, .hero img, figure { 
    margin-left: 0 !important; 
    margin-right: 0 !important; 
  }

  /* Navigation: stack items and reduce padding */
  .nav, nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  nav a, .nav a {
    padding: 10px 12px !important;
    font-size: 15px !important;
  }
  
  /* Allow horizontal menu to wrap instead of overflow */
  nav ul { 
    overflow: visible !important; 
    white-space: normal !important; 
  }

  /* Buttons and tap targets */
  button, .btn, [role="button"], input[type="submit"] {
    min-height: 44px !important;
    padding: 10px 14px !important;
    font-size: 15px !important;
  }
  a, button { touch-action: manipulation; }

  /* Forms */
  input, select, textarea {
    width: 100% !important;
    font-size: 16px !important; /* prevents iOS zoom */
    padding: 10px 12px !important;
  }
  label { 
    font-size: 14px !important; 
    display: block; 
    margin-bottom: 6px; 
  }

  /* Tables: enable horizontal scroll as a safe default */
  table { 
    display: block; 
    width: 100%; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
  }
  th, td { 
    white-space: nowrap; 
    padding: 10px; 
  }

  /* Cards and columns: collapse to single column for grids */
  .grid, .row, [class*="columns"], [class*="grid"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  
  /* Override specific Tailwind grid classes */
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .grid-cols-5,
  .md\\:grid-cols-2,
  .md\\:grid-cols-3,
  .md\\:grid-cols-4,
  .md\\:grid-cols-5,
  .lg\\:grid-cols-2,
  .lg\\:grid-cols-3,
  .lg\\:grid-cols-4,
  .lg\\:grid-cols-5 {
    grid-template-columns: 1fr !important;
  }

  .col, [class*="col-"], [class*="span-"] { 
    width: 100% !important; 
  }

  /* Modals and dialogs: full width on mobile */
  .modal, .dialog {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    height: 100vh !important;
    top: 0; 
    left: 0;
    border-radius: 0;
  }
  .modal .content, .dialog .content { 
    padding: 16px; 
  }

  /* Sticky headers and footers with safe areas */
  .header, .footer, .sticky {
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* Reduce excessive Tailwind spacing classes */
  .py-32 {
    padding-top: var(--space-xl) !important;
    padding-bottom: var(--space-xl) !important;
  }
  
  .py-24 {
    padding-top: var(--space-lg) !important;
    padding-bottom: var(--space-lg) !important;
  }
  
  .py-16 {
    padding-top: var(--space-md) !important;
    padding-bottom: var(--space-md) !important;
  }

  .mb-16 {
    margin-bottom: var(--space-lg) !important;
  }
  
  .mb-12 {
    margin-bottom: var(--space-md) !important;
  }
  
  .mb-8 {
    margin-bottom: var(--space-sm) !important;
  }

  /* Reduce motion where possible */
  @media (prefers-reduced-motion: reduce) {
    * { 
      animation-duration: 0.001ms !important; 
      animation-iteration-count: 1 !important; 
      transition-duration: 0.001ms !important; 
    }
  }

  /* Mobile-specific logo sizing */
  .navbar-logo-mobile {
    height: 40px !important;
    width: auto !important;
  }

  /* Hero headline mobile adjustments */
  .hero-headline-mobile {
    font-size: clamp(2.5rem, 8vw, 4rem) !important;
    padding-top: 60px !important;
    text-align: center !important;
  }

  /* Hero content mobile centering */
  .hero-content-mobile {
    text-align: center !important;
  }

  .hero-content-mobile p {
    margin: 0 auto !important;
  }

  .hero-button-mobile {
    text-align: center !important;
    padding-bottom: 40px !important;
  }

  /* Hero subheadline mobile sizing */
  .hero-content-mobile p {
    font-size: 20px !important;
  }

  /* Mission statement mobile sizing */
  .mission-text-mobile {
    font-size: clamp(1.5rem, 6vw, 2.5rem) !important;
  }

  /* Video section mobile adjustments */
  .video-section-mobile {
    height: 50vh !important;
  }

  .video-container-mobile {
    height: 100% !important;
  }

  .video-mobile {
    height: 100% !important;
    object-fit: cover !important;
  }


  /* Feature card headlines mobile sizing */
  .feature-card h4 {
    font-size: 1.75rem !important;
    line-height: 1.2 !important;
  }

  /* Blog section mobile accordion */
  .blog-section-mobile {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  .blog-mobile-container {
    max-width: 100% !important;
    padding: 0 1rem !important;
  }

  .blog-card-mobile {
    display: block !important;
    background: white !important;
    border: 1px solid #000 !important;
    margin-bottom: 1rem !important;
    border-radius: 0 !important;
    overflow: hidden !important;
  }

  .blog-header-mobile {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1.5rem 1rem !important;
    cursor: pointer !important;
    border-bottom: none !important;
  }

  .blog-title-mobile {
    font-size: 1.1rem !important;
    font-weight: 600 !important;
    color: #000 !important;
    margin: 0 !important;
    line-height: 1.3 !important;
    max-width: 85% !important;
  }

  .blog-arrow-mobile {
    width: 20px !important;
    height: 20px !important;
    transition: transform 0.3s ease !important;
    color: #1e40af !important;
    flex-shrink: 0 !important;
  }

  .blog-arrow-mobile.expanded {
    transform: rotate(180deg) !important;
  }

  .blog-content-mobile {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
  }

  .blog-content-mobile.expanded {
    max-height: 300px !important;
  }

  .blog-inner-content-mobile {
    padding: 1rem !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .blog-meta-mobile {
    font-size: 0.8rem !important;
    color: #6b7280 !important;
    margin-bottom: 0.5rem !important;
  }

  .blog-excerpt-mobile {
    color: #4b5563 !important;
    line-height: 1.4 !important;
    font-size: 0.9rem !important;
  }

  .blog-link-mobile {
    color: #1e40af !important;
    font-weight: 500 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    text-decoration: none !important;
    font-size: 0.85rem !important;
    margin-top: 0.5rem !important;
  }

  /* Hide desktop blog layout on mobile */
  .blog-desktop-layout {
    display: none !important;
  }

  /* Services pages - add extra padding above section headlines on mobile */
  /* Target the small uppercase section headers (h2) that appear before main headlines */
  h2.text-xl.uppercase.text-gray-500 {
    margin-top: 3rem !important;
  }
  
  /* First section after hero shouldn't have extra top margin */
  section:first-of-type h2.text-xl.uppercase.text-gray-500 {
    margin-top: 0 !important;
  }

  /* Hide values section on about page for mobile only */
  .values-section-mobile-hide {
    display: none !important;
  }

  /* Respiratory testing pathogen list - compact mobile layout */
  .pathogen-grid-mobile {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }

  .pathogen-item-mobile {
    padding: 0.75rem 0.5rem !important;
    font-size: 0.8rem !important;
  }

  .pathogen-item-mobile .h-5 {
    width: 1rem !important;
    height: 1rem !important;
  }

  .pathogen-item-mobile span {
    font-size: 0.75rem !important;
    line-height: 1.2 !important;
  }

  /* Utility classes for mobile */
  .stack { 
    display: grid; 
    gap: 16px; 
  }
  
  .pad { 
    padding: 16px; 
  }
  
  .pad-sm { 
    padding: 8px; 
  }
  
  .mt-sm { 
    margin-top: 8px; 
  }
  
  .mt-md { 
    margin-top: 16px; 
  }
  
  .text-center { 
    text-align: center; 
  }
  
  .full-bleed { 
    margin-left: -16px; 
    margin-right: -16px; 
  }

  /* Services section mobile accordion */
  .services-section-mobile {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  .services-mobile-container {
    max-width: 100% !important;
    padding: 0 1rem !important;
    space-y: 0 !important;
  }

  .service-card-mobile {
    display: block !important;
    background: white !important;
    border: 1px solid #000 !important;
    margin-bottom: 1rem !important;
    border-radius: 0 !important;
    overflow: hidden !important;
  }

  .service-header-mobile {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1.5rem 1rem !important;
    cursor: pointer !important;
    border-bottom: none !important;
  }

  .service-title-mobile {
    font-size: 1.25rem !important;
    font-weight: 600 !important;
    color: #000 !important;
    margin: 0 !important;
  }

  .service-arrow-mobile {
    width: 20px !important;
    height: 20px !important;
    transition: transform 0.3s ease !important;
    color: #1e40af !important;
  }

  .service-arrow-mobile.expanded {
    transform: rotate(180deg) !important;
  }

  .service-content-mobile {
    max-height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease !important;
  }

  .service-content-mobile.expanded {
    max-height: 500px !important;
  }

  .service-inner-content-mobile {
    padding: 1rem !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .service-image-mobile {
    width: 100% !important;
    height: 150px !important;
    object-fit: cover !important;
    border-radius: 0 !important;
  }

  .service-description-mobile {
    color: #6b7280 !important;
    line-height: 1.5 !important;
    font-size: 0.95rem !important;
  }

  .service-link-mobile {
    color: #1e40af !important;
    font-weight: 500 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    text-decoration: none !important;
    font-size: 0.9rem !important;
  }

  /* Hide desktop layout on mobile */
  .services-desktop-layout {
    display: none !important;
  }

  /* Testimonials headline mobile adjustments */
  .testimonials-headline-mobile {
    padding-top: 40px !important;
  }

  /* Hide university testing intro paragraph on mobile */
  .university-intro-paragraph-mobile {
    display: none !important;
  }

  /* Test menu tab buttons mobile styling */
  .test-menu-tabs-mobile {
    gap: 8px !important;
  }

  .test-menu-tab-button-mobile {
    padding: 8px 12px !important;
    font-size: 0.8rem !important;
    min-width: auto !important;
    flex: 0 0 auto !important;
  }

  /* Test menu search input mobile adjustments */
  .test-search-input-mobile {
    padding-left: 3rem !important;
    font-size: 1rem !important;
  }

  .test-search-icon-mobile {
    left: 1rem !important;
    width: 1rem !important;
    height: 1rem !important;
  }

  /* Hide provider portal laptop icon on mobile */
  .provider-portal-icon-mobile {
    display: none !important;
  }

  /* Mobile forms layout overrides - only apply on mobile */
  .forms-mobile-grid {
    gap: 8px !important;
  }

  .forms-mobile-grid > div {
    width: 100% !important;
  }

  .forms-mobile-grid .bg-white {
    padding: 6px !important;
    font-size: 0.7rem !important;
  }

  .forms-mobile-grid h3 {
    font-size: 0.8rem !important;
    line-height: 1.1 !important;
    margin-bottom: 2px !important;
  }

  .forms-mobile-grid p {
    font-size: 0.65rem !important;
    line-height: 1.2 !important;
    margin-bottom: 6px !important;
  }

  /* Hide metadata grid on mobile */
  .forms-mobile-grid .grid {
    display: none !important;
  }

  .forms-mobile-grid .w-6,
  .forms-mobile-grid .w-8 {
    width: 1.5rem !important;
    height: 1.5rem !important;
  }

  .forms-mobile-grid svg {
    width: 0.8rem !important;
    height: 0.8rem !important;
  }

  .forms-mobile-grid button {
    font-size: 0.6rem !important;
    padding: 2px 4px !important;
  }
}

/* Tighter rules for very narrow phones */
@media (max-width: 480px) {
  h1 { 
    font-size: clamp(20px, 7vw, 26px) !important; 
  }
  
  .hero { 
    padding-top: 24px !important; 
    padding-bottom: 24px !important; 
  }
  
  .hide-on-mobile { 
    display: none !important; 
  }
  
  /* Line clamp utility for long content */
  .clamp-3 { 
    display: -webkit-box; 
    -webkit-line-clamp: 3; 
    -webkit-box-orient: vertical; 
    overflow: hidden; 
  }
  
  /* Even tighter spacing for very small screens */
  .py-32 {
    padding-top: 20px !important;
    padding-bottom: 20px !important;
  }
  
  .container, .wrapper, .content, [class*="container"] {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}