/* CLBox Lightbox — front-end styles
 * Configurable values arrive as CSS custom properties on :root (see PHP).
 * Fallbacks below keep things sane if the inline block is ever missing.
 */

:root {
	--clbox-overlay: rgba(0, 0, 0, 0.85);
	--clbox-max-width: 1200px;
	--clbox-padding: 20px;
	--clbox-content-bg: #ffffff;
	--clbox-radius: 8px;
	--clbox-iframe-height: 80vh;
	--clbox-video-aspect: 56.25%;
}

/* Hide the trigger's default nothing — keep cursor a pointer. */
a.clbox,
.clbox a {
	cursor: pointer;
}

/* ---------- Overlay ---------- */
.clbox-overlay {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
	box-sizing: border-box;
	background: var(--clbox-overlay);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.22s ease, visibility 0.22s ease;
	-webkit-tap-highlight-color: transparent;
}

.clbox-overlay.is-open {
	opacity: 1;
	visibility: visible;
}

/* Lock background scroll without layout shift. */
html.clbox-lock,
body.clbox-lock {
	overflow: hidden;
}

/* ---------- Content stage ---------- */
.clbox-stage {
	position: relative;
	width: 100%;
	max-width: var(--clbox-max-width);
	max-height: 92vh;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	transform: scale(0.97);
	transition: transform 0.22s ease;
}

.clbox-overlay.is-open .clbox-stage {
	transform: scale(1);
}

.clbox-content {
	position: relative;
	width: 100%;
	max-height: 92vh;
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	border-radius: var(--clbox-radius);
}

/* Inline page content + images get the configured background + padding. */
.clbox-content.is-page,
.clbox-content.is-image {
	background: var(--clbox-content-bg);
}

.clbox-content.is-page .clbox-page {
	padding: var(--clbox-padding);
	color: #1b1b1b;
	box-sizing: border-box;
}

.clbox-content.is-page .clbox-page img {
	max-width: 100%;
	height: auto;
}

/* Images. */
.clbox-content.is-image {
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.clbox-content.is-image img {
	display: block;
	max-width: 100%;
	max-height: 92vh;
	width: auto;
	height: auto;
}

/* Responsive video — keep the configured aspect ratio. */
.clbox-content.is-video {
	background: transparent;
	border-radius: var(--clbox-radius);
	overflow: hidden;
}

.clbox-ratio {
	position: relative;
	width: 100%;
	padding-bottom: var(--clbox-video-aspect);
	height: 0;
	background: #000;
}

.clbox-ratio iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

/* Full-page iframe (page_mode = iframe, or inline fallback). */
.clbox-content.is-frame {
	background: var(--clbox-content-bg);
}

.clbox-content.is-frame iframe {
	display: block;
	width: 100%;
	height: var(--clbox-iframe-height);
	border: 0;
}

/* ---------- Loading + error ---------- */
.clbox-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	min-height: 180px;
	padding: 40px;
	color: #fff;
}

.clbox-spinner {
	width: 38px;
	height: 38px;
	border: 3px solid rgba(255, 255, 255, 0.25);
	border-top-color: #fff;
	border-radius: 50%;
	animation: clbox-spin 0.8s linear infinite;
}

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

.clbox-error {
	padding: 40px;
	text-align: center;
	color: #fff;
}

.clbox-error a {
	color: #fff;
	text-decoration: underline;
}

/* ---------- Controls ---------- */
.clbox-btn {
	position: absolute;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.55);
	color: #fff;
	cursor: pointer;
	line-height: 1;
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	transition: background 0.15s ease, transform 0.15s ease;
}

.clbox-btn:hover,
.clbox-btn:focus-visible {
	background: rgba(0, 0, 0, 0.8);
	outline: 2px solid rgba(255, 255, 255, 0.7);
	outline-offset: 2px;
}

.clbox-btn svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2.4;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* Close — upper right, sits above the stage. */
.clbox-close {
	top: max(10px, env(safe-area-inset-top));
	right: max(10px, env(safe-area-inset-right));
}

/* Prev / next — vertically centred against the viewport. */
.clbox-prev,
.clbox-next {
	top: 50%;
	transform: translateY(-50%);
}

.clbox-prev { left: max(10px, env(safe-area-inset-left)); }
.clbox-next { right: max(10px, env(safe-area-inset-right)); }

.clbox-prev:hover,
.clbox-next:hover { transform: translateY(-50%) scale(1.06); }

.clbox-btn[hidden] { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
	.clbox-overlay { padding: 0; }

	.clbox-stage {
		max-width: 100%;
		max-height: 100%;
		height: 100%;
		justify-content: center;
	}

	.clbox-content { max-height: 100%; border-radius: 0; }
	.clbox-content.is-image img { max-height: 80vh; }

	/* Move prev/next to the bottom so they don't fight the content. */
	.clbox-prev,
	.clbox-next {
		top: auto;
		bottom: max(14px, env(safe-area-inset-bottom));
		transform: none;
	}
	.clbox-prev:hover,
	.clbox-next:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
	.clbox-overlay,
	.clbox-stage { transition: none; }
	.clbox-spinner { animation: none; }
}

/* ================================================================== *
 * Layout shortcodes (work on the page AND inside the lightbox)
 * Classic 4% gutter system: any valid row of fractions sums to 100%.
 * ================================================================== */
.clbox-col {
	float: left;
	margin-right: 4%;
	margin-bottom: 1.2em;
	box-sizing: border-box;
}

.clbox-col.clbox-last { margin-right: 0; }

.clbox-one-half     { width: 48%; }
.clbox-one-third    { width: 30.66%; }
.clbox-two-third    { width: 65.33%; }
.clbox-one-fourth   { width: 22%; }
.clbox-three-fourth { width: 74%; }
.clbox-one-fifth    { width: 16.8%; }
.clbox-two-fifth    { width: 37.6%; }
.clbox-three-fifth  { width: 58.4%; }
.clbox-four-fifth   { width: 79.2%; }
.clbox-one-sixth    { width: 13.33%; }
.clbox-five-sixth   { width: 82.66%; }

.clbox-clear { clear: both; }

/* Colour boxes. Text colour is set at runtime for contrast (see JS). */
.clbox-bg {
	padding: var(--clbox-bg-padding, 20px);
	border-radius: var(--clbox-radius, 8px);
}

.clbox-bg > :first-child { margin-top: 0; }
.clbox-bg > :last-child { margin-bottom: 0; }

/* Stack columns on phones/tablets. */
@media (max-width: 781px) {
	.clbox-col {
		float: none;
		width: 100% !important;
		margin-right: 0;
	}
}
