/*
 * Primary menu, second level: desktop dropdown + mobile accordion.
 * Markup: header.php (wp_nav_menu, depth 2) and template-parts/mobile-nav.php.
 *
 * Hand-written, outside the Gulp build: src/styles is behind the deployed
 * dist/css/main.css, so main.css can't be rebuilt safely yet. Move these rules
 * into the SCSS once the sources are reconciled.
 * Enqueued after main.css in inc/enqueue.php.
 */

/* ------------------------------------------------------------------------
 * Desktop (the desktop header is shown from 1001px): dropdown on hover,
 * on keyboard focus, and on tap for touch screens (focus / sticky hover).
 * --------------------------------------------------------------------- */
@media screen and (min-width: 1001px) {
	.primary-menu > li.menu-item-has-children {
		position: relative;
	}

	.primary-menu > li.menu-item-has-children > a {
		cursor: pointer;
	}

	/* Chevron after the group label */
	.primary-menu > li.menu-item-has-children > a > span::after {
		content: '';
		display: inline-block;
		width: 6px;
		height: 6px;
		margin-left: 7px;
		border-right: 2px solid currentColor;
		border-bottom: 2px solid currentColor;
		transform: translateY(-3px) rotate(45deg);
		transition: transform .2s ease;
	}

	/* Group label stays highlighted while its dropdown is open */
	.primary-menu > li.menu-item-has-children:hover > a > span,
	.primary-menu > li.menu-item-has-children:focus-within > a > span {
		color: var(--color-global-primary);
	}

	.primary-menu > li.menu-item-has-children:hover > a > span::after,
	.primary-menu > li.menu-item-has-children:focus-within > a > span::after {
		transform: translateY(1px) rotate(-135deg);
	}

	.primary-menu .sub-menu {
		position: absolute;
		z-index: 10;
		top: 100%;
		left: 50%;
		min-width: 230px;
		margin: 12px 0 0;
		padding: 8px 0;
		list-style: none;
		text-align: left;
		background: #fff;
		border-top: 3px solid var(--color-global-primary);
		border-radius: 0 0 4px 4px;
		box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
		opacity: 0;
		visibility: hidden;
		transform: translate(-50%, 8px);
		transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
	}

	/* Invisible bridge over the 12px gap, so the dropdown doesn't close on the way down */
	.primary-menu .sub-menu::before {
		content: '';
		position: absolute;
		top: -15px;
		left: 0;
		right: 0;
		height: 15px;
	}

	.primary-menu > li:hover > .sub-menu,
	.primary-menu > li:focus-within > .sub-menu {
		opacity: 1;
		visibility: visible;
		transform: translate(-50%, 0);
		transition: opacity .2s ease, transform .2s ease, visibility 0s;
	}

	.primary-menu .sub-menu li {
		display: block;
		margin: 0;
	}

	.primary-menu .sub-menu a {
		font-size: 14px;
		padding: 9px 22px;
		white-space: nowrap;
	}

	.primary-menu .sub-menu a span {
		border-top: 0;
	}

	.primary-menu .sub-menu a:hover,
	.primary-menu .sub-menu a:focus {
		background: rgba(0, 0, 0, .04);
	}

	/* Current page: highlight the group label and the current sub-item */
	.primary-menu > li.current-menu-parent > a span,
	.primary-menu > li.current-menu-ancestor > a span,
	.primary-menu .sub-menu li.current-menu-item > a span {
		color: var(--color-global-primary);
	}
}

/* ------------------------------------------------------------------------
 * Mobile side panel (#menu): <details> accordion, no JavaScript.
 * --------------------------------------------------------------------- */
#menu li.has-sub-menu summary {
	position: relative;
	display: block;
	padding-right: 30px;
	cursor: pointer;
	list-style: none;
	color: #fff;
	-webkit-tap-highlight-color: transparent;
}

#menu li.has-sub-menu summary::-webkit-details-marker {
	display: none;
}

