.product-gallery {
  display: grid;
  gap: var(--sp-3);
  min-width: 0;
}

.product-gallery__main {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
}

.product-gallery__open {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.product-gallery__image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: var(--sp-4);
  pointer-events: none;
}

.product-gallery__placeholder {
  display: block;
  background: var(--c-bg-alt);
}

.product-gallery__badges {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  max-width: 45%;
  pointer-events: none;
}

.product-gallery__nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
  transform: translateY(-50%);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.product-gallery__nav--prev {
  left: var(--sp-2);
}

.product-gallery__nav--next {
  right: var(--sp-2);
}

.product-gallery__nav:hover,
.product-gallery__nav:focus-visible {
  border-color: var(--c-accent);
  color: var(--c-accent-dark);
  background: var(--c-accent-bg);
}

.product-gallery:not([data-gallery-multi]) .product-gallery__nav,
.product-gallery:not([data-gallery-multi]) .gallery-lightbox__nav {
  display: none;
}

.product-gallery__thumbs {
  display: flex;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.product-gallery__thumbs li {
  flex: 0 0 auto;
}

.product-gallery__thumb {
  display: block;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.product-gallery__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-gallery__thumb:hover,
.product-gallery__thumb:focus-visible {
  border-color: var(--c-accent);
}

.product-gallery__thumb.is-active,
.product-gallery__thumb[aria-pressed="true"] {
  border-color: var(--c-accent);
}

.product-gallery__thumb.is-active:hover,
.product-gallery__thumb[aria-pressed="true"]:hover,
.product-gallery__thumb.is-active:focus-visible,
.product-gallery__thumb[aria-pressed="true"]:focus-visible {
  border-color: var(--c-accent-dark);
}

.gallery-lightbox {
  width: min(calc(100% - 2 * var(--sp-4)), 56rem);
  max-height: min(92dvh, calc(100dvh - var(--safe-top) - var(--safe-bottom)));
  margin: auto;
  padding: calc(var(--sp-6) + var(--safe-top)) var(--sp-5) calc(var(--sp-5) + var(--safe-bottom));
  overflow: hidden;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow-lg);
  -webkit-tap-highlight-color: transparent;
}

.gallery-lightbox::backdrop {
  background: rgba(16, 24, 40, 0.72);
}

.gallery-lightbox__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 12rem;
}

.gallery-lightbox__image {
  display: block;
  width: 100%;
  max-height: min(72dvh, 40rem);
  object-fit: contain;
}

.gallery-lightbox__nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-md);
  transform: translateY(-50%);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.gallery-lightbox__nav--prev {
  left: 0;
}

.gallery-lightbox__nav--next {
  right: 0;
}

.gallery-lightbox__nav:hover,
.gallery-lightbox__nav:focus-visible,
.gallery-lightbox__close:hover,
.gallery-lightbox__close:focus-visible {
  border-color: var(--c-accent);
  color: var(--c-accent-dark);
  background: var(--c-accent-bg);
}

.gallery-lightbox__close {
  position: absolute;
  top: calc(var(--sp-3) + var(--safe-top));
  right: var(--sp-3);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.gallery-lightbox__counter {
  margin: var(--sp-3) 0 0;
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  text-align: center;
}

@media (min-width: 768px) {
  .product-gallery__main {
    aspect-ratio: 4 / 5;
  }

  .product-gallery__nav--prev {
    left: var(--sp-3);
  }

  .product-gallery__nav--next {
    right: var(--sp-3);
  }
}

@media (min-width: 1024px) {
  .product-gallery__thumb {
    width: 80px;
    height: 80px;
  }

  .gallery-lightbox {
    width: min(calc(100% - 4rem), 64rem);
  }

  .gallery-lightbox__image {
    max-height: min(78dvh, 48rem);
  }
}

@media (max-width: 767px) {
  .product-gallery__thumb {
    width: 64px;
    height: 64px;
  }

  .product-gallery__nav--prev {
    left: var(--sp-1);
  }

  .product-gallery__nav--next {
    right: var(--sp-1);
  }

  .gallery-lightbox {
    width: calc(100% - 1rem);
    padding-inline: var(--sp-3);
  }

  .gallery-lightbox__nav--prev {
    left: var(--sp-1);
  }

  .gallery-lightbox__nav--next {
    right: var(--sp-1);
  }
}
