/* =======================================================
   Bliss Simple Zoom — Ultra-Specific CSS Override (v1.7.0 B)
   Purpose: Maximum specificity to override theme styles
   Author: Specto Design
   ======================================================= */

/* OUTER CONTAINERS — Remove any max-width constraints */
body.single-product .wp-block-woocommerce-product-image-gallery,
body.single-product .wp-block-woocommerce-product-gallery,
body.single-product .woocommerce div.product .woocommerce-product-gallery,
body.single-product div.product .woocommerce-product-gallery {
  width: 100% !important;
  max-width: 100% !important;
  clear: none !important;
  display: block !important;
}

/* INNER WRAPPER — Force 2-column grid on desktop */
body.single-product .wc-block-product-gallery__wrapper,
body.single-product .woocommerce div.product .woocommerce-product-gallery .woocommerce-product-gallery__wrapper,
body.single-product div.product .woocommerce-product-gallery__wrapper {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  grid-auto-flow: row !important;
  gap: var(--bliss-gap, 0) !important;
  width: 100% !important;
  max-width: 100% !important;
}

/* UNHIDE any image >= 3 */
body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:nth-child(n+3),
body.single-product .wc-block-product-gallery__wrapper > *:nth-child(n+3),
body.single-product .woocommerce-product-gallery__wrapper > *:nth-child(n+3) {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* REMOVE THEME'S HIDING RULE */
body.single-product .woocommerce div.product .woocommerce-product-gallery__image:nth-child(n+3) {
  display: block !important;
  visibility: visible !important;
}

/* CHILD ITEMS — Neutralize theme floats/flex overrides */
body.single-product .wc-block-product-gallery__wrapper > *,
body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper > *,
body.single-product div.product .woocommerce-product-gallery__wrapper > * {
  float: none !important;
  flex: initial !important;
  width: auto !important;
  margin: 0 !important;
  position: static !important;
  box-sizing: border-box;
}

/* IMAGES — Fill grid cell naturally */
body.single-product .wc-block-product-gallery__wrapper img,
body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper img,
body.single-product div.product .woocommerce-product-gallery__wrapper img {
  width: 100% !important;
  height: auto !important;
  object-fit: contain !important;
  display: block !important;
}

/* FLEXSLIDER / LEGACY INLINE OVERRIDES */
body.single-product .woocommerce div.product .flex-viewport,
body.single-product div.product .flex-viewport {
  height: auto !important;
  overflow: visible !important;
  max-width: 100% !important;
}

body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper,
body.single-product div.product .woocommerce-product-gallery__wrapper {
  width: 100% !important;
  max-width: 100% !important;
  transform: none !important;
  transition: none !important;
}

body.single-product .woocommerce div.product .woocommerce-product-gallery__image,
body.single-product div.product .woocommerce-product-gallery__image {
  float: none !important;
  width: auto !important;
  margin: 0 !important;
  position: static !important;
  overflow: visible !important;
}

/* ZOOM OVERLAY */
.bliss-zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 999999;
  display: grid;
  place-items: center;
}

.bliss-zoom-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.bliss-zoom-overlay__img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  background: #fff;
}

.bliss-zoom-overlay__close {
  position: fixed;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.95);
  color: #666;
  border: 1px solid #bbb;
  padding: 6px 10px;
  font: 500 14px/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial;
  cursor: pointer;
}

.bliss-zoom-overlay__close:focus {
  outline: 2px solid #999;
  outline-offset: 2px;
}

:root {
  --bliss-gap: 0;
}

