/* Gallery Viewer
 * High-resolution image viewer (OpenSeadragon) — designed for Elementor popups, works anywhere.
 * Architecture: BEM. State classes prefixed with `is-`. Control position via prefix-class on root.
 */

/* Fill the parent Elementor container in both axes. Elementor's element wrappers
 * don't propagate height down the chain by default, so the widget would collapse
 * to its content unless every ancestor up to the column/container is height:100%. */
.elementor-widget-gallery_viewer,
.elementor-widget-gallery_viewer > .elementor-widget-container {
	width: 100%;
	height: 100%;
}

.gallery-viewer {
	--gv-ctrl-offset: 20px;
	position: relative;
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	contain: layout paint;
}

.gallery-viewer *,
.gallery-viewer *::before,
.gallery-viewer *::after {
	box-sizing: border-box;
}

.gallery-viewer__layout {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	width: 100%;
	height: 100%;
	min-height: 80vh;
	gap: 0;
}

/* ------- Left panel ------- */
.gallery-viewer__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: center;
	background: #f5f4f0;
	overflow: hidden;
	z-index: 1;
}

.gallery-viewer__panel::before {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.gallery-viewer__panel-inner {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 20px;
	width: 100%;
}

.gallery-viewer__title {
	margin: 0;
	font-size: clamp(1.5rem, 2.5vw, 2.25rem);
	line-height: 1.15;
}

.gallery-viewer__details,
.gallery-viewer__description {
	line-height: 1.5;
}

.gallery-viewer__details > *:first-child,
.gallery-viewer__description > *:first-child { margin-top: 0; }
.gallery-viewer__details > *:last-child,
.gallery-viewer__description > *:last-child { margin-bottom: 0; }

/* ------- Stage / viewer area ------- */
.gallery-viewer__stage {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
	background: #1a1a1a;
	overflow: hidden;
	isolation: isolate;
}

.gallery-viewer__canvas {
	/* OpenSeadragon injects `position: relative` inline on this element during
	 * construction. In the desktop row layout the stage has a definite (stretched)
	 * height, so the canvas's `height: 100%` still resolves and OSD measures correctly.
	 * But in the tablet/mobile COLUMN layout the stage only has `min-height` (its
	 * computed `height` is auto), so `height: 100%` resolves to 0 — OSD then measures a
	 * zero-height container and renders nothing. Forcing `position: absolute` to win over
	 * OSD's inline value keeps the `inset: 0` fill at all times and on every breakpoint,
	 * so OSD always measures the real stage size. */
	position: absolute !important;
	inset: 0;
	width: 100%;
	height: 100%;
	cursor: grab;
	touch-action: none;
	transform: translateZ(0); /* promote to its own GPU layer */
	will-change: transform;
}

.gallery-viewer__canvas:active { cursor: grabbing; }

/* OpenSeadragon injects a canvas; let it fill. */
.gallery-viewer__canvas .openseadragon-canvas {
	outline: none !important;
}
.gallery-viewer__canvas .openseadragon-canvas canvas {
	image-rendering: -webkit-optimize-contrast;
	image-rendering: crisp-edges;
}

/* Fallback image — visible until OpenSeadragon takes over to avoid flash-of-empty-stage. */
.gallery-viewer__fallback {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	pointer-events: none;
	user-select: none;
	-webkit-user-drag: none;
	opacity: 1;
	transition: opacity 200ms ease;
}

.gallery-viewer.is-ready .gallery-viewer__fallback {
	opacity: 0;
}

/* ------- Floating controls (zoom / fullscreen / close) ------- */
.gallery-viewer__controls {
	position: absolute;
	display: flex;
	flex-direction: row;
	gap: 8px;
	z-index: 4;
	pointer-events: none; /* let buttons enable themselves below */
}

.gallery-viewer__controls > * { pointer-events: auto; }

/* Position classes are added by Elementor's `prefix_class` to the widget *wrapper*
 * (`.elementor-widget-gallery_viewer`), not to our inner `.gallery-viewer` element.
 * Selectors must therefore be descendant, not joined-class. */
.gv-controls-pos-top-left .gallery-viewer__controls {
	top: var(--gv-ctrl-offset);
	left: var(--gv-ctrl-offset);
}
.gv-controls-pos-top-right .gallery-viewer__controls {
	top: var(--gv-ctrl-offset);
	right: var(--gv-ctrl-offset);
}
.gv-controls-pos-bottom-left .gallery-viewer__controls {
	bottom: var(--gv-ctrl-offset);
	left: var(--gv-ctrl-offset);
}
.gv-controls-pos-bottom-right .gallery-viewer__controls {
	bottom: var(--gv-ctrl-offset);
	right: var(--gv-ctrl-offset);
}

/* Side-center positions — buttons row across the top/bottom edge or column down the left/right edge. */
.gv-controls-pos-top .gallery-viewer__controls {
	top: var(--gv-ctrl-offset);
	left: 50%;
	transform: translateX(-50%);
}
.gv-controls-pos-bottom .gallery-viewer__controls {
	bottom: var(--gv-ctrl-offset);
	left: 50%;
	transform: translateX(-50%);
}
.gv-controls-pos-left .gallery-viewer__controls {
	left: var(--gv-ctrl-offset);
	top: 50%;
	transform: translateY(-50%);
	flex-direction: column;
}
.gv-controls-pos-right .gallery-viewer__controls {
	right: var(--gv-ctrl-offset);
	top: 50%;
	transform: translateY(-50%);
	flex-direction: column;
}

.gallery-viewer__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	margin: 0;
	border: 0;
	background: rgba(0, 0, 0, 0.6);
	color: #fff;
	cursor: pointer;
	transition: background-color 150ms ease, color 150ms ease, transform 150ms ease, border-color 150ms ease;
	-webkit-tap-highlight-color: transparent;
}

