/**
 * Premium product gallery.
 *
 * Complements assets/css/woocommerce.css (which sets the 2-col product grid and
 * base .woocommerce-product-gallery styles). This file:
 *   - gives the main stage a consistent 1/1 aspect-ratio box (object-fit:contain
 *     on a neutral --surface ground so mixed-size photos never resize it),
 *   - on desktop turns the gallery into a VERTICAL thumbnail rail (left) + large
 *     sticky stage (right),
 *   - on mobile reflows to a single full-width swipeable stage with a horizontal
 *     thumbnail strip + slide counter.
 *
 * All colours come from CSS custom properties (works in dark & light).
 * Mobile-first: base rules target small screens, desktop rail is layered on at
 * the same 860px breakpoint the product grid uses.
 */

/* -----------------------------------------------------------------------------
 * Main stage: consistent square box, contained photo on a neutral ground.
 * Applies before AND after FlexSlider initialises.
 * -------------------------------------------------------------------------- */
.single-product div.product .woocommerce-product-gallery {
	position: relative; /* anchor for the mobile counter / arrows */
}

.single-product div.product .woocommerce-product-gallery__wrapper {
	margin: 0;
}

.single-product div.product .woocommerce-product-gallery__image {
	margin: 0;
}

.single-product div.product .woocommerce-product-gallery__image img,
.single-product div.product .woocommerce-product-gallery__image--placeholder img {
	display: block;
	width: 100%;
	height: auto;
	/* Catalogue photos are natively 4:3 — a 4:3 stage fills the frame with no
	   letterbox bars. object-fit: contain stays as a safety net so an oddly
	   proportioned image is fitted (padded) rather than cropped. */
	aspect-ratio: 4 / 3;
	object-fit: contain;
	background: var(--surface);
	border-radius: var(--radius);
}

/* FlexSlider sets an inline pixel height on the viewport (with overflow:hidden)
   that can mis-measure and clip the bottom of the image. Let the frame follow
   the image's own 4:3 ratio instead so nothing is cropped. */
.single-product div.product .woocommerce-product-gallery .flex-viewport {
	height: auto !important;
}

/* PhotoSwipe fullscreen trigger (core markup) restyled with theme vars. */
.single-product div.product .woocommerce-product-gallery__trigger {
	position: absolute;
	top: .75rem;
	right: .75rem;
	z-index: 3;
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	background: color-mix(in srgb, var(--bg) 72%, transparent);
	border: 1px solid var(--border);
	color: var(--text);
	backdrop-filter: blur(4px);
	transition: border-color .15s ease, color .15s ease;
}

.single-product div.product .woocommerce-product-gallery__trigger:hover,
.single-product div.product .woocommerce-product-gallery__trigger:focus-visible {
	border-color: var(--accent);
	color: var(--accent-text);
}

.single-product div.product .woocommerce-product-gallery__trigger:focus-visible {
	outline: 2px solid var(--accent-text);
	outline-offset: 2px;
}

/* -----------------------------------------------------------------------------
 * Thumbnail rail (FlexSlider builds ol.flex-control-thumbs from data-thumb).
 * -------------------------------------------------------------------------- */
.single-product div.product .flex-control-thumbs {
	list-style: none;
	margin: .75rem 0 0;
	padding: 0;
	display: flex;
	gap: .5rem;
	/* Mobile default: horizontal scroll strip below the stage. */
	overflow-x: auto;
	scrollbar-width: thin;
	-webkit-overflow-scrolling: touch;
}

.single-product div.product .flex-control-thumbs li {
	flex: 0 0 auto;
	margin: 0;
	list-style: none;
}

.single-product div.product .flex-control-thumbs img {
	display: block;
	width: 64px;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	border-radius: var(--radius-sm);
	border: 2px solid var(--border);
	background: var(--surface);
	opacity: .65;
	cursor: pointer;
	transition: opacity .15s ease, border-color .15s ease;
}

.single-product div.product .flex-control-thumbs img:hover,
.single-product div.product .flex-control-thumbs img.flex-active {
	opacity: 1;
	border-color: var(--accent);
}

/* Keyboard focus ring on the (JS-enhanced) focusable thumbnails. */
.single-product div.product .flex-control-thumbs li:focus-visible,
.single-product div.product .flex-control-thumbs img:focus-visible {
	outline: 2px solid var(--accent-text);
	outline-offset: 2px;
	opacity: 1;
}

/* -----------------------------------------------------------------------------
 * Mobile slide counter (e.g. "2 / 5"). Filled + un-hidden by gallery.js.
 * -------------------------------------------------------------------------- */
.brrr-gallery-counter {
	display: none; /* hidden on desktop; shown on mobile below */
	position: absolute;
	left: 50%;
	bottom: .75rem;
	transform: translateX(-50%);
	z-index: 3;
	padding: .2rem .7rem;
	font-size: .8rem;
	font-weight: 600;
	line-height: 1.4;
	color: var(--text);
	background: color-mix(in srgb, var(--bg) 72%, transparent);
	border: 1px solid var(--border);
	border-radius: 999px;
	backdrop-filter: blur(4px);
	pointer-events: none;
}

/* -----------------------------------------------------------------------------
 * Direction arrows (core .flex-direction-nav). Hidden on mobile (swipe), shown
 * over the stage on desktop.
 * -------------------------------------------------------------------------- */
