/**
 * Flexa Extra — Product Gallery slider (storefront).
 *
 * `--fxe-gallery-*` custom properties are written inline on the root by
 * GalleryRenderer::style_vars() (mirroring SwatchRenderer::css_vars()); every
 * one has a fallback here so an empty/theme-default setting still renders.
 *
 * Before JS runs (`:not(.is-ready)`), every slide is a stacked, visible block:
 * that is the entire no-JS fallback, not just a loading state. `.is-ready`
 * switches the track to the real carousel layout.
 */

.flexa-extra-gallery {
	--fxe-gallery-arrow-color: #111827;
	--fxe-gallery-arrow-bg: #ffffff;
	--fxe-gallery-dot-color: rgba(17, 24, 39, 0.25);
	--fxe-gallery-dot-active-color: #111827;
	--fxe-gallery-lightbox-overlay: rgba(17, 24, 39, 0.92);
	--fxe-gallery-aspect-ratio: 1 / 1;
	--fxe-gallery-thumb-size: 64px;
	--fxe-gallery-zoom-level: 2;

	position: relative;
	display: flex;
	flex-direction: column;
	gap: 0.75em;
}

/* The rail is the last child, after the main viewport, so a plain `row` puts
   it on the right and `row-reverse` on the left. Reading the modifier the
   other way round was what put a `left` rail down the right-hand side. */
.flexa-extra-gallery--thumbs-left,
.flexa-extra-gallery--thumbs-right {
	flex-direction: row;
}

.flexa-extra-gallery--thumbs-left {
	flex-direction: row-reverse;
}

/* The image column: the viewport plus the arrows, dots and whatever
   `woocommerce_product_thumbnails` printed. Positioned, so a badge or a ribbon
   anchors to the image and not to the image plus the thumbnail rail. */
.flexa-extra-gallery__main {
	position: relative;
	min-width: 0;
	flex: 1 1 auto;
}

.flexa-extra-gallery__viewport {
	position: relative;
	overflow: hidden;
	border-radius: 4px;
	background: #f3f4f6;
}

.flexa-extra-gallery__track {
	display: flex;
	aspect-ratio: var( --fxe-gallery-aspect-ratio );
}

/* No-JS / pre-init fallback: every slide stacked and fully visible. */
.flexa-extra-gallery:not( .is-ready ) .flexa-extra-gallery__track {
	display: block;
	aspect-ratio: auto;
}

.flexa-extra-gallery:not( .is-ready ) .flexa-extra-gallery__slide {
	display: block;
	width: 100%;
	margin-bottom: 0.5em;
}

.flexa-extra-gallery.is-ready .flexa-extra-gallery__slide {
	flex: 0 0 100%;
	width: 100%;
	aspect-ratio: var( --fxe-gallery-aspect-ratio );
	transition-property: opacity;
	transition-timing-function: ease;
}

/* Fade transition: gallery.js only ever toggles each slide's opacity here (it
   never transforms the track), so slides must stack on top of one another
   instead of sitting side-by-side in the track's flex row — otherwise only
   slide 0's box is ever inside the visible, clickable viewport. */
.flexa-extra-gallery[data-transition='fade'].is-ready .flexa-extra-gallery__track {
	position: relative;
	display: block;
}

