/* ============================================================
   birchivy — PDP WordPress/WooCommerce overrides
   Adapts the prototype's bespoke markup to WooCommerce's native
   single-product DOM (gallery, variations form, tabs, related).
   Loaded AFTER birchivy-product.css.
   ============================================================ */

/* Anchor the sale flash to the product/gallery area (native renders it
   as a direct child of .product, before the gallery). */
div.product.pdp { position: relative; }

/* ---- Native product gallery → design gallery look ---- */
.woocommerce-product-gallery { margin: 0; }
.woocommerce-product-gallery .woocommerce-product-gallery__image,
.woocommerce-product-gallery .woocommerce-product-gallery__image a,
.woocommerce-product-gallery .woocommerce-product-gallery__image img {
  border-radius: var(--radius);
  display: block;
}
.woocommerce-product-gallery .flex-viewport,
.woocommerce-product-gallery > .woocommerce-product-gallery__wrapper {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper-2);
}
.woocommerce-product-gallery img { width: 100%; height: auto; display: block; }

/* Thumbnails: left column on desktop, row on mobile (matches the design). */
.woocommerce-product-gallery .flex-control-thumbs {
  list-style: none; margin: 14px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
}
.woocommerce-product-gallery .flex-control-thumbs li { margin: 0; }
.woocommerce-product-gallery .flex-control-thumbs img {
  border-radius: var(--radius); cursor: pointer; opacity: 0.55;
  border: 1px solid var(--line); transition: opacity .3s var(--ease), border-color .3s var(--ease);
  aspect-ratio: 1; object-fit: cover;
}
.woocommerce-product-gallery .flex-control-thumbs img.flex-active,
.woocommerce-product-gallery .flex-control-thumbs img:hover { opacity: 1; border-color: var(--ink); }

@media (min-width: 1001px) {
  /* Left thumbnail column like the design. */
  .woocommerce-product-gallery { display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: start; }
  .woocommerce-product-gallery .flex-control-thumbs {
    grid-column: 1; grid-row: 1; margin: 0;
    display: flex; flex-direction: column; gap: 12px;
  }
  .woocommerce-product-gallery > .woocommerce-product-gallery__wrapper,
  .woocommerce-product-gallery .flex-viewport { grid-column: 2; grid-row: 1; }
  .woocommerce-product-gallery .flex-control-thumbs img { width: 76px; }
}

/* Zoom hint chip (native zoom is enabled via theme support). */
.woocommerce-product-gallery__trigger { z-index: 4; }

/* ---- Variations: hide native dropdowns; swatches injected by JS ---- */
.variations_form table.variations { display: none; margin: 0; }
.variations_form table.variations + .birchivy-swatches { margin-top: 0; }
.birchivy-swatches { display: flex; flex-direction: column; gap: 1.6rem; }

/* Reset / "Clear" link styling */
.variations_form .reset_variations { font-size: 0.8rem; color: var(--muted); text-decoration: underline; }
.variations_form .reset_variations:hover { color: var(--accent-ink); }

/* Top price shows the selected variation (populated by JS); hide WooCommerce's
   lower duplicate inside the add-to-cart form so the price appears only once,
   prominently under the title. */
.single_variation .woocommerce-variation-price { display: none; }
.summary > p.price { margin: 0 0 0.3rem; }

/* Native matched-variation price → the design's prominent price block. */
.woocommerce-variation-price { margin-bottom: 0.2rem; }
.woocommerce-variation-price .price { margin: 0; display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; }
.woocommerce-variation-price del { color: var(--muted); font-size: 1.2rem; text-decoration-thickness: 1px; }
.woocommerce-variation-price ins { text-decoration: none; }
.woocommerce-variation-price .amount { font-family: var(--display); font-size: 2.5rem; font-weight: 500; color: var(--ink); }
.woocommerce-variation-availability { font-size: 0.86rem; color: var(--ink-soft); margin: 0.3rem 0 0; }

/* WooCommerce notices, styled to fit the palette. */
.woocommerce-notices-wrapper .woocommerce-message,
.woocommerce-notices-wrapper .woocommerce-info,
.woocommerce-notices-wrapper .woocommerce-error {
  max-width: var(--container); margin: 1rem auto; padding: 12px 18px;
  border-radius: var(--radius); background: var(--tint-sage); border: 1px solid var(--line);
  font-size: 0.9rem; list-style: none;
}

