/**
 * Gallery display – grid, slider, lightbox
 * Uses theme CSS vars (e.g. --sb-color-primary) where applicable.
 */

/* Single gallery block */
.sb-gallery {
	margin: 0 0 1.5rem;
}

.sb-gallery__inner {
	width: 100%;
}

/* Grid layout */
.sb-gallery-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 0.75rem;
	list-style: none;
	margin: 0;
	padding: 0;
}

@media (min-width: 600px) {
	.sb-gallery-grid {
		grid-template-columns: repeat(3, 1fr);
		gap: 1rem;
	}
}

@media (min-width: 900px) {
	.sb-gallery-grid {
		grid-template-columns: repeat(4, 1fr);
		gap: 1.25rem;
	}
}

@media (min-width: 1100px) {
	.sb-gallery-grid {
		grid-template-columns: repeat(5, 1fr);
		gap: 1.25rem;
	}
}

.sb-gallery-grid__item {
	position: relative;
	margin: 0;
	padding: 0;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	border-radius: 8px;
	background: transparent;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
	transition: box-shadow 0.25s ease;
}

.sb-gallery-grid__item:hover {
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.sb-gallery-grid__link {
	position: absolute;
	inset: 0;
	display: block;
	text-decoration: none;
	color: inherit;
	cursor: pointer;
	padding: 0;
}

/* Override theme .entry-content img (margin + height:auto) so image fills the card with no spacing */
.sb-gallery-grid__item .sb-gallery-grid__link .sb-gallery-grid__img {
	margin: 0;
	max-width: none;
	width: 100%;
	height: 100%;
}

.sb-gallery-grid__img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	display: block;
	transition: transform 0.25s ease;
}

.sb-gallery-grid__link:hover .sb-gallery-grid__img,
.sb-gallery-grid__link:focus .sb-gallery-grid__img {
	transform: scale(1.03);
}

/* Slider (single gallery display=slider) */
.sb-gallery-slider {
	position: relative;
	width: 100%;
	max-width: 900px;
	margin: 0 auto;
}

.sb-gallery-slider__viewport {
	overflow: hidden;
	border-radius: 12px;
	background: #f5f5f5;
}

.sb-gallery-slider__track {
	display: flex;
	transition: transform 0.35s ease;
}

.sb-gallery-slider__slide {
	flex: 0 0 100%;
	min-width: 0;
}

.sb-gallery-slider__img {
	width: 100%;
	height: auto;
	display: block;
	aspect-ratio: 16 / 10;
	object-fit: contain;
	background: #f5f5f5;
}

.sb-gallery-slider__controls {
	position: absolute;
	top: 50%;
	left: 0;
	right: 0;
	transform: translateY(-50%);
	pointer-events: none;
	display: flex;
	justify-content: space-between;
	padding: 0 8px;
}

.sb-gallery-slider__prev,
.sb-gallery-slider__next {
	pointer-events: auto;
	width: 44px;
	height: 44px;
	border: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.95);
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
	cursor: pointer;
	font-size: 1.5rem;
	line-height: 1;
	color: var(--sb-color-primary, #2271b1);
	transition: background 0.2s, transform 0.2s;
}

.sb-gallery-slider__prev:hover,
.sb-gallery-slider__next:hover {
	background: #fff;
	transform: scale(1.05);
}

.sb-gallery-slider__dots {
	display: flex;
	justify-content: center;
	gap: 8px;
	margin-top: 12px;
	flex-wrap: wrap;
}

.sb-gallery-slider__dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	border: none;
	background: rgba(0, 0, 0, 0.2);
	cursor: pointer;
	padding: 0;
	transition: background 0.2s, transform 0.2s;
}

.sb-gallery-slider__dot:hover {
	background: rgba(0, 0, 0, 0.35);
}

.sb-gallery-slider__dot.is-active {
	background: var(--sb-color-primary, #2271b1);
	transform: scale(1.2);
}

/* Archive sections – same section layout as reviews/categories */
.sb-gallery-archive__section {
	margin: 0;
}

/* First section: remove extra top margin from title so no big gap under header */
.sb-gallery-archive__section--first .sb-home-section-heading {
	margin-top: 0;
}
.sb-gallery-archive__section--first .sb-home-section-heading__title {
	margin-top: 0;
}

/* Keep gap between multiple gallery sections */
.sb-gallery-archive__section + .sb-gallery-archive__section {
	margin-top: var(--sb-home-section-gap, 2.5rem);
}

/* Prevent theme .entry-content h2 margin from adding extra space above gallery titles.
   Match home page section title: same size and weight. Tighter spacing: title ↔ subtitle, heading ↔ images. */
.sb-gallery-archive__section .sb-home-section-heading__title {
	margin-top: 0;
	margin-bottom: 0;
	font-size: var(--sb-fs-h2);
	font-weight: 900;
	line-height: var(--sb-lh-heading);
	letter-spacing: -0.02em;
	color: var(--sb-home-dark, #1d2327);
}

.sb-gallery-archive__section .sb-home-section-heading__subtitle {
	margin-top: 0;
	margin-bottom: 4px;
}

.sb-gallery-archive__section .sb-home-section-heading {
	margin-bottom: 0.75rem;
}

/* Gallery archive: left-aligned heading (class added in PHP); grid uses full section width */
.sb-gallery-archive__section .sb-home-section-heading--left {
	text-align: left;
}

.sb-gallery-archive--empty {
	padding: 1rem 0;
}

.sb-gallery-archive__empty {
	margin: 0;
	color: rgba(0, 0, 0, 0.6);
}

/* Fullscreen lightbox – thumbs always visible at bottom; main image uses remaining space */
.sb-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 56px 16px 16px;
	box-sizing: border-box;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.25s ease, visibility 0.25s ease;
}

.sb-gallery-lightbox.is-open {
	opacity: 1;
	visibility: visible;
}

.sb-gallery-lightbox__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.92);
	cursor: pointer;
}