/* ===== MOBILE RESPONSIVE (CSS-ONLY WITH :has()) ===== */
@media (max-width: 768px) {

  /* DEFAULT: Single column for 1 or 3+ images */
  body.single-product .wc-block-product-gallery__wrapper,
  body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper,
  body.single-product div.product .woocommerce-product-gallery__wrapper {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* CSS-ONLY: If wrapper has EXACTLY 2 children, show side-by-side */
  /* body.single-product .wc-block-product-gallery__wrapper:has(> *:nth-child(2):last-child),
  body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper:has(> *:nth-child(2):last-child),
  body.single-product div.product .woocommerce-product-gallery__wrapper:has(> *:nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  } */

  /* MOBILE: if wrapper has 2 OR MORE images → keep 2-column grid */
  body.single-product .wc-block-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2)),
  body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2)),
  body.single-product div.product .woocommerce-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2)) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Alternative selector for browsers with full :has() support */
  body.single-product .woocommerce-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Force gallery ancestors to expand */
  body.single-product .wp-block-woocommerce-product-image-gallery,
  body.single-product .woocommerce div.product .woocommerce-product-gallery,
  body.single-product div.product .woocommerce-product-gallery,
  body.single-product .woocommerce div.product .flex-viewport,
  body.single-product div.product .flex-viewport {
    height: auto !important;
    overflow: visible !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Stack page columns */
  body.single-product .wp-block-columns,
  body.single-product div.product {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body.single-product .wp-block-columns.is-layout-flow,
  body.single-product .wp-block-columns.is-layout-flex {
    display: block !important;
  }
  
  body.single-product .wp-block-column {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Child items */
  body.single-product .woocommerce div.product .woocommerce-product-gallery__wrapper > *,
  body.single-product div.product .woocommerce-product-gallery__wrapper > * {
    float: none !important;
    flex: initial !important;
    width: auto !important;
    margin: 0 !important;
    position: static !important;
  }

  /* DEFAULT: Bottom borders for stacked images */
  body.single-product .woocommerce-product-gallery__image {
    border-bottom: 4px solid white !important;
    border-right: none !important;
  }

  /* When exactly 2 images: right border on first, none on second */
  body.single-product .woocommerce-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2):last-child) .woocommerce-product-gallery__image:first-child {
    border-right: 4px solid white !important;
    border-bottom: none !important;
  }
  
  body.single-product .woocommerce-product-gallery__wrapper:has(> .woocommerce-product-gallery__image:nth-child(2):last-child) .woocommerce-product-gallery__image:last-child {
    border-bottom: none !important;
    border-right: none !important;
  }

  /* Fluid gallery */
  body.single-product .woocommerce-product-gallery,
  body.single-product .woocommerce-product-gallery__wrapper,
  body.single-product .woocommerce-product-gallery__image,
  body.single-product .woocommerce-product-gallery__image a,
  body.single-product .woocommerce-product-gallery__image img {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
  }

  body.single-product .woocommerce .flex-viewport {
    height: auto !important;
    overflow: visible !important;
  }

  /* Prevent horizontal scroll */
  html, body {
    overflow-x: hidden;
  }
  
  body.single-product .woocommerce-product-gallery,
  body.single-product .wp-block-columns {
    overflow-x: hidden;
  }

  /* Clear floats after gallery */
  body.single-product .woocommerce-tabs {
    position: relative;
    z-index: 1;
    clear: both;
  }
}

/* Ensure sections after gallery can't overlap */
body.single-product .related,
body.single-product .upsells,
body.single-product .cross-sells {
  clear: both !important;
}

/* Tame thumbnail sizes */
.flex-control-nav.flex-control-thumbs img {
  width: 100px !important;
  height: auto !important;
  max-width: 100% !important;
}

/* FALLBACK: For browsers without :has() support, use quantity query */
@supports not selector(:has(*)) {
  @media (max-width: 768px) {
    /* First of exactly 2 children */
    body.single-product .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child:nth-last-child(2) {
      border-right: 4px solid white !important;
      border-bottom: none !important;
    }
    
    /* Second of exactly 2 children */
    body.single-product .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child:nth-last-child(2) ~ .woocommerce-product-gallery__image {
      border-right: none !important;
      border-bottom: none !important;
    }
    
    /* When parent has exactly 2 children, make them side-by-side */
    /* This requires parent targeting which isn't possible without :has(), */
    /* but we can at least style the children correctly */
  }
}



