/* Category Gallery Manager — front end */
.cgm-gallery {
	--c: var(--cgm-cols-d, 3);
	--cgm-radius: 4px;
	--cgm-accent: #1d1d1f;
	position: relative;
	margin: 1.5em 0;
	box-sizing: border-box;
}
.cgm-gallery *,
.cgm-gallery *::before,
.cgm-gallery *::after { box-sizing: border-box; }

@media (max-width: 1024px) { .cgm-gallery { --c: var(--cgm-cols-t, 2); } }
@media (max-width: 600px)  { .cgm-gallery { --c: var(--cgm-cols-m, 1); } }

.cgm-item { margin: 0; padding: 0; position: relative; }
.cgm-link { display: block; color: inherit; text-decoration: none; }
a.cgm-link { cursor: zoom-in; }
.cgm-media { display: block; overflow: hidden; border-radius: var(--cgm-radius); background: #eee; }
.cgm-img { display: block; width: 100%; height: auto; margin: 0; transition: transform .4s ease; }
a.cgm-link:hover .cgm-img { transform: scale(1.04); }

/* Fixed image shape */
.cgm-has-ratio .cgm-media { aspect-ratio: var(--cgm-ratio, 4/3); }
.cgm-has-ratio .cgm-img { height: 100%; object-fit: cover; }

/* Caption always sits inside the image, on all display types */
.cgm-caption {
	position: absolute; left: 0; right: 0; bottom: 0;
	padding: 2.2em .9em .8em;
	color: #fff;
	background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,0));
	border-radius: 0 0 var(--cgm-radius) var(--cgm-radius);
	pointer-events: none;
	line-height: 1.35;
	z-index: 1;
}
.cgm-title { display: block; font-weight: 600; font-size: 12px; }
.cgm-desc { display: block; font-size: 10px; opacity: .9; margin-top: .15em; }

/* Image columns */
.cgm-type-columns .cgm-items {
	display: grid;
	grid-template-columns: repeat(var(--c), minmax(0, 1fr));
	gap: var(--cgm-gap, 15px);
}

/* Masonry — items are absolutely positioned by JS into the shortest column,
   so tiles pack tightly with no leftover gaps at the end of a column. */
.cgm-type-masonry .cgm-items {
	position: relative;
}
.cgm-type-masonry .cgm-item {
	position: absolute;
	top: 0;
	left: 0;
	margin: 0;
}
/* Hide items until JS has positioned them, to avoid a flash of stacked tiles */
.cgm-type-masonry .cgm-items:not(.cgm-packed) .cgm-item { visibility: hidden; }

/* Carousel */
.cgm-carousel { position: relative; }
.cgm-track {
	display: flex;
	gap: var(--cgm-gap, 15px);
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
	outline: none;
}
.cgm-track::-webkit-scrollbar { display: none; }
.cgm-type-carousel .cgm-item {
	flex: 0 0 calc((100% - (var(--c) - 1) * var(--cgm-gap, 15px)) / var(--c));
	scroll-snap-align: start;
}
.cgm-nav {
	position: absolute; top: 50%; z-index: 2;
	transform: translateY(-50%);
	width: 42px; height: 42px; padding: 0;
	border: 0; border-radius: 50%;
	background: rgba(255,255,255,.92);
	color: var(--cgm-accent);
	box-shadow: 0 1px 6px rgba(0,0,0,.25);
	font-size: 28px; line-height: 1; cursor: pointer;
	display: flex; align-items: center; justify-content: center;
	transition: background .2s ease, transform .2s ease;
}
.cgm-nav:hover { background: #fff; transform: translateY(-50%) scale(1.06); }
.cgm-nav:focus-visible { outline: 2px solid var(--cgm-accent); outline-offset: 2px; }
.cgm-prev { left: 10px; }
.cgm-next { right: 10px; }
.cgm-dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.cgm-dot {
	width: 9px; height: 9px; padding: 0; border: 0; border-radius: 50%;
	background: currentColor; opacity: .25; cursor: pointer;
	transition: opacity .2s ease, transform .2s ease;
}
.cgm-dot.is-active { opacity: .85; transform: scale(1.25); }
.cgm-dot:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.cgm-empty { padding: 1em; background: #fff8e5; border-left: 4px solid #dba617; }

/* Lightbox */
.cgm-lb {
	position: fixed; inset: 0; z-index: 999999;
	display: none; align-items: center; justify-content: center;
	background: rgba(10,10,10,.92);
	padding: 24px;
}
.cgm-lb.is-open { display: flex; }
.cgm-lb-inner { max-width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; }
.cgm-lb-img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 3px; }
.cgm-lb-cap { color: #fff; text-align: center; margin-top: 14px; max-width: 720px; line-height: 1.45; }
.cgm-lb-cap strong { display: block; font-size: 1.1em; }
.cgm-lb-cap span { display: block; opacity: .8; font-size: .92em; margin-top: 3px; }
.cgm-lb button {
	position: absolute; border: 0; background: rgba(255,255,255,.14); color: #fff;
	width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 26px; line-height: 1;
	display: flex; align-items: center; justify-content: center; padding: 0;
}
.cgm-lb button:hover { background: rgba(255,255,255,.28); }
.cgm-lb button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.cgm-lb-close { top: 16px; right: 16px; }
.cgm-lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.cgm-lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
body.cgm-lb-lock { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
	.cgm-img, .cgm-nav, .cgm-dot, .cgm-caption { transition: none; }
	.cgm-track { scroll-behavior: auto; }
}
