/* =========================================================
   Mignon Faget — PDP stacked gallery (final layout)
   Desktop: stacked media column | sticky buy box
   Mobile (<992px, Bootstrap 3 md breakpoint): swipe strip with counter
   ========================================================= */

:root {
  --mf-sticky-offset: 24px;   /* sticky header height + breathing room */
  --mf-gap: 16px;
  --mf-teal: #0d3b3d;
  --mf-img-bg: #f2f2f0;
}


/* ---------- Page layout (Bootstrap 3 row: .col-md-7 + .col-md-5) ----------
   Bootstrap 3 columns are floats, and position: sticky doesn't work on
   floats, so at md+ the row becomes a flex row. */
@media (min-width: 992px) {
  .mf-pdp { display: flex; align-items: flex-start; }
  .mf-pdp::before, .mf-pdp::after { display: none; }   /* BS3 clearfix pseudo-elements */
  .mf-pdp > .mf-pdp__media,
  .mf-pdp > .mf-pdp__info { float: none; }
  .mf-pdp__info { position: sticky; top: var(--mf-sticky-offset); }
}

/* ---------- Stack ---------- */
.mf-gallery { position: relative; }
.mf-gallery__stack {
  display: flex;
  flex-direction: column;
  gap: var(--mf-gap);
  position: relative;
}
.mf-gallery__item { margin: 0; background: var(--mf-img-bg); }
.mf-gallery__open {
  display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in;
}
.mf-gallery__open:focus-visible { outline: 2px solid var(--mf-teal); outline-offset: 2px; }
.mf-gallery__item img,
.mf-gallery__video { display: block; width: 100%; height: auto; }

/* Main image: square crop (725x725 at full column width).
   Lightbox shows the full uncropped closeup. */
.mf-gallery__item--main img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center;
}

/* Pause / play control on autoplaying videos (WCAG 2.2.2) */
.mf-gallery__item { position: relative; }
.mf-gallery__vidtoggle {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  width: 44px; height: 44px;                /* 44px minimum touch target */
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,.92); color: var(--mf-teal); cursor: pointer;
}
.mf-gallery__vidtoggle .mf-icon-play { display: none; }
.mf-gallery__vidtoggle.is-paused .mf-icon-play { display: block; }
.mf-gallery__vidtoggle.is-paused .mf-icon-pause { display: none; }
.mf-gallery__vidtoggle:focus-visible,
.mf-gallery__yt-play:focus-visible,
.mf-gallery__stack:focus-visible { outline: 2px solid var(--mf-teal); outline-offset: 2px; }

/* Videos: vertical only (9:16). Capped at 80% of the screen height so a
   full-width vertical clip doesn't run ~1,100px tall; gray bars fill the sides. */
.mf-gallery__item--video .mf-gallery__open {
  display: flex; justify-content: center; cursor: pointer;
}
.mf-gallery__item--video .mf-gallery__video {
  aspect-ratio: 9 / 16;
  width: auto;
  height: min(80vh, 900px);
  max-width: 100%;
  object-fit: cover;
}

/* "Only X left!" flag (your existing .product-item-flag span), pinned to the main image.
   Empty when stock is 10+ or 0, so hide it then. */
.mf-gallery__badge { position: absolute; top: 20px; left: 22px; z-index: 2; pointer-events: none; }
.mf-gallery__badge:empty { display: none; }

/* ---------- View all images ---------- */
.mf-gallery__view-all {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; min-height: 52px; margin-top: var(--mf-gap);
  border: 1px solid var(--mf-teal); background: #fff; color: var(--mf-teal);
  font-size: 15px; font-weight: 500; line-height: 1.2;
  letter-spacing: .12em; text-transform: uppercase;
  cursor: pointer;
}
.mf-gallery__view-all:hover { background: var(--mf-teal); color: #fff; }
.mf-gallery__view-all:focus-visible { outline: 2px solid var(--mf-teal); outline-offset: 2px; }
.mf-gallery__view-all[hidden] { display: none; }

.mf-gallery__counter { display: none; }

/* ---------- Lightbox ---------- */
.mf-lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #fff;
  display: none;
  grid-template-columns: 64px 1fr 64px;
  grid-template-rows: 1fr auto;
}
.mf-lightbox[open] { display: grid; }
.mf-lightbox::backdrop { background: rgba(0,0,0,.6); }
.mf-lightbox__stage {
  grid-column: 2; grid-row: 1; margin: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center; padding: 48px 0 16px;
}
.mf-lightbox__yt {
  width: min(100%, calc((100vh - 200px) * 16 / 9));
  aspect-ratio: 16 / 9; height: auto; border: 0;
}
.mf-lightbox__stage img,
.mf-lightbox__stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
.mf-lightbox__nav {
  grid-row: 1; align-self: center; justify-self: center; width: 48px; height: 48px;
  border: 0; background: none; font-size: 44px; line-height: 1; color: var(--mf-teal); cursor: pointer;
}
.mf-lightbox__prev { grid-column: 1; }
.mf-lightbox__next { grid-column: 3; }
.mf-lightbox--single .mf-lightbox__nav,
.mf-lightbox--single .mf-lightbox__footer { display: none; }
.mf-lightbox__close {
  position: absolute; top: 12px; right: 16px; width: 44px; height: 44px;
  border: 0; background: none; font-size: 32px; line-height: 1; color: var(--mf-teal); cursor: pointer;
}
.mf-lightbox__footer {
  grid-column: 1 / -1; grid-row: 2;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px 20px;
}
.mf-lightbox__count { font-size: 13px; letter-spacing: .08em; }
.mf-lightbox__strip {
  display: flex; gap: 8px; margin: 0; padding: 0; list-style: none;
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.mf-lightbox__strip button {
  position: relative; display: block; padding: 0; border: 0; background: var(--mf-img-bg);
  opacity: .5; cursor: pointer; border-bottom: 2px solid transparent;
}
.mf-lightbox__strip button[aria-current="true"] { opacity: 1; border-bottom-color: var(--mf-teal); }
.mf-lightbox__strip img,
.mf-lightbox__nothumb { display: block; width: 64px; height: 64px; object-fit: contain; }
/* Play badge on video thumbs */
.mf-lightbox__strip .is-video::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 22px; height: 22px;
  margin: -11px 0 0 -11px; border-radius: 50%;
  background: rgba(255,255,255,.92)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M3.5 2.5v5l4-2.5z' fill='%230d3b3d'/%3E%3C/svg%3E")
    center/12px no-repeat;
}
.mf-lightbox button:focus-visible { outline: 2px solid var(--mf-teal); outline-offset: 2px; }

