/* ========================================================
   MOBILE PDP MASTER FIX — loaded last, highest priority
   Fixes: image overflow, gallery sizing, purchase panel,
          layout containment, sticky bar, reviews UI
   ======================================================== */

/* 1. CONTAIN the entire page — no horizontal overflow */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}

.product-page-shell {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* 2. GALLERY — fixed height, contained, no overflow */
.product-gallery {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

.gallery-main {
  position: relative !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
  background: #f8fafc !important;
  border-radius: 12px !important;
  border: 1px solid #e2e8f0 !important;
  /* Fixed aspect ratio — no infinite height */
  aspect-ratio: 1 / 1 !important;
}

/* The primary image: fills container, no padding bleed */
.gallery-primary-img {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  padding: 12px !important;
  background: #ffffff !important;
  display: block !important;
  /* Disable zoom on mobile — prevents overflow */
  transform: none !important;
}

/* Thumbnails: horizontal scroll strip */
.gallery-thumbnails {
  display: flex !important;
  flex-direction: row !important;
  gap: 8px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
  padding: 4px 0 6px !important;
  width: 100% !important;
  max-width: 100% !important;
  flex-wrap: nowrap !important;
}

.gallery-thumbnails::-webkit-scrollbar {
  display: none !important;
}

.thumb-btn,
.gallery-thumbnails button {
  flex: 0 0 62px !important;
  width: 62px !important;
  height: 62px !important;
  min-width: 62px !important;
  border-radius: 8px !important;
  overflow: hidden !important;
}

/* Arrow buttons — keep inside box */
.gallery-arrow {
  width: 32px !important;
  height: 32px !important;
}

/* 3. PURCHASE PANEL — full-width stack on mobile */
@media (max-width: 767px) {
  /* product-detail: single column, no overflow */
  .product-detail,
  .product-detail.luxury-pdp-layout,
  .product-detail.professional-pdp {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    width: 100% !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  /* Gallery: contained square on mobile */
  .product-gallery {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .gallery-main {
    aspect-ratio: 1 / 1 !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
  }

  /* Product summary below image */
  .product-summary {
    width: 100% !important;
    padding: 16px 0 0 !important;
    position: static !important;
  }

  /* Breadcrumbs: single line, truncate */
  .breadcrumbs {
    font-size: 11px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Purchase panel rows */
  .pdp-purchase-actions-stack {
    gap: 10px !important;
    margin-top: 14px !important;
  }

  .pdp-qty-wishlist-row {
    display: grid !important;
    grid-template-columns: 80px 1fr 44px !important;
    gap: 8px !important;
    align-items: center !important;
    width: 100% !important;
  }

  .pdp-qty-wishlist-row .add-cart-button {
    width: 100% !important;
    min-height: 44px !important;
    height: 44px !important;
    font-size: 12px !important;
  }

  .pdp-buy-now-full {
    min-height: 46px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
  }

  /* Dynamic price box */
  .pdp-dynamic-price-box {
    font-size: 13px !important;
    padding: 12px 14px !important;
  }

  /* Trust grid: 2 columns on mobile */
  .shopify-trust-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    margin-top: 14px !important;
  }

  .shopify-trust-card {
    padding: 10px !important;
    gap: 8px !important;
  }

  .shopify-trust-card strong {
    font-size: 11px !important;
  }

  .shopify-trust-card small {
    font-size: 10px !important;
  }

  /* Accordions */
  .pdp-accordions {
    margin-top: 12px !important;
  }

  .pdp-accordions details summary {
    font-size: 13px !important;
    padding: 12px 0 !important;
  }

  /* Reviews section */
  .product-reviews-section {
    margin: 24px 0 16px !important;
    padding-top: 20px !important;
  }

  .reviews-summary-card {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 16px !important;
  }

  .rating-score-box {
    border-right: none !important;
    border-bottom: 1px solid #e2e8f0 !important;
    padding-right: 0 !important;
    padding-bottom: 14px !important;
  }

  .score-number {
    font-size: 40px !important;
  }

  .form-grid-two {
    grid-template-columns: 1fr !important;
  }

  .review-form-card {
    padding: 16px !important;
  }

  .reviews-header-block {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .reviews-header-block h2 {
    font-size: 20px !important;
  }

  /* Sticky Buy Bar: hidden on mobile — MobileBottomNav handles CTA */
  .sticky-buy-bar {
    display: none !important;
  }

  /* Product page shell padding */
  .product-page-shell {
    padding-inline: 14px !important;
    padding-bottom: 80px !important; /* space for mobile nav */
  }

  /* Gallery inline margin reset */
  .product-page-shell .product-detail {
    margin-inline: -14px !important;
    width: calc(100% + 28px) !important;
  }

  .product-page-shell .product-summary {
    padding-inline: 14px !important;
  }
}

@media (max-width: 400px) {
  .pdp-qty-wishlist-row {
    grid-template-columns: 72px 1fr 40px !important;
    gap: 6px !important;
  }

  .pdp-buy-now-full {
    font-size: 11px !important;
  }

  .shopify-trust-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }
}
