/*
 * Shared front gallery — grid (single-listing) + slider (tight spots: review,
 * popup, sidebar) layouts over ONE item contract. `--sp-gallery-size` is the
 * configurable inline image size (px); `--sp-gallery-cols` the fixed-column
 * fallback when no size is set. The lightbox itself is inline-styled in the JS.
 */

.sp-gallery {
	--sp-gallery-size: 200px;
	margin: 0;
}

/* ---- Grid (single-listing) — FLUID, no breakpoints ----
   Shows UP TO `--sp-gallery-cols` columns, each at least `--sp-gallery-min`
   wide, and drops a column smoothly whenever the container gets too narrow to
   keep them that wide. The `max(min-width, 100%/cols)` term is the classic
   "up-to-N-columns responsive" trick: on a wide container `100%/cols` wins → the
   grid caps at `cols` columns; as it narrows, the min-width wins → the count
   reduces one at a time (5→4→3→2→1). No media queries, no jumps. */
.sp-gallery--grid {
	--sp-gallery-gap: 10px;
	display: grid;
	gap: var(--sp-gallery-gap);
	grid-template-columns: repeat(
		auto-fill,
		minmax(
			max(
				var(--sp-gallery-min, 150px),
				calc((100% - (var(--sp-gallery-cols, 3) - 1) * var(--sp-gallery-gap)) / var(--sp-gallery-cols, 3))
			),
			1fr
		)
	);
}

/* ---- Slider (review / popup / sidebar) ---- */
.sp-gallery--slider {
	display: flex;
	gap: 10px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	padding-bottom: 2px;
}

.sp-gallery--slider .sp-gallery__item {
	flex: 0 0 var(--sp-gallery-min, 200px);
	scroll-snap-align: start;
}

/* ---- Item (shared) ---- */
.sp-gallery__item {
	display: block;
	position: relative;
	overflow: hidden;
	border-radius: 6px;
	aspect-ratio: 4 / 3;
	cursor: zoom-in;
	background: #f1f2f4;
	line-height: 0;
}

/* aspect-ratio fallback for older engines: a padding-box when unsupported. */
@supports not (aspect-ratio: 1) {
	.sp-gallery__item { height: 0; padding-top: 75%; }
	.sp-gallery__item > img { position: absolute; inset: 0; }
}

.sp-gallery__item > img {
	width: 100%;
	height: 100%;
	-o-object-fit: cover;
	   object-fit: cover;
	display: block;
	transition: transform 0.2s ease;
}

.sp-gallery__item:hover > img {
	transform: scale(1.05);
}

/* Click-to-enlarge affordance: a centred magnifier glyph that fades in on hover
   over any lightbox thumbnail (directory grid, review slider, map popup/sidebar),
   matching the zoom-in cursor. Pure CSS — the SVG is an inline data URI. */
.sp-gallery__item::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 46px;
	height: 46px;
	transform: translate(-50%, -50%) scale(0.7);
	border-radius: 50%;
	background: rgba(17, 24, 39, 0.55) no-repeat center / 22px 22px
		url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27%23fff%27 stroke-width=%272.2%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3E%3Ccircle cx=%2710.5%27 cy=%2710.5%27 r=%276.5%27/%3E%3Cline x1=%2721%27 y1=%2721%27 x2=%2715.4%27 y2=%2715.4%27/%3E%3C/svg%3E");
	opacity: 0;
	transition: opacity 0.18s ease, transform 0.18s ease;
	pointer-events: none;
	z-index: 1;
}
.sp-gallery__item:hover::after {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

.sp-gallery__item:focus-visible {
	outline: 2px solid var(--w2dc-primary, var(--w2dc-primary, #2271b1));
	outline-offset: 2px;
}

/* Per-image caption (attachment title) — a one-line bottom overlay on the thumb;
   the FULL caption shows in the lightbox (data-caption). */
.sp-gallery__caption {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	margin: 0;
	padding: 14px 8px 6px;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
	color: #fff;
	font-size: 12px;
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	pointer-events: none;
}