/* Chevron on the right, points up when open */
#menu li.has-sub-menu summary::after {
	content: '';
	position: absolute;
	top: 50%;
	right: 6px;
	width: 9px;
	height: 9px;
	margin-top: -8px;
	border-right: 2px solid #fff;
	border-bottom: 2px solid #fff;
	transform: rotate(45deg);
	transition: transform .2s ease;
}

#menu li.has-sub-menu details[open] > summary::after {
	margin-top: -3px;
	transform: rotate(-135deg);
}

/* Full width inside the parent item (which has 10px 20px padding) */
#menu .mobile-sub-menu {
	margin: 4px -20px -10px;
	padding: 0;
	list-style: none;
}

/* Sub-items line up with the group label text: 20px padding + 25px icon + .8rem margin + a space */
#menu .mobile-sub-menu li {
	position: relative;
	font-size: 18px;
	padding: 9px 20px 9px 58px;
	border-top: 1px solid rgba(255, 255, 255, .15);
	border-bottom: 0;
}

#menu .mobile-sub-menu li a {
	display: block;
}

/* Current page: same white bar + tint as the top-level items */
#menu .mobile-sub-menu li::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 5px;
	height: 100%;
	opacity: 0;
	background: #fff;
}

#menu .mobile-sub-menu li.active {
	background: rgba(0, 0, 0, .05);
}

#menu .mobile-sub-menu li.active::before {
	opacity: 1;
}

/* ------------------------------------------------------------------------
 * Mobile tap feedback (with js/menu.js):
 * - :active = finger down, the row darkens right away;
 * - .is-tapped = tap done, the highlight moves to the tapped row and its
 *   label pulses until the next page shows up.
 * --------------------------------------------------------------------- */
#menu .sub-menu-container a {
	-webkit-tap-highlight-color: transparent;
}

/* The link covers the whole row (padding included), so a tap anywhere on the row
   both navigates and shows the feedback. Same layout as before: the negative margin
   cancels the extra padding. The "Me suivre" row (several links) is left alone. */
#menu li.sub-menu-container > ul > li:not(.has-sub-menu) > a:only-child {
	display: block;
	margin: -10px -20px;
	padding: 10px 20px;
}

#menu .mobile-sub-menu li > a {
	margin: -9px -20px -9px -58px;
	padding: 9px 20px 9px 58px;
}

/* Instant, no transition: a local page replaces this one in about 0.25s */
#menu li.sub-menu-container > ul > li:not(.has-sub-menu):active,
#menu .mobile-sub-menu li:active,
#menu li.sub-menu-container > ul > li.is-tapped,
#menu .mobile-sub-menu li.is-tapped {
	background: rgba(0, 0, 0, .16);
}

#menu li.sub-menu-container > ul > li.is-tapped::before,
#menu .mobile-sub-menu li.is-tapped::before {
	opacity: 1;
}

#menu li.sub-menu-container > ul > li.is-tapped > a,
#menu .mobile-sub-menu li.is-tapped > a {
	animation: smile-menu-tap-loading 1.2s ease-in-out .3s infinite;
}

/* The current page gives up its highlight to the tapped item */
#menu .sub-menu-container.has-tapped li.active:not(.is-tapped) {
	background: none;
}

#menu .sub-menu-container.has-tapped li.active:not(.is-tapped)::before {
	opacity: 0;
}

@keyframes smile-menu-tap-loading {
	0%, 100% { opacity: 1; }
	50% { opacity: .55; }
}

@media (prefers-reduced-motion: reduce) {
	.primary-menu .sub-menu,
	.primary-menu > li.menu-item-has-children > a > span::after,
	#menu li.has-sub-menu summary::after {
		transition: none;
	}

	#menu li.sub-menu-container > ul > li.is-tapped > a,
	#menu .mobile-sub-menu li.is-tapped > a {
		animation: none;
	}
}