/* "View cart" link under the drawer checkout button. */
.drawer__viewcart { display: block; text-align: center; margin-top: 12px; font-size: 0.82rem; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 2px; }
.drawer__viewcart:hover { color: var(--accent-ink); }
.line-item__qtytxt { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }

/* Loading state on the add-to-cart button during AJAX. */
.single_add_to_cart_button.loading { opacity: 0.75; pointer-events: none; }

/* ------------------------------------------------------------
   CRITICAL LAYOUT FIX
   In real WooCommerce variable.php, woocommerce_before_add_to_cart_button
   (urgency) and woocommerce_after_add_to_cart_button (trust row + delivery)
   render INSIDE .woocommerce-variation-add-to-cart, next to the quantity and
   the button. The prototype assumed those were separate siblings and styled
   the container as one stretched flex row — which balloons the quantity box
   and the Add-to-Cart button to the height of the trust block and overflows
   the column. Lay them out as stacked full-width rows instead, with only the
   quantity + button sharing a line at their natural height.
   ------------------------------------------------------------ */
.woocommerce-variation-add-to-cart,
.single_variation_wrap .woocommerce-variation-add-to-cart {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 12px;
}
.woocommerce-variation-add-to-cart > .pdp-urgency,
.woocommerce-variation-add-to-cart > .pdp-trust,
.woocommerce-variation-add-to-cart > .pdp-delivery {
  flex: 1 0 100%;
  width: 100%;
}
.woocommerce-variation-add-to-cart > .quantity {
  flex: 0 0 auto;
  align-self: center;
}
.woocommerce-variation-add-to-cart > .single_add_to_cart_button {
  flex: 1 1 200px;
  height: 52px;
  min-height: 52px;
  align-self: center;
}
/* Keep the trust row a clean 2-up grid below the button. */
.woocommerce-variation-add-to-cart > .pdp-trust { margin-top: 0.2rem; }

/* Tabs: never let them overflow the viewport. */
.woocommerce-tabs .wc-tabs { flex-wrap: wrap; max-width: 100%; }
.woocommerce-tabs .wc-tabs li a { white-space: nowrap; }

/* ------------------------------------------------------------
   Star rating — re-implemented with unicode because we drop
   WooCommerce's default CSS (and its star webfont) on the PDP.
   Native markup: <span class="star-rating"><span style="width:%">Rated…</span></span>
   ------------------------------------------------------------ */
.star-rating {
  display: inline-block; position: relative;
  width: 5.6em; height: 1.1em; line-height: 1; overflow: hidden;
  font-size: 0.95rem; letter-spacing: 2px; color: transparent;
  font-family: var(--sans); vertical-align: middle;
}
.star-rating::before {
  content: "\2605\2605\2605\2605\2605"; color: var(--line);
  position: absolute; left: 0; top: 0; white-space: nowrap;
}
.star-rating > span { position: absolute; left: 0; top: 0; overflow: hidden; white-space: nowrap; }
.star-rating > span::before {
  content: "\2605\2605\2605\2605\2605"; color: var(--accent);
  position: absolute; left: 0; top: 0;
}
.woocommerce-product-rating .star-rating { margin: 0; }

/* Gallery: WooCommerce normally un-hides this once flexslider boots; keep it visible.
   NOTE: do not set position here — the design uses position:sticky on desktop and
   position:static on mobile; overriding it re-applied the sticky top:92px offset on
   mobile and pushed the gallery over the title. The product div anchors the sale flash. */
.woocommerce-product-gallery { opacity: 1 !important; }

/* Minimal flexslider core (normally from woocommerce.css, which we drop on the PDP). */
.woocommerce-product-gallery .flex-viewport { overflow: hidden; max-height: none; }
.woocommerce-product-gallery .woocommerce-product-gallery__wrapper { margin: 0; padding: 0; list-style: none; position: relative; }
.woocommerce-product-gallery figure { margin: 0; }
.woocommerce-product-gallery .woocommerce-product-gallery__image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.woocommerce-product-gallery__trigger { position: absolute; top: 0.875em; right: 0.875em; z-index: 5; }