.flexa-extra-gallery[data-transition='fade'].is-ready .flexa-extra-gallery__slide {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.flexa-extra-gallery__slide[data-type='video'] {
	background: #000;
}

/* Scoped through the root class on purpose: woocommerce-layout.css carries
   `.woocommerce img { height: auto }`, which outweighs a lone class selector
   and was leaving every image at its natural height inside the frame. */
.flexa-extra-gallery .flexa-extra-gallery__link,
.flexa-extra-gallery .flexa-extra-gallery__image,
.flexa-extra-gallery .flexa-extra-gallery__video,
.flexa-extra-gallery .flexa-extra-gallery__video-frame {
	display: block;
	width: 100%;
	height: 100%;
}

/* `height: 100%` only resolves against an ancestor with a definite height, and
   a slide sized by `aspect-ratio` alone does not have one: the image fell back
   to its natural height, spilled past the viewport's clip, and a portrait photo
   in a square frame lost its bottom. Filling the slide from an absolute box
   gives the image a real height, and object-fit takes over from there. The fade
   transition already positions its slides absolutely, so this only has to set
   `relative` for the sliding track. */
.flexa-extra-gallery.is-ready .flexa-extra-gallery__slide {
	position: relative;
}

.flexa-extra-gallery.is-ready .flexa-extra-gallery__link,
.flexa-extra-gallery.is-ready .flexa-extra-gallery__video,
.flexa-extra-gallery.is-ready .flexa-extra-gallery__video-link {
	position: absolute;
	inset: 0;
}

.flexa-extra-gallery__image,
.flexa-extra-gallery__video {
	object-fit: cover;
}

/* The `original` aspect ratio: the frame already matches the main image, and
   every other image is shown whole against the viewport background rather
   than cropped to fit. Set by GalleryRenderer::gallery_html(). */
.flexa-extra-gallery--fit-contain .flexa-extra-gallery__image,
.flexa-extra-gallery--fit-contain .flexa-extra-gallery__video {
	object-fit: contain;
}

.flexa-extra-gallery.is-ready .flexa-extra-gallery__image {
	transform-origin: var( --fxe-gallery-zoom-x, 50% ) var( --fxe-gallery-zoom-y, 50% );
	transition: transform 0.15s ease-out;
}

.flexa-extra-gallery__slide.is-zoomed .flexa-extra-gallery__image {
	transform: scale( var( --fxe-gallery-zoom-level ) );
	cursor: zoom-out;
}

.flexa-extra-gallery__slide:not( .is-zoomed ) .flexa-extra-gallery__link {
	cursor: zoom-in;
}

/* Video slides: a centered play glyph over the poster/link, decorative only
   (the whole link/video is the click target). */
.flexa-extra-gallery__video-link {
	position: relative;
}

/* The still behind the play glyph, dimmed so the white triangle keeps its
   contrast over a light product photo. Scoped through the root class for the
   same `.woocommerce img { height: auto }` reason as the slide images. */
.flexa-extra-gallery .flexa-extra-gallery__video-poster {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	filter: brightness( 0.7 );
}

.flexa-extra-gallery--fit-contain .flexa-extra-gallery__video-poster {
	object-fit: contain;
}

.flexa-extra-gallery__video-link::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 3.5em;
	height: 3.5em;
	margin: -1.75em 0 0 -1.75em;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.55 );
	pointer-events: none;
}

.flexa-extra-gallery__video-link::before {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	margin: -0.6em 0 0 -0.4em;
	border-style: solid;
	border-width: 0.6em 0 0.6em 1em;
	border-color: transparent transparent transparent #ffffff;
	z-index: 1;
	pointer-events: none;
}

/* Arrows */
.flexa-extra-gallery__arrow {
	position: absolute;
	top: 50%;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.25em;
	height: 2.25em;
	margin-top: -1.125em;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --fxe-gallery-arrow-bg );
	color: var( --fxe-gallery-arrow-color );
	box-shadow: 0 1px 3px rgba( 0, 0, 0, 0.25 );
	cursor: pointer;
	transition: filter 0.15s ease, box-shadow 0.15s ease;
}

.flexa-extra-gallery__arrow:hover {
	filter: brightness( 0.92 );
	box-shadow: 0 2px 6px rgba( 0, 0, 0, 0.3 );
}

.flexa-extra-gallery:not( .is-ready ) .flexa-extra-gallery__arrow,
.flexa-extra-gallery__arrow[ hidden ] {
	display: none;
}

.flexa-extra-gallery__arrow--prev {
	left: 0.5em;
}

.flexa-extra-gallery__arrow--next {
	right: 0.5em;
}

.flexa-extra-gallery__arrow svg,
.flexa-extra-gallery__arrow::before {
	pointer-events: none;
}

.flexa-extra-gallery__arrow svg {
	flex: 0 0 auto;
	width: 1.125em;
	height: 1.125em;
}

/* Dots */
.flexa-extra-gallery__dots {
	position: absolute;
	left: 50%;
	bottom: 0.6em;
	z-index: 2;
	display: flex;
	gap: 0.4em;
	transform: translateX( -50% );
}

.flexa-extra-gallery:not( .is-ready ) .flexa-extra-gallery__dots {
	display: none;
}

.flexa-extra-gallery__dot {
	width: 0.5em;
	height: 0.5em;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --fxe-gallery-dot-color );
	cursor: pointer;
	transition: filter 0.15s ease;
}

