/* ==========================================================================
   Simple Product Gallery
   Override any --spg-* variable in your theme, e.g.
   .spg { --spg-accent: #0f766e; --spg-radius: 4px; }
   ========================================================================== */

.spg {
	--spg-columns: 4;
	--spg-gap: clamp(1rem, 2.5vw, 1.75rem);
	--spg-min: 160px;               /* Smallest a card may get before the grid wraps. */
	--spg-ratio: 1/1;               /* Thumbnail shape. */
	--spg-radius: 12px;
	--spg-surface: #f3f2ef;
	--spg-muted: #6b6a66;
	--spg-border: rgba(0, 0, 0, 0.12);
	--spg-accent: #1c1b19;
	--spg-accent-contrast: #ffffff;

	margin-block: 2rem;
}

/* Image-only galleries: tighter grid, softer corners. Override like any other variable. */
.spg--images {
	--spg-gap: clamp(0.5rem, 1.2vw, 0.85rem);
	--spg-radius: 6px;
	--spg-min: 110px;
}

/* Visually hidden helper text (in case the theme or editor doesn't define it). */
.spg .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Grid -------------------------------------------------------------- */

.spg__grid {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: var(--spg-gap);
	/* Honours the "columns" setting on wide screens, wraps gracefully on small ones. */
	grid-template-columns: repeat(
		auto-fill,
		minmax(max(var(--spg-min), calc((100% - (var(--spg-columns) - 1) * var(--spg-gap)) / var(--spg-columns))), 1fr)
	);
}

.spg__item {
	margin: 0;
	padding: 0;
}

.spg__item::before,
.spg__item::marker {
	content: none;
}

/* ---- Card -------------------------------------------------------------- */

.spg-card {
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: 0.8rem;
	height: 100%;
}

/* Uniform thumbnails, part 2: every frame has the same shape,
   whatever the original image size or orientation. */
.spg-card__media {
	position: relative;
	display: block;
	aspect-ratio: var(--spg-ratio);
	overflow: hidden;
	border-radius: var(--spg-radius);
	background: var(--spg-surface);
	cursor: zoom-in;
	isolation: isolate;
}

.spg-card__media--empty {
	cursor: default;
	background:
		linear-gradient(135deg, transparent 49.5%, var(--spg-border) 50%, transparent 50.5%),
		var(--spg-surface);
}

.spg-card__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	margin: 0 !important;
	object-fit: cover;
	object-position: center;
	transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.spg-card__media:hover .spg-card__img,
.spg-card__media:focus-visible .spg-card__img {
	transform: scale(1.045);
}

.spg-card__zoom {
	position: absolute;
	right: 0.75rem;
	bottom: 0.75rem;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.92)
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231c1b19' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4.5 4.5M11 8.5v5M8.5 11h5'/%3E%3C/svg%3E")
		center / 1.1rem no-repeat;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
	opacity: 0;
	transform: translateY(6px);
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.spg-card__media:hover .spg-card__zoom,
.spg-card__media:focus-visible .spg-card__zoom {
	opacity: 1;
	transform: none;
}

.spg-card__media:focus-visible {
	outline: 2px solid var(--spg-accent);
	outline-offset: 3px;
}

.spg-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	padding-inline: 0.15rem;
}

.spg-card__title {
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.35;
	color: inherit;
	text-decoration: none;
}

.spg-card__title:hover,
.spg-card__title:focus-visible {
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.spg-card__price {
	font-size: 0.95rem;
	color: var(--spg-muted);
	font-variant-numeric: tabular-nums;
}

.spg-card__price del {
	opacity: 0.65;
	margin-right: 0.35em;
}

.spg-card__price ins {
	text-decoration: none;
	color: inherit;
}

/* ---- Numbered pagination ------------------------------------------------ */

.spg-pagination {
	margin-top: clamp(2rem, 4vw, 3rem);
}

.spg-pagination__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 0.4rem;
}

.spg-pagination__list li {
	margin: 0;
}

.spg-pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.35em;
	min-width: 2.6rem;
	height: 2.6rem;
	padding: 0 0.85rem;
	border: 1px solid var(--spg-border);
	border-radius: 999px;
	font-size: 0.95rem;
	line-height: 1;
	color: inherit;
	text-decoration: none;
	font-variant-numeric: tabular-nums;
	transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.spg-pagination a.page-numbers:hover {
	border-color: var(--spg-accent);
}

.spg-pagination a.page-numbers:focus-visible {
	outline: 2px solid var(--spg-accent);
	outline-offset: 2px;
}