/* Quantity input base (WC general normally provides this). */
.quantity input.qty { -moz-appearance: textfield; }

/* Hide the WooCommerce "Reviews (n)" default heading duplication if present. */
#reviews #comments > h2:first-child { font-family: var(--display); font-weight: 500; }

/* Related products: native loop uses ul.products li.product; align to the design grid. */
.related.products ul.products,
.related.products .products {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px 24px;
  list-style: none; margin: 0; padding: 0;
}
.related.products ul.products li.product { margin: 0; width: auto; float: none; }
.related.products ul.products li.product img { border-radius: var(--radius); margin-bottom: 14px; }
.related.products ul.products li.product .woocommerce-loop-product__title { font-size: 1.06rem; font-weight: 600; margin: 0 0 4px; }
.related.products ul.products li.product .price { font-size: 1rem; color: var(--ink); }
.related.products ul.products li.product .star-rating { color: var(--accent); font-size: 0.8rem; margin: 6px 0; }
.related.products ul.products li.product a.button { display: none; }

@media (max-width: 1100px) {
  .related.products ul.products, .related.products .products { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .related.products ul.products, .related.products .products { grid-template-columns: 1fr 1fr; gap: 16px 14px; }
  .woocommerce-product-gallery .flex-control-thumbs { grid-template-columns: repeat(5, 1fr); }
}

/* ============================================================
   Micro UX/UI refinements (desktop + mobile, segmented)
   ============================================================ */

/* Gallery: show the artwork at its natural ratio — the forced 4/5 container left
   a tall empty cream box under square art. Let the image define the height. */
.woocommerce-product-gallery .woocommerce-product-gallery__image { aspect-ratio: auto; }
.woocommerce-product-gallery .woocommerce-product-gallery__image a { display: block; }
.woocommerce-product-gallery .woocommerce-product-gallery__image img { width: 100%; height: auto; }
.woocommerce-product-gallery .woocommerce-product-gallery__wrapper { background: transparent; position: relative; }

/* Desktop: single-image products shouldn't reserve the empty 76px thumbnail column. */
@media (min-width: 1001px) {
  .woocommerce-product-gallery:not(:has(.flex-control-thumbs)) { grid-template-columns: 1fr; }
}

/* Mobile refinements */
@media (max-width: 600px) {
  /* Keep ADD TO CART on one line (price is already shown up top + in the sticky bar). */
  .woocommerce-variation-add-to-cart > .single_add_to_cart_button { white-space: nowrap; letter-spacing: 0.06em; }
  .woocommerce-variation-add-to-cart > .single_add_to_cart_button .bi-addprice { display: none; }
  /* Tighten the gap before the tabs. */
  .woocommerce-tabs { margin-top: 2.6rem; }
}

/* ============================================================
   Scroll-snap gallery carousel (replaces flexslider)
   Native finger-swipe on mobile (+ dots); thumbnail rail on desktop.
   Scoped to .bv-gallery (added by JS) so it overrides the flexslider rules above.
   ============================================================ */
.woocommerce-product-gallery.bv-gallery { opacity: 1 !important; }

.bv-gallery .woocommerce-product-gallery__wrapper {
  display: flex;
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  border-radius: var(--radius);
  background: var(--paper-2);
}
.bv-gallery .woocommerce-product-gallery__wrapper::-webkit-scrollbar { display: none; }

.bv-gallery .woocommerce-product-gallery__image {
  flex: 0 0 100%;
  width: 100%;
  margin: 0;
  scroll-snap-align: center;
  aspect-ratio: 1 / 1;            /* uniform, proportional across all images */
}
.bv-gallery .woocommerce-product-gallery__image a,
.bv-gallery .woocommerce-product-gallery__image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
}

/* Dots (mobile) */
.bv-gallery__dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.bv-gallery__dots .bv-dot {
  width: 7px; height: 7px; padding: 0; border: none; border-radius: 50%;
  background: var(--line); cursor: pointer;
  transition: transform .3s var(--ease), background .3s var(--ease);
}
.bv-gallery__dots .bv-dot.is-active { background: var(--accent); transform: scale(1.3); }

