/* ============================================================
   gallery.css
   ------------------------------------------------------------
   แกลเลอรี่รูปภาพ + กล่องดูรูปใหญ่ (lightbox)
   เขียนขึ้นเองเพื่อแทน unitegallery

   ทำไมต้องเขียนเอง
   - unitegallery ต้องโหลด jQuery 1.11 เพิ่มอีกตัว (ของเก่า มีช่องโหว่ XSS)
     รวมไฟล์ที่ต้องโหลดกว่า 300 KB เพื่อแค่โชว์รูป
   - ของใหม่ใช้ CSS Grid + JavaScript ธรรมดา ไม่พึ่ง jQuery
     ขนาดรวมไม่ถึง 10 KB และทำงานบนมือถือลื่นกว่า
   ============================================================ */

/* ---------- ตารางรูป ---------- */
.cg-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	gap: 10px;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* แถวสูงขึ้นสำหรับแกลเลอรี่ที่ตั้ง data-row-height ไว้มาก */
.cg-grid[data-size="large"] {
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.cg-item {
	position: relative;
	display: block;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border-radius: 10px;
	background: #f2f2f2;
	cursor: zoom-in;
	border: 0;
	/* สัดส่วนคงที่ กันหน้าเว็บกระตุกตอนรูปโหลด (ช่วยคะแนน CLS ของ Google) */
	aspect-ratio: 4 / 3;
	box-shadow: 0 2px 8px rgba(0,0,0,.08);
	transition: box-shadow .25s ease, transform .25s ease;
}

.cg-item:hover,
.cg-item:focus-visible {
	box-shadow: 0 8px 22px rgba(0,0,0,.22);
	transform: translateY(-3px);
	outline: none;
}

.cg-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	/* ไม่มีการซูมภาพตามที่ต้องการ — แค่หน้ากากสีจาง ๆ ตอนชี้ */
}

/* ฝ้าสีเหลืองจาง ๆ ตอนเอาเมาส์ชี้ (โทนเดียวกับเว็บ) */
.cg-item::after {
	content: "";
	position: absolute;
	inset: 0;
	background: #FCDF15;
	opacity: 0;
	transition: opacity .25s ease;
	pointer-events: none;
}

.cg-item:hover::after,
.cg-item:focus-visible::after { opacity: .28; }

/* ไอคอนแว่นขยายมุมขวาล่าง */
.cg-item__icon {
	position: absolute;
	right: 8px;
	bottom: 8px;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(0,0,0,.55);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	opacity: 0;
	transform: translateY(6px);
	transition: all .25s ease;
	pointer-events: none;
	z-index: 2;
}

.cg-item:hover .cg-item__icon,
.cg-item:focus-visible .cg-item__icon { opacity: 1; transform: translateY(0); }

/* ---------- กล่องดูรูปใหญ่ (lightbox) ---------- */
.cg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	background: rgba(12,12,12,.94);
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	visibility: hidden;
	transition: opacity .25s ease, visibility .25s ease;
	/* ไม่ให้ซูม/ลากภาพ ตามที่ต้องการ */
	touch-action: pan-y;
}

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

.cg-lightbox__stage {
	position: relative;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 56px 16px 72px;
	box-sizing: border-box;
}

.cg-lightbox__img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 6px;
	box-shadow: 0 10px 40px rgba(0,0,0,.6);
	/* ขนาดคงที่ ไม่ซูม ไม่ pan */
	user-select: none;
	-webkit-user-drag: none;
}

.cg-lightbox__img.is-loading { opacity: .25; }

/* ปุ่มต่าง ๆ */
.cg-btn {
	position: absolute;
	border: 0;
	background: rgba(255,255,255,.12);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	backdrop-filter: blur(6px);
	transition: background .2s ease, transform .2s ease;
	z-index: 3;
}

.cg-btn:hover  { background: #FCDF15; color: #202020; }
.cg-btn:active { transform: scale(.93); }
.cg-btn:focus-visible { outline: 3px solid #FCDF15; outline-offset: 3px; }

.cg-btn--close { top: 14px; right: 14px; width: 46px; height: 46px; font-size: 20px; }
.cg-btn--prev  { left: 14px;  top: 50%; margin-top: -26px; width: 52px; height: 52px; font-size: 20px; }
.cg-btn--next  { right: 14px; top: 50%; margin-top: -26px; width: 52px; height: 52px; font-size: 20px; }

/* คำบรรยาย + ตัวนับรูป */
.cg-lightbox__bar {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 12px 70px 16px;
	text-align: center;
	color: #fff;
	font-size: 14px;
	line-height: 1.5;
	background: linear-gradient(to top, rgba(0,0,0,.75), transparent);
	pointer-events: none;
	z-index: 2;
}

.cg-lightbox__count {
	display: inline-block;
	margin-top: 4px;
	font-size: 12px;
	color: #FCDF15;
	letter-spacing: .5px;
}

/* ---------- มือถือ ---------- */
@media (max-width: 575px) {
	.cg-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 7px; }
	.cg-grid[data-size="large"] { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
	.cg-lightbox__stage { padding: 52px 8px 84px; }
	.cg-btn--prev { left: 8px;  width: 44px; height: 44px; }
	.cg-btn--next { right: 8px; width: 44px; height: 44px; }
	.cg-lightbox__bar { padding: 10px 14px 14px; font-size: 13px; }
}

/* ---------- เคารพการตั้งค่า "ลดการเคลื่อนไหว" ของเครื่องผู้ใช้ ---------- */
@media (prefers-reduced-motion: reduce) {
	.cg-item, .cg-item::after, .cg-item__icon, .cg-lightbox, .cg-btn {
		transition: none !important;
	}
	.cg-item:hover { transform: none; }
}
