/**
 * Beeline Product Gallery
 *
 * Everything tuneable is a custom property, so a theme can restyle the gallery
 * without a single override selector. Deliberately quiet: this component sits
 * inside someone else's design.
 */

/*
 * The gallery carries WooCommerce's own gallery classes so that theme layout
 * rules apply to it. Two of those rules have to be undone: core hides the
 * gallery until flexslider fades it in, and flexslider's own float/width
 * rules assume a markup structure this gallery does not use.
 */
.woocommerce-product-gallery.bpg,
.bpg {
	opacity: 1 !important;
	visibility: visible !important;
	float: none;
	max-width: 100%;
}

/*
 * Placed by hand: the container decides the width, so nothing here should
 * constrain it. This overrides WooCommerce's 48% column rule, which does not
 * apply when the gallery is not standing in for the product column.
 */
.bpg.bpg--standalone {
	width: 100%;
	max-width: none;
	float: none;
	margin: 0;
	clear: both;
}

.bpg-stage {
	width: 100%;
}

.bpg--placeholder img {
	width: 100%;
	height: auto;
	display: block;
	border-radius: var( --bpg-radius, 4px );
}

.bpg {
	--bpg-gap: 0.75rem;
	--bpg-thumb-size: 72px;
	--bpg-radius: 4px;
	--bpg-surface: #f6f6f6;
	--bpg-ink: #1a1a1a;
	--bpg-ink-invert: #fff;
	--bpg-accent: currentColor;
	--bpg-shadow: 0 1px 3px rgba( 0, 0, 0, 0.12 );
	--bpg-aspect: 1;
	--bpg-speed: 350ms;

	display: grid;
	gap: var( --bpg-gap );
	position: relative;
}

.bpg--thumbs-left,
.bpg--thumbs-right {
	grid-template-columns: var( --bpg-thumb-size ) 1fr;
	align-items: start;
}

.bpg--thumbs-right {
	grid-template-columns: 1fr var( --bpg-thumb-size );
}

.bpg--thumbs-left .bpg-thumbs { order: -1; }

/* Stage ------------------------------------------------------------------ */

.bpg-stage {
	position: relative;
	aspect-ratio: var( --bpg-aspect );
	overflow: hidden;
	border-radius: var( --bpg-radius );
	background: var( --bpg-surface );
	cursor: zoom-in;
	touch-action: pan-y;
}

.bpg-slide {
	position: absolute;
	inset: 0;
	margin: 0;
	opacity: 0;
	visibility: hidden;
	transition: opacity var( --bpg-speed ) ease;
}

.bpg-slide.is-active {
	opacity: 1;
	visibility: visible;
}

.bpg--slide .bpg-slide {
	transform: translateX( 8px );
	transition: opacity var( --bpg-speed ) ease, transform var( --bpg-speed ) ease;
}

.bpg--slide .bpg-slide.is-active {
	transform: none;
}

.bpg-slide img,
.bpg-slide video {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
}

.bpg-caption {
	position: absolute;
	inset: auto 0 0 0;
	padding: 0.5em 0.75em;
	font-size: 0.8125rem;
	color: var( --bpg-ink-invert );
	background: linear-gradient( transparent, rgba( 0, 0, 0, 0.6 ) );
}

/* Video controls --------------------------------------------------------- */

.bpg-unmute {
	position: absolute;
	right: 0.75rem;
	bottom: 0.75rem;
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	padding: 0.4em 0.75em;
	border: 0;
	border-radius: 999px;
	font: inherit;
	font-size: 0.8125rem;
	line-height: 1;
	color: var( --bpg-ink-invert );
	background: rgba( 0, 0, 0, 0.62 );
	backdrop-filter: blur( 6px );
	cursor: pointer;
	transition: background 150ms ease;
}

.bpg-unmute:hover { background: rgba( 0, 0, 0, 0.8 ); }

.bpg-unmute__icon {
	width: 14px;
	height: 14px;
	background: currentColor;
	/* Muted speaker; swapped for a plain speaker once sound is on. */
	mask: url( "data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4V5Z'/%3E%3Cpath d='m16 9 5 6m0-6-5 6' stroke='%23000' stroke-width='2' fill='none'/%3E%3C/svg%3E" ) center / contain no-repeat;
}

.bpg-unmute.is-on .bpg-unmute__label { display: none; }

.bpg-unmute.is-on .bpg-unmute__icon {
	mask-image: url( "data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4V5Z'/%3E%3Cpath d='M15 9a4 4 0 0 1 0 6' stroke='%23000' stroke-width='2' fill='none'/%3E%3C/svg%3E" );
}

.bpg-video-progress {
	position: absolute;
	inset: auto 0 0 0;
	height: 2px;
	background: rgba( 0, 0, 0, 0.15 );
}

.bpg-video-progress i {
	display: block;
	height: 100%;
	background: var( --bpg-ink );
	transform: scaleX( 0 );
	transform-origin: left;
}

.bpg-slide--video.is-blocked::after {
	content: "";
	position: absolute;
	inset: 50% auto auto 50%;
	width: 64px;
	height: 64px;
	translate: -50% -50%;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.55 ) url( "data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E" ) center / 40% no-repeat;
}

/* Arrows and counter ----------------------------------------------------- */

.bpg-arrow {
	position: absolute;
	top: 50%;
	translate: 0 -50%;
	width: 40px;
	height: 40px;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.9 );
	box-shadow: var( --bpg-shadow );
	cursor: pointer;
	opacity: 0;
	transition: opacity 150ms ease;
}