/* ---------- Mobile progress bar (hidden on desktop) ---------- */
.mf-gallery__progress { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 991px) {
  .mf-pdp__media { margin-bottom: 24px; }

  /* Full-bleed: the JS sets an exact pixel width and left offset from the real
     viewport (clientWidth, which excludes any scrollbar). 100vw was the cause of
     the horizontal scroll: it includes the scrollbar, so the strip ran ~15px wider
     than the page whenever a desktop-style scrollbar was present. */
  .mf-gallery { position: relative; }

  /* Belt and braces: nothing on a phone-width product page should scroll sideways.
     iOS Safari ignores overflow-x on <body>, so it has to go on <html>. */
  html:has(body.PROD) { overflow-x: hidden; }
  body.PROD { overflow-x: clip; }

  /* "You Might Also Like": a .row nested directly inside another .row doubles the
     gutters (already fixed at the source; kept as a guard). The collection banner is
     intentionally left alone: the theme crops it on mobile. */
  .PROD #related-products .row .row { margin-left: 0; margin-right: 0; }

  .mf-gallery__stack {
    flex-direction: row; gap: 0;
    overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .mf-gallery__stack::-webkit-scrollbar { display: none; }
  .mf-gallery__item {
    flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always;
    aspect-ratio: 1 / 1;                 /* slides match the square main image */
    display: flex; align-items: center;
  }
  .mf-gallery__item .mf-gallery__open {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    cursor: zoom-in;                     /* tap opens the lightbox */
  }
  /* Every image cropped to fill the square slide (centered crop) */
  .mf-gallery__item .mf-gallery__open img {
    width: 100%; height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    object-position: center;
  }
  /* Vertical video fills the slide height, centered */
  .mf-gallery__item--video .mf-gallery__video { height: 100%; width: auto; max-height: none; }

  /* Deep jade swipe indicator: light track, solid segment that follows the swipe */
  .mf-gallery__progress {
    display: block;
    position: relative;
    height: 3px;
    background: #e6e3dc;
    overflow: hidden;
  }
  .mf-gallery__progress[hidden] { display: none; }
  .mf-gallery__progress-bar {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: #0C3A40;                 /* brand deep jade */
    will-change: transform;
  }

  /* No button and no lightbox on mobile */
  .mf-gallery__view-all { display: none !important; }

  /* Counter stays for screen readers only */
  .mf-gallery__counter {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  /* Existing YouTube video as the last slide: thumbnail, tap to play inline */
  .mf-gallery__item--youtube { background: #000; }
  .mf-gallery__yt-play {
    position: relative; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  }
  .mf-gallery__yt-play img { width: 100%; height: 100%; object-fit: cover; }
  .mf-gallery__yt-icon {
    position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px;
    border-radius: 50%;
    background: rgba(255,255,255,.92)
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M3.5 2.5v5l4-2.5z' fill='%230C3A40'/%3E%3C/svg%3E")
      center/30px no-repeat;
  }
  .mf-gallery__yt-frame { width: 100%; aspect-ratio: 16 / 9; border: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mf-gallery__stack { scroll-behavior: auto; }
}

/* Hide the shipping/inventory message until the starting variant's message has loaded
   (mvscreen.js removes .mf-await-variant). visibility keeps its space, so nothing jumps. */
.mf-await-variant .js-variant-inventory-message { visibility: hidden; }
