/**
 * Webnation galerie — styles front.
 * Conventions BEM préfixées. Couleur/radius pilotés par des CSS custom properties.
 */

.wn-gallery {
	--wn-gal-tab-bg: #111111;
	--wn-gal-tab-radius: 16px;
	--wn-gal-gap: 14px;
	--wn-gal-tabs-gap: 2.5rem;
	--wn-gal-cols: 3;

	width: 100%;
	margin: 0 0 1.5rem;
}

/**
 * Empêche le wrapper (ex. widget shortcode Elementor dans un conteneur flex
 * en align-items:center) de se rétrécir à la largeur du contenu pendant le
 * chargement. On force l'étirement pleine largeur dès qu'il contient la galerie.
 */
.elementor-widget-shortcode:has( .wn-gallery ),
.elementor-shortcode:has( .wn-gallery ) {
	width: 100% !important;
	max-width: 100% !important;
	align-self: stretch !important;
	flex-basis: 100% !important;
}

/* Onglets -------------------------------------------------------------- */

.wn-gallery__tabs {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 10px;
	margin: 0 0 var(--wn-gal-tabs-gap);
	padding: 0;
}

.wn-gallery__tab {
	appearance: none;
	border: 0 !important;
	box-shadow: none !important;
	cursor: pointer;
	padding: 0.6em 1.3em;
	font: inherit;
	line-height: 1.2;
	color: #fff;
	background: var(--wn-gal-tab-bg);
	border-radius: var(--wn-gal-tab-radius);
	opacity: 0.55;
	transition: opacity 0.2s ease;
}

.wn-gallery__tab:hover {
	opacity: 0.8;
}

.wn-gallery__tab:focus-visible {
	outline: 2px solid var(--wn-gal-tab-bg);
	outline-offset: 2px;
}

/* Au focus, Elementor écrase la couleur : on force la couleur primaire globale. */
.wn-gallery__tab:focus,
.wn-gallery__tab:focus-visible,
.wn-gallery__tab--active:focus,
.wn-gallery__tab--active:focus-visible {
	background-color: var(--e-global-color-primary) !important;
	color: #fff !important;
}

.wn-gallery__tab--active {
	opacity: 1;
}

/* Panneaux & grille masonry -------------------------------------------- */

.wn-gallery__panel[hidden] {
	display: none;
}

.wn-gallery__grid {
	list-style: none;
	margin: 0;
	padding: 0;
	/* Masonry via colonnes CSS. */
	column-count: var(--wn-gal-cols);
	column-gap: var(--wn-gal-gap);
}

.wn-gallery__item {
	position: relative;
	margin: 0 0 var(--wn-gal-gap);
	padding: 0;
	overflow: hidden;
	border-radius: 10px;
	background: #f0f0f0;
	/* Évite la coupure d'un élément entre deux colonnes. */
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	display: block;
}

.wn-gallery__item--image {
	cursor: zoom-in;
}

/* Effet « en chargement » (shimmer) tant que le média n'est pas peint. */
.wn-gallery__item--loading,
.wn-gallery__skeleton {
	background-image: linear-gradient(
		100deg,
		#ececec 30%,
		#f6f6f6 50%,
		#ececec 70%
	);
	background-size: 200% 100%;
	background-repeat: no-repeat;
	animation: wn-gallery-shimmer 1.3s ease-in-out infinite;
}

/* Placeholders affichés avant l'arrivée des médias (sections / « charger plus »). */
.wn-gallery__skeleton {
	display: block;
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	margin: 0 0 var(--wn-gal-gap);
	border-radius: 10px;
	background-color: #ececec;
}

.wn-gallery__skeleton:nth-child(4n + 1) { height: 200px; }
.wn-gallery__skeleton:nth-child(4n + 2) { height: 260px; }
.wn-gallery__skeleton:nth-child(4n + 3) { height: 180px; }
.wn-gallery__skeleton:nth-child(4n)     { height: 230px; }

