/* ===== tsn-media.css — สไลด์ภาพ และแกลเลอรี่ (คู่กับ js/tsn-media.js) ===== */

/* ---------- สไลด์ ---------- */
.tsn-slider {
	position: relative;
	width: 100%;
	aspect-ratio: var(--tsn-ratio, 16 / 9);
	overflow: hidden;
	background: #e9efe9;
	border-radius: var(--tsn-radius, 0);
}
/* ก่อน JavaScript ทำงาน: ซ่อนภาพไม่ให้กองซ้อนกัน แต่เว้นพื้นที่ไว้ หน้าเว็บจึงไม่กระตุก */
.tsn-slider:not(.is-ready) > * { display: none; }
.tsn-slider-track, .tsn-slide { position: absolute; inset: 0; }
.tsn-slide {
	opacity: 0;
	visibility: hidden;
	transition: opacity .7s ease, visibility 0s linear .7s;
}
.tsn-slide.is-active {
	opacity: 1;
	visibility: visible;
	transition: opacity .7s ease;
	z-index: 1;
}
.tsn-slide > a, .tsn-slide > img, .tsn-slide > a > img { display: block; width: 100%; height: 100%; }
.tsn-slide img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	/* ไม่มีการเลื่อนหรือซูมภาพ */
	transform: none;
}

/* คำบรรยายบนสไลด์ */
.tsn-caption {
	position: absolute;
	left: 0; right: 0; bottom: 0;
	padding: 18px 90px 22px 20px;
	color: #fff;
	background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,.45) 70%, rgba(0,0,0,0));
	pointer-events: none;
	z-index: 2;
}
.tsn-caption-title { display: block; font-size: 1.45rem; line-height: 1.3; }
.tsn-caption-date  { display: block; margin-top: 4px; font-size: .95rem; opacity: .9; }
.tsn-slide > a.tsn-slide-link { position: absolute; inset: 0; z-index: 3; }

/* ปุ่มก่อนหน้า/ถัดไป */
.tsn-slider-btn {
	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: 30px;
	line-height: 1;
	cursor: pointer;
	opacity: 0;
	transition: opacity .2s ease, background-color .2s ease;
}
.tsn-slider-prev { left: 12px; }
.tsn-slider-next { right: 12px; }
.tsn-slider:hover .tsn-slider-btn, .tsn-slider-btn:focus-visible { opacity: 1; }
.tsn-slider-btn:hover { background: rgba(7,101,56,.85); }
.tsn-slider-btn:focus-visible, .tsn-slider-dot:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
@media (hover: none) { .tsn-slider-btn { opacity: .85; } }

