/**
 * WP Gallery Lightbox — stili frontend
 * Pulsanti toggle (stile minimal/ghost) + layout gallerie + lightbox.
 * Le classi (image-gallery, igt-*, wlb-*) sono mantenute per retrocompatibilità.
 * Il colore accent è guidato dalla variabile --wpgl-accent (definita inline dalle opzioni).
 */

/* ==========================================================================
   Toggle Buttons — Minimal / Ghost con underline animato
   ========================================================================== */

.image-gallery-toggle-buttons {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: clamp(16px, 4vw, 36px);
	margin: 0 0 32px;
	padding: 8px 0;
	flex-wrap: wrap;
}

.igt-btn {
	--igt-underline: 0;
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 8px 2px;
	background: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	line-height: 1.2;
	color: currentColor;
	opacity: 0.5;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: opacity 0.2s ease, color 0.2s ease;
}

/* Underline animato (accent) */
.igt-btn::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: -4px;
	height: 2px;
	background: var(--wpgl-accent, #fcc203);
	transform: scaleX(var(--igt-underline));
	transform-origin: center;
	transition: transform 0.25s ease;
	pointer-events: none;
}

.igt-btn:hover {
	opacity: 0.85;
	--igt-underline: 0.45;
}

.igt-btn.active {
	opacity: 1;
	font-weight: 700;
	cursor: default;
	--igt-underline: 1;
}