/* Thumbnail rail (desktop) */
.bv-gallery__thumbs { display: none; }
.bv-gallery__thumbs .bv-thumb {
  padding: 0; border: 1px solid var(--line); background: var(--paper-2);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; aspect-ratio: 1 / 1;
  opacity: .55; transition: opacity .3s var(--ease), border-color .3s var(--ease);
}
.bv-gallery__thumbs .bv-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.bv-gallery__thumbs .bv-thumb.is-active,
.bv-gallery__thumbs .bv-thumb:hover { opacity: 1; border-color: var(--ink); }

@media (min-width: 1001px) {
  .woocommerce-product-gallery.bv-gallery { display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: start; }
  .bv-gallery__thumbs {
    display: flex; flex-direction: column; gap: 12px;
    grid-column: 1; grid-row: 1; max-height: 78vh; overflow-y: auto; scrollbar-width: none;
  }
  .bv-gallery__thumbs::-webkit-scrollbar { display: none; }
  .bv-gallery__thumbs .bv-thumb { width: 76px; }
  .bv-gallery .woocommerce-product-gallery__wrapper { grid-column: 2; grid-row: 1; }
  .bv-gallery__dots { display: none; }
}

/* Single-image products: no carousel chrome needed. */
.bv-gallery--single .woocommerce-product-gallery__wrapper { overflow: visible; }

/* ------------------------------------------------------------
   CLS FIX: the carousel row layout must apply from FIRST PAINT, not only after
   JS adds .bv-gallery. Otherwise the gallery renders as N stacked full-size squares
   pre-JS (~3000px tall) and collapses to a single row on init — and on mobile the
   summary sits directly below the gallery, so it leaps up (the 0.26 CLS).
   Apply the single-image scroll-row unconditionally.
   ------------------------------------------------------------ */
.woocommerce-product-gallery .woocommerce-product-gallery__wrapper {
  display: flex !important;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.woocommerce-product-gallery .woocommerce-product-gallery__wrapper::-webkit-scrollbar { display: none; }
.woocommerce-product-gallery .woocommerce-product-gallery__image {
  flex: 0 0 100% !important;
  width: 100% !important;
  aspect-ratio: 1 / 1 !important;
  scroll-snap-align: center;
}
.woocommerce-product-gallery .woocommerce-product-gallery__image a,
.woocommerce-product-gallery .woocommerce-product-gallery__image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
/* Reserve the dot-strip height (mobile) so appending dots after JS doesn't shift. */
@media (max-width: 1000px) {
  .woocommerce-product-gallery { padding-bottom: 29px; position: relative; }
  .bv-gallery__dots { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; height: 21px; }
}

/* ============================================================
   Mobile fixes: sticky bar fit + compact size grid + related grid
   ============================================================ */
/* Related "Complete the wall" — same card grid as homepage/shop */
.related-pieces .products { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(1rem, 2vw, 1.8rem); margin-top: 2rem; }
@media (max-width: 900px) { .related-pieces .products { grid-template-columns: repeat(2, 1fr); } }

/* Sticky bar: clear the mobile bottom nav (incl. iPhone safe-area) at every width it shows */
@media (max-width: 900px) {
  .pdp-stickybar { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 600px) {
  /* Compact single-row bar that always fits: nowrap, price shrinks, button stays tappable */
  .pdp-stickybar__in { padding: 8px 14px; gap: 10px; flex-wrap: nowrap; }
  .pdp-stickybar__price { margin-left: 0; font-size: 1.05rem; white-space: nowrap; flex: none; }
  .pdp-stickybar__price del { display: none; } /* range/sale clutter never overflows the row */
  .pdp-stickybar .single_add_to_cart_button { flex: 1 1 auto; min-width: 0; height: 46px; padding: 0 1rem; font-size: 0.8rem; }

  /* Size selector: 2-up compact grid instead of a giant 1-per-row stack */
  .size-opts { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .size-btn { padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
  .size-btn .nm { font-size: 0.85rem; }
  .size-btn .dim { font-size: 0.68rem; margin-top: 1px; }
  .size-btn .pr { font-size: 0.72rem; }
}
