/* ==========================================================================
   WN Product Gallery Styles (WooCommerce Customization)
   Version: Force Thumbnail Height to Match Featured Image (CSS Grid)
   ========================================================================== */

.fancybox-thumbs {
  top: auto;
  width: auto;
  bottom: 0;
  left: 0;
  right: 0;
  height: 95px;
  padding: 10px 10px 5px 10px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.3);
}
.fancybox-show-thumbs .fancybox-inner {
  right: 0;
  bottom: 95px;
}
.fancybox-show-thumbs .fancybox-thumbs__list {
  margin: 0 auto;
}
.fancybox-thumbs__list a:before {
  border: 6px solid var(--primary-color);
}

/* --- Base Container --- */
.wn-pd-gallery {
  position: relative;
  opacity: 0; /* Start hidden for JS fade-in */
  transition: opacity 0.25s ease-in-out;
  overflow: hidden;
  background-color: #fff;
}

/* Default link styles */
.wn-pd-gallery a {
  display: block;
  line-height: 0;
  color: inherit;
  text-decoration: none;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  border-radius: inherit;
}

/* Default image styles */
.wn-pd-gallery img {
  display: block;
  max-width: 100%;
  height: auto; /* Default height */
  border-radius: inherit;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* --- Layout: >= 5 Images (1 Large + 4 Thumbs) --- */
/* Use CSS Grid for the main wrapper, align items top */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__wrapper {
  display: grid;
  grid-template-columns: 1.01fr 1fr;
  grid-template-rows: auto; /* Row height determined by content */
  gap: 10px; /* Small gap between columns */
  align-items: start; /* Align top edges */
}

/* Featured Image Container (Grid Item 1) */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__featured {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  aspect-ratio: 16 / 10;
  /* Height determined by image content */
}

.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__featured a {
  /* Inherits styles */
}

/* Featured image itself */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__featured img {
  width: 100%;
  height: 100%; /* Let height be natural, this defines row height */
  object-fit: cover; /* Still cover its container */
}

/* Thumbnails Container (Grid Item 2) */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnails {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 2x2 inner grid */
  /* Define 2 explicit rows that will take up the available height */
  grid-template-rows: repeat(2, 1fr);
  gap: 10px; /* Small gap between thumbs */
  height: 100%; /* <<< FORCE thumbnail container height to match row height (set by featured img) */
  min-height: 0; /* Help prevent overflow issues */
}

/* Individual Thumbnail Item (Inner grid items) */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail {
  position: relative;
  aspect-ratio: 16/10;
  overflow: hidden;
  border-radius: 10px;
}

.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail a {
  /* Inherits styles */
}

/* Image inside thumbnail */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail img {
  width: 100%;
  height: 100%; /* Image must fill the variable-height container */
  object-fit: cover; /* Crop image to cover the area */
}

/* Hover effect */
.wn-pd-gallery.gallery-total-5-plus
  .wn-pd-gallery__thumbnail:not(.wn-pd-gallery__thumbnail--more)
  a:hover
  img {
  transform: scale(1.05);
  opacity: 0.9;
}

/* Active state */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail.is-active {
  /* border: 2px solid #0073aa; */
}

/* '+X' More Thumbnail Styles */
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail--more {
  cursor: pointer;
  position: relative;
  /* border: 1px solid #eee; */ /* Optional border */
}
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail--more img {
  opacity: 0.4;
  filter: blur(1px);
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail--more:hover img {
  transform: none;
  opacity: 0.5;
}
.wn-pd-gallery.gallery-total-5-plus
  .wn-pd-gallery__thumbnail--more
  .more-count {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5em;
  color: white;
  background-color: rgba(0, 0, 0, 0.55);
  font-weight: bold;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}

/* --- Layout: 4 Images (Grid 2x2) --- */
.wn-pd-gallery.gallery-total-4 .wn-pd-gallery__wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
}
.wn-pd-gallery.gallery-total-4 .wn-pd-gallery__grid-item {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 10px;
}

/* --- Layout: 3 Images (Grid 1x3) --- */
.wn-pd-gallery.gallery-total-3 .wn-pd-gallery__wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.wn-pd-gallery.gallery-total-3 .wn-pd-gallery__grid-item {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 10px;
}

/* --- Layout: 2 Images (Grid 1x2) --- */
.wn-pd-gallery.gallery-total-2 .wn-pd-gallery__wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
}
.wn-pd-gallery.gallery-total-2 .wn-pd-gallery__grid-item {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 10px;
}

