/*
 * Autoplius-style product gallery.
 * Restyles the stock WooCommerce/FlexSlider gallery (slider support is on in the
 * parent theme, so the thumbnail nav + lightbox trigger already exist):
 *   - vertical thumbnail rail on the LEFT, big main image on the right (desktop)
 *   - horizontal scrollable thumb strip UNDER the image (mobile)
 *   - "N / total" counter badge (injected by product-page-gallery.js)
 *   - circular fullscreen/zoom trigger
 * PhotoSwipe lightbox + zoom stay untouched (still driven by WC).
 */

.single-product .woocommerce-product-gallery {
	position: relative;
}

/* ===== Main image: crop to a fixed square box =====
   Sources are mixed portrait/landscape; without a crop the portrait ones
   balloon vertically. object-fit:cover makes every image fill column 1 at a
   consistent size without overgrowing. Full-res image is untouched in the
   lightbox (PhotoSwipe uses data-large_image). */
.single-product .woocommerce-product-gallery .woocommerce-product-gallery__image {
	aspect-ratio: 1 / 1;
	overflow: hidden;
	border-radius: 10px;
}
.single-product .woocommerce-product-gallery .woocommerce-product-gallery__image > a {
	display: block;
	width: 100%;
	height: 100%;
}
.single-product .woocommerce-product-gallery__wrapper img {
	width: 100% !important;
	height: 100% !important;
	object-fit: cover !important;
	border-radius: 0;
}

/* Fullscreen / zoom trigger — circular button, top-right of the image. */
.single-product .woocommerce-product-gallery__trigger {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 4;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, .92);
	box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background .15s, transform .15s;
}
.single-product .woocommerce-product-gallery__trigger:hover {
	background: #fff;
	transform: scale(1.06);
}

/* Anchor for the counter badge: JS moves the badge into .flex-viewport (the main
   image), so that container must be the positioning context. All widths. */
.single-product .woocommerce-product-gallery .flex-viewport {
	position: relative;
}

/* "N / total" image counter (injected by JS), bottom-right of the main image. */
.single-product .printley-gallery-count {
	position: absolute;
	bottom: 12px;
	right: 12px;
	z-index: 4;
	background: rgba(0, 0, 0, .64);
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	line-height: 1;
	padding: 5px 10px;
	border-radius: 20px;
	pointer-events: none;
	letter-spacing: .2px;
}

/* ===== Desktop: horizontal thumbnail strip UNDER the main image ===== */
@media (min-width: 993px) {

	.single-product .woocommerce-product-gallery {
		display: flex;
		flex-direction: column;
		align-items: stretch;
		gap: 12px;
	}

	/* Main image viewport (FlexSlider wraps the slides in .flex-viewport). */
	.single-product .woocommerce-product-gallery .flex-viewport {
		order: 1;
		width: 100%;
		min-width: 0;
	}

	/* Thumbnail GRID under the image (autoplius-style): all thumbs visible at once,
	   wrapping into rows — NOT a horizontal scroller. auto-fill packs as many
	   ~110px columns per row as the media column allows. */
	.single-product .woocommerce-product-gallery .flex-control-thumbs {
		order: 2;
		margin: 0;
		padding: 2px;
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
		gap: 8px;
		overflow: visible;
	}
	.single-product .woocommerce-product-gallery .flex-control-thumbs li {
		width: 100% !important;
	}
}

/* ===== Thumbnail states (shared) =====
   The parent theme sizes thumbs with higher specificity (li img {width:60px},
   li {width:25%; float:right}), which forced fixed-width imgs with height:auto
   (→ ragged heights) inside %-width li (→ right-edge clip, left-only rounding).
   Override with a uniform object-fit box; !important to beat the theme cascade. */
.single-product .woocommerce-product-gallery .flex-control-thumbs li {
	list-style: none !important;
	margin: 0 !important;
	float: none !important;
	clear: none !important;
	position: relative; /* anchor for the "+N" overflow overlay */
}

/* "+N" overlay on the last visible thumbnail (injected by JS): dark scrim over the
   photo with a centred "+N" — clicking it opens the full gallery lightbox. */
.single-product .woocommerce-product-gallery .flex-control-thumbs .printley-thumb-more {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, .55);
	color: #fff;
	font-size: 20px;
	font-weight: 700;
	border-radius: 2px;
	cursor: pointer;
	transition: background .15s;
}
.single-product .woocommerce-product-gallery .flex-control-thumbs .printley-thumb-more:hover {
	background: rgba(0, 0, 0, .68);
}
.single-product .woocommerce-product-gallery .flex-control-thumbs img {
	display: block;
	width: 100% !important;
	height: 109px !important;
	object-fit: cover !important;
	border: 2px solid transparent;
	opacity: .55;
	cursor: pointer;
	transition: opacity .15s, border-color .15s;
}

/* Corner rounding — separate rule, half the previous radius (was 4px → 2px). */
.single-product .woocommerce-product-gallery .flex-control-thumbs img {
	border-radius: 2px;
}
.single-product .woocommerce-product-gallery .flex-control-thumbs img:hover {
	opacity: 1;
}
.single-product .woocommerce-product-gallery .flex-control-thumbs img.flex-active {
	opacity: 1;
	border-color: #dc9814;
}

/* ===== Mobile / tablet (<993px): thumbs as a wrapping GRID under the image ===== */
@media (max-width: 992px) {
	.single-product .woocommerce-product-gallery .flex-control-thumbs {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
		gap: 8px;
		margin: 10px 0 0;
		padding: 2px;
		max-height: none;
		overflow: visible;
	}
	.single-product .woocommerce-product-gallery .flex-control-thumbs li {
		list-style: none;
		width: 100%;
		margin: 0;
		float: none;
	}
}
