/**
 * PDP product gallery — main frame + thumbnail rail + lightbox.
 * Packshots use contain inside a controlled stage (not cover / not 4:5 crop).
 * Secondary full-size slides stay in the DOM for srcset/variation swap but are never stacked.
 */

/* Hide full-size secondary slides (root cause fix without FlexSlider).
   display:none keeps lazy secondary assets out of the initial paint path;
   JS copies src/srcset onto the main frame on thumb select. */
.woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:not(:first-child) {
  display: none !important;
}

.woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child {
  --pdp-gallery-pad: clamp(18px, 2.8vw, 36px);
  position: relative;
  width: 100%;
  aspect-ratio: auto;
  height: clamp(420px, 58vh, 580px);
  max-height: min(580px, 68vh);
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-card, var(--surface));
  box-sizing: border-box;
  padding: 0;
}

.woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child a {
  display: block;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
}

.woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child img {
  position: absolute;
  inset: var(--pdp-gallery-pad);
  width: auto;
  height: auto;
  max-width: calc(100% - (2 * var(--pdp-gallery-pad)));
  max-height: calc(100% - (2 * var(--pdp-gallery-pad)));
  margin: auto;
  object-fit: contain;
  object-position: center;
  border-radius: var(--radius-sm, 12px);
  display: block;
  transition: opacity 140ms ease;
}

@media (max-width: 767px) {
  .woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child {
    --pdp-gallery-pad: clamp(14px, 4vw, 24px);
    height: clamp(240px, 52vw, 320px);
    max-height: min(320px, 48vh);
  }
}

@media (prefers-reduced-motion: reduce) {
  .woocommerce-product-gallery .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child img {
    transition: none;
  }
}

.woocommerce-product-gallery.bof-gallery--switching .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child img {
  opacity: 0.72;
}

/* Thumbnail rail */
.bof-gallery-thumbs-wrap {
  display: none;
  position: relative;
  margin-top: 12px;
  align-items: center;
  gap: 8px;
}

.woocommerce-product-gallery.bof-gallery--multi .bof-gallery-thumbs-wrap {
  display: flex;
}

.bof-gallery-thumbs {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px;
}

.bof-gallery-thumbs::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.bof-gallery-thumb {
  flex: 0 0 auto;
  width: 80px;
  height: 80px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  scroll-snap-align: start;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 120ms ease, opacity 120ms ease;
}

.bof-gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
}

.bof-gallery-thumb[aria-pressed="true"],
.bof-gallery-thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.bof-gallery-thumb:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.bof-gallery-thumbs__nav {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.bof-gallery-thumbs__nav[hidden] {
  display: none !important;
}

.bof-gallery-thumbs__nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.bof-gallery-thumbs__nav:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.bof-gallery-thumbs__nav svg {
  width: 14px;
  height: 14px;
  display: block;
}

@media (max-width: 979px) {
  .bof-gallery-thumb {
    width: 68px;
    height: 68px;
    border-radius: 10px;
  }

  .bof-gallery-thumbs {
    gap: 8px;
  }

  .bof-gallery-thumbs__nav {
    display: none;
  }
}

@media (max-width: 430px) {
  .bof-gallery-thumb {
    width: 64px;
    height: 64px;
  }
}

/* ── Fullscreen gallery lightbox (theme-owned; Photoswipe remains dequeued) ── */
.ek-gallery-lightbox {
  --ek-lb-chrome-h: 52px;
  position: fixed;
  z-index: var(--z-toast, 120);
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding:
    max(8px, env(safe-area-inset-top, 0px))
    max(8px, env(safe-area-inset-right, 0px))
    max(8px, env(safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, #2a1f1a 88%, transparent);
  color: var(--paper, #f7f5f0);
  box-sizing: border-box;
  overflow: hidden;
}

.ek-gallery-lightbox[hidden] {
  display: none !important;
}

.ek-gallery-lightbox__chrome {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--ek-lb-chrome-h);
  padding: 2px 2px 6px;
  pointer-events: none;
}

.ek-gallery-lightbox__chrome > * {
  pointer-events: auto;
}

.ek-gallery-lightbox__chrome-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.ek-gallery-lightbox__counter {
  min-width: 3.5ch;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper, #f7f5f0) 14%, transparent);
  color: var(--paper, #f7f5f0);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.ek-gallery-lightbox__counter[hidden],
.ek-gallery-lightbox__nav[hidden] {
  display: none !important;
}

.ek-gallery-lightbox__close,
.ek-gallery-lightbox__zoom {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--paper, #f7f5f0) 28%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper, #f7f5f0) 92%, #fff);
  color: var(--ink, #1f1816);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ek-gallery-lightbox__close:hover,
.ek-gallery-lightbox__zoom:hover {
  background: var(--paper, #f7f5f0);
}

.ek-gallery-lightbox__zoom[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent, #b45309) 55%, var(--paper, #f7f5f0));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #b45309) 35%, transparent);
}

.ek-gallery-lightbox__close:focus-visible,
.ek-gallery-lightbox__nav:focus-visible,
.ek-gallery-lightbox__zoom:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.ek-gallery-lightbox__close svg,
.ek-gallery-lightbox__zoom svg {
  width: 18px;
  height: 18px;
  display: block;
}

.ek-gallery-lightbox__body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.ek-gallery-lightbox__viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.ek-gallery-lightbox.is-zoomed .ek-gallery-lightbox__viewport {
  cursor: grab;
}

.ek-gallery-lightbox.is-panning .ek-gallery-lightbox__viewport {
  cursor: grabbing;
}

.ek-gallery-lightbox__frame {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
  transform: translate3d(0, 0, 0) scale(1);
}

.ek-gallery-lightbox__frame.is-animating {
  transition: transform 160ms ease;
}

.ek-gallery-lightbox__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: var(--radius-sm, 12px);
  background: transparent;
  transition: opacity 150ms ease;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.ek-gallery-lightbox__img.is-switching {
  opacity: 0.72;
}

.ek-gallery-lightbox__nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--paper, #f7f5f0) 35%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper, #f7f5f0) 90%, #fff);
  color: var(--ink, #1f1816);
  cursor: pointer;
  transform: translateY(-50%);
  appearance: none;
  -webkit-appearance: none;
}

.ek-gallery-lightbox__nav:hover {
  background: var(--paper, #f7f5f0);
}

.ek-gallery-lightbox__nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.ek-gallery-lightbox__prev {
  left: max(4px, env(safe-area-inset-left, 0px));
}

.ek-gallery-lightbox__next {
  right: max(4px, env(safe-area-inset-right, 0px));
}

.ek-gallery-lightbox__nav svg {
  width: 16px;
  height: 16px;
  display: block;
}

@media (max-width: 767px) {
  .ek-gallery-lightbox {
    --ek-lb-chrome-h: 48px;
  }

  .ek-gallery-lightbox__nav {
    width: 44px;
    height: 44px;
    top: auto;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    transform: none;
  }

  .ek-gallery-lightbox__prev {
    left: max(12px, env(safe-area-inset-left, 0px));
  }

  .ek-gallery-lightbox__next {
    right: max(12px, env(safe-area-inset-right, 0px));
  }

  /* Keep media above bottom nav overlay without shrinking the centering box with magic dvh offsets. */
  .ek-gallery-lightbox__viewport {
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .ek-gallery-lightbox {
    --ek-lb-chrome-h: 40px;
  }

  .ek-gallery-lightbox__viewport {
    bottom: 0;
  }

  .ek-gallery-lightbox__nav {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ek-gallery-lightbox__img,
  .ek-gallery-lightbox__frame.is-animating {
    transition: none;
  }
}
