/**
 * CompactGallery front end styles.
 *
 * Everything is scoped under .cg- classes so themes stay untouched.
 */

.cg-gallery-list,
.cg-gallery {
	--cg-cols: 4;
	--cg-cols-tablet: 2;
	--cg-cols-mobile: 1;
	--cg-gap: 20px;
	--cg-radius: 6px;
}

/*
 * --cg-row-gap is intentionally left undefined: every rule falls back to
 * --cg-gap, so setting the row gap is opt in and one value still drives both
 * directions.
 */
.cg-grid {
	display: grid;
	grid-template-columns: repeat(var(--cg-cols), minmax(0, 1fr));
	gap: var(--cg-row-gap, var(--cg-gap)) var(--cg-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Masonry uses CSS columns: no JavaScript layout pass. */
.cg-layout-masonry .cg-grid {
	display: block;
	column-count: var(--cg-cols);
	column-gap: var(--cg-gap);
}

/* CSS columns have no row gap of their own, so the children carry it. */
.cg-layout-masonry .cg-grid > * {
	break-inside: avoid;
	margin-bottom: var(--cg-row-gap, var(--cg-gap));
}

/* Cards ------------------------------------------------------------------- */

.cg-gallery-card {
	margin: 0;
	min-width: 0;
}

.cg-gallery-card-link {
	display: block;
	color: inherit;
	text-decoration: none;
}

.cg-gallery-thumbnail {
	position: relative;
	overflow: hidden;
	border-radius: var(--cg-radius);
	background: rgba(127, 127, 127, 0.12);
	aspect-ratio: 4 / 3;
}

.cg-gallery-thumbnail .cg-gallery-image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.35s ease, opacity 0.35s ease;
}

.cg-gallery-placeholder {
	display: block;
	width: 100%;
	height: 100%;
}

.cg-gallery-content {
	padding: 0.6em 0 0;
}

.cg-gallery-title {
	margin: 0 0 0.15em;
	font-size: 1.05em;
	line-height: 1.3;
}

.cg-gallery-count {
	display: block;
	font-size: 0.85em;
	opacity: 0.72;
}

.cg-gallery-description {
	margin: 0.5em 0 0;
	font-size: 0.9em;
	opacity: 0.85;
}

/* Images ------------------------------------------------------------------ */

.cg-gallery-item {
	position: relative;
	margin: 0;
	min-width: 0;
	overflow: hidden;
	border-radius: var(--cg-radius);
}

.cg-gallery-link {
	display: block;
	position: relative;
	overflow: hidden;
	border-radius: var(--cg-radius);
	background: rgba(127, 127, 127, 0.12);
	aspect-ratio: 4 / 3;
	cursor: zoom-in;
}

.cg-gallery-link .cg-gallery-image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.35s ease, opacity 0.35s ease;
}

.cg-layout-masonry .cg-gallery-link {
	aspect-ratio: auto;
}

.cg-layout-masonry .cg-gallery-link .cg-gallery-image {
	height: auto;
}

.cg-gallery-caption {
	padding: 0.5em 0 0;
	font-size: 0.85em;
	line-height: 1.4;
	opacity: 0.8;
}

/* Hover states ------------------------------------------------------------ */

.cg-hover-zoom:hover .cg-gallery-image {
	transform: scale(1.06);
}

.cg-hover-fade:hover .cg-gallery-image {
	opacity: 0.78;
}

.cg-hover-lift {
	transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cg-hover-lift:hover {
	transform: translateY(-4px);
	box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.cg-gallery-link:focus-visible,
.cg-gallery-card-link:focus-visible,
.cg-load-more:focus-visible {
	outline: 3px solid currentColor;
	outline-offset: 2px;
}

/* Pagination and Load More ------------------------------------------------ */

.cg-load-more-wrap {
	margin: calc(var(--cg-row-gap, var(--cg-gap)) * 1.2) 0 0;
	text-align: center;
}

.cg-load-more {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	padding: 0.7em 1.6em;
	border: 1px solid currentColor;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
	transition: opacity 0.2s ease;
}

.cg-load-more[disabled] {
	cursor: default;
	opacity: 0.55;
}

.cg-load-more-status {
	margin: 0.6em 0 0;
	text-align: center;
	font-size: 0.85em;
	opacity: 0.75;
}

.cg-spinner {
	display: none;
	width: 0.9em;
	height: 0.9em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: cg-spin 0.7s linear infinite;
}

.cg-load-more.is-loading .cg-spinner {
	display: inline-block;
}

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

.cg-pagination {
	margin: calc(var(--cg-row-gap, var(--cg-gap)) * 1.2) 0 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.4em;
	justify-content: center;
}

.cg-pagination .page-numbers {
	display: inline-block;
	padding: 0.35em 0.75em;
	border: 1px solid rgba(127, 127, 127, 0.4);
	border-radius: 4px;
	text-decoration: none;
}

.cg-pagination .page-numbers.current {
	border-color: currentColor;
	font-weight: 600;
}

.cg-empty {
	margin: 1em 0;
	opacity: 0.8;
}

.cg-gallery-heading {
	margin: 0 0 0.6em;
}

.cg-archive-card {
	margin: 0 0 1em;
}

.cg-archive-card-link {
	display: block;
}

.cg-archive-header {
	margin-bottom: 1.5em;
}

/* New items appended through AJAX fade in. */
.cg-gallery-item.is-new,
.cg-gallery-card.is-new {
	animation: cg-fade-in 0.35s ease both;
}

@keyframes cg-fade-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.cg-gallery-image,
	.cg-hover-lift,
	.cg-gallery-item.is-new,
	.cg-gallery-card.is-new {
		transition: none;
		animation: none;
	}

	.cg-hover-zoom:hover .cg-gallery-image,
	.cg-hover-lift:hover {
		transform: none;
	}
}

/* Responsive columns ------------------------------------------------------ */

@media (max-width: 1024px) {
	.cg-grid {
		grid-template-columns: repeat(var(--cg-cols-tablet), minmax(0, 1fr));
	}

	.cg-layout-masonry .cg-grid {
		column-count: var(--cg-cols-tablet);
	}
}

@media (max-width: 600px) {
	.cg-grid {
		grid-template-columns: repeat(var(--cg-cols-mobile), minmax(0, 1fr));
	}

	.cg-layout-masonry .cg-grid {
		column-count: var(--cg-cols-mobile);
	}
}

/* A card that opens the photos in the lightbox instead of a gallery page. */
.cg-gallery-card-popup {
	cursor: zoom-in;
}

.cg-gallery-card-static {
	cursor: default;
}