.flexa-extra-gallery__dot:hover:not( .is-active ) {
	filter: brightness( 0.85 );
}

.flexa-extra-gallery__dot.is-active {
	background: var( --fxe-gallery-dot-active-color );
}

.flexa-extra-gallery--dots-lines .flexa-extra-gallery__dot {
	width: 1.5em;
	height: 0.3em;
	border-radius: 2px;
}

.flexa-extra-gallery--dots-numbers .flexa-extra-gallery__dot {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.4em;
	height: 1.4em;
	border-radius: 50%;
	color: #fff;
	font-size: 0.7em;
	line-height: 1;
}

.flexa-extra-gallery__dot-number {
	display: none;
	pointer-events: none;
}

.flexa-extra-gallery--dots-numbers .flexa-extra-gallery__dot-number {
	display: block;
}

.flexa-extra-gallery--dots-none .flexa-extra-gallery__dots {
	display: none;
}

/* Thumbnails */
.flexa-extra-gallery__thumbs {
	display: flex;
	gap: 0.5em;
	overflow-x: auto;
	scrollbar-width: thin;
}

.flexa-extra-gallery--thumbs-bottom .flexa-extra-gallery__thumbs {
	flex-direction: row;
}

/* `flex: 0 0 auto` on purpose: the rail is a flex item of the gallery root
   here, and the default `0 1 auto` let anything else that ends up in that row
   shrink it until the thumbnails were a clipped strip. Its width is the thumb
   size and nothing else. */
.flexa-extra-gallery--thumbs-left .flexa-extra-gallery__thumbs,
.flexa-extra-gallery--thumbs-right .flexa-extra-gallery__thumbs {
	flex: 0 0 auto;
	flex-direction: column;
	overflow-x: visible;
	overflow-y: auto;
	max-height: 100%;
}

.flexa-extra-gallery--thumbs-hidden .flexa-extra-gallery__thumbs {
	display: none;
}

.flexa-extra-gallery__thumb {
	flex: 0 0 auto;
	width: var( --fxe-gallery-thumb-size );
	height: var( --fxe-gallery-thumb-size );
	padding: 0;
	border: 2px solid transparent;
	border-radius: 4px;
	overflow: hidden;
	cursor: pointer;
	opacity: 0.7;
	transition: opacity 0.15s ease, border-color 0.15s ease;
}

.flexa-extra-gallery__thumb:hover:not( .is-active ) {
	opacity: 0.9;
	border-color: var( --fxe-gallery-dot-color );
}

/* Also scoped through the root class, for the same `.woocommerce img` reason
   as the slide images above; here it is only a tie, decided by load order. */
.flexa-extra-gallery .flexa-extra-gallery__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.flexa-extra-gallery__thumb.is-active {
	opacity: 1;
	border-color: var( --fxe-gallery-dot-active-color );
}

/* The video thumbnail. It used to be an empty span, so the browser painted a
   bare grey button and nothing said "video". Now it is the product's own still
   under a play badge, which is what makes it readable at 48px. */
.flexa-extra-gallery__thumb--video {
	position: relative;
	background: #1a1a1a;
}

.flexa-extra-gallery .flexa-extra-gallery__thumb--video img {
	filter: brightness( 0.65 );
}

.flexa-extra-gallery__thumb-play {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

.flexa-extra-gallery__thumb-play::before {
	content: '';
	width: 46%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.55 );
	box-shadow: 0 1px 4px rgba( 0, 0, 0, 0.35 );
}

/* Nudged right of centre: a triangle's visual mass sits left of its bounding
   box, so a mathematically centred one looks off inside the circle. */
.flexa-extra-gallery__thumb-play::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	margin: -0.3em 0 0 -0.15em;
	border-style: solid;
	border-width: 0.3em 0 0.3em 0.5em;
	border-color: transparent transparent transparent #ffffff;
}

/* Lightbox (built lazily by gallery.js, appended to <body>) */
.flexa-extra-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: none;
	align-items: center;
	justify-content: center;
	background: var( --fxe-gallery-lightbox-overlay, rgba( 17, 24, 39, 0.92 ) );
}

.flexa-extra-gallery-lightbox.is-open {
	display: flex;
}

.flexa-extra-gallery-lightbox__stage {
	position: relative;
	max-width: 92vw;
	max-height: 88vh;
	overflow: hidden;
	touch-action: none;
}