.spg-pagination .page-numbers.current {
	background: var(--spg-accent);
	border-color: var(--spg-accent);
	color: var(--spg-accent-contrast);
	font-weight: 600;
}

.spg-pagination .page-numbers.dots {
	min-width: auto;
	padding: 0 0.2rem;
	border-color: transparent;
}

@media (max-width: 480px) {
	.spg-pagination .prev,
	.spg-pagination .next {
		font-size: 0;
		padding: 0;
		width: 2.6rem;
	}

	.spg-pagination .prev span,
	.spg-pagination .next span {
		font-size: 1.1rem;
	}
}

.spg-empty {
	padding: 2rem;
	text-align: center;
	color: var(--spg-muted);
}

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

html.spg-lock {
	overflow: hidden;
}

.spg-lightbox {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: #fff;
	overflow: hidden;
}

.spg-lightbox::backdrop {
	background: rgba(14, 14, 16, 0.93);
}

.spg-lightbox[open] {
	animation: spg-fade 0.22s ease;
}

.spg-lightbox[open]::backdrop {
	animation: spg-fade 0.22s ease;
}

.spg-lightbox__stage {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 4.5rem 5.5rem 2rem;
}

.spg-lightbox__figure {
	position: relative;
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	max-width: 100%;
	max-height: 100%;
}

.spg-lightbox__img {
	display: block;
	width: auto;
	height: auto;
	max-width: min(100%, 1400px);
	max-height: calc(100vh - 10rem);
	max-height: calc(100dvh - 10rem);
	object-fit: contain;
	border-radius: 6px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
	transition: opacity 0.25s ease;
	user-select: none;
	-webkit-user-drag: none;
}

.spg-lightbox.is-loading .spg-lightbox__img {
	opacity: 0;
}

.spg-lightbox__spinner {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 2.25rem;
	height: 2.25rem;
	margin: -1.125rem 0 0 -1.125rem;
	border: 3px solid rgba(255, 255, 255, 0.2);
	border-top-color: #fff;
	border-radius: 50%;
	opacity: 0;
	animation: spg-spin 0.8s linear infinite;
	pointer-events: none;
}

.spg-lightbox.is-loading .spg-lightbox__spinner {
	opacity: 1;
}

.spg-lightbox__caption {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: baseline;
	gap: 0.4rem 1rem;
	font-size: 0.95rem;
	text-align: center;
}

.spg-lightbox__title {
	font-weight: 600;
}

.spg-lightbox__title:empty,
.spg-lightbox__caption:not(:has(:not(:empty))) {
	display: none;
}

.spg-lightbox__count {
	opacity: 0.65;
	font-variant-numeric: tabular-nums;
}

.spg-lightbox__btn {
	position: fixed;
	z-index: 1;
	display: grid;
	place-items: center;
	width: 3rem;
	height: 3rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	cursor: pointer;
	transition: background-color 0.2s ease, transform 0.2s ease;
}

.spg-lightbox__btn svg {
	width: 1.35rem;
	height: 1.35rem;
}

.spg-lightbox__btn:hover {
	background: rgba(255, 255, 255, 0.24);
}

.spg-lightbox__btn:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.spg-lightbox__close {
	top: 1rem;
	right: 1rem;
}

.spg-lightbox__prev,
.spg-lightbox__next {
	top: 50%;
	transform: translateY(-50%);
}

.spg-lightbox__prev {
	left: 1.25rem;
}

.spg-lightbox__next {
	right: 1.25rem;
}

.spg-lightbox:not(.has-many) .spg-lightbox__prev,
.spg-lightbox:not(.has-many) .spg-lightbox__next,
.spg-lightbox:not(.has-many) .spg-lightbox__count {
	display: none;
}

@media (max-width: 640px) {
	.spg-lightbox__stage {
		padding: 4rem 0.75rem 5.5rem;
	}

	.spg-lightbox__prev,
	.spg-lightbox__next {
		top: auto;
		bottom: 1.25rem;
		transform: none;
	}

	.spg-lightbox__prev {
		left: calc(50% - 3.5rem);
	}

	.spg-lightbox__next {
		right: calc(50% - 3.5rem);
	}
}

@keyframes spg-fade {
	from { opacity: 0; }
	to   { opacity: 1; }
}

@keyframes spg-spin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.spg-card__img,
	.spg-card__zoom,
	.spg-lightbox__img,
	.spg-lightbox[open],
	.spg-lightbox[open]::backdrop {
		transition: none;
		animation: none;
	}

	.spg-card__media:hover .spg-card__img {
		transform: none;
	}
}
