/**
 * NCB Photo Gallery — front-end styles.
 *
 * @package NCB_Photo_Gallery
 * @author  NCB Software
 */

.ncbpg-gallery {
	--ncbpg-gap: 8px;
	--ncbpg-columns: 3;
	--ncbpg-row-height: 240px;
	margin: 0 0 1.5em;
}

.ncbpg-gallery__items {
	display: grid;
	gap: var(--ncbpg-gap);
	grid-template-columns: repeat(var(--ncbpg-columns), minmax(0, 1fr));
}

.ncbpg-gallery__item {
	position: relative;
	margin: 0;
	padding: 0;
	overflow: hidden;
	min-width: 0;
}

.ncbpg-gallery__image {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
	border-radius: inherit;
}

.ncbpg-gallery__trigger {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	cursor: zoom-in;
	line-height: 0;
	-webkit-appearance: none;
	appearance: none;
}

.ncbpg-gallery__trigger:focus-visible {
	outline: 3px solid currentColor;
	outline-offset: -3px;
}

.ncbpg-gallery__caption {
	margin: 0.4em 0 0;
	font-size: 0.85em;
	line-height: 1.4;
	opacity: 0.8;
}

/* 1. Grid — every tile the same, images cropped to a square. */
.ncbpg-gallery--grid .ncbpg-gallery__item {
	aspect-ratio: 1 / 1;
}

.ncbpg-gallery--grid .ncbpg-gallery__caption {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	margin: 0;
	padding: 0.5em 0.7em;
	background: rgba(0, 0, 0, 0.55);
	color: #fff;
	opacity: 1;
}

/* 2. Masonry — JS assigns each photo to the shortest column. */
.ncbpg-gallery--masonry .ncbpg-gallery__items {
	display: flex;
	align-items: flex-start;
}

.ncbpg-gallery__column {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	gap: var(--ncbpg-gap);
	min-width: 0;
}

.ncbpg-gallery--masonry .ncbpg-gallery__item {
	width: 100%;
}

.ncbpg-gallery--masonry .ncbpg-gallery__image {
	height: auto;
}

/* 3. Justified — JS stretches each row to the full width. */
.ncbpg-gallery--justified .ncbpg-gallery__items {
	display: block;
}

.ncbpg-gallery__row {
	display: flex;
	gap: var(--ncbpg-gap);
	margin-bottom: var(--ncbpg-gap);
}

.ncbpg-gallery__row:last-child {
	margin-bottom: 0;
}

.ncbpg-gallery--justified .ncbpg-gallery__item {
	flex: 0 0 auto;
}

/* 4. Mosaic — a repeating pattern of one large tile and four small ones. */
.ncbpg-gallery--mosaic .ncbpg-gallery__items {
	grid-template-columns: repeat(4, minmax(0, 1fr));
	grid-auto-rows: 1fr;
	grid-auto-flow: dense;
}

.ncbpg-gallery--mosaic .ncbpg-gallery__item {
	aspect-ratio: 1 / 1;
}

.ncbpg-gallery--mosaic .ncbpg-gallery__item:nth-child(6n + 1) {
	grid-column: span 2;
	grid-row: span 2;
	aspect-ratio: auto;
}

.ncbpg-gallery--mosaic .ncbpg-gallery__item:nth-child(6n + 6) {
	grid-column: span 2;
	aspect-ratio: 2 / 1;
}

/* Responsive. */
@media (max-width: 900px) {
	.ncbpg-gallery__items {
		grid-template-columns: repeat(min(var(--ncbpg-columns), 3), minmax(0, 1fr));
	}
}

@media (max-width: 600px) {
	.ncbpg-gallery__items {
		grid-template-columns: repeat(min(var(--ncbpg-columns), 2), minmax(0, 1fr));
	}

	.ncbpg-gallery--mosaic .ncbpg-gallery__items {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.ncbpg-gallery--mosaic .ncbpg-gallery__item:nth-child(6n + 6) {
		grid-column: span 2;
	}
}

/* Lightbox. */
.ncbpg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(0, 0, 0, 0.92);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;
	box-sizing: border-box;
}

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

.ncbpg-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
}

.ncbpg-lightbox__image {
	display: block;
	max-width: 100%;
	max-height: calc(100vh - 140px);
	width: auto;
	height: auto;
	object-fit: contain;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.ncbpg-lightbox__caption {
	max-width: 60ch;
	margin: 14px 0 0;
	color: #fff;
	font-size: 0.9rem;
	line-height: 1.5;
	text-align: center;
}

.ncbpg-lightbox__button {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.ncbpg-lightbox__button:hover,
.ncbpg-lightbox__button:focus-visible {
	background: rgba(255, 255, 255, 0.28);
}

.ncbpg-lightbox__button:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.ncbpg-lightbox__button svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ncbpg-lightbox__close {
	top: 16px;
	right: 16px;
}

.ncbpg-lightbox__prev {
	top: 50%;
	left: 16px;
	transform: translateY(-50%);
}

.ncbpg-lightbox__next {
	top: 50%;
	right: 16px;
	transform: translateY(-50%);
}

.ncbpg-lightbox__counter {
	position: absolute;
	top: 24px;
	left: 50%;
	transform: translateX(-50%);
	color: rgba(255, 255, 255, 0.75);
	font-size: 0.85rem;
	letter-spacing: 0.03em;
}

.ncbpg-lightbox.is-single .ncbpg-lightbox__prev,
.ncbpg-lightbox.is-single .ncbpg-lightbox__next,
.ncbpg-lightbox.is-single .ncbpg-lightbox__counter {
	display: none;
}

@media (max-width: 600px) {
	.ncbpg-lightbox {
		padding: 12px;
	}

	.ncbpg-lightbox__prev {
		left: 8px;
	}

	.ncbpg-lightbox__next {
		right: 8px;
	}

	.ncbpg-lightbox__image {
		max-height: calc(100vh - 120px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.ncbpg-lightbox,
	.ncbpg-lightbox__button {
		transition: none;
	}
}

html.ncbpg-lightbox-open {
	overflow: hidden;
}
