/**
 * Galerie produit — pile (desktop) + slider horizontal (mobile).
 * S’appuie sur le markup WooCommerce (.woocommerce-product-gallery__image).
 *
 * Compatibilité lecteur Woo (woocommerce/product-gallery-large-image) :
 * le PHP de Woo ne rend les grandes images que via le bloc interne
 * woocommerce/product-image. Si on le retire, la zone « images » est vide :
 * le conteneur n’a plus d’aspect-ratio et .wc-block-product-gallery-large-image__inner-blocks
 * reste en position:absolute avec height:calc(100% - 10px) → hauteur nulle → galerie invisible.
 * @see https://woocommerce.com/document/product-gallery-block
 */

/* Rétablit un flux visible quand notre galerie remplace le bloc Image produit dans le lecteur. */
.wc-block-product-gallery-large-image:has(.adlm-product-gallery-vertical) {
  aspect-ratio: auto;
  min-height: min(90vw, 42rem);
  overflow: visible;
}

.wc-block-product-gallery-large-image:has(.adlm-product-gallery-vertical) .wc-block-product-gallery-large-image__inner-blocks {
  position: static;
  top: auto;
  left: auto;
  width: 100%;
  height: auto;
  flex: 1 1 auto;
}

/* Évite une colonne à ~50 % dans le flex du bloc Product Gallery Woo. */
.wc-block-product-gallery .adlm-product-gallery-vertical {
  flex: 1 1 100%;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.adlm-product-gallery-vertical {
  --adlm-gallery-gap: 16px;
  --adlm-gallery-mobile-max-height: 78vh;
  width: 100%;
  max-width: 100%;
}

.adlm-product-gallery-vertical__track {
  display: flex;
  flex-direction: column;
  gap: var(--adlm-gallery-gap);
  width: 100%;
}

/*
 * Le track réutilise la classe legacy `.images` (woocommerce-product-gallery__wrapper).
 * woocommerce.css applique encore float:left + width:48% sur div.product div.images — en FSE
 * la colonne reste souvent sous .woocommerce/.product, d’où une galerie à ~50 %.
 */
.adlm-product-gallery-vertical .adlm-product-gallery-vertical__track.images {
  float: none !important;
  width: 100% !important;
  max-width: 100%;
  margin: 0 !important;
  clear: none;
}

.adlm-product-gallery-vertical__cell {
  flex-shrink: 0;
  width: 100%;
}

.adlm-product-gallery-vertical .woocommerce-product-gallery__image {
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.adlm-product-gallery-vertical .woocommerce-product-gallery__image a {
  display: block;
  line-height: 0;
}

/* Clic = ouverture modale (front) ; pas de lien direct Woo. */
.adlm-product-gallery-vertical .adlm-pgv__trigger {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  text-align: inherit;
  font: inherit;
  color: inherit;
  line-height: 0;
  box-sizing: border-box;
}

.adlm-product-gallery-vertical .adlm-pgv__trigger:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.adlm-product-gallery-vertical .woocommerce-product-gallery__image img,
.adlm-product-gallery-vertical .adlm-pgv__trigger img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  vertical-align: middle;
}

/* Éditeur : pas de bouton / pas de navigation vers le fichier média. */
.adlm-product-gallery-vertical--block-editor .woocommerce-product-gallery__image {
  pointer-events: none;
  user-select: none;
}

.adlm-product-gallery-vertical .woocommerce-product-gallery__image iframe,
.adlm-product-gallery-vertical .woocommerce-product-gallery__image video {
  width: 100%;
  height: auto;
  display: block;
}

.adlm-product-gallery-vertical--editor-notice .adlm-product-gallery-vertical__notice {
  margin: 0;
  font-size: 0.875rem;
  color: #50575e;
}

/* Modale native (<dialog>) — proche du ressenti lightbox, sans dépendre du module core/image. */
.adlm-pgv__dialog {
  margin: auto;
  padding: 0;
  border: none;
  max-width: min(96vw, 1200px);
  max-height: 96vh;
  background: transparent;
}

.adlm-pgv__dialog::backdrop {
  background: rgb(0 0 0 / 88%);
}

.adlm-pgv__dialog-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  padding: 2.5rem 0.5rem 0.5rem;
  box-sizing: border-box;
}

.adlm-pgv__dialog-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgb(255 255 255 / 95%);
  color: #1e1e1e;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.adlm-pgv__dialog-close:hover {
  background: #fff;
}

.adlm-pgv__dialog-body {
  max-width: 100%;
  max-height: calc(96vh - 3rem);
  overflow: auto;
}

.adlm-pgv__dialog-body img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(96vh - 4rem);
  margin: 0 auto;
  object-fit: contain;
}

@media (max-width: 781px) {
  .adlm-product-gallery-vertical__track {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 0;
    gap: var(--adlm-gallery-gap);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .adlm-product-gallery-vertical__cell {
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    max-height: var(--adlm-gallery-mobile-max-height);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .adlm-product-gallery-vertical__cell .woocommerce-product-gallery__image {
    max-height: var(--adlm-gallery-mobile-max-height);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .adlm-product-gallery-vertical__cell .woocommerce-product-gallery__image img {
    width: 100%;
    height: 100%;
    max-height: var(--adlm-gallery-mobile-max-height);
    object-fit: contain;
  }
}
