/* =====================================================================
   AMS components — self-written replacements for LayerSlider,
   Unite Gallery and the old carousel plugins.
   Used with theme/js/ams-components.js (no jQuery required).
   ===================================================================== */

:root {
	--ams-accent: var(--color-primary, #0ea5d7);
	--ams-radius: 10px;
}

/* ---------------------------------------------------------------------
   Image slider  (.ams-slider)
   Markup:
   <div class="ams-slider" data-interval="5000" style="--ams-ratio: 16 / 9">
     <div class="ams-slide"> <img src="..."> [<div class="ams-slide__caption">..</div>] [<a class="ams-slide__link" href="..."></a>] </div>
   </div>
   Slides cross-fade only — no pan and no zoom.
   --------------------------------------------------------------------- */
.ams-slider {
	position: relative;
	width: 100%;
	aspect-ratio: var(--ams-ratio, 16 / 9);
	overflow: hidden;
	background: #e9eef2;
	isolation: isolate;
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
}
.ams-slider:focus-visible {
	outline: 3px solid var(--ams-accent);
	outline-offset: 2px;
}
.ams-slide {
	position: absolute;
	inset: 0;
	opacity: 0;
	visibility: hidden;
	transition: opacity .8s ease, visibility 0s linear .8s;
	z-index: 0;
}
.ams-slide.is-active {
	opacity: 1;
	visibility: visible;
	transition: opacity .8s ease, visibility 0s;
	z-index: 1;
}
/* Before JS runs, show the first slide only */
.ams-slider:not(.is-ready) .ams-slide:first-child {
	opacity: 1;
	visibility: visible;
}
.ams-slide > img,
.ams-slide > a > img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: var(--ams-fit, cover);
	object-position: var(--ams-position, 50% 50%);
	/* Never pan / zoom the image */
	transform: none !important;
	animation: none !important;
}
.ams-slide__link {
	position: absolute;
	inset: 0;
	z-index: 2;
}
.ams-slide__caption {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 3;
	padding: 14px 20px 34px;
	background: linear-gradient(to top, rgba(0, 0, 0, .78), rgba(0, 0, 0, .45) 70%, rgba(0, 0, 0, 0));
	color: #fff;
	pointer-events: none;
}
.ams-slide__title {
	display: block;
	font-size: clamp(15px, 2.2vw, 24px);
	line-height: 1.3;
	font-weight: 600;
}
.ams-slide__meta {
	display: block;
	margin-top: 4px;
	font-size: clamp(12px, 1.4vw, 16px);
	opacity: .9;
}

/* Arrows */
.ams-slider__arrow {
	position: absolute;
	top: 50%;
	z-index: 4;
	width: 44px;
	height: 44px;
	margin-top: -22px;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, .38);
	color: #fff;
	font-size: 18px;
	line-height: 44px;
	text-align: center;
	cursor: pointer;
	opacity: 0;
	transition: opacity .25s ease, background-color .25s ease;
}
.ams-slider__arrow--prev { left: 12px; }
.ams-slider__arrow--next { right: 12px; }
.ams-slider:hover .ams-slider__arrow,
.ams-slider:focus-within .ams-slider__arrow { opacity: 1; }
.ams-slider__arrow:hover,
.ams-slider__arrow:focus-visible { background: var(--ams-accent); outline: none; }
.ams-slider__arrow::before {
	content: "";
	display: inline-block;
	width: 11px;
	height: 11px;
	border-top: 2px solid currentColor;
	border-right: 2px solid currentColor;
	vertical-align: middle;
}
.ams-slider__arrow--prev::before { transform: translateX(2px) rotate(-135deg); }
.ams-slider__arrow--next::before { transform: translateX(-2px) rotate(45deg); }
@media (hover: none) {
	.ams-slider__arrow { opacity: .85; }
}

/* Dots */
.ams-slider__dots {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 10px;
	z-index: 4;
	display: flex;
	justify-content: center;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 12px;
	margin: 0;
	list-style: none;
}
.ams-slider__dot {
	width: 12px;
	height: 12px;
	padding: 0;
	border: 2px solid #fff;
	border-radius: 50%;
	background: rgba(255, 255, 255, .35);
	box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
	cursor: pointer;
	transition: background-color .2s ease, transform .2s ease;
}
.ams-slider__dot:hover { transform: scale(1.15); }
.ams-slider__dot.is-active {
	background: var(--ams-accent);
	border-color: var(--ams-accent);
}
.ams-slider__dot:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Progress bar (time until next slide) */
.ams-slider__progress {
	position: absolute;
	left: 0;
	bottom: 0;
	z-index: 4;
	height: 3px;
	width: 100%;
	background: var(--ams-accent);
	transform-origin: left center;
	transform: scaleX(0);
	pointer-events: none;
}
.ams-slider__progress.is-running {
	transition: transform linear var(--ams-interval, 5000ms);
	transform: scaleX(1);
}
.ams-slider.is-paused .ams-slider__progress { transition: none; }

