/**
 * Single-product gallery layout.
 * Loaded on product pages only (inc/ms-shop-product-gallery.php).
 *
 * Desktop: vertical thumbnail column on the left (scrolls), large rounded main
 * image on the right with round prev/next arrows and an expand button.
 * Mobile: main image on top, thumbnails in a horizontal scrolling row below.
 *
 * FlexSlider builds this DOM inside .woocommerce-product-gallery:
 *   a.woocommerce-product-gallery__trigger   (expand / lightbox)
 *   div.flex-viewport > .woocommerce-product-gallery__wrapper > slides
 *   ol.flex-control-thumbs > li > img
 *   ul.flex-direction-nav > li > a.flex-prev / a.flex-next
 * The trigger and arrows are placed in the same grid area as the viewport.
 */

/* -------------------------------------------------------------------------
 * Tokens
 * ---------------------------------------------------------------------- */
.single-product div.product .woocommerce-product-gallery {
  --ms-shop-gallery-bg: #f5f5f5;
  --ms-shop-gallery-radius: 16px;
  --ms-shop-gallery-thumb-size: 84px;
  --ms-shop-gallery-gap: 12px;
  --ms-shop-gallery-ink: #111;

  /*
   * Tallest the main image may be: the window height minus the header and some
   * breathing room, so the whole image fits on short screens. Never below 320px.
   */
  --ms-shop-gallery-max-height: max(320px, calc(100vh - 190px));
}

@supports (height: 100svh) {
  .single-product div.product .woocommerce-product-gallery {
    --ms-shop-gallery-max-height: max(320px, calc(100svh - 190px));
  }
}

/* -------------------------------------------------------------------------
 * Column widths (desktop): wider gallery, narrower summary.
 * Storefront: gallery ~41% / summary ~53% (~39% / ~57% on full-width pages).
 * ---------------------------------------------------------------------- */
@media (min-width: 768px) {
  .single-product div.product .woocommerce-product-gallery,
  .storefront-full-width-content.single-product
    div.product
    .woocommerce-product-gallery {
    width: 50%;
    margin-right: 4%;
  }

  .single-product div.product .summary,
  .storefront-full-width-content.single-product div.product .summary {
    width: 46%;
  }
}

@media (min-width: 1200px) {
  .single-product div.product .woocommerce-product-gallery,
  .storefront-full-width-content.single-product
    div.product
    .woocommerce-product-gallery {
    width: 54%;
  }

  .single-product div.product .summary,
  .storefront-full-width-content.single-product div.product .summary {
    width: 42%;
  }
}

/* -------------------------------------------------------------------------
 * Grid layout (only when there are thumbnails, i.e. more than one slide)
 * ---------------------------------------------------------------------- */
.single-product
  div.product
  .woocommerce-product-gallery:has(> .flex-control-thumbs) {
  position: relative;
  display: grid;
  grid-template-columns: var(--ms-shop-gallery-thumb-size) minmax(0, 1fr);
  grid-template-areas: "thumbs main";
  gap: var(--ms-shop-gallery-gap);
  align-items: start;
}

.single-product div.product .woocommerce-product-gallery > .flex-viewport {
  grid-area: main;
  border-radius: var(--ms-shop-gallery-radius);
  background: var(--ms-shop-gallery-bg);
}

/* Absolutely positioned grid children use their grid area as containing block. */
.single-product
  div.product
  .woocommerce-product-gallery
  > .woocommerce-product-gallery__trigger,
.single-product div.product .woocommerce-product-gallery > .flex-direction-nav {
  grid-area: main;
}

/* Single image (no slider): same rounded frame. */
.single-product
  div.product
  .woocommerce-product-gallery:not(:has(> .flex-viewport))
  .woocommerce-product-gallery__wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--ms-shop-gallery-radius);
  /* background: var(--ms-shop-gallery-bg); */
}

/*
 * Square, but never taller than --ms-shop-gallery-max-height: on short windows the
 * slide gets wider than tall and the image (contain) shrinks to fit the height.
 */
.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__image:not(.ms-shop-video-slide)
  > a,
.single-product
  div.product
  .woocommerce-product-gallery
  .ms-shop-video-slide__frame {
  display: block;
  aspect-ratio: 1 / 1;
  max-height: var(--ms-shop-gallery-max-height);
}

.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__image:not(.ms-shop-video-slide)
  img:not(.zoomImg) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.single-product div.product .woocommerce-product-gallery .zoomImg {
  background: #fff;
}

/* -------------------------------------------------------------------------
 * Thumbnail column
 * ---------------------------------------------------------------------- */
