/**
 * DICM Image Gallery for Divi 5 — Lightbox styles.
 * Port of the Divi 4 DICM_Lightbox_Helper CSS. Safari desktop tweaks are
 * applied via the .dmg-safari class (added by lightbox.js) instead of PHP UA
 * sniffing.
 */

/* ── BASE MODAL ─────────────────────────────────────────────────────────── */
#dmg-modal {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(255, 255, 255, 0.93);
	z-index: 9999999;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	box-sizing: border-box;
	transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
		visibility 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
	backdrop-filter: blur(2px);
}

#dmg-modal.dmg-safari {
	transition: opacity 0.2s ease, visibility 0.2s ease;
	backdrop-filter: none;
}

#dmg-modal.active {
	display: flex !important;
	opacity: 1 !important;
	visibility: visible !important;
	pointer-events: auto;
	justify-content: center;
	align-items: center;
}

/* ── TOOLBAR ────────────────────────────────────────────────────────────── */
#dmg-modal .dmg-toolbar {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	padding: 15px;
	display: flex;
	justify-content: space-between;
	z-index: 10001;
	box-sizing: border-box;
}

#dmg-modal .dmg-left-controls,
#dmg-modal .dmg-right-controls {
	display: flex;
	align-items: center;
}

#dmg-modal .dmg-right-controls {
	gap: 30px;
}

/* ── CONTROLS (close / download / mode-toggle) ──────────────────────────── */
#dmg-modal .dmg-close,
#dmg-modal .dmg-download,
#dmg-modal .dmg-mode-toggle {
	cursor: pointer;
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 6px;
	padding: 8px;
	transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}

#dmg-modal .dmg-close:hover,
#dmg-modal .dmg-download:hover,
#dmg-modal .dmg-mode-toggle:hover {
	transform: scale(1.1);
	opacity: 0.8;
}

/* Window-mode toolbar button bg */
#dmg-modal.dmg-window-mode .dmg-close,
#dmg-modal.dmg-window-mode .dmg-download,
#dmg-modal.dmg-window-mode .dmg-mode-toggle {
	background: rgba(0, 0, 0, 0.04);
}

#dmg-modal.dmg-window-mode .dmg-close:hover,
#dmg-modal.dmg-window-mode .dmg-download:hover,
#dmg-modal.dmg-window-mode .dmg-mode-toggle:hover {
	background: rgba(0, 0, 0, 0.12);
}

/* Fullscreen-mode toolbar button bg */
#dmg-modal.dmg-fullscreen-mode .dmg-toolbar {
	background: rgba(0, 0, 0, 0.02);
}

#dmg-modal.dmg-fullscreen-mode .dmg-close,
#dmg-modal.dmg-fullscreen-mode .dmg-download,
#dmg-modal.dmg-fullscreen-mode .dmg-mode-toggle {
	background: rgba(255, 255, 255, 0.1);
}

#dmg-modal.dmg-fullscreen-mode .dmg-close:hover,
#dmg-modal.dmg-fullscreen-mode .dmg-download:hover,
#dmg-modal.dmg-fullscreen-mode .dmg-mode-toggle:hover {
	background: rgba(255, 255, 255, 0.2);
	transform: scale(1.05);
}

/* ── NAVIGATION ARROWS ──────────────────────────────────────────────────── */
#dmg-modal .dmg-prev,
#dmg-modal .dmg-next {
	position: absolute;
	z-index: 10001;
	top: 50%;
	transform: translateY(-50%);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.3s ease;
}

#dmg-modal .dmg-prev {
	left: 40px;
}

#dmg-modal .dmg-next {
	right: 40px;
}

#dmg-modal.dmg-window-mode .dmg-prev,
#dmg-modal.dmg-window-mode .dmg-next {
	width: 50px;
	height: 50px;
	background: rgba(0, 0, 0, 0.04);
}

#dmg-modal.dmg-fullscreen-mode .dmg-prev,
#dmg-modal.dmg-fullscreen-mode .dmg-next {
	width: 60px;
	height: 60px;
	background: rgba(255, 255, 255, 0.1);
	backdrop-filter: blur(10px);
}

#dmg-modal.dmg-safari.dmg-fullscreen-mode .dmg-prev,
#dmg-modal.dmg-safari.dmg-fullscreen-mode .dmg-next {
	backdrop-filter: none;
}

#dmg-modal .dmg-prev:hover,
#dmg-modal .dmg-next:hover {
	transform: translateY(-50%) scale(1.1);
	opacity: 0.8;
}

#dmg-modal .dmg-prev:active,
#dmg-modal .dmg-next:active {
	transform: translateY(-50%) scale(0.95) !important;
}

