/* SS Posters — product gallery lightbox (full preview stack) */

/* Hide legacy theme copy (flatsome-child/lightbox-preview) if it still injects. */
body.aip-product-page #aip-lightbox:not(.aip-lightbox--plugin),
body.aip-product-page #aip-lightbox-img {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

#aip-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  box-sizing: border-box;
  /* Prefer dynamic viewport on mobile (browser chrome) so height fit matches JS visualViewport. */
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  background: rgba(0, 0, 0, 0.58);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

#aip-lightbox.is-open {
  opacity: 1;
  visibility: visible;
  touch-action: none;
}

/* Poster only — no white card / theme panel / drop-shadow around the art.
 * No hard max-height here — JS layoutFullFrame sizes the stage to visualViewport − pad. */
#aip-lightbox-panel,
#aip-lightbox.aip-lightbox--plugin #aip-lightbox-panel {
  position: relative;
  display: block;
  width: fit-content;
  max-width: min(96vw, 920px);
  max-height: none;
  margin: 0 auto;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  transform: scale(0.94);
  transition: transform 0.25s ease;
}

#aip-lightbox.is-open #aip-lightbox-panel {
  transform: scale(1);
}

/* First paint: hide stage until full image + matte crop are ready (no img1→img2 flash). */
#aip-lightbox.is-preparing #aip-lightbox-stage {
  opacity: 0;
}
#aip-lightbox.is-preparing #aip-lightbox-panel {
  transform: scale(0.94);
  transition: none;
}
#aip-lightbox.is-open:not(.is-preparing) #aip-lightbox-stage {
  opacity: 1;
  transition: opacity 0.12s ease;
}

/* Cloned gallery host (poster + text). Frame is hidden in JS.
 * Open framing = matte-hole crop (poster art only — no baked white margin/shadow). */
#aip-lightbox-stage,
#aip-lightbox.aip-lightbox--plugin #aip-lightbox-stage {
  position: relative;
  display: block;
  width: min(100%, 920px);
  max-width: min(96vw - 2.5rem, 920px);
  max-height: min(90vh, 90dvh);
  margin: 0;
  padding: 0 !important;
  overflow: hidden;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  filter: none !important;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

/* Pinch/pan layer — stage overflow clips shop-preview matte + shadow. */
#aip-lightbox-zoom {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  will-change: transform;
}

#aip-lightbox-stage.aip-lightbox-stage--matte-crop {
  /* JS sizes stage to art hole and offsets the clone — crops baked white shop-preview matte.
   * Do not also clamp with max-height here: CSS clip without JS re-fit shifts the crop (img3). */
  max-width: none;
  max-height: none;
  filter: none !important;
  background: transparent !important;
}

#aip-lightbox-stage .aip-lightbox-clone {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  pointer-events: none;
}

#aip-lightbox-stage.aip-lightbox-stage--matte-crop .aip-lightbox-clone {
  /* left/top/width/height set in JS for hole alignment */
  max-width: none;
}

#aip-lightbox-stage .aip-lightbox-clone > img {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  margin: 0;
}

#aip-lightbox-stage .aip-lightbox-clone > img.frame-image {
  display: none !important;
}

#aip-lightbox-stage .aip-lightbox-fallback-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(90vh, 90dvh);
  object-fit: contain;
  /* Full-frame size set in JS; matte-crop helpers kept but unused on open. */
}

/* Round × — sit on the visible poster corner.
 * !important beats flatsome-child lightbox-preview/main-new.css if still loaded. */
#aip-lightbox.aip-lightbox--plugin #aip-lightbox-close {
  appearance: none;
  -webkit-appearance: none;
  position: absolute !important;
  top: 0.35rem !important;
  right: 0.35rem !important;
  bottom: auto !important;
  left: auto !important;
  z-index: 3;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 2.65rem !important;
  height: 2.65rem !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: #459577 !important;
  color: #fff !important;
  font-size: 0 !important;
  line-height: 0 !important;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
  transition: background 0.15s ease, transform 0.15s ease;
}

#aip-lightbox.aip-lightbox--plugin #aip-lightbox-close svg {
  display: block;
  width: 1.05rem;
  height: 1.05rem;
  pointer-events: none;
}

#aip-lightbox.aip-lightbox--plugin #aip-lightbox-close:hover,
#aip-lightbox.aip-lightbox--plugin #aip-lightbox-close:focus-visible {
  background: #3a7d63 !important;
  outline: none;
}

#aip-lightbox.aip-lightbox--plugin #aip-lightbox-close:active {
  transform: scale(0.96);
}

@media (max-width: 480px) {
  #aip-lightbox {
    padding: 0.75rem;
  }

  #aip-lightbox.aip-lightbox--plugin #aip-lightbox-close {
    width: 2.45rem !important;
    height: 2.45rem !important;
  }
}