@keyframes wn-gallery-shimmer {
	from { background-position: 200% 0; }
	to   { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
	.wn-gallery__item--loading,
	.wn-gallery__skeleton {
		animation: none;
	}
}

.wn-gallery__item:focus-visible {
	outline: 2px solid var(--wn-gal-tab-bg);
	outline-offset: 2px;
}

.wn-gallery__media {
	display: block;
	width: 100%;
	height: auto;
}

.wn-gallery__item--video .wn-gallery__media {
	background: #000;
}

/* Ratio de repli uniquement si la vidéo n'a pas de dimensions connues. */
.wn-gallery__item--video .wn-gallery__media:not([width]) {
	aspect-ratio: 16 / 9;
}

.wn-gallery__media:not([src]) {
	min-height: 120px;
	opacity: 0;
}

.wn-gallery__media[src] {
	opacity: 1;
	transition: opacity 0.3s ease;
}

/* Bouton « agrandir » -------------------------------------------------- */

.wn-gallery__zoom {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 34px !important;
	height: 34px !important;
	min-width: 34px;
	min-height: 34px;
	padding: 0 !important;
	margin: 0;
	line-height: 1 !important;
	box-sizing: border-box;
	border: 0 !important;
	box-shadow: none !important;
	border-radius: 50% !important;
	color: #fff;
	background: transparent !important;
	cursor: pointer;
	opacity: 0;
	transition: opacity 0.2s ease;
}

.wn-gallery__zoom svg {
	display: block;
	width: 20px;
	height: 20px;
	/* Ombre portée pour rester lisible sur fond clair. */
	filter: drop-shadow( 0 1px 2px rgba( 0, 0, 0, 0.6 ) );
}

.wn-gallery__item:hover .wn-gallery__zoom,
.wn-gallery__zoom:focus-visible {
	opacity: 1;
}

.wn-gallery__zoom:hover {
	opacity: 0.85;
}

/* Actions -------------------------------------------------------------- */

.wn-gallery__actions {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 10px;
	margin-top: var(--wn-gal-tabs-gap);
}

.wn-gallery__load-more {
	appearance: none;
	cursor: pointer;
	border: 0 !important;
	box-shadow: none !important;
	padding: 0.6em 1.4em;
	font: inherit;
	color: #fff;
	background: var(--wn-gal-tab-bg);
	border-radius: var(--wn-gal-tab-radius);
}

.wn-gallery__load-more[hidden] {
	display: none;
}

.wn-gallery__load-more[disabled] {
	opacity: 0.5;
	cursor: default;
}

.wn-gallery__load-more:focus-visible {
	outline: 2px solid var(--wn-gal-tab-bg);
	outline-offset: 2px;
}

.wn-gallery__loading {
	width: 18px;
	height: 18px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: wn-gallery-spin 0.7s linear infinite;
}

.wn-gallery__loading[hidden] {
	display: none;
}

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

/* Lightbox ------------------------------------------------------------- */

.wn-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 4vmin;
	background: rgba(0, 0, 0, 0.9);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.25s ease, visibility 0.25s ease;
}

.wn-gallery-lightbox.is-open {
	opacity: 1;
	visibility: visible;
}

.wn-gallery-lightbox__content {
	max-width: 92vw;
	max-height: 92vh;
	display: flex;
	align-items: center;
	justify-content: center;
}

.wn-gallery-lightbox__content img,
.wn-gallery-lightbox__content video {
	max-width: 92vw;
	max-height: 92vh;
	width: auto;
	height: auto;
	display: block;
	border-radius: 6px;
}

.wn-gallery-lightbox__close {
	position: absolute;
	top: 12px;
	right: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px !important;
	height: 56px !important;
	min-width: 0;
	padding: 0 !important;
	margin: 0;
	border: 0 !important;
	border-radius: 0 !important;
	background: transparent !important;
	box-shadow: none !important;
	color: #fff;
	line-height: 1 !important;
	cursor: pointer;
	transition: opacity 0.2s ease;
}

.wn-gallery-lightbox__close svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wn-gallery-lightbox__close:hover {
	opacity: 0.7;
}

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

@media (max-width: 782px) {
	.wn-gallery {
		--wn-gal-cols: 2;
	}
}

@media (max-width: 480px) {
	.wn-gallery {
		--wn-gal-cols: 1;
	}
}

/* Notice (admins uniquement) ------------------------------------------- */

.wn-gallery--notice {
	padding: 12px 16px;
	border: 1px dashed #c00;
	color: #c00;
	border-radius: 6px;
	background: #fff5f5;
}
