/**
 * gallery-lightbox.css
 */

/* Trigger: Gallery Lightbox */
.product-gallery-track[role='button'] {
  cursor: zoom-in;

  /* The reset removes a div's outline, so this brings the browser's own back, inset because the gallery clips anything outside it. */
  &:focus-visible {
    outline: auto;
    outline-offset: -2px;
  }
}

/* Component: Gallery Lightbox */
.gallery-lightbox {
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--color-white);
  color: var(--color-black);
  /* Distance of the arrows from the viewport edge. */
  --lightbox-edge: 16px;

  /* The dialog holds focus on open, and a ring around the whole screen says nothing. */
  &:focus {
    outline: none;
  }

  .gallery-nav.is-prev {
    left: max(var(--lightbox-edge), env(safe-area-inset-left));
  }

  .gallery-nav.is-next {
    right: max(var(--lightbox-edge), env(safe-area-inset-right));
  }

  .gallery-lightbox-track {
    display: flex;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }
  }

  .gallery-lightbox-slide {
    /* The theme has no global border-box, and padding would make a slide wider than the track and throw off the snap points. */
    box-sizing: border-box;
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  .gallery-lightbox-count {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    margin: 0;
    /* Centred on the buttons, which are 40px high. */
    line-height: 40px;
    font-size: 14px;
    transform: translateX(-50%);
  }
}

/* Scroll lock: Gallery Lightbox */
html:has(.gallery-lightbox[open]) {
  overflow: hidden;
}

/* Desktop + Tablet: Gallery Lightbox */
@media (min-width: 768px) {
  .gallery-lightbox {
    --lightbox-edge: 24px;

    .gallery-lightbox-slide {
      /* Keeps the arrows off the photo. */
      padding-inline: 80px;
    }
  }
}

/* Mobile: Gallery Lightbox */
@media (max-width: 767px) {
  .gallery-lightbox .gallery-lightbox-count {
    /* Centred on the buttons, which are 48px high. */
    line-height: 48px;
  }
}