.flexa-extra-gallery-lightbox__image {
	display: block;
	max-width: 92vw;
	max-height: 88vh;
	touch-action: none;
}

/* The outgoing image during a slide/fade, parked over the stage. gallery.js
   sets the duration from the gallery's own transition speed for the swap, then
   clears it so the 0.15s below is what pinch-zoom gets back. */
.flexa-extra-gallery-lightbox__image,
.flexa-extra-gallery-lightbox__ghost {
	transition-property: transform, opacity;
	transition-duration: 0.15s;
	transition-timing-function: ease-out;
}

.flexa-extra-gallery-lightbox__ghost {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	opacity: 0;
	pointer-events: none;
}

/* The video slide inside the lightbox. No `display` here on purpose: gallery.js
   toggles the `hidden` attribute, and any author `display` would override it.
   The 16:9 box is what gives the stage a size, since a player has no intrinsic
   one the way an image does. */
.flexa-extra-gallery-lightbox__video {
	width: min( 92vw, 1200px );
	max-height: 88vh;
	aspect-ratio: 16 / 9;
	background: #000;
	transition-property: opacity;
	transition-duration: 0.15s;
	transition-timing-function: ease-out;
}

.flexa-extra-gallery-lightbox__player {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

/* `padding: 0` is load-bearing, not tidiness. Themes style bare `button`
   generously (Storefront ships `padding: .618em 1.41575em`), and with
   `box-sizing: border-box` that horizontal padding is wider than the 2.5em
   button, so the content box collapses to zero and the icon, a flex item with
   the default `flex-shrink: 1`, is squeezed out of existence. The result is a
   grey circle with nothing in it. */
.flexa-extra-gallery-lightbox__close,
.flexa-extra-gallery-lightbox__arrow {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	line-height: 1;
	background: rgba( 255, 255, 255, 0.15 );
	color: #ffffff;
	cursor: pointer;
	transition: background 0.15s ease;
}

.flexa-extra-gallery-lightbox__close:hover,
.flexa-extra-gallery-lightbox__arrow:hover {
	background: rgba( 255, 255, 255, 0.28 );
}

/* Belt and braces for the padding reset above: pin the glyph's box here too,
   so a theme that pads buttons with `!important` or restyles `svg` still gets
   a visible icon instead of a blank circle. */
.flexa-extra-gallery-lightbox__close svg,
.flexa-extra-gallery-lightbox__arrow svg {
	flex: 0 0 auto;
	width: 1.125em;
	height: 1.125em;
	pointer-events: none;
}

.flexa-extra-gallery-lightbox__arrow svg {
	width: 1.25em;
	height: 1.25em;
}

.flexa-extra-gallery-lightbox__close {
	top: 1em;
	right: 1em;
	width: 2.5em;
	height: 2.5em;
}

.flexa-extra-gallery-lightbox__arrow {
	top: 50%;
	width: 3em;
	height: 3em;
	margin-top: -1.5em;
}

.flexa-extra-gallery-lightbox__arrow--prev {
	left: 1em;
}

.flexa-extra-gallery-lightbox__arrow--next {
	right: 1em;
}

.flexa-extra-gallery-lightbox__counter {
	position: absolute;
	bottom: 1em;
	left: 50%;
	transform: translateX( -50% );
	margin: 0;
	color: #ffffff;
	font-size: 0.85em;
}

html.flexa-extra-gallery-lightbox-lock {
	overflow: hidden;
}

@media ( prefers-reduced-motion: reduce ) {
	.flexa-extra-gallery__track,
	.flexa-extra-gallery__slide,
	.flexa-extra-gallery__image,
	.flexa-extra-gallery__arrow,
	.flexa-extra-gallery__dot,
	.flexa-extra-gallery__thumb,
	.flexa-extra-gallery-lightbox__image,
	.flexa-extra-gallery-lightbox__ghost,
	.flexa-extra-gallery-lightbox__video,
	.flexa-extra-gallery-lightbox__close,
	.flexa-extra-gallery-lightbox__arrow {
		transition-duration: 0ms !important;
		animation-duration: 0ms !important;
	}
}

@media ( max-width: 480px ) {
	.flexa-extra-gallery--thumbs-left,
	.flexa-extra-gallery--thumbs-right {
		flex-direction: column;
	}
}