.single-product div.product .flex-direction-nav {
	list-style: none;
	margin: 0;
	padding: 0;
	display: none;
}

.single-product div.product .flex-direction-nav a {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 3;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	background: color-mix(in srgb, var(--bg) 72%, transparent);
	border: 1px solid var(--border);
	/* Kill the core "Previous"/"Next" label: transparent alone still takes
	   space in the flex row and pushes the chevron into the clipped edge. */
	font-size: 0;
	line-height: 0;
	color: transparent;
	overflow: hidden;
	backdrop-filter: blur(4px);
	transition: border-color .15s ease, opacity .15s ease;
	pointer-events: auto;
}

.single-product div.product .flex-direction-nav a::before {
	content: "";
	width: 10px;
	height: 10px;
	border-right: 2px solid var(--text);
	border-bottom: 2px solid var(--text);
}

.single-product div.product .flex-direction-nav a:hover::before,
.single-product div.product .flex-direction-nav a:focus-visible::before {
	border-color: var(--accent-text);
}

.single-product div.product .flex-direction-nav a.flex-prev {
	left: .75rem;
}

.single-product div.product .flex-direction-nav a.flex-prev::before {
	transform: rotate(135deg); /* chevron tip points left */
	margin-left: 4px;          /* optical centering */
}

.single-product div.product .flex-direction-nav a.flex-next {
	right: .75rem;
}

.single-product div.product .flex-direction-nav a.flex-next::before {
	transform: rotate(-45deg); /* chevron tip points right */
	margin-right: 4px;
}

.single-product div.product .flex-direction-nav a.flex-disabled {
	opacity: .25;
	cursor: default;
}

/* -----------------------------------------------------------------------------
 * DESKTOP: full-width main image on top, horizontal thumbnail row below.
 * A plain block box (no side rail) means FlexSlider measures the full column
 * width, the image spans it edge-to-edge and reaches the top of the column
 * (flush with the product title), and the thumbnails fill the space underneath.
 * Same breakpoint the 2-col product grid uses (woocommerce.css @ 860px).
 * -------------------------------------------------------------------------- */
@media (min-width: 860px) {
	/* Plain in-flow block, top-aligned with the summary column. NOTE: do NOT use
	   position:sticky+top here — in this grid the sticky declaration loses the
	   cascade to WooCommerce core and computes to `position:relative`, but the
	   `top` still applies, shifting the whole gallery box down by that offset.
	   That caused the ~84px gap above the image AND the thumbnails overlapping
	   the tabs row below (visual box shifted, layout box didn't). */
	.single-product div.product .woocommerce-product-gallery {
		display: block;
		margin: 0;
	}

	/* Main image = full width, top of the column. Kill FlexSlider's inline sizes. */
	.single-product div.product .woocommerce-product-gallery .flex-viewport,
	.single-product div.product .woocommerce-product-gallery > .woocommerce-product-gallery__wrapper {
		width: auto !important;
		height: auto !important;
		margin: 0 !important;
		min-width: 0;
	}

	/* Round the VIEWPORT (the visible one-slide window), not the image: the
	   image's right corners are covered by the adjacent FlexSlider slide, so
	   rounding the image only would show on the left. */
	.single-product div.product .woocommerce-product-gallery .flex-viewport {
		border-radius: var(--radius);
		overflow: hidden;
	}

	/* Thumbnails = horizontal wrapping row BELOW the image. The `div.images`
	   in the selector matches WooCommerce core's own
	   `.woocommerce div.product div.images .flex-control-thumbs { margin:0; overflow:hidden }`
	   specificity (0,4,2) so — loading later — our gap + visible overflow win.
	   Without it core zeroes the top margin (thumbnails glued to the image) and
	   clips the wrapped rows. */
	.single-product div.product div.images .flex-control-thumbs {
		display: flex;
		flex-flow: row wrap;
		gap: .5rem;
		margin: 4px 0 0;
		padding: 0;
		max-height: none;
		overflow: visible;
	}
	/* FlexSlider gives each <li> a horizontal percentage width; force a fixed
	   thumbnail size so the row is even and predictable. */
	.single-product div.product .flex-control-thumbs li {
		width: auto !important;
		margin: 0 !important;
		float: none !important;
		flex: 0 0 auto;
	}
	.single-product div.product .flex-control-thumbs img {
		width: 76px !important;
		height: auto !important;
	}

	/* Prev/next arrows over the IMAGE only. left:0/right:0 sets the width, and
	   aspect-ratio 4/3 makes this overlay match the image height so the arrows
	   centre on the image, not on the image + thumbnail row. */
	.single-product div.product .flex-direction-nav {
		display: block;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		aspect-ratio: 4 / 3;
		pointer-events: none; /* only the buttons themselves are clickable */
		z-index: 3;
	}
}

/* -----------------------------------------------------------------------------
 * MOBILE: full-width stage + counter, arrows hidden (native swipe).
 * -------------------------------------------------------------------------- */
@media (max-width: 859.98px) {
	.brrr-gallery-counter:not([hidden]) {
		display: block;
	}
}

/* Respect reduced-motion for our own transitions. */
@media (prefers-reduced-motion: reduce) {
	.single-product div.product .flex-control-thumbs img,
	.single-product div.product .woocommerce-product-gallery__trigger,
	.single-product div.product .flex-direction-nav a {
		transition: none;
	}
}