/* ── SVG ICONS ──────────────────────────────────────────────────────────── */
#dmg-modal .dmg-close svg,
#dmg-modal .dmg-prev svg,
#dmg-modal .dmg-next svg,
#dmg-modal .dmg-download svg,
#dmg-modal .dmg-mode-toggle svg {
	color: inherit;
	display: block;
}

#dmg-modal .dmg-close svg *,
#dmg-modal .dmg-prev svg *,
#dmg-modal .dmg-next svg *,
#dmg-modal .dmg-download svg *,
#dmg-modal .dmg-mode-toggle svg * {
	fill: currentColor;
}

/* ── MODAL CONTENT ──────────────────────────────────────────────────────── */
#dmg-modal .dmg-slider-container {
	position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
	overflow: hidden;
}

#dmg-modal .dmg-modal-image {
	display: block;
	transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
	will-change: opacity, transform;
	backface-visibility: hidden;
}

/* ── SLIDE TRANSITION ───────────────────────────────────────────────────── */
/*
 * The outgoing frame is cloned into this layer so the live <img> can resize to
 * the next picture while the old one is still fading. It is absolutely
 * positioned with explicit pixel dimensions set by lightbox.js, which is why
 * it deliberately does NOT inherit .dmg-modal-image's sizing rules.
 * .dmg-slider-container has overflow:hidden, so the drift is cleanly masked.
 */
#dmg-modal .dmg-modal-ghost {
	position: absolute;
	margin: 0;
	padding: 0;
	display: block;
	object-fit: contain;
	pointer-events: none;
	z-index: 2;
	will-change: opacity, transform;
	backface-visibility: hidden;
}

/* Shown only when a slide takes longer than ~180ms to decode, so cached
   images (the normal case, since neighbours are prefetched) never flash it. */
#dmg-modal .dmg-slider-container::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
	z-index: 3;
	transition: opacity 0.2s ease;
}

#dmg-modal .dmg-slider-container.dmg-loading::after {
	opacity: 0.4;
	animation: dmgSpin 0.7s linear infinite;
}

@keyframes dmgSpin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	#dmg-modal .dmg-slider-container.dmg-loading::after {
		animation: none;
	}
}

#dmg-modal.dmg-safari .dmg-modal-image {
	transition: opacity 0.25s ease;
}

/* ── TYPOGRAPHY ─────────────────────────────────────────────────────────── */
#dmg-modal .dmg-lb-title {
	display: block;
	margin: 0 0 1rem;
	font-size: 24px;
	font-weight: 700;
	color: #000000;
}

#dmg-modal .dmg-lb-desctext {
	display: block;
	margin: 0;
	word-wrap: break-word;
	font-size: 16px;
	line-height: 1.6em;
	color: #666666;
}

/* ── FULLSCREEN MODE ────────────────────────────────────────────────────── */
#dmg-modal.dmg-fullscreen-mode .dmg-desc-container {
	display: none !important;
}

#dmg-modal.dmg-fullscreen-mode .dmg-modal-content {
	width: 100vw !important;
	height: 100vh !important;
	max-width: 100vw !important;
	max-height: 100vh !important;
	margin: 0 !important;
	padding: 0 !important;
	display: flex !important;
	flex-direction: column !important;
	justify-content: center !important;
	align-items: center !important;
}

#dmg-modal.dmg-fullscreen-mode .dmg-slider-container {
	width: 100% !important;
	height: 100% !important;
	max-width: 100% !important;
	max-height: 100% !important;
	flex: 1 !important;
}

#dmg-modal.dmg-fullscreen-mode .dmg-modal-image {
	width: 100% !important;
	height: 100% !important;
	object-fit: contain !important;
}

/* ── WINDOW MODE — ONE COLUMN ───────────────────────────────────────────── */
#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-modal-content {
	width: 80%;
	max-width: 900px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	gap: 0.5rem;
}

#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-slider-container {
	width: 100%;
	max-width: 90%;
	height: 90vh;
	flex: none;
}

#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-modal-image {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
}

#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-desc-container.window-text {
	position: relative;
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
	padding: 0 2rem;
}

/* ── WINDOW MODE — TWO COLUMNS (GRID) ───────────────────────────────────── */
#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-content {
	width: 90%;
	max-width: 1400px;
	margin: 0 auto;
	padding: 1rem;
	display: grid;
	grid-template-columns: 1.5fr 0.5fr;
	align-items: center;
	gap: 1.5rem;
	position: relative;
}

#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-slider-container {
	width: 100%;
	overflow: hidden;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
}

#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-image {
	max-width: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
}

#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-image.dmg-portrait {
	max-height: 92vh;
}

#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-image.dmg-landscape {
	max-height: 80vh;
}

#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-desc-container.window-text {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	text-align: left;
	padding: 2rem;
	overflow-y: auto;
	max-height: 80vh;
}