/* Shared styles for images inside grid items (Layouts 2, 3, 4) */
.wn-pd-gallery.gallery-total-4 .wn-pd-gallery__grid-item img,
.wn-pd-gallery.gallery-total-3 .wn-pd-gallery__grid-item img,
.wn-pd-gallery.gallery-total-2 .wn-pd-gallery__grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* Shared hover */
.wn-pd-gallery.gallery-total-4 .wn-pd-gallery__grid-item a:hover img,
.wn-pd-gallery.gallery-total-3 .wn-pd-gallery__grid-item a:hover img,
.wn-pd-gallery.gallery-total-2 .wn-pd-gallery__grid-item a:hover img {
  transform: scale(1.05);
  opacity: 0.9;
}

/* --- Layout: 1 Image --- */
.wn-pd-gallery.gallery-total-1 .wn-pd-gallery__wrapper {
  display: block;
}
.wn-pd-gallery.gallery-total-1 .wn-pd-gallery__single {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 10px;
}
.wn-pd-gallery.gallery-total-1 .wn-pd-gallery__single img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Responsive Adjustments --- */
@media (max-width: 850px) {
  /* Tablet breakpoint */
  /* Layout >= 5: Stack */
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__wrapper {
    display: block;
    gap: 0;
  }
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__featured {
    width: 100%;
    max-width: 100%;
    margin-bottom: 5px;
    height: auto;
  }
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__featured img {
    height: auto;
    object-fit: cover;
  }
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnails {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 1fr;
    width: 100%;
    gap: 3px;
    height: auto; /* Reset height */
  }
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail {
    border: none;
    aspect-ratio: 1 / 1; /* Back to square on mobile? Or keep non-square? Let's try square*/
    border-radius: 10px;
  }
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnail--more {
    border: none;
  }

  /* Other layouts */
  .wn-pd-gallery.gallery-total-3 .wn-pd-gallery__wrapper {
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
  }
  .wn-pd-gallery.gallery-total-4 .wn-pd-gallery__wrapper,
  .wn-pd-gallery.gallery-total-2 .wn-pd-gallery__wrapper {
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
  }
  /* Keep aspect ratios */
  .wn-pd-gallery.gallery-total-4 .wn-pd-gallery__grid-item {
    aspect-ratio: 16 / 10;
  }
  .wn-pd-gallery.gallery-total-3 .wn-pd-gallery__grid-item {
    aspect-ratio: 2 / 3;
  }
  .wn-pd-gallery.gallery-total-2 .wn-pd-gallery__grid-item {
    aspect-ratio: 16 / 10;
  }

  .wn-pd-gallery.gallery-total-5-plus
    .wn-pd-gallery__thumbnail--more
    .more-count {
    font-size: 1.4em;
  }
}

@media (max-width: 550px) {
  /* Mobile breakpoint */
  .wn-pd-gallery.gallery-total-5-plus .wn-pd-gallery__thumbnails {
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
  }
  .wn-pd-gallery.gallery-total-4 .wn-pd-gallery__wrapper,
  .wn-pd-gallery.gallery-total-3 .wn-pd-gallery__wrapper {
    grid-template-columns: repeat(1, 1fr);
    gap: 2px;
  }
  .wn-pd-gallery.gallery-total-2 .wn-pd-gallery__wrapper {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  /* Keep aspect ratios */
  .wn-pd-gallery.gallery-total-4 .wn-pd-gallery__grid-item {
    aspect-ratio: 16 / 10;
  }
  .wn-pd-gallery.gallery-total-3 .wn-pd-gallery__grid-item {
    aspect-ratio: 2 / 3;
  }
  .wn-pd-gallery.gallery-total-2 .wn-pd-gallery__grid-item {
    aspect-ratio: 16 / 10;
  }

  .wn-pd-gallery.gallery-total-5-plus
    .wn-pd-gallery__thumbnail--more
    .more-count {
    font-size: 1.2em;
  }
}

/* --- Final Visibility --- */
.wn-pd-gallery.woocommerce-product-gallery {
  opacity: 1 !important;
}

/* Optional: Hide default Woo trigger */
.woocommerce-product-gallery__trigger {
  display: none !important;
}
