
/* === Mobile-only patch for narrow phones (iPhone SE 375x667 and similar) === */
/* Drop this file AFTER styles.css. It does not change desktop/tablet layouts. */

@media (max-width: 400px) {
  /* Prevent any horizontal scroll caused by wide children */
  html, body { overflow-x: hidden; }

  /* Tighten horizontal padding so content uses the full width */
  .site-header .container,
  .container { padding-left: 12px; padding-right: 12px; }

  /* Header layout: ensure it spans edge-to-edge and doesn't overflow */
  .nav {
    grid-template-columns: 1fr auto;    /* logo left, cta right */
    grid-auto-flow: row;                 /* allow wrapping when needed */
    align-items: center;
  }
  .main-nav { display: none; }           /* hide desktop links on tiny screens */
  .nav-cta {
    justify-self: end;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .nav-cta .phone span { display: none; } /* show just the phone icon on very small devices */
  .nav-cta .phone { padding: 8px; }       /* compact icon button */
  .btn.btn-emergency {
    padding: 10px 12px;
    border-radius: 10px;
    white-space: nowrap;                  /* keep it on one line */
  }

  /* Make any grid columns shrink properly without forcing overflow */
  .hero-wrap,
  .about-grid,
  .card-grid,
  .metrics,
  .row,
  .row.two {
    grid-template-columns: minmax(0,1fr) !important;
  }

  /* Images/cards: stay within viewport width */
  img, video, canvas { max-width: 100%; height: auto; }
  .hero-photo, .service-media img { width: 100%; }

  /* Defensive: avoid any rogue element pushing layout horizontally */
  header, main, section, footer,
  .hero, .services, .about, .reviews, .cta, .contact, .banner,
  .site-header, .nav, .footer {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

/* === Mobile review order fix === */
@media (max-width: 400px) {
  .reviews .review-list {
    display: flex;
    flex-direction: column;
  }
  .reviews .review-michael { order: 1; }
  .reviews .review-emily   { order: 2; }
  .reviews .review-david   { order: 3; }
}

/* === Mobile-wide review layout fix (phones & small tablets up to 768px) === */
@media (max-width: 768px) {
  /* Prevent any residual horizontal scroll */
  html, body { overflow-x: hidden; }

  /* Stack review cards vertically and keep DOM order: Michael -> Emily -> David */
  .reviews .review-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 18px;
  }
  .reviews .review-grid > article.review {
    order: 0; /* keep natural order unless overridden */
    width: 100%;
  }

  /* Safety: make sure no child has fixed widths that cause clipping */
  .reviews .review-grid > * {
    max-width: 100%;
    overflow: visible;
  }
}

/* === iPhone XR specific header fix (414x896 and similar up to 430px) === */
@media (min-width: 401px) and (max-width: 430px) {
  /* Keep everything inside the viewport and account for padding */
  .site-header, .site-header .container, .nav {
    box-sizing: border-box;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .site-header .container { padding-left: 12px; padding-right: 12px; }

  /* Simple two-column header: logo left, actions right */
  .nav {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 10px;
  }

  /* Hide desktop nav on XR width too */
  .main-nav { display: none; }

  /* Compact the action area so nothing pushes off-screen */
  .nav-cta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;          /* allow shrink */
  }
  .nav-cta .phone span { display: none; }   /* icon-only phone on XR */
  .nav-cta .phone { padding: 8px; }

  /* Emergency button: allow gentle shrink without overflowing */
  .btn.btn-emergency {
    font-size: 0.95rem;
    line-height: 1.15;
    padding: 10px 12px;
    border-radius: 10px;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 0 1 auto;        /* allow it to shrink slightly if needed */
  }
}