.gallery-viewer__btn:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.gallery-viewer__btn:hover {
	background: rgba(0, 0, 0, 0.85);
}

.gallery-viewer__btn svg {
	width: 20px;
	height: 20px;
	fill: currentColor;
	display: block;
}

.gallery-viewer__btn i {
	font-size: 20px;
	line-height: 1;
}

/* ------- Navigation buttons (prev/next) ------- */
.gallery-viewer__nav {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin-top: auto; /* push nav to bottom of the panel column */
	padding-top: 24px;
}

.gallery-viewer__nav-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 12px 20px;
	border: 1px solid currentColor;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
	text-decoration: none;
	transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.gallery-viewer__nav-btn svg,
.gallery-viewer__nav-btn i {
	width: 16px;
	height: 16px;
	font-size: 16px;
	line-height: 1;
	display: inline-block;
	fill: currentColor;
}

.gallery-viewer__nav-btn:hover {
	background: currentColor;
}
.gallery-viewer__nav-btn:hover .gallery-viewer__nav-text,
.gallery-viewer__nav-btn:hover .gallery-viewer__nav-icon { /* keep readable on inverted bg */
	mix-blend-mode: difference;
}
.gallery-viewer__nav-btn:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.gallery-viewer__nav-btn.is-disabled,
.gallery-viewer__nav-btn[disabled] {
	opacity: 0.4;
	cursor: not-allowed;
	pointer-events: none;
}

.gallery-viewer.is-loading {
	cursor: progress;
}

.gallery-viewer.is-loading::after {
	content: '';
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.25);
	z-index: 5;
	pointer-events: none;
}

/* ------- Fullscreen mode ------- */
.gallery-viewer.is-fullscreen {
	position: fixed !important;
	inset: 0 !important;
	width: 100vw !important;
	height: 100vh !important;
	max-width: none !important;
	max-height: none !important;
	margin: 0 !important;
	padding: 0 !important;
	z-index: 99999;
	background: #000;
}

.gallery-viewer.is-fullscreen .gallery-viewer__layout {
	flex-direction: row;
	min-height: 100vh;
	height: 100vh;
	gap: 0;
}

.gallery-viewer.is-fullscreen .gallery-viewer__panel {
	display: none !important;
}

.gallery-viewer.is-fullscreen .gallery-viewer__stage {
	flex: 1 1 100%;
	max-width: 100%;
	border-radius: 0 !important;
	margin: 0 !important;
}

body.gallery-viewer-fullscreen-active {
	overflow: hidden;
}

/* Native fullscreen API targets the stage element — fill the viewport with a black backdrop. */
.gallery-viewer__stage:fullscreen,
.gallery-viewer__stage:-webkit-full-screen {
	width: 100vw;
	height: 100vh;
	background: #000;
	border-radius: 0 !important;
	margin: 0 !important;
}

/* ------- Responsive ------- */
@media (max-width: 1024px) {
	.gallery-viewer__layout {
		flex-direction: column;
		min-height: 0;
	}
	.gallery-viewer__panel {
		flex: 0 0 auto !important;
		max-width: 100% !important;
		width: 100% !important;
	}
	.gallery-viewer__stage {
		min-height: 60vh;
	}
}

@media (max-width: 600px) {
	.gallery-viewer__stage {
		min-height: 50vh;
	}
	.gallery-viewer__nav {
		flex-direction: row;
		justify-content: space-between;
	}
}

/* Reduce motion preferences. */
@media (prefers-reduced-motion: reduce) {
	.gallery-viewer__fallback,
	.gallery-viewer__btn,
	.gallery-viewer__nav-btn {
		transition: none;
	}
}