.sb-gallery-lightbox__content {
	position: relative;
	z-index: 1;
	width: 100%;
	max-width: 1200px;
	height: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
}

.sb-gallery-lightbox__close {
	position: absolute;
	top: -44px;
	right: 0;
	width: 44px;
	height: 44px;
	border: none;
	background: transparent;
	color: #fff;
	font-size: 2rem;
	line-height: 1;
	cursor: pointer;
	opacity: 0.9;
	transition: opacity 0.2s;
}

.sb-gallery-lightbox__close:hover {
	opacity: 1;
}

.sb-gallery-lightbox__prev,
.sb-gallery-lightbox__next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 52px;
	height: 52px;
	border: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	color: #fff;
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
	transition: background 0.2s;
}

.sb-gallery-lightbox__prev {
	left: 8px;
}

.sb-gallery-lightbox__next {
	right: 8px;
}

.sb-gallery-lightbox__prev:hover,
.sb-gallery-lightbox__next:hover {
	background: rgba(255, 255, 255, 0.25);
}

/* Main image area: takes remaining space above thumbs */
.sb-gallery-lightbox__main {
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	width: 100%;
}

.sb-gallery-lightbox__img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	display: block;
}

/* Thumbnails: always visible at bottom; scrollable/slider when many */
.sb-gallery-lightbox__thumbs-wrap {
	flex: 0 0 auto;
	width: 100%;
	max-width: 100%;
	margin-top: 12px;
	padding: 0 36px;
	position: relative;
}

.sb-gallery-lightbox__thumbs {
	display: flex;
	gap: 8px;
	padding: 8px 0;
	overflow-x: auto;
	justify-content: center;
	flex-wrap: nowrap;
	max-width: 100%;
	scroll-behavior: smooth;
	scrollbar-width: thin;
	-webkit-overflow-scrolling: touch;
}

.sb-gallery-lightbox__thumbs.is-slider {
	justify-content: flex-start;
}

/* Thumb uses background-image (set in JS) so image always fills full width and height */
.sb-gallery-lightbox__thumb {
	flex: 0 0 64px;
	width: 64px;
	height: 48px;
	min-height: 48px;
	max-height: 48px;
	min-width: 0;
	padding: 0;
	border: 2px solid transparent;
	border-radius: 6px;
	overflow: hidden;
	cursor: pointer;
	opacity: 0.7;
	transition: opacity 0.2s, border-color 0.2s;
	position: relative;
	display: block;
	background-color: #333;
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	box-sizing: border-box;
	align-self: flex-start;
}

.sb-gallery-lightbox__thumb:hover {
	opacity: 1;
}

.sb-gallery-lightbox__thumb.is-active {
	border-color: #fff;
	opacity: 1;
}

/* Thumb strip prev/next when many thumbnails */
.sb-gallery-lightbox__thumbs-prev,
.sb-gallery-lightbox__thumbs-next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
	font-size: 1.1rem;
	line-height: 1;
	cursor: pointer;
	transition: background 0.2s;
	padding: 0;
}

.sb-gallery-lightbox__thumbs-prev {
	left: 0;
}

.sb-gallery-lightbox__thumbs-next {
	right: 0;
}

.sb-gallery-lightbox__thumbs-prev:hover,
.sb-gallery-lightbox__thumbs-next:hover {
	background: rgba(255, 255, 255, 0.35);
}

.sb-gallery-lightbox__thumbs-prev.is-hidden,
.sb-gallery-lightbox__thumbs-next.is-hidden {
	visibility: hidden;
	pointer-events: none;
}

@media (max-width: 768px) {
	.sb-gallery-lightbox {
		padding: 50px 12px 12px;
	}
	.sb-gallery-lightbox__prev,
	.sb-gallery-lightbox__next {
		width: 44px;
		height: 44px;
		font-size: 1.5rem;
	}
	.sb-gallery-lightbox__thumbs-wrap {
		padding: 0 28px;
	}
	.sb-gallery-lightbox__thumb {
		flex: 0 0 52px;
		width: 52px;
		height: 40px;
	}
}
