/**
 * Content Manager gallery grid + lightbox.
 */

.cpd-gallery {
	width: 100%;
}

.cpd-gallery__grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 1rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cpd-gallery__item {
	display: flex;
	flex-direction: column;
	margin: 0;
	min-width: 0;
}

.cpd-gallery__link {
	display: block;
	overflow: hidden;
	aspect-ratio: 4 / 3;
	background: #f1f5f9;
	text-decoration: none;
	outline-offset: 2px;
}

.cpd-gallery__link:focus-visible {
	outline: 2px solid #0f172a;
}

.cpd-gallery__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.25s ease;
}

.cpd-gallery__link:hover .cpd-gallery__img,
.cpd-gallery__link:focus-visible .cpd-gallery__img {
	transform: scale(1.03);
}

.cpd-gallery__caption {
	margin: 0.5rem 0 0;
	font-size: 0.875rem;
	line-height: 1.4;
	color: #475569;
}

.cpd-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
	box-sizing: border-box;
	background: rgba(15, 23, 42, 0.88);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;
	touch-action: pan-y;
}

.cpd-gallery-lightbox.is-open {
	opacity: 1;
	visibility: visible;
}

.cpd-gallery-lightbox__dialog {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	max-width: min(1100px, 100%);
	max-height: 100%;
	outline: none;
}

.cpd-gallery-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	margin: 0;
	max-width: 100%;
	max-height: calc(100vh - 3rem);
}

.cpd-gallery-lightbox__img {
	display: block;
	max-width: 100%;
	max-height: calc(100vh - 7rem);
	width: auto;
	height: auto;
	object-fit: contain;
	background: #0f172a;
}

.cpd-gallery-lightbox__caption {
	margin: 0.75rem 0 0;
	max-width: 40rem;
	text-align: center;
	font-size: 0.95rem;
	line-height: 1.45;
	color: #f8fafc;
}

.cpd-gallery-lightbox__caption:empty {
	display: none;
}

.cpd-gallery-lightbox__close,
.cpd-gallery-lightbox__prev,
.cpd-gallery-lightbox__next {
	position: absolute;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;
	border: 1px solid rgba(248, 250, 252, 0.35);
	border-radius: 2px;
	background: rgba(15, 23, 42, 0.55);
	color: #f8fafc;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.cpd-gallery-lightbox__close:hover,
.cpd-gallery-lightbox__prev:hover,
.cpd-gallery-lightbox__next:hover,
.cpd-gallery-lightbox__close:focus-visible,
.cpd-gallery-lightbox__prev:focus-visible,
.cpd-gallery-lightbox__next:focus-visible {
	background: rgba(15, 23, 42, 0.85);
	outline: none;
}

.cpd-gallery-lightbox__close {
	top: 0;
	right: 0;
}

.cpd-gallery-lightbox__prev,
.cpd-gallery-lightbox__next {
	top: 50%;
	transform: translateY(-50%);
}

.cpd-gallery-lightbox__prev {
	left: 0.25rem;
}

.cpd-gallery-lightbox__next {
	right: 0.25rem;
}

.cpd-gallery-lightbox__prev[hidden],
.cpd-gallery-lightbox__next[hidden] {
	display: none;
}

body.cpd-gallery-lightbox-open {
	overflow: hidden;
}

@media (max-width: 600px) {
	.cpd-gallery__grid {
		grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
		gap: 0.75rem;
	}

	.cpd-gallery-lightbox {
		padding: 0.75rem;
	}

	.cpd-gallery-lightbox__prev,
	.cpd-gallery-lightbox__next {
		width: 2.25rem;
		height: 2.25rem;
		font-size: 1.25rem;
	}
}