.bpg-stage:hover .bpg-arrow,
.bpg-arrow:focus-visible { opacity: 1; }

.bpg-arrow--prev { left: 0.75rem; }
.bpg-arrow--next { right: 0.75rem; }

.bpg-arrow::before {
	content: "";
	display: block;
	width: 9px;
	height: 9px;
	margin: 0 auto;
	border: 2px solid var( --bpg-ink );
	border-width: 2px 2px 0 0;
	rotate: -135deg;
	translate: 2px 0;
}

.bpg-arrow--next::before {
	rotate: 45deg;
	translate: -2px 0;
}

.bpg-counter {
	position: absolute;
	left: 0.75rem;
	top: 0.75rem;
	padding: 0.2em 0.5em;
	border-radius: 999px;
	font-size: 0.75rem;
	color: var( --bpg-ink-invert );
	background: rgba( 0, 0, 0, 0.5 );
}

/* Thumbnails ------------------------------------------------------------- */

.bpg-thumbs {
	display: flex;
	gap: 0.5rem;
	overflow: auto;
	scrollbar-width: thin;
	scroll-snap-type: x proximity;
}

.bpg--thumbs-left .bpg-thumbs,
.bpg--thumbs-right .bpg-thumbs {
	flex-direction: column;
	max-height: 100%;
	scroll-snap-type: y proximity;
}

.bpg-thumb {
	flex: 0 0 var( --bpg-thumb-size );
	width: var( --bpg-thumb-size );
	height: var( --bpg-thumb-size );
	padding: 0;
	border: 0;
	border-radius: var( --bpg-radius );
	background: var( --bpg-surface );
	overflow: hidden;
	cursor: pointer;
	scroll-snap-align: start;
	position: relative;
	opacity: 0.55;
	transition: opacity 150ms ease;
}

.bpg-thumb:hover { opacity: 0.85; }

.bpg-thumb.is-active {
	opacity: 1;
	outline: 2px solid var( --bpg-ink );
	outline-offset: -2px;
}

.bpg-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.bpg-thumb--video::after {
	content: "";
	position: absolute;
	inset: 50% auto auto 50%;
	width: 22px;
	height: 22px;
	translate: -50% -50%;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.6 ) url( "data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E" ) center / 45% no-repeat;
}

/* Lightbox --------------------------------------------------------------- */

.bpg-lightbox {
	width: 100vw;
	max-width: 100vw;
	height: 100dvh;
	max-height: 100dvh;
	padding: 0;
	border: 0;
	background: #0b0b0b;
	color: #fff;
	overflow: hidden;
}

.bpg-lightbox::backdrop { background: rgba( 0, 0, 0, 0.9 ); }

.bpg-lightbox__stage {
	position: absolute;
	inset: 0 0 96px 0;
	display: grid;
	place-items: center;
	overflow: hidden;
	cursor: zoom-in;
}

.bpg-lightbox__stage.is-zoomed { cursor: grab; }

.bpg-lightbox__img,
.bpg-lightbox__video {
	max-width: 92%;
	max-height: 92%;
	object-fit: contain;
	transform-origin: center;
	will-change: transform;
}

.bpg-lightbox__close,
.bpg-lightbox__nav {
	position: absolute;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.12 );
	cursor: pointer;
}

.bpg-lightbox__close { top: 1rem; right: 1rem; }
.bpg-lightbox__nav--prev { left: 1rem; top: calc( 50% - 70px ); }
.bpg-lightbox__nav--next { right: 1rem; top: calc( 50% - 70px ); }

.bpg-lightbox__close::before,
.bpg-lightbox__close::after {
	content: "";
	position: absolute;
	inset: 50% auto auto 50%;
	width: 16px;
	height: 2px;
	background: #fff;
	translate: -50% -50%;
	rotate: 45deg;
}

.bpg-lightbox__close::after { rotate: -45deg; }

.bpg-lightbox__nav::before {
	content: "";
	display: block;
	width: 10px;
	height: 10px;
	margin: 0 auto;
	border: 2px solid #fff;
	border-width: 2px 2px 0 0;
	rotate: -135deg;
}

.bpg-lightbox__nav--next::before { rotate: 45deg; }

.bpg-lightbox__thumbs {
	position: absolute;
	inset: auto 0 0 0;
	height: 96px;
	display: flex;
	gap: 0.5rem;
	padding: 1rem;
	overflow-x: auto;
	justify-content: center;
}

.bpg-lightbox__thumb {
	flex: 0 0 56px;
	height: 56px;
	padding: 0;
	border: 0;
	background: none;
	opacity: 0.4;
	cursor: pointer;
}

.bpg-lightbox__thumb.is-active { opacity: 1; }

.bpg-lightbox__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Quality floor ---------------------------------------------------------- */

.bpg :focus-visible {
	outline: 2px solid var( --bpg-accent, currentColor );
	outline-offset: 2px;
}

@media ( max-width: 768px ) {
	.bpg--thumbs-left,
	.bpg--thumbs-right {
		grid-template-columns: 1fr;
	}

	.bpg--thumbs-left .bpg-thumbs,
	.bpg--thumbs-right .bpg-thumbs {
		flex-direction: row;
		order: 0;
	}

	.bpg-arrow { display: none; }
}

@media ( prefers-reduced-motion: reduce ) {
	.bpg-slide,
	.bpg-arrow,
	.bpg-thumb {
		transition: none;
	}
}

/* No JS: stack the slides so every image is still reachable. */
.no-js .bpg-slide,
.bpg:not( .bpg--ready ) .bpg-slide:first-child {
	position: relative;
	opacity: 1;
	visibility: visible;
}
