/*
Name: 			image-gallery.css
Description:	แกลเลอรี่รูปแบบตาราง + lightbox (ใช้คู่กับ js/image-gallery.js) แทน unitegallery
*/

/* ---------- ตารางรูป ---------- */
.image-gallery {
	--gallery-tile-min: 176px;
	--gallery-gap: 10px;
	--gallery-overlay: rgba(21, 105, 172, .6);
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--gallery-tile-min), 1fr));
	gap: var(--gallery-gap);
	margin: 0;
}

.image-gallery-item {
	position: relative;
	display: block;
	overflow: hidden;
	aspect-ratio: 176 / 130;
	border-radius: 5px;
	background: #e9eef3;
}

.image-gallery-item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform .4s ease;
}

.image-gallery-item::after {
	content: "\f00e";
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--gallery-overlay);
	color: #FFF;
	font-family: "Font Awesome 5 Free";
	font-weight: 900;
	font-size: 26px;
	opacity: 0;
	transition: opacity .3s ease;
}

.image-gallery-item:hover::after,
.image-gallery-item:focus-visible::after {
	opacity: 1;
}

.image-gallery-item:hover img,
.image-gallery-item:focus-visible img {
	transform: scale(1.08);
}

.image-gallery-item:focus-visible {
	outline: 3px solid #1569AC;
	outline-offset: 2px;
}

@media (max-width: 575.98px) {
	.image-gallery {
		--gallery-tile-min: 130px;
		--gallery-gap: 8px;
	}
}

/* ---------- Lightbox ---------- */
html.gallery-lightbox-open {
	overflow: hidden;
}

.gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100001;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, .8);
	opacity: 0;
	transition: opacity .25s ease;
}

.gallery-lightbox[hidden] {
	display: none;
}

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

.gallery-lightbox-figure {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	max-width: calc(100vw - 140px);
	max-height: calc(100vh - 100px);
	margin: 0;
	touch-action: pan-y;
}

.gallery-lightbox-img {
	display: block;
	max-width: 100%;
	max-height: calc(100vh - 100px);
	width: auto;
	height: auto;
	border-radius: 4px;
	box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
	user-select: none;
	-webkit-user-drag: none;
	transition: opacity .2s ease;
}

.gallery-lightbox.is-loading .gallery-lightbox-img {
	opacity: 0;
}

.gallery-lightbox.is-loading .gallery-lightbox-figure::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 40px;
	height: 40px;
	margin: -20px 0 0 -20px;
	border: 3px solid rgba(255, 255, 255, .3);
	border-top-color: #FFF;
	border-radius: 50%;
	animation: gallery-lightbox-spin .8s linear infinite;
}

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

.gallery-lightbox-counter {
	position: absolute;
	top: 18px;
	left: 20px;
	color: #FFF;
	font-size: 15px;
	font-family: 'Maitree', serif;
}

.gallery-lightbox-close,
.gallery-lightbox-prev,
.gallery-lightbox-next {
	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, .12);
	color: #FFF;
	cursor: pointer;
	transition: background-color .2s;
}

.gallery-lightbox-close:hover,
.gallery-lightbox-prev:hover,
.gallery-lightbox-next:hover {
	background: rgba(255, 255, 255, .28);
}

.gallery-lightbox-close:focus-visible,
.gallery-lightbox-prev:focus-visible,
.gallery-lightbox-next:focus-visible {
	outline: 2px solid #FFF;
	outline-offset: 2px;
}

.gallery-lightbox-close svg,
.gallery-lightbox-prev svg,
.gallery-lightbox-next svg {
	width: 22px;
	height: 22px;
}

.gallery-lightbox-close {
	top: 10px;
	right: 12px;
}

.gallery-lightbox-prev,
.gallery-lightbox-next {
	top: 50%;
	margin-top: -24px;
}

.gallery-lightbox-prev { left: 12px; }
.gallery-lightbox-next { right: 12px; }

.gallery-lightbox.is-single .gallery-lightbox-prev,
.gallery-lightbox.is-single .gallery-lightbox-next {
	display: none;
}

@media (max-width: 767.98px) {
	.gallery-lightbox-figure {
		max-width: 100vw;
		max-height: calc(100vh - 140px);
	}

	.gallery-lightbox-img {
		max-height: calc(100vh - 140px);
		border-radius: 0;
	}

	.gallery-lightbox-prev,
	.gallery-lightbox-next {
		top: auto;
		bottom: 16px;
		margin-top: 0;
	}

	.gallery-lightbox-prev { left: calc(50% - 64px); }
	.gallery-lightbox-next { right: calc(50% - 64px); }
}

@media (prefers-reduced-motion: reduce) {
	.image-gallery-item img,
	.gallery-lightbox,
	.gallery-lightbox-img {
		transition: none;
	}
}