/* Focus accessibile da tastiera */
.igt-btn:focus-visible {
	outline: 2px solid var(--wpgl-accent, #fcc203);
	outline-offset: 4px;
	opacity: 0.95;
}

.igt-icon {
	font-size: 1em;
	line-height: 1;
}

/* ==========================================================================
   Gallery Container
   ========================================================================== */

.image-gallery {
	text-align: center;
	transition: opacity 0.3s ease;
}

.image-gallery img {
	display: inline-block;
	border-radius: 4px;
}

/* --- Modalità Thumbnails --- */
.image-gallery.igt-mode-thumbs {
	display: flex !important;
	flex-direction: row !important;
	flex-wrap: wrap !important;
	justify-content: center !important;
	align-items: flex-start !important;
	gap: 12px !important;
	text-align: center !important;
}

.image-gallery.igt-mode-thumbs a,
.image-gallery.igt-mode-thumbs a.lightbox,
.image-gallery.igt-mode-thumbs > img {
	width: calc((100% - 60px) / 5) !important;
	max-width: none !important;
	height: auto !important;
	flex: 0 0 auto !important;
	margin: 0 !important;
	padding: 0 !important;
	display: block !important;
}

.image-gallery.igt-mode-thumbs a,
.image-gallery.igt-mode-thumbs a.lightbox {
	position: relative !important;
	cursor: pointer !important;
}

.image-gallery.igt-mode-thumbs img {
	width: 100% !important;
	height: auto !important;
	max-width: 100% !important;
	object-fit: cover !important;
	cursor: pointer !important;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
	border-radius: 8px !important;
	display: block !important;
	user-select: none !important;
	-webkit-user-select: none !important;
	pointer-events: auto !important;
	touch-action: manipulation !important;
}

/* --- Modalità Full Images --- */
.image-gallery.igt-mode-full {
	display: flex !important;
	flex-direction: column !important;
	flex-wrap: nowrap !important;
	align-items: center !important;
	text-align: center !important;
	gap: 8px !important;
}

.image-gallery.igt-mode-full a,
.image-gallery.igt-mode-full a.lightbox {
	width: 100% !important;
	max-width: 100% !important;
	display: block !important;
	margin: 0 !important;
	flex: none !important;
}

.image-gallery.igt-mode-full img,
.image-gallery.igt-mode-full > img {
	width: 100% !important;
	max-width: 100% !important;
	height: auto !important;
	display: block !important;
	margin: 0 auto !important;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
	cursor: pointer !important;
	user-select: none !important;
	-webkit-user-select: none !important;
	pointer-events: auto !important;
	touch-action: manipulation !important;
}

@media (min-width: 600px) {
	.image-gallery.igt-mode-full a,
	.image-gallery.igt-mode-full a.lightbox,
	.image-gallery.igt-mode-full > img {
		width: 95% !important;
		max-width: 95% !important;
	}
}

@media (min-width: 768px) {
	.image-gallery.igt-mode-full a,
	.image-gallery.igt-mode-full a.lightbox,
	.image-gallery.igt-mode-full > img {
		width: 90% !important;
		max-width: 90% !important;
	}
}

@media (min-width: 1024px) {
	.image-gallery.igt-mode-full a,
	.image-gallery.igt-mode-full a.lightbox,
	.image-gallery.igt-mode-full > img {
		width: 85% !important;
		max-width: 85% !important;
	}
}

@media (min-width: 1440px) {
	.image-gallery.igt-mode-full a,
	.image-gallery.igt-mode-full a.lightbox,
	.image-gallery.igt-mode-full > img {
		width: 80% !important;
		max-width: 900px !important;
	}
}

/* --- Responsive Thumbnails --- */
@media (max-width: 1024px) and (min-width: 769px) {
	.image-gallery.igt-mode-thumbs a,
	.image-gallery.igt-mode-thumbs a.lightbox,
	.image-gallery.igt-mode-thumbs > img {
		width: calc((100% - 30px) / 4) !important;
	}
	.image-gallery.igt-mode-thumbs {
		gap: 10px !important;
	}
}

@media (max-width: 768px) and (min-width: 481px) {
	.image-gallery.igt-mode-thumbs a,
	.image-gallery.igt-mode-thumbs a.lightbox,
	.image-gallery.igt-mode-thumbs > img {
		width: calc((100% - 16px) / 3) !important;
	}
	.image-gallery.igt-mode-thumbs {
		gap: 8px !important;
	}
}

@media (max-width: 480px) {
	.image-gallery.igt-mode-thumbs a,
	.image-gallery.igt-mode-thumbs a.lightbox,
	.image-gallery.igt-mode-thumbs > img {
		width: calc((100% - 8px) / 3) !important;
		max-width: calc((100% - 8px) / 3) !important;
		flex: 0 0 calc((100% - 8px) / 3) !important;
	}
	.image-gallery.igt-mode-thumbs {
		gap: 4px !important;
	}
	.image-gallery-toggle-buttons {
		margin-bottom: 20px;
	}
	.image-gallery.igt-mode-thumbs img {
		border-radius: 4px !important;
	}
}

/* --- Placeholder caricamento --- */
.image-gallery img:not(.igt-img-loaded) {
	background-color: #f0f0f0;
	min-height: 100px;
}

.image-gallery img.igt-img-loaded {
	background-color: transparent;
	min-height: 0;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */

.wlb-lightbox {
	display: none;
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.95);
	z-index: 999999;
	touch-action: none;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
}

.wlb-lightbox.active {
	display: flex;
	align-items: center;
	justify-content: center;
}

.wlb-container {
	position: relative;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.wlb-image-wrapper {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.wlb-image {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	user-select: none;
	-webkit-user-drag: none;
	opacity: 0;
	transition: opacity 0.3s, transform 0.2s ease-out;
	transform-origin: center;
}

.wlb-image.loaded {
	opacity: 1;
}

.wlb-loading {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 40px;
	height: 40px;
	margin: -20px 0 0 -20px;
	border: 3px solid rgba(255, 255, 255, 0.3);
	border-top-color: #fff;
	border-radius: 50%;
	animation: wlb-spin 0.8s linear infinite;
	display: none;
	pointer-events: none;
}

.wlb-loading.active {
	display: block;
}

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

.wlb-close,
.wlb-prev,
.wlb-next {
	position: absolute;
	background: rgba(255, 255, 255, 0.1);
	border: none;
	color: #fff;
	font-size: 36px;
	width: 50px;
	height: 50px;
	opacity: 0.7;
	transition: opacity 0.2s, background 0.2s;
	-webkit-tap-highlight-color: transparent;
	border-radius: 50%;
	line-height: 1;
	padding: 0;
	z-index: 10;
	backdrop-filter: blur(10px);
	cursor: pointer;
}

.wlb-close:hover,
.wlb-prev:hover,
.wlb-next:hover,
.wlb-close:active,
.wlb-prev:active,
.wlb-next:active {
	opacity: 1;
	background: rgba(255, 255, 255, 0.2);
}

.wlb-close:focus-visible,
.wlb-prev:focus-visible,
.wlb-next:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
	opacity: 1;
}

.wlb-close {
	top: 15px;
	right: 15px;
}

.wlb-prev {
	left: 15px;
	top: 50%;
	margin-top: -25px;
}

.wlb-next {
	right: 15px;
	top: 50%;
	margin-top: -25px;
}

.wlb-prev:disabled,
.wlb-next:disabled {
	opacity: 0.3;
	cursor: not-allowed;
}

.wlb-counter {
	position: absolute;
	bottom: 20px;
	left: 50%;
	transform: translateX(-50%);
	color: #fff;
	font-size: 14px;
	background: rgba(0, 0, 0, 0.5);
	padding: 6px 14px;
	border-radius: 20px;
	pointer-events: none;
	z-index: 10;
	backdrop-filter: blur(10px);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (min-width: 768px) {
	.wlb-close,
	.wlb-prev,
	.wlb-next {
		width: 60px;
		height: 60px;
		font-size: 42px;
	}
	.wlb-prev {
		left: 25px;
	}
	.wlb-next {
		right: 25px;
	}
	.wlb-counter {
		font-size: 16px;
	}
}

/* ==========================================================================
   Accessibilità / preferenze utente
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.igt-btn,
	.igt-btn::after,
	.image-gallery,
	.wlb-image,
	.wlb-loading {
		transition: none !important;
		animation: none !important;
	}
}

@media (prefers-contrast: high) {
	.igt-btn {
		opacity: 1;
	}
	.igt-btn::after {
		height: 3px;
	}
	.wlb-lightbox {
		background: rgba(0, 0, 0, 0.98);
	}
	.wlb-close,
	.wlb-prev,
	.wlb-next {
		background: rgba(255, 255, 255, 0.2);
		border: 1px solid rgba(255, 255, 255, 0.5);
	}
}

@media (prefers-color-scheme: dark) {
	.image-gallery img {
		box-shadow: 0 2px 8px rgba(255, 255, 255, 0.08);
	}
}

@media print {
	.image-gallery-toggle-buttons,
	.wlb-lightbox {
		display: none !important;
	}
	.image-gallery {
		display: block !important;
	}
	.image-gallery img {
		width: 100% !important;
		max-width: 100% !important;
		page-break-inside: avoid;
	}
}
