/*
 * Animations : apparition au défilement, ouverture des menus, accordéons, fenêtres, « Découvrir ».
 * Toutes neutralisées si l'utilisateur a demandé à réduire les animations.
 */

/* Apparition au défilement (classe posée par main.js, seulement sous la ligne de flottaison). */
.chn-reveal {
	opacity: 0;
	transform: translateY(24px);
	transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
	transition-delay: var(--chn-reveal-delay, 0ms);
}

.chn-reveal.is-revealed {
	opacity: 1;
	transform: none;
}

/* Titre de l'accueil */
@keyframes chn-rise {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
}

@keyframes chn-fade {
	from {
		opacity: 0;
	}
}

.chn-hero__word {
	animation: chn-rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.chn-hero .chn-hero__title {
	animation: chn-fade 0.9s 0.25s ease both;
}

.chn-profiles {
	animation: chn-rise 0.8s 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

/* Changement de profil « Je suis » */
.chn-bento:not([hidden]) > * {
	animation: chn-rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.chn-bento > :nth-child(2) { animation-delay: 30ms; }
.chn-bento > :nth-child(3) { animation-delay: 60ms; }
.chn-bento > :nth-child(4) { animation-delay: 90ms; }
.chn-bento > :nth-child(5) { animation-delay: 120ms; }
.chn-bento > :nth-child(6) { animation-delay: 150ms; }
.chn-bento > :nth-child(7) { animation-delay: 180ms; }
.chn-bento > :nth-child(8) { animation-delay: 210ms; }
.chn-bento > :nth-child(9) { animation-delay: 240ms; }
.chn-bento > :nth-child(n+10) { animation-delay: 270ms; }

/* « Découvrir » : la flèche descend en boucle */
@keyframes chn-scroll-hint {
	0%, 100% {
		transform: translateY(0);
	}
	50% {
		transform: translateY(8px);
	}
}

.chn-scroll a::before {
	animation: chn-scroll-hint 2s ease-in-out infinite;
}

/* Méga-menu et menu mobile */
@keyframes chn-drop {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
}

@keyframes chn-slide-in {
	from {
		opacity: 0;
		transform: translateX(24px);
	}
}

.chn-panel:not([hidden]) {
	animation: chn-drop 0.25s ease both;
}

.chn-drawer:not([hidden]) {
	animation: chn-fade 0.2s ease both;
}

.chn-drawer__level:not([hidden]) {
	animation: chn-slide-in 0.3s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

/* Fenêtres (recherche, candidature) */
dialog[open].chn-search,
dialog[open].chn-modal {
	animation: chn-rise 0.3s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

dialog[open].chn-search::backdrop,
dialog[open].chn-modal::backdrop {
	animation: chn-fade 0.3s ease both;
}

/* Accordéons : ouverture progressive */
:root {
	interpolate-size: allow-keywords;
}

.wp-block-details::details-content {
	block-size: 0;
	overflow: clip;
	transition: block-size 0.35s ease, content-visibility 0.35s allow-discrete;
}

.wp-block-details[open]::details-content {
	block-size: auto;
}

.wp-block-accordion-panel {
	animation: chn-drop 0.3s ease both;
}

.wp-block-accordion-heading__toggle,
.wp-block-details > summary {
	transition: background-color 0.2s;
}

.wp-block-accordion-heading__toggle:hover,
.wp-block-details > summary:hover {
	background: var(--wp--preset--color--light-purple-400);
}

/* Changement d'onglet */
.wp-block-tab-panel:not([hidden]) {
	animation: chn-fade 0.35s ease both;
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
	}

	.chn-reveal {
		opacity: 1;
		transform: none;
	}
}

/* =====================================================================
   Fluidité : transitions entre les pages, défilement, effets liés au défilement.
   ===================================================================== */

:root {
	--chn-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
	--chn-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* Lenis : seuls les contenus embarqués en cours de défilement sont désactivés. */
.lenis.lenis-smooth iframe {
	pointer-events: auto;
}

.lenis.lenis-scrolling iframe {
	pointer-events: none;
}

html.lenis {
	scroll-behavior: auto;
}

/* Les pages larges (carrousel jusqu'au bord) ne créent pas de défilement horizontal.
   Sur le conteneur et non sur body : la valeur de body est reportée sur la fenêtre, et un mobile
   élargit alors quand même la page. */
.wp-site-blocks {
	overflow-x: clip;
}

/* Mots ou adresses web très longs saisis dans les contenus : passage à la ligne. */
body {
	overflow-wrap: break-word;
}

@media (prefers-reduced-motion: no-preference) {
	/* ---------- Transitions entre les pages (navigateurs compatibles) ---------- */
	@view-transition {
		navigation: auto;
	}

	::view-transition-old(root) {
		animation: chn-page-out 0.32s var(--chn-ease-in-out) both;
	}

	::view-transition-new(root) {
		animation: chn-page-in 0.55s var(--chn-ease-out) both;
	}

	/* L'en-tête, les accès rapides et le titre restent en place pendant la transition. */
	.chn-header {
		view-transition-name: chn-header;
	}

	.chn-quick {
		view-transition-name: chn-quick;
	}

	.chn-page-title {
		view-transition-name: chn-title;
	}

	.chn-breadcrumbs {
		view-transition-name: chn-breadcrumbs;
	}

	::view-transition-group(chn-header),
	::view-transition-group(chn-quick) {
		animation-duration: 0.45s;
		animation-timing-function: var(--chn-ease-out);
	}

	::view-transition-old(chn-title),
	::view-transition-old(chn-breadcrumbs) {
		animation: chn-page-out 0.25s var(--chn-ease-in-out) both;
	}

	::view-transition-new(chn-title),
	::view-transition-new(chn-breadcrumbs) {
		animation: chn-page-in 0.5s 0.05s var(--chn-ease-out) both;
	}

	/* La photo d'une carte se transforme en image de l'article ouvert. */
	::view-transition-group(*.chn-media) {
		animation-duration: 0.6s;
		animation-timing-function: var(--chn-ease-out);
	}

	::view-transition-old(*.chn-media),
	::view-transition-new(*.chn-media) {
		height: 100%;
		object-fit: cover;
	}

	/* ---------- En-tête qui se masque et réapparaît ---------- */
	.chn-header {
		transition: transform 0.5s var(--chn-ease-out);
	}

	/* ---------- Effets liés au défilement ---------- */
	@supports (animation-timeline: scroll()) {
		/* Titre de l'accueil : le grand mot glisse plus lentement que la page. */
		.chn-hero__word {
			animation: chn-rise 0.9s var(--chn-ease-out) both, chn-hero-parallax linear both;
			animation-range: normal, 0 70vh;
			animation-timeline: auto, scroll(root);
		}

		/* Photos : léger dézoom pendant leur entrée dans l'écran. */
		.chn-news-slider__feature .chn-news-feature__img,
		.chn-photo-card > .wp-block-image img,
		.wp-block-group.is-style-photo-card > .wp-block-image img,
		.chn-main .wp-block-post-featured-image img {
			animation: chn-image-settle linear both;
			animation-range: entry 0% cover 45%;
			animation-timeline: view();
		}

		/* Image d'en-tête d'un article ou d'un service : effet de profondeur. */
		.chn-main .wp-block-post-featured-image img {
			animation-name: chn-image-depth;
			animation-range: cover 0% cover 100%;
		}
	}

	/* ---------- Méga-menu et menu mobile : liens en cascade ---------- */
	.chn-panel:not([hidden]) .chn-links,
	.chn-panel:not([hidden]) .chn-panel__title {
		animation: chn-rise 0.45s var(--chn-ease-out) both;
	}

	.chn-panel:not([hidden]) .chn-links:nth-child(2) { animation-delay: 40ms; }
	.chn-panel:not([hidden]) .chn-links:nth-child(3) { animation-delay: 80ms; }
	.chn-panel:not([hidden]) .chn-links:nth-child(4) { animation-delay: 120ms; }
	.chn-panel:not([hidden]) .chn-links:nth-child(n+5) { animation-delay: 160ms; }

	.chn-drawer__level:not([hidden]) li {
		animation: chn-slide-in 0.45s var(--chn-ease-out) both;
	}

	.chn-drawer__level:not([hidden]) li:nth-child(2) { animation-delay: 30ms; }
	.chn-drawer__level:not([hidden]) li:nth-child(3) { animation-delay: 60ms; }
	.chn-drawer__level:not([hidden]) li:nth-child(4) { animation-delay: 90ms; }
	.chn-drawer__level:not([hidden]) li:nth-child(5) { animation-delay: 120ms; }
	.chn-drawer__level:not([hidden]) li:nth-child(6) { animation-delay: 150ms; }
	.chn-drawer__level:not([hidden]) li:nth-child(n+7) { animation-delay: 180ms; }

	/* ---------- Micro-interactions ---------- */
	.chn-btn,
	.chn-pill,
	.chn-filter,
	.chn-arrow,
	.chn-doctolib,
	.wp-block-button__link,
	.chn-choice,
	.chn-quick__item {
		transition-duration: 0.3s;
		transition-timing-function: var(--chn-ease-out);
	}

	.chn-btn:active,
	.chn-pill:active,
	.chn-filter:active,
	.chn-arrow:active:not(:disabled),
	.chn-doctolib:active,
	.wp-block-button__link:active,
	.chn-choice:active {
		transform: scale(0.96);
	}

	.chn-quick__item {
		transition-property: background-color, transform, box-shadow;
	}

	.chn-quick__item:hover {
		box-shadow: 0 10px 24px -12px rgba(43, 40, 104, 0.6);
		transform: translateX(-4px);
	}

	.chn-quick__label {
		transition: max-width 0.45s var(--chn-ease-out), padding 0.45s var(--chn-ease-out);
	}

	/* Soulignement animé des liens de menu. */
	.chn-links a,
	.chn-menu--legal a {
		background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
		transition: background-size 0.35s var(--chn-ease-out), color 0.2s;
	}

	.chn-links a:hover,
	.chn-menu--legal a:hover {
		background-size: 100% 1px;
		text-decoration: none;
	}

	/* Cartes : survol plus doux. */
	.chn-news-card,
	.chn-regard-card,
	.chn-job-card,
	.chn-result,
	.wp-block-group.is-style-card {
		transition: background-color 0.35s ease, transform 0.5s var(--chn-ease-out), box-shadow 0.5s var(--chn-ease-out);
	}

	.chn-news-card:hover,
	.chn-regard-card:hover,
	.chn-job-card:hover,
	.wp-block-group.is-style-card:hover {
		box-shadow: 0 18px 40px -28px rgba(43, 40, 104, 0.55);
		transform: translateY(-4px);
	}

	.chn-tile {
		transition: transform 0.5s var(--chn-ease-out), box-shadow 0.5s var(--chn-ease-out);
	}

	/* Carrousel en cours de glisser : pas d'accroche ni de sélection de texte. */
	.chn-news-slider__track {
		cursor: grab;
	}

	.chn-news-slider__track.is-dragging {
		cursor: grabbing;
		scroll-snap-type: none;
		user-select: none;
	}

	.chn-news-slider__track.is-dragging a {
		pointer-events: none;
	}

	/* Images : fondu une fois chargées. */
	.chn-img-wait {
		opacity: 0;
	}

	.chn-img-wait,
	.chn-main img.chn-img-loaded {
		transition: opacity 0.6s ease;
	}

	/* Apparition au défilement : plus de profondeur. */
	.chn-reveal {
		transform: translate3d(0, 32px, 0);
		transition: opacity 0.9s var(--chn-ease-out), transform 0.9s var(--chn-ease-out);
		transition-delay: var(--chn-reveal-delay, 0ms);
	}
}

@keyframes chn-page-out {
	to {
		opacity: 0;
		transform: translateY(-12px);
	}
}

@keyframes chn-page-in {
	from {
		opacity: 0;
		transform: translateY(18px);
	}
}

@keyframes chn-hero-parallax {
	to {
		opacity: 0.25;
		transform: translateY(18vh);
	}
}

@keyframes chn-image-settle {
	from {
		scale: 1.12;
	}
	to {
		scale: 1;
	}
}

@keyframes chn-image-depth {
	from {
		scale: 1.08;
		translate: 0 -3%;
	}
	to {
		scale: 1.08;
		translate: 0 3%;
	}
}

/* Ombre de l'en-tête au défilement : fondu d'un pseudo-élément (pas de repeinture de l'ombre). */
.chn-header::after {
	box-shadow: 0 12px 30px -24px rgba(43, 40, 104, 0.45);
	content: "";
	inset: 0;
	opacity: 0;
	pointer-events: none;
	position: absolute;
	transition: opacity 0.4s ease;
	z-index: -1;
}

.chn-header.is-scrolled::after {
	opacity: 1;
}
