/**
 * Shared Image Lightbox Styles
 *
 * Styles for the reusable lightbox component.
 * Any element with [data-lightbox-src] will automatically gain lightbox functionality.
 *
 * Usage:
 * - Add data-lightbox-src="full-image-url.jpg" to any clickable element
 * - Optionally add data-lightbox-caption="Caption text"
 * - Optionally add data-lightbox-group="gallery-name" for gallery navigation
 *
 * @package TMW_Core_Child
 * @since 1.3.0
 * @version 1.4.0
 */

/* ==========================================================================
   Lightbox Trigger Styles
   Applied to any element with [data-lightbox-src]
   ========================================================================== */

[data-lightbox-src] {
	cursor: zoom-in;
}

[data-lightbox-src]:focus {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
}

[data-lightbox-src]:focus:not(:focus-visible) {
	outline: none;
}

/* ==========================================================================
   Lightbox Modal Overlay
   ========================================================================== */

.image-lightbox {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: rgb(0 0 0 / 90%);
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--transition-base), visibility var(--transition-base);
}

.image-lightbox.active {
	opacity: 1;
	visibility: visible;
}

.image-lightbox[hidden] {
	display: none;
}

/* ==========================================================================
   Lightbox Content Container
   ========================================================================== */

.image-lightbox__content {
	position: relative;
	max-width: 90vw;
	max-height: 90vh;
	display: flex;
	flex-direction: column;
	align-items: center;
}

/* ==========================================================================
   Close Button
   ========================================================================== */

.image-lightbox__close {
	position: absolute;
	top: -50px;
	right: 0;
	width: 44px;
	height: 44px;
	padding: 0;
	border: none;
	background: transparent;
	color: var(--wp--preset--color--white);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: color var(--transition-fast), transform var(--transition-fast);
}

.image-lightbox__close:hover,
.image-lightbox__close:focus {
	color: var(--color-primary);
	transform: scale(1.1);
}

.image-lightbox__close:focus-visible {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
}

.image-lightbox__close:focus:not(:focus-visible) {
	outline: none;
}

.image-lightbox__close svg {
	width: 32px;
	height: 32px;
}

/* ==========================================================================
   Navigation Buttons (Prev/Next)
   ========================================================================== */

.image-lightbox__nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 48px;
	height: 48px;
	padding: 0;
	border: none;
	background: rgb(0 0 0 / 40%);
	border-radius: var(--radius-full);
	color: var(--wp--preset--color--white);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
	z-index: 1;
}

.image-lightbox__nav[hidden] {
	display: none;
}

.image-lightbox__nav--prev {
	left: var(--space-lg);
}

.image-lightbox__nav--next {
	right: var(--space-lg);
}

.image-lightbox__nav:hover,
.image-lightbox__nav:focus {
	background: rgb(0 0 0 / 60%);
	color: var(--color-primary);
	transform: translateY(-50%) scale(1.1);
}

.image-lightbox__nav:focus-visible {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
}

.image-lightbox__nav:focus:not(:focus-visible) {
	outline: none;
}

.image-lightbox__nav svg {
	width: 28px;
	height: 28px;
}

/* ==========================================================================
   Image Wrapper & Image
   ========================================================================== */

.image-lightbox__image-wrapper {
	display: flex;
	align-items: center;
	justify-content: center;
	max-width: 100%;
	max-height: calc(90vh - 80px);
	position: relative;
}

.image-lightbox__image {
	max-width: 100%;
	max-height: calc(90vh - 80px);
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: var(--radius-button);
	box-shadow: var(--shadow-card);
}

/* Error state */
.image-lightbox__error {
	color: var(--wp--preset--color--white);
	font-size: var(--font-size-lead);
	padding: var(--space-xl);
}

/* ==========================================================================
   Caption
   ========================================================================== */

.image-lightbox__caption {
	margin-top: var(--space-md);
	color: var(--wp--preset--color--white);
	font-size: var(--font-size-lead);
	text-align: center;
	max-width: 600px;
}

.image-lightbox__caption:empty {
	display: none;
}

/* ==========================================================================
   Counter (e.g., "2 of 8")
   ========================================================================== */

.image-lightbox__counter {
	margin-top: var(--space-xs);
	color: rgb(255 255 255 / 60%);
	font-size: var(--font-size-small);
	text-align: center;
	letter-spacing: 0.05em;
}

.image-lightbox__counter[hidden] {
	display: none;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.image-lightbox.loading .image-lightbox__image-wrapper::after {
	content: "";
	position: absolute;
	width: 40px;
	height: 40px;
	border: 3px solid rgb(255 255 255 / 30%);
	border-top-color: var(--wp--preset--color--white);
	border-radius: var(--radius-full);
	animation: lightbox-spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Body Class (prevents scroll when open)
   ========================================================================== */

body.lightbox-open {
	overflow: hidden;
}

/* ==========================================================================
   Responsive - Tablet
   ========================================================================== */


/* ==========================================================================
   Responsive - Mobile
   ========================================================================== */

@media (width <= 768px) {
	.image-lightbox__close {
		top: -45px;
		width: 40px;
		height: 40px;
	}

	.image-lightbox__close svg {
		width: 28px;
		height: 28px;
	}

	.image-lightbox__caption {
		font-size: var(--font-size-body);
		padding: 0 var(--space-md);
	}

	.image-lightbox__nav {
		width: 40px;
		height: 40px;
	}

	.image-lightbox__nav--prev {
		left: var(--space-sm);
	}

	.image-lightbox__nav--next {
		right: var(--space-sm);
	}

	.image-lightbox__nav svg {
		width: 22px;
		height: 22px;
	}
}

/* ==========================================================================
   Reduced Motion Preference
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.image-lightbox,
	.image-lightbox__close,
	.image-lightbox__nav,
	[data-lightbox-src] {
		transition: none;
	}

	.image-lightbox.loading .image-lightbox__image-wrapper::after {
		animation: none;
	}
}
