/*
 * Shopee Style Product Gallery for WooCommerce — v1.0.0
 * Elementor Pro compatible
 */

/* ─────────────────────────────────────────────
   CSS custom properties
   Set inline on .shopee-gallery from PHP options
───────────────────────────────────────────── */
.shopee-gallery {
  --sgw-color:      #ee4d2d;
  --sgw-thumb:      80px;
  --sgw-gap:        8px;
  --sgw-radius:     2px;
  --sgw-transition: 0.22s ease;
  --sgw-bg:         #f5f5f5;

  width: 100%;
  position: relative;
  box-sizing: border-box;
}

/* ─────────────────────────────────────────────
   Elementor Pro — reset WooCommerce gallery defaults
   Elementor hides .woocommerce-product-gallery (opacity:0)
   and waits for WC flexslider JS to reveal it.
   We bypass that entirely.
───────────────────────────────────────────── */
.woocommerce-product-gallery.shopee-gallery,
.elementor-widget-woocommerce-product-images .woocommerce-product-gallery.shopee-gallery,
.e-wc-product-images .woocommerce-product-gallery.shopee-gallery {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Elementor sometimes limits image widget width — allow our gallery to fill */
.elementor-widget-woocommerce-product-images .shopee-gallery,
.e-wc-product-images .shopee-gallery {
  max-width: 100%;
}

/* Remove Elementor's own product gallery styles that conflict */
.elementor-widget-woocommerce-product-images .woocommerce-product-gallery__image,
.elementor-widget-woocommerce-product-images .flex-viewport,
.elementor-widget-woocommerce-product-images .flex-control-nav,
.elementor-widget-woocommerce-product-images ol.flex-control-thumbs {
  display: none !important;
}

/* ─────────────────────────────────────────────
   Main image wrapper
───────────────────────────────────────────── */
.shopee-gallery__main {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--sgw-bg);
  border-radius: var(--sgw-radius);
  touch-action: pan-y pinch-zoom;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  cursor: grab;
  /* prevent Elementor's skeleton pulse from being inherited */
  animation: none;
}

/* Fallback for browsers without aspect-ratio (Safari < 15) */
@supports not (aspect-ratio: 1) {
  .shopee-gallery__main {
    padding-bottom: 100%;
    height: 0;
  }
  .shopee-gallery__main-img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

/* ─────────────────────────────────────────────
   Main image
───────────────────────────────────────────── */
.shopee-gallery__main-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity var(--sgw-transition);
  pointer-events: none;
  -webkit-user-drag: none;
  /* WooCommerce / Elementor sometimes max-height images — reset */
  max-height: none !important;
  max-width: none !important;
}

.shopee-gallery__main-img.is-fading {
  opacity: 0;
}

/* ─────────────────────────────────────────────
   Thumbnail strip
───────────────────────────────────────────── */
.shopee-gallery__thumbs {
  margin-top: 10px;
  position: relative;
  /* prevent Elementor stretching */
  flex-shrink: 0;
}

.shopee-gallery__track {
  display: flex;
  gap: var(--sgw-gap);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 3px 1px 6px;
  -webkit-overflow-scrolling: touch;
  align-items: center;
  flex-wrap: nowrap;
  cursor: grab;
}

.shopee-gallery__track:active {
  cursor: grabbing;
  /* disable smooth scroll while mouse-dragging so movement feels immediate */
  scroll-behavior: auto;
}

.shopee-gallery__track::-webkit-scrollbar {
  display: none;
}

/* ─────────────────────────────────────────────
   Individual thumbnail
───────────────────────────────────────────── */
.shopee-gallery__thumb {
  flex: 0 0 var(--sgw-thumb);
  width:  var(--sgw-thumb);
  height: var(--sgw-thumb);
  box-sizing: border-box;
  border: 2px solid transparent;
  border-radius: var(--sgw-radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--sgw-bg);
  transition:
    border-color var(--sgw-transition),
    transform 0.15s ease,
    box-shadow 0.15s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.shopee-gallery__thumb:hover {
  border-color: var(--sgw-color);
  transform: scale(1.04);
}

.shopee-gallery__thumb:focus-visible {
  border-color: var(--sgw-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sgw-color) 28%, transparent);
}

.shopee-gallery__thumb.is-active {
  border-color: var(--sgw-color);
}

.shopee-gallery__thumb.is-active:hover {
  transform: none;
}

.shopee-gallery__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
  /* prevent Elementor's image widget styles */
  max-width: 100% !important;
  max-height: 100% !important;
}

/* ─────────────────────────────────────────────
   Placeholder / empty state
───────────────────────────────────────────── */
.shopee-gallery--empty img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--sgw-bg);
  border-radius: var(--sgw-radius);
}

/* ─────────────────────────────────────────────
   Mobile (≤ 600 px)
───────────────────────────────────────────── */
@media (max-width: 600px) {
  .shopee-gallery__main {
    border-radius: 0;
  }

  .shopee-gallery__thumb {
    --sgw-thumb: 68px;
  }
}