/* Slider variants used by the theme */
.ams-slider--hero {
	--ams-ratio: 1600 / 800;
	max-width: 1600px;
	margin: 0 auto;
}
.ams-slider--news {
	--ams-ratio: 1000 / 650;
	--ams-position: 50% 0%;
	margin: 0 auto 40px;
	border-radius: var(--ams-radius);
}
.ams-slider--banner {
	--ams-ratio: 1100 / 630;
	border-radius: var(--ams-radius);
}
.ams-slider--person {
	--ams-ratio: 270 / 350;
	--ams-position: 50% 0%;
	max-width: 290px;
	border: 10px solid #fff;
	box-shadow: 0 3px 13px #ececec;
	box-sizing: border-box;
}
.ams-slider--person .ams-slide__caption {
	padding: 10px 8px 26px;
	text-align: center;
}
.ams-slider--person .ams-slide__title {
	font-family: 'Bai Jamjuree', sans-serif;
	font-size: 17px;
}
.ams-slider--person .ams-slider__arrow {
	width: 34px;
	height: 34px;
	margin-top: -17px;
	line-height: 34px;
}
.ams-slider--person .ams-slider__dots { bottom: 6px; gap: 6px; }
.ams-slider--person .ams-slider__dot { width: 9px; height: 9px; border-width: 1.5px; }

@media (max-width: 575.98px) {
	.ams-slider--news { --ams-ratio: 4 / 3; margin-bottom: 30px; }
	.ams-slider__arrow { width: 36px; height: 36px; margin-top: -18px; line-height: 36px; }
}

/* ---------------------------------------------------------------------
   Justified gallery  (.ams-gallery)
   Markup:
   <div class="ams-gallery" data-row-height="140">
     <a class="ams-gallery__item" href="full.jpg"><img src="thumb.jpg" alt=""></a>
   </div>
   --------------------------------------------------------------------- */
.ams-gallery {
	--ams-row: 140px;
	--ams-gap: 6px;
	display: flex;
	flex-wrap: wrap;
	gap: var(--ams-gap);
	margin: 0 0 20px;
}
.ams-gallery::after {
	/* stops the last row from stretching */
	content: "";
	flex-grow: 999999;
}
.ams-gallery__item {
	position: relative;
	display: block;
	flex: 1 1 calc(var(--ams-row) * 1.333);
	height: var(--ams-row);
	overflow: hidden;
	border-radius: var(--ams-radius);
	background: #e9eef2;
	cursor: zoom-in;
}
.ams-gallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	transition: opacity .25s ease;
}
.ams-gallery__item::after {
	content: "";
	position: absolute;
	inset: 0;
	background: var(--ams-accent);
	opacity: 0;
	transition: opacity .25s ease;
}
.ams-gallery__item:hover::after,
.ams-gallery__item:focus-visible::after { opacity: .35; }
.ams-gallery__item:focus-visible { outline: 3px solid var(--ams-accent); outline-offset: 2px; }

@media (max-width: 575.98px) {
	.ams-gallery { --ams-row: 96px; --ams-gap: 4px; }
}

/* ---------------------------------------------------------------------
   Lightbox (opened from .ams-gallery)
   --------------------------------------------------------------------- */
.ams-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(10, 12, 16, .92);
	opacity: 0;
	visibility: hidden;
	transition: opacity .25s ease, visibility 0s linear .25s;
	touch-action: pan-y;
}
.ams-lightbox.is-open {
	opacity: 1;
	visibility: visible;
	transition: opacity .25s ease, visibility 0s;
}
.ams-lightbox__figure {
	margin: 0;
	max-width: calc(100vw - 120px);
	max-height: calc(100vh - 110px);
	display: flex;
	flex-direction: column;
	align-items: center;
}
.ams-lightbox__img {
	display: block;
	max-width: calc(100vw - 120px);
	max-height: calc(100vh - 110px);
	width: auto;
	height: auto;
	object-fit: contain;
	box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
	transition: opacity .2s ease;
}
.ams-lightbox.is-loading .ams-lightbox__img { opacity: .25; }
.ams-lightbox__bar {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 14px;
	color: #fff;
	font-size: 15px;
}
.ams-lightbox__counter { opacity: .85; }
.ams-lightbox__btn {
	border: 0;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	font-size: 26px;
	line-height: 44px;
	text-align: center;
	cursor: pointer;
	padding: 0;
	transition: background-color .2s ease;
}
.ams-lightbox__btn:hover,
.ams-lightbox__btn:focus-visible { background: var(--ams-accent); outline: none; }
.ams-lightbox__nav {
	position: absolute;
	top: 50%;
	margin-top: -24px;
	width: 48px;
	height: 48px;
}
.ams-lightbox__nav--prev { left: 12px; }
.ams-lightbox__nav--next { right: 12px; }
.ams-lightbox__nav::before {
	content: "";
	display: inline-block;
	width: 12px;
	height: 12px;
	border-top: 2px solid currentColor;
	border-right: 2px solid currentColor;
	vertical-align: middle;
}
.ams-lightbox__nav--prev::before { transform: translateX(3px) rotate(-135deg); }
.ams-lightbox__nav--next::before { transform: translateX(-3px) rotate(45deg); }
.ams-lightbox__caption {
	margin-top: 10px;
	color: #ddd;
	font-size: 14px;
	text-align: center;
	max-width: 90vw;
}
.ams-lightbox.is-single .ams-lightbox__nav,
.ams-lightbox.is-single .ams-lightbox__counter { display: none; }
body.ams-lightbox-open { overflow: hidden; }

@media (max-width: 575.98px) {
	.ams-lightbox__figure,
	.ams-lightbox__img { max-width: 100vw; max-height: calc(100vh - 130px); }
	.ams-lightbox__nav { top: auto; bottom: 14px; margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.ams-slide,
	.ams-slide.is-active,
	.ams-lightbox,
	.ams-slider__progress.is-running { transition: none; }
}
