/* ═══════════════════════════════════════
   MOBILE RESPONSIVE — Complete Adaptation
   ═══════════════════════════════════════ */

/* ─── Global Mobile ─── */
@media (max-width: 768px) {
  .container { padding: 0 14px !important; }
  
  /* Product Grid — 2 columns on tablet */
  .products-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  .product-info { padding: 10px 12px; }
  .product-name { font-size: 13px; -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
  .product-price { font-size: 15px; }
  
  /* Cart table */
  .cart-table th:nth-child(n+3), .cart-table td:nth-child(n+3) { display: none; }
  .cart-table { font-size: 13px; }
  
  /* Checkout */
  .checkout-grid { grid-template-columns: 1fr !important; }
  .form-row.two-col { grid-template-columns: 1fr !important; }
  
  /* Search page */
  .search-results-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  
  /* Footer */
  .footer-grid-portal { grid-template-columns: 1fr 1fr !important; gap: 20px !important; }
  .footer-bottom { flex-direction: column; gap: 8px; text-align: center; }
  .footer-links { flex-wrap: wrap; justify-content: center; }
  
  /* Hero sections */
  .hero h1 { font-size: 24px !important; }
  .hero p { font-size: 14px !important; }
  
  /* Pagination */
  .pagination { gap: 6px; }
  .pagination a, .pagination span { padding: 8px 12px; font-size: 13px; }
  
  /* Blog grid */
  .blog-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  
  /* Brand grid */
  .brands-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  
  /* Compare */
  .compare-grid { overflow-x: auto; }
  
  /* Wiki / Guide */
  .wiki-grid, .guide-grid { grid-template-columns: 1fr !important; }
  
  /* Collections */
  .collections-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  
  /* Actions */
  .actions-grid { grid-template-columns: 1fr !important; }
  
  /* Product detail: features cards */
  .pd-features-cards { grid-template-columns: 1fr !important; }
  
  /* Sticky bar mobile-friendly */
  .pd-sticky-inner { gap: 10px; }
  .pd-sticky-name { display: none; }
  .pd-sticky-btn { padding: 10px 20px; font-size: 13px; }
}

@media (max-width: 480px) {
  .container { padding: 0 10px !important; }
  
  /* Product Grid — still 2 columns but tighter */
  .products-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .product-card { border-radius: 8px; }
  .product-info { padding: 8px 10px; }
  .product-name { font-size: 12px; }
  .product-price { font-size: 14px; }
  .product-rating { font-size: 11px; }
  
  /* Product page */
  .pd-title { font-size: 18px !important; }
  .pd-price { font-size: 24px !important; }
  .pd-was-price { font-size: 15px; }
  .pd-actions { flex-direction: column !important; }
  .pd-qty-wrap { width: 100%; justify-content: center; }
  .pd-add-cart { width: 100% !important; text-align: center; }
  .pd-features-row { grid-template-columns: 1fr !important; }
  .pd-trust-row { grid-template-columns: 1fr !important; }
  .pd-trust-line { flex-direction: column !important; align-items: flex-start !important; gap: 6px !important; }
  .pd-reviews-summary { padding: 16px !important; gap: 16px !important; }
  .pd-reviews-big { font-size: 36px !important; }
  .pd-features-grid { grid-template-columns: 1fr !important; }
  .pd-tabs-nav { gap: 0; }
  .pd-tab { padding: 10px 12px !important; font-size: 12px !important; }
  
  /* Review cards */
  .pd-review { padding: 14px; }
  .pd-review-header { gap: 8px; }
  .pd-review-avatar { width: 32px; height: 32px; font-size: 13px; }
  
  /* Footer */
  .footer-grid-portal { grid-template-columns: 1fr !important; }
  
  /* Cart */
  .cart-table th, .cart-table td { padding: 8px 6px; font-size: 12px; }
  
  /* Checkout */
  .checkout-form input, .checkout-form textarea, .checkout-form select { padding: 10px; font-size: 14px; }
  .payment-methods { flex-direction: column; }
  
  /* Search */
  .search-results-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  
  /* Category bar */
  .catbar-link { padding: 6px 10px !important; font-size: 11px !important; }
  
  /* Breadcrumbs */
  .bc-list { font-size: 12px; }
  
  /* Forum */
  .ft-products-grid { grid-template-columns: repeat(2, 1fr) !important; }
  
  /* Blog */
  .blog-card-img { height: 160px; }
  
  /* Collections */
  .collections-grid { grid-template-columns: 1fr !important; }
  
  /* Action hero */
  .action-hero h1 { font-size: 22px !important; }
}

/* ─── Touch-friendly improvements ─── */
@media (hover: none) and (pointer: coarse) {
  /* Larger tap targets */
  .pd-tab { min-height: 44px; display: flex; align-items: center; }
  .pd-var-btn { min-height: 44px; }
  .catbar-link { min-height: 40px; display: inline-flex; align-items: center; }
  .pagination a, .pagination span { min-height: 40px; min-width: 40px; display: flex; align-items: center; justify-content: center; }
  
  /* Remove hover effects that don't work on touch */
  .product-card:hover { transform: none; box-shadow: none; }
  .pd-main-wrap:hover .pd-main-img { transform: none; }
}

/* ─── Safe area for phones with notch ─── */
@supports (padding: env(safe-area-inset-bottom)) {
  .pd-sticky-bar.visible {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* ─── Landscape phone ─── */
@media (max-width: 768px) and (orientation: landscape) {
  .pd-grid { grid-template-columns: 1fr !important; gap: 20px !important; }
  .hero { padding: 30px 0; }
}

/* Related products - horizontal scroll on mobile */
@media (max-width: 768px) {
  .prod-grid-portal {
    display: flex !important;
    grid-template-columns: unset !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 12px !important;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
  .prod-grid-portal::-webkit-scrollbar { display: none; }
  .prod-grid-portal > div {
    min-width: 42% !important;
    max-width: 42% !important;
    flex-shrink: 0;
    scroll-snap-align: start;
  }
}

/* Hide superadmin bar on mobile */
@media (max-width: 768px) {
  #admin-toolbar { display: none !important; }
}



/* Tabs on mobile - horizontal scroll, NOT sticky */
@media (max-width: 768px) {
  .pd-tabs-nav, .pd-tabs-nav-sticky {
    position: relative !important;
    top: auto !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    box-shadow: none !important;
  }
  .pd-tabs-nav::-webkit-scrollbar, .pd-tabs-nav-sticky::-webkit-scrollbar { display: none; }
}



/* FBT mobile layout */
@media (max-width: 768px) {
  .fbt-main { flex-direction: column !important; gap: 16px !important; }
  .fbt-products { flex-wrap: nowrap !important; overflow-x: auto !important; justify-content: flex-start !important; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .fbt-products::-webkit-scrollbar { display: none; }
  .fbt-card { width: 140px !important; min-width: 140px !important; flex-shrink: 0 !important; padding: 12px !important; }
  .fbt-card div[style*=width:140px] { width: 110px !important; height: 110px !important; }
  .fbt-summary { min-width: unset !important; width: 100% !important; padding: 20px !important; }
}

/* FBT Amazon style mobile */
@media (max-width: 768px) {
  .fbt-row { justify-content: center !important; gap: 8px !important; }
  .fbt-item { width: 100px !important; }
  .fbt-item div[style*=width:120px] { width: 90px !important; height: 90px !important; }
  .fbt-summary-compact { width: 100% !important; padding: 12px !important; border-top: 1px solid #f0f0f0; margin-top: 8px; }
}

/* FBT clean mobile */
@media (max-width: 768px) {
  .fbt-wrapper { flex-direction: column !important; }
  .fbt-products-row { flex-wrap: nowrap !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 10px !important; }
  .fbt-products-row::-webkit-scrollbar { display: none; }
  .fbt-product { min-width: 140px !important; max-width: 140px !important; flex-shrink: 0 !important; }
  .fbt-total-box { min-width: unset !important; width: 100% !important; border-left: none !important; border-top: 1px solid #f0f0f0 !important; padding-left: 0 !important; padding-top: 16px !important; text-align: center; align-items: center !important; }
}

/* ═══════════════════════════════════════════════════════════════════════
   2026-05-23 mobile audit fixes
   ─────────────────────────────────────────────────────────────────────
   1. Grid blowout safety — any grid item inside .pd-grid or .bu-grid can
      blow out the 1fr column if its content min-width > available space.
      Force min-width:0 so 1fr can shrink to viewport.
   2. Stack inline 2-column grids (donor template + lifecycle/tech-stack
      cards in services/) that escape their per-component media queries.
   3. Global horizontal-overflow guard on <body> so any straggler doesn't
      cause horizontal scrolling (Google Mobile-Friendly demerit).
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .pd-grid > *, .pd-grid > * > * { min-width: 0; }
  .pd-grid img, .pd-grid video, .pd-grid iframe, .pd-grid canvas, .pd-grid svg {
    max-width: 100%; height: auto;
  }
  /* Tables on /p/ pages — donor-template + service renderers (tech_stack,
     forecast_breakdown, etc.) emit `<table style="width:100%">` blocks
     that table-layout:auto can still grow past 100% when content min-w
     exceeds the parent. Force display:block + horizontal scroll inside
     the table wrapper so the page itself doesn't widen.
     NOTE: do NOT use table-layout:fixed or word-break:break-word — those
     cause Postgres-style narrow columns to render each character on its
     own line ("A / p / p / b / u / n / d / l / e..."). Just display:block
     + overflow-x:auto lets the table scroll inside its card. */
  main table {
    display: block; max-width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Sweeping fix for the dozens of inline-styled `display:grid;
     grid-template-columns:1fr 1fr` (or 2fr 1fr / 1fr 2fr) blocks that
     services/lifecycle/tech_stack/etc emit. Each one ships its own
     #anchor-id specific media query but they're brittle to DOM nesting
     changes. Catch them all in one rule: any /p/ inline grid with two
     fr-columns stacks vertically below 760px. */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"],
  [style*="grid-template-columns:1fr 2fr"],
  [style*="grid-template-columns: 1fr 2fr"],
  [style*="grid-template-columns:repeat(2"],
  [style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
  }
  /* Make sure direct grid children can shrink — same min-width:0 trick
     for the inline grids we just rewrote. */
  [style*="display:grid"] > *, [style*="display: grid"] > * { min-width: 0; }
  /* Belt + braces: prevent any rogue element from causing a horizontal
     scroll. Body should NEVER scroll horizontally on mobile — Google's
     mobile-usability report flags it as a critical issue. */
  html, body { overflow-x: hidden; max-width: 100vw; }
}

/* /analytics/{ios,android} sort tabs (Top Grossing / Top Rated / Trending
   / Newest / Most…) — 5 buttons in a no-wrap flex row that overflows ~77px
   past a 390px viewport. body{overflow-x:hidden} masks it but the last
   button "Most…" gets clipped. Allow wrap + drop the desktop margin-left:auto
   that pushes to the right edge. */
@media (max-width: 640px) {
  .sort-row .sort-tabs, .toolbar .sort-tabs {
    flex-wrap: wrap !important;
    margin-left: 0 !important;
    gap: 6px !important;
  }
  .sort-row .sort-tabs a, .toolbar .sort-tabs a {
    padding: 6px 12px !important;
    font-size: 12px !important;
  }
}

/* Investment-matrix header label overlap on small screens — the eyebrow
   row had two inline labels ("BU INVESTMENT MATRIX" + "DYNAMIC SCORING 0–10")
   that overlap below ~480px. Stack vertically on small phones. */
@media (max-width: 480px) {
  .bu-im-eyebrow, .bu-im-header,
  [class*="investment-matrix"] [class*="header"],
  [class*="investment-matrix"] [class*="eyebrow"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 4px !important;
  }
}

/* /analytics/* hero — donor template renders a fixed-width image at left
   + h1 in right column at 390px viewport, breaking each word onto its own
   line. Stack vertically below 768px. The hero container is usually a
   flex/grid with the image first. */
@media (max-width: 768px) {
  .analytics-hero, .bu-analytics-hero,
  section.hero[class*="analytics"],
  /* heuristic fallback: any hero section with an h1 + img siblings */
  section.hero > .hero-grid,
  .hero-grid[class*="analytics"] {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    text-align: center;
  }
  .analytics-hero h1, .bu-analytics-hero h1 {
    font-size: 28px !important; line-height: 1.2 !important;
  }
}
