/* #877: product page on phones and tablets (the single-column layout, 1040px and under).
   1. The buy box moves up to sit right under the gallery; the review spotlight follows it.
   2. The gallery thumbnails become one swipeable row.
   3. A buy bar stays pinned to the bottom of the screen while the real Add to cart is off screen.
   Selectors start at .product-page so they win over the bundle, which loads after this file.
   Desktop never matches the layout block, and the bar is display: none there. */

.buy-bar { display: none; }

@media (max-width: 1040px) {
  /* ---- 1. order: gallery, buy box, review spotlight, then the rest ----
     49-product-redesign.css already dissolves .fw-left / .fw-right here. Dissolving .product-media too
     makes the gallery and the spotlight separate grid items, so the buy box can sit between them. */
  .product-page .fw-grid .product-media { display: contents; }
  .product-page .fw-grid { grid-template-columns: minmax(0, 1fr); }
  /* min-width: 0 so the one-row thumbnail strip scrolls inside the column and cannot widen it */
  .product-page .fw-grid .product-media > * { order: -3; min-width: 0; }
  .product-page .fw-grid .buy-box { order: -2; }
  .product-page .fw-grid .product-media > .product-review-spotlight,
  .product-page .fw-grid .product-media > .product-review-spotlight-v2,
  .product-page .fw-grid .product-media > .product-review-spotlight-v3 { order: -1; margin-top: 0; }

  /* ---- 2. thumbnails: one row, swipe sideways ---- */
  .product-page .lab-gallery .gallery-thumbs {
    flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px;
  }
  .product-page .lab-gallery .gallery-thumbs::-webkit-scrollbar { display: none; }
  .product-page .lab-gallery .gallery-thumb { flex: 0 0 auto; scroll-snap-align: start; }

  /* ---- 3. sticky buy bar ---- */
  .buy-bar {
    --buy-bar-h: 68px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;   /* under the cart drawer (80) and lightbox (90) */
    display: flex; align-items: center; gap: 14px;
    min-height: var(--buy-bar-h);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface-sunken, #0c0c0e);
    border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    box-shadow: 0 -10px 28px -12px rgba(0, 0, 0, 0.7);
    transform: translateY(105%); visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  .buy-bar.is-on { transform: none; visibility: visible; transition: transform 0.22s ease, visibility 0s; }

  .buy-bar-info {
    display: flex; flex-direction: column; justify-content: center; gap: 2px;
    flex: 1 1 auto; min-width: 0; text-decoration: none; line-height: 1.15;
  }
  .buy-bar-term {
    display: inline-flex; align-items: center; gap: 5px;
    font-family: var(--font-body); font-size: 12.5px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .buy-bar-term svg { flex-shrink: 0; color: var(--text-muted); }
  .buy-bar-price {
    font-family: var(--font-display); font-weight: var(--weight-extra, 800); font-size: 20px;
    letter-spacing: -0.01em; color: var(--text-primary); white-space: nowrap;
  }
  .buy-bar .buy-bar-btn { flex: 0 0 auto; min-width: 46%; min-height: 46px; padding-inline: 18px; white-space: nowrap; }

  /* Room for the bar: the footer's last lines stay readable, and the chat launcher rides above it. */
  :root.has-buy-bar body { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
  :root.has-buy-bar .ac-chat-launcher { transform: translateY(calc(-68px - env(safe-area-inset-bottom, 0px))); }
  .ac-chat-launcher { transition: transform 0.22s ease; }
}

@media (max-width: 1040px) and (prefers-reduced-motion: reduce) {
  .buy-bar, .buy-bar.is-on, .ac-chat-launcher { transition: none; }
}
