/*
 * Products Hub — single product gallery and full-screen image viewer (v1.9.0).
 *
 * Replaces the earlier stage/canvas overrides and inline !important rules.
 * The viewer is a native <dialog> shown with showModal(): it renders in the
 * browser top layer, so theme z-index, transforms and overflow cannot clip
 * or cover it.
 */

/* ---------------------------------------------------------------------------
 * Gallery
 * ------------------------------------------------------------------------ */
.productshub-gallery {
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: 100%;
	min-width: 0;
	margin: 0;
}

/* Square, consistent stage. The image is contained (never cropped or
 * stretched) and centered, whatever its proportions. */
.productshub-gallery-stage {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 1 / 1;
	margin: 0;
	padding: 0;
	background: var(--productshub-well, #f7f7f7);
	border-radius: var(--productshub-radius, 18px);
	overflow: hidden;
}

.productshub-gallery-stage .productshub-gallery-main {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	padding: 4%;
	border: 0;
	border-radius: 0;
	object-fit: contain;
	object-position: center;
	box-shadow: none;
	transition: transform 0.25s ease;
}

.productshub-gallery.is-zooming .productshub-gallery-main {
	transform: scale(1.8);
	cursor: zoom-in;
}

.productshub-gallery-stage .productshub-gallery-open {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 0;
	border-radius: inherit;
	box-shadow: none;
	color: inherit;
	font: inherit;
	cursor: zoom-in;
}

.productshub-gallery-stage .productshub-gallery-open:focus-visible {
	outline: 2px solid var(--productshub-accent, #2563eb);
	outline-offset: -4px;
}

.productshub-gallery-expand {
	position: absolute;
	right: 14px;
	bottom: 14px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	background: rgba(255, 255, 255, 0.92);
	border-radius: 50%;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
	color: #222;
	opacity: 0.85;
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
}

.productshub-gallery-open:hover .productshub-gallery-expand {
	opacity: 1;
	transform: scale(1.05);
}

/* Previous / next arrows on the main image. */
.productshub-gallery .productshub-gallery-nav {
	position: absolute;
	top: 50%;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	min-height: 0;
	margin: 0;
	padding: 0;
	background: rgba(255, 255, 255, 0.94);
	border: 1px solid rgba(0, 0, 0, 0.06);
	border-radius: 50%;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
	color: #1c1c1c;
	font: inherit;
	line-height: 1;
	cursor: pointer;
	opacity: 0;
	transform: translateY(-50%);
	transition: opacity 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.productshub-gallery .productshub-gallery-nav svg {
	display: block;
	pointer-events: none;
}

.productshub-gallery .productshub-gallery-prev {
	left: 12px;
}

.productshub-gallery .productshub-gallery-next {
	right: 12px;
}

.productshub-gallery-stage:hover .productshub-gallery-nav,
.productshub-gallery-stage:focus-within .productshub-gallery-nav {
	opacity: 1;
}

.productshub-gallery .productshub-gallery-nav:hover {
	background: #fff;
	transform: translateY(-50%) scale(1.06);
}

.productshub-gallery .productshub-gallery-nav:focus-visible {
	outline: 2px solid var(--productshub-accent, #2563eb);
	outline-offset: 2px;
	opacity: 1;
}

@media (hover: none) {
	.productshub-gallery .productshub-gallery-nav {
		width: 36px;
		height: 36px;
		opacity: 1;
	}
}

.productshub-gallery-count {
	position: absolute;
	left: 14px;
	bottom: 14px;
	z-index: 1;
	padding: 4px 10px;
	background: rgba(255, 255, 255, 0.92);
	border-radius: 999px;
	color: #333;
	font-size: 0.78rem;
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	line-height: 1.3;
	pointer-events: none;
}

/* Thumbnail rail: a scrolling strip with optional scroll buttons. Horizontal
 * by default (small screens, Editorial); vertical beside the image below. */
.productshub-gallery-rail {
	position: relative;
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
	max-width: 100%;
}

.productshub-gallery-thumbs {
	display: flex;
	flex: 1 1 auto;
	flex-direction: row;
	gap: 10px;
	min-width: 0;
	max-width: 100%;
	margin: 0;
	padding: 3px;
	list-style: none;
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-x: contain;
	scroll-snap-type: x proximity;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.productshub-gallery-thumbs::-webkit-scrollbar {
	display: none;
}

.productshub-gallery-thumbs li {
	flex: 0 0 auto;
	width: var(--productshub-thumb-size, 76px);
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
	scroll-snap-align: start;
}

.productshub-gallery .productshub-rail-btn {
	display: none;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	min-height: 0;
	margin: 0;
	padding: 0;
	background: var(--productshub-surface, #fff);
	border: 1px solid var(--productshub-border, #e5e5e5);
	border-radius: 50%;
	box-shadow: none;
	color: #333;
	font: inherit;
	line-height: 1;
	cursor: pointer;
	transition: opacity 0.2s ease, background-color 0.2s ease;
}

.productshub-gallery .productshub-rail-btn svg {
	display: block;
	pointer-events: none;
}

.productshub-gallery .productshub-rail-btn:hover {
	background: var(--productshub-well, #f7f7f7);
}

.productshub-gallery .productshub-rail-btn:disabled {
	opacity: 0.35;
	cursor: default;
}

@media (hover: hover) and (pointer: fine) {
	.productshub-gallery.is-rail-overflowing .productshub-rail-btn {
		display: inline-flex;
	}
}

.productshub-gallery-thumbs li::before,
.productshub-gallery-thumbs li::marker {
	content: none;
}

.productshub-gallery .productshub-gallery-thumb {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 1 / 1;
	min-height: 0;
	margin: 0;
	padding: 6px;
	background: var(--productshub-well, #f7f7f7);
	border: 2px solid transparent;
	border-radius: 12px;
	box-shadow: none;
	cursor: pointer;
	opacity: 0.72;
	transition: opacity 0.2s ease, border-color 0.2s ease;
}

/* Never let thumb styles override [hidden] (empty featured-only gallery box). */
.productshub-gallery .productshub-gallery-thumb[hidden],
.productshub-gallery .productshub-gallery-slide-data,
.productshub-gallery .productshub-gallery-slide-data[hidden],
.productshub-gallery-rail:empty {
	display: none !important;
}

.productshub-gallery .productshub-gallery-thumb img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: contain;
	border-radius: 6px;
	pointer-events: none;
}

.productshub-gallery .productshub-gallery-thumb:hover {
	opacity: 1;
}

.productshub-gallery .productshub-gallery-thumb.is-active {
	border-color: var(--productshub-accent, #2563eb);
	opacity: 1;
}

.productshub-gallery .productshub-gallery-thumb:focus-visible {
	outline: 2px solid var(--productshub-accent, #2563eb);
	outline-offset: 2px;
}

/* Vertical rail beside the image on wide pages. The rail takes the stage's
 * height (height: 0 + min-height: 100%) and scrolls inside it. */
@container productshub-single (min-width: 760px) {
	.productshub-gallery.is-rail-vertical.has-thumbs {
		display: grid;
		grid-template-columns: var(--productshub-rail-width, 84px) minmax(0, 1fr);
		gap: 14px;
		align-items: stretch;
	}

	.productshub-gallery.is-rail-vertical .productshub-gallery-rail {
		grid-column: 1;
		grid-row: 1;
		flex-direction: column;
		height: 0;
		min-height: 100%;
	}

	.productshub-gallery.is-rail-vertical .productshub-gallery-stage {
		grid-column: 2;
		grid-row: 1;
	}

	.productshub-gallery.is-rail-vertical .productshub-gallery-thumbs {
		flex-direction: column;
		width: 100%;
		min-height: 0;
		overflow-x: hidden;
		overflow-y: auto;
		/* No overscroll containment: at the end of the rail the page scrolls on. */
		overscroll-behavior-y: auto;
		scroll-snap-type: y proximity;
	}

	.productshub-gallery.is-rail-vertical .productshub-gallery-thumbs li {
		width: 100%;
	}

	.productshub-gallery.is-rail-vertical .productshub-rail-btn svg {
		transform: rotate(90deg);
	}
}

/* ---------------------------------------------------------------------------
 * Full-screen viewer
 * ------------------------------------------------------------------------ */
.productshub-lightbox {
	position: fixed;
	inset: 0;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	color: #fff;
	overflow: hidden;
	overscroll-behavior: contain;
}

.productshub-lightbox:not([open]) {
	display: none;
}

.productshub-lightbox::backdrop {
	background: rgba(12, 13, 15, 0.94);
}

/* Fallback when showModal() is not supported. */
.productshub-lightbox.is-fallback-open {
	z-index: 2147483000;
	background: rgba(12, 13, 15, 0.94);
}

.productshub-lightbox-frame {
	position: relative;
	display: grid;
	place-items: center;
	width: 100%;
	height: 100%;
	padding: clamp(56px, 7vh, 72px) clamp(12px, 7vw, 96px);
}

.productshub-lightbox-figure {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
}

.productshub-lightbox .productshub-lightbox-image {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	object-fit: contain;
	box-shadow: none;
	user-select: none;
	transition: opacity 0.18s ease;
}

.productshub-lightbox.is-loading .productshub-lightbox-image {
	opacity: 0.35;
}

.productshub-lightbox-figure {
	flex-direction: column;
	gap: 12px;
}

.productshub-lightbox-figure .productshub-lightbox-image {
	flex: 1 1 0;
	min-height: 0;
}

.productshub-lightbox-caption {
	flex: 0 0 auto;
	max-width: 70ch;
	margin: 0;
	color: rgba(255, 255, 255, 0.86);
	font-size: 0.92rem;
	line-height: 1.5;
	text-align: center;
}

.productshub-lightbox-caption[hidden] {
	display: none;
}

.productshub-lightbox button {
	position: absolute;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	min-height: 0;
	margin: 0;
	padding: 0;
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.18);
	border-radius: 50%;
	box-shadow: none;
	color: #fff;
	font: inherit;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.productshub-lightbox button:hover,
.productshub-lightbox button:focus-visible {
	background: rgba(255, 255, 255, 0.24);
	color: #fff;
}

.productshub-lightbox button:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.productshub-lightbox button svg {
	display: block;
	pointer-events: none;
}

.productshub-lightbox .productshub-lightbox-close {
	top: max(14px, env(safe-area-inset-top));
	right: max(14px, env(safe-area-inset-right));
}

.productshub-lightbox .productshub-lightbox-prev,
.productshub-lightbox .productshub-lightbox-next {
	top: 50%;
	transform: translateY(-50%);
}

.productshub-lightbox .productshub-lightbox-prev {
	left: max(14px, env(safe-area-inset-left));
}

.productshub-lightbox .productshub-lightbox-next {
	right: max(14px, env(safe-area-inset-right));
}

.productshub-lightbox-counter {
	position: absolute;
	bottom: max(16px, env(safe-area-inset-bottom));
	left: 50%;
	margin: 0;
	padding: 5px 12px;
	background: rgba(255, 255, 255, 0.12);
	border-radius: 999px;
	color: rgba(255, 255, 255, 0.9);
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
	transform: translateX(-50%);
}

/* Phones: arrows move to the bottom edge so they never cover the image. */
@media (max-width: 600px) {
	.productshub-lightbox-frame {
		padding: 64px 8px 84px;
	}

	.productshub-lightbox .productshub-lightbox-prev,
	.productshub-lightbox .productshub-lightbox-next {
		top: auto;
		bottom: max(14px, env(safe-area-inset-bottom));
		transform: none;
	}

	.productshub-lightbox-counter {
		bottom: max(26px, calc(env(safe-area-inset-bottom) + 12px));
	}
}

@media (prefers-reduced-motion: reduce) {
	.productshub-gallery-main,
	.productshub-lightbox-image,
	.productshub-gallery-thumb,
	.productshub-gallery-nav,
	.productshub-rail-btn {
		transition: none;
	}
}