/* ── TWO COLUMNS — ARROWS ON THE IMAGE COLUMN ───────────────────────────── */
/*
 * By default the arrows are pinned to the screen edges, which in the two
 * column layout leaves the "next" arrow floating over the caption. Here they
 * are placed against the left and right edges of the IMAGE column instead.
 *
 * The arrows are siblings of .dmg-modal-content (absolutely positioned against
 * #dmg-modal), so the column geometry has to be recreated with calc. #dmg-modal
 * has no padding, so a percentage means the same thing for the arrows as it
 * does for .dmg-modal-content's own width — the two stay in sync.
 *
 * The variables below MUST mirror the .dmg-modal-content rule above:
 *   width: min(90%, 1400px) · padding: 1rem · gap: 1.5rem · 1.5fr 0.5fr
 * The 0.75 factor is the image column's share: 1.5 / (1.5 + 0.5).
 *
 * Only from 1025px up: below that the layout collapses to a single column and
 * the default screen-edge arrows are the right call again.
 */
@media (min-width: 1025px) {
	#dmg-modal.dmg-window-mode.dmg-layout-two-columns {
		--dmg-2col-width: min(90%, 1400px);
		--dmg-2col-padding: 1rem;
		--dmg-2col-gap: 1.5rem;
		--dmg-2col-image: calc(
			(var(--dmg-2col-width) - 2 * var(--dmg-2col-padding) - var(--dmg-2col-gap)) * 0.75
		);
		--dmg-2col-left: calc((100% - var(--dmg-2col-width)) / 2 + var(--dmg-2col-padding));
		/* How far inside the column edge each arrow sits. */
		--dmg-2col-inset: 10px;
		/* Arrow width (50px in window mode) + inset + breathing room, so the
		   image never slides underneath an arrow. */
		--dmg-2col-clearance: calc(var(--dmg-2col-inset) + 50px + 14px);
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-prev {
		left: calc(var(--dmg-2col-left) + var(--dmg-2col-inset));
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-next {
		right: calc(
			100% - var(--dmg-2col-left) - var(--dmg-2col-image) + var(--dmg-2col-inset)
		);
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-slider-container {
		box-sizing: border-box;
		padding-left: var(--dmg-2col-clearance);
		padding-right: var(--dmg-2col-clearance);
	}
}

/* ── HIDDEN ─────────────────────────────────────────────────────────────── */
.hidden,
#dmg-modal .dmg-desc-container.hidden {
	display: none !important;
}

/* ── OPEN ANIMATION ─────────────────────────────────────────────────────── */
@keyframes dmgFadeInUp {
	from {
		opacity: 0;
		transform: translateY(30px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

#dmg-modal.active .dmg-modal-content {
	animation: dmgFadeInUp 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

#dmg-modal.dmg-safari.active .dmg-modal-content {
	animation: none;
}

/* ── RESPONSIVE ─────────────────────────────────────────────────────────── */
@media (min-width: 1025px) and (max-width: 1400px) {
	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-content {
		grid-template-columns: 1.5fr 0.5fr;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-desc-container.window-text {
		padding: 1.5rem;
	}
}

@media (max-width: 1024px) {
	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-content {
		grid-template-columns: 1fr !important;
		gap: 1rem !important;
		overflow-y: auto !important;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-slider-container {
		width: 100% !important;
		max-height: 50vh;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-image {
		max-height: 50vh;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-desc-container.window-text {
		text-align: center !important;
		align-items: center !important;
		padding: 1rem !important;
		max-height: none;
	}
}

@media (min-width: 600px) and (max-width: 1024px) {
	#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-modal-content {
		width: 90%;
		gap: 1.5rem;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-slider-container {
		height: 60vh;
	}

	#dmg-modal .dmg-prev {
		left: 30px;
	}

	#dmg-modal .dmg-next {
		right: 30px;
	}
}

@media (max-width: 599px) {
	#dmg-modal.dmg-window-mode .dmg-modal-content {
		width: 95%;
		gap: 1rem;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-one-column .dmg-slider-container {
		height: 65vh;
	}

	#dmg-modal.dmg-window-mode.dmg-layout-two-columns .dmg-modal-content {
		grid-template-columns: 1fr !important;
		padding: 0.5rem;
	}

	#dmg-modal .dmg-toolbar {
		padding: 15px;
	}

	#dmg-modal .dmg-right-controls {
		gap: 20px;
	}

	#dmg-modal .dmg-prev,
	#dmg-modal .dmg-next {
		width: 50px !important;
		height: 50px !important;
	}

	#dmg-modal .dmg-prev {
		left: 20px !important;
	}

	#dmg-modal .dmg-next {
		right: 20px !important;
	}

	#dmg-modal .dmg-lb-title {
		font-size: 20px;
	}

	#dmg-modal .dmg-lb-desctext {
		font-size: 14px;
	}
}