/* จุดบอกตำแหน่ง */
.tsn-slider-dots {
	position: absolute;
	right: 14px; bottom: 12px;
	z-index: 4;
	display: flex;
	gap: 6px;
}
.tsn-slider-dot {
	width: 10px; height: 10px;
	padding: 0;
	border: 2px solid #fff;
	border-radius: 50%;
	background: transparent;
	cursor: pointer;
	box-shadow: 0 0 2px rgba(0,0,0,.4);
}
.tsn-slider-dot.is-active { background: #00914d; border-color: #00914d; }

/* แบนเนอร์ด้านบนของหน้า (เดิม Unite Gallery กว้าง 1450 สูง 300) */
.tsn-slider--banner { --tsn-ratio: 1450 / 300; min-height: 120px; }
.tsn-slider--banner .tsn-slider-dots { left: 0; right: 0; justify-content: center; }
/* สไลด์ข่าวล่าสุดในหน้าแรก (เดิม LayerSlider 1000×680) */
.tsn-slider--hero { --tsn-ratio: 1000 / 680; --tsn-radius: 4px; }

@media (max-width: 575.98px) {
	.tsn-caption { padding: 12px 14px 30px; }
	.tsn-caption-title { font-size: 1.05rem; }
	.tsn-caption-date { font-size: .8rem; }
	.tsn-slider-btn { width: 36px; height: 36px; margin-top: -18px; font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
	.tsn-slide, .tsn-slide.is-active { transition: none; }
}

/* ---------- แกลเลอรี่ ---------- */
.tsn-gallery {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr)); /* 4 คอลัมน์ทุกขนาดจอ */
	gap: 10px;
	margin: 0 auto;
}
.tsn-gallery > img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; } /* ก่อน JS ทำงาน / ปิด JS */
.tsn-gallery-item {
	position: relative;
	display: block;
	padding: 0;
	border: 0;
	border-radius: 8px;
	overflow: hidden;
	aspect-ratio: 1;
	background: #e9efe9;
	cursor: zoom-in;
}
/* selector สองชั้นให้น้ำหนักมากกว่า .news-content img ที่ประกาศทีหลังในหน้า */
.tsn-gallery .tsn-gallery-item img {
	/* !important: กันกฎรูปของหน้าข่าว (.news-content img { height:auto !important; max-width:640px; margin... }) ทำให้ไม่เป็นสี่เหลี่ยมจัตุรัส */
	position: absolute;
	inset: 0;
	display: block !important;
	width: 100% !important;
	height: 100% !important; /* วางเต็มกรอบ — height:100% เฉยๆ คำนวณไม่ได้ในปุ่มที่สูงตาม aspect-ratio */
	max-width: none !important;
	margin: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	object-fit: cover;
	transition: opacity .2s ease;
}
.tsn-gallery-item::after {
	content: "";
	position: absolute; inset: 0;
	background: rgba(0,0,0,0);
	transition: background-color .2s ease;
}
.tsn-gallery-item:hover::after { background: rgba(0,0,0,.25); }
.tsn-gallery-item:focus-visible { outline: 3px solid #076538; outline-offset: 2px; }
@media (max-width: 575.98px) { .tsn-gallery { gap: 4px; } .tsn-gallery-item { border-radius: 5px; } }

/* ---------- lightbox ---------- */
html.tsn-lb-open { overflow: hidden; }
.tsn-lightbox {
	position: fixed; inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0,0,0,.9);
}
.tsn-lightbox[hidden] { display: none; }
.tsn-lb-figure { margin: 0; max-width: calc(100vw - 140px); max-height: calc(100vh - 80px); text-align: center; }
.tsn-lb-img {
	display: block;
	max-width: calc(100vw - 140px);
	max-height: calc(100vh - 90px);
	margin: 0 auto;
	object-fit: contain;
	border-radius: 4px;
	box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.tsn-lb-count { margin-top: 10px; color: #ddd; font-size: 14px; }
.tsn-lb-close, .tsn-lb-prev, .tsn-lb-next {
	position: absolute;
	border: 0;
	border-radius: 50%;
	background: rgba(255,255,255,.12);
	color: #fff;
	cursor: pointer;
	line-height: 1;
}
.tsn-lb-close { top: 14px; right: 16px; width: 44px; height: 44px; font-size: 32px; }
.tsn-lb-prev, .tsn-lb-next { top: 50%; width: 52px; height: 52px; margin-top: -26px; font-size: 38px; }
.tsn-lb-prev { left: 14px; }
.tsn-lb-next { right: 14px; }
.tsn-lb-close:hover, .tsn-lb-prev:hover, .tsn-lb-next:hover { background: rgba(7,101,56,.9); }
.tsn-lb-close:focus-visible, .tsn-lb-prev:focus-visible, .tsn-lb-next:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.tsn-lightbox.is-single .tsn-lb-prev, .tsn-lightbox.is-single .tsn-lb-next { display: none; }
@media (max-width: 575.98px) {
	.tsn-lb-figure, .tsn-lb-img { max-width: 100vw; }
	.tsn-lb-img { border-radius: 0; }
	.tsn-lb-prev, .tsn-lb-next { top: auto; bottom: 18px; margin-top: 0; }
}