.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs {
  grid-area: thumbs;
  position: relative; /* offsetParent for the thumbnails (JS keeps the active one in view) */
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 2px;
  overflow-x: hidden;
  overflow-y: auto;
  contain: size; /* match the main image height instead of growing the row */
  align-self: stretch;
  scrollbar-width: none; /* up/down buttons instead (ms-shop-product-gallery.js) */
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs::-webkit-scrollbar {
  display: none;
}

/* nth-child(n) lifts specificity over Storefront's per-column nth-child rules. */
.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li:nth-child(n) {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  margin: 0;
  float: none;
  clear: none;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--ms-shop-gallery-bg);
  background-clip: padding-box; /* keep the (dark video) background out of the border */
  transition: border-color 0.15s ease;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li:hover {
  border-color: #b5b5b5;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li:has(> img.flex-active) {
  border-color: var(--ms-shop-gallery-ink);
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li
  img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  opacity: 1;
  mix-blend-mode: multiply;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li.ms-shop-video-thumb {
  background: #0b1726;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-control-thumbs
  li.ms-shop-video-thumb
  img {
  /* object-fit: cover; */
  mix-blend-mode: normal;
}

/* -------------------------------------------------------------------------
 * Thumbnail column up / down buttons (added by ms-shop-product-gallery.js,
 * shown only when the column overflows; hidden at the top / bottom end).
 * ---------------------------------------------------------------------- */
.single-product div.product .woocommerce-product-gallery > .ms-shop-thumbs-nav {
  grid-area: thumbs;
  position: absolute;
  left: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0 0 0 -16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition:
    opacity 0.15s ease,
    box-shadow 0.15s ease;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav--up {
  top: 4px;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav--down {
  bottom: 4px;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav:focus-visible {
  outline: 2px solid var(--ms-shop-gallery-ink);
  outline-offset: 2px;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Chevron */
.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav::before {
  content: "";
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--ms-shop-gallery-ink);
  border-left: 2px solid var(--ms-shop-gallery-ink);
  transform: translateY(2px) rotate(45deg);
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .ms-shop-thumbs-nav--down::before {
  transform: translateY(-2px) rotate(-135deg);
}

/* -------------------------------------------------------------------------
 * Prev / next arrows
 * ---------------------------------------------------------------------- */
.single-product div.product .woocommerce-product-gallery > .flex-direction-nav {
  position: absolute;
  inset: 0;
  z-index: 10;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

.single-product
  div.product
  .woocommerce-product-gallery
  > .flex-direction-nav
  li {
  margin: 0;
}

.single-product div.product .woocommerce-product-gallery .flex-direction-nav a {
  position: absolute;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  color: transparent;
  font-size: 0; /* link text ("Previous image") stays for screen readers */
  line-height: 0;
  text-decoration: none;
  pointer-events: auto;
  transition:
    box-shadow 0.15s ease,
    opacity 0.15s ease;
}

.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  a:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  a:focus-visible {
  outline: 2px solid var(--ms-shop-gallery-ink);
  outline-offset: 2px;
}

.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  .flex-prev {
  left: 16px;
}

.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  .flex-next {
  right: 16px;
}

/* Chevron */
.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  a::before {
  content: "";
  width: 10px;
  height: 10px;
  border-bottom: 2px solid var(--ms-shop-gallery-ink);
  border-left: 2px solid var(--ms-shop-gallery-ink);
  transform: translateX(2px) rotate(45deg);
}

.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  .flex-next::before {
  transform: translateX(-2px) rotate(-135deg);
}

/* First / last slide (animationLoop is off). */
.single-product
  div.product
  .woocommerce-product-gallery
  .flex-direction-nav
  a.flex-disabled {
  opacity: 0;
  pointer-events: none;
}

/* -------------------------------------------------------------------------
 * Expand (lightbox) button: round, top-right, expand icon instead of the emoji
 * ---------------------------------------------------------------------- */
.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__trigger {
  top: 16px;
  right: 16px;
  z-index: 11;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23111' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7'/%3E%3C/svg%3E")
    center / 20px 20px no-repeat;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

/* Hide WooCommerce's emoji and Storefront's Font Awesome magnifier (::before). */
.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__trigger
  > span,
.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__trigger::before,
.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__trigger::after {
  display: none;
}

.single-product
  div.product
  .woocommerce-product-gallery
  .woocommerce-product-gallery__trigger:focus-visible {
  outline: 2px solid var(--ms-shop-gallery-ink);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------------
 * Sale ribbon: moved into the main image by ms-shop-product-gallery.js so the
 * thumbnail column doesn't sit under it. Hidden until moved (the gallery itself
 * is also invisible until WooCommerce's script runs).
 * ---------------------------------------------------------------------- */
.single-product div.product > .custom-winter-sale-badge.single-product {
  visibility: hidden;
}

/* -------------------------------------------------------------------------
 * Mobile: thumbnails in a row under the main image
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {
  .single-product div.product .woocommerce-product-gallery {
    --ms-shop-gallery-thumb-size: 64px;
    --ms-shop-gallery-radius: 12px;
  }

  .single-product
    div.product
    .woocommerce-product-gallery:has(> .flex-control-thumbs) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "main"
      "thumbs";
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    > .flex-control-thumbs {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    contain: none;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    > .flex-control-thumbs
    li:nth-child(n) {
    width: var(--ms-shop-gallery-thumb-size);
  }

  /* The row is swiped sideways on phones; no up/down buttons. */
  .single-product
    div.product
    .woocommerce-product-gallery
    > .ms-shop-thumbs-nav {
    display: none;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    .flex-direction-nav
    a,
  .single-product
    div.product
    .woocommerce-product-gallery
    .woocommerce-product-gallery__trigger {
    width: 36px;
    height: 36px;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    .flex-direction-nav
    a {
    margin-top: -18px;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    .flex-direction-nav
    .flex-prev {
    left: 8px;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    .flex-direction-nav
    .flex-next {
    right: 8px;
  }

  .single-product
    div.product
    .woocommerce-product-gallery
    .woocommerce-product-gallery__trigger {
    top: 8px;
    right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .single-product
    div.product
    .woocommerce-product-gallery
    > .flex-control-thumbs
    li:nth-child(n),
  .single-product
    div.product
    .woocommerce-product-gallery
    .flex-direction-nav
    a,
  .single-product
    div.product
    .woocommerce-product-gallery
    > .ms-shop-thumbs-nav {
    transition: none;
  }
}
