/*
 * Header v2 : menu principal, méga-menu (sous-menus), header mobile, menu catégories.
 * Chargé après style.css (voir functions.php). Pour revenir en arrière :
 * retirer l'enqueue 'header-v2' dans functions.php.
 */

:root {
	--hv2-bg: #1a1a1a;
	--hv2-panel: #242424;
	--hv2-card: #2f2f2f;
	--hv2-line: rgba(255, 255, 255, .12);
	--hv2-accent: #e4002b;
	--hv2-text: #fff;
	--hv2-muted: #b5b5b5;
}

/* ------------------------------------------------------------------ */
/* Accessibilité : focus visible sur tout le header                    */
/* ------------------------------------------------------------------ */
#masthead a:focus-visible,
#masthead [role="button"]:focus-visible,
.jj-slide-in-menu a:focus-visible,
.jj-slide-in-menu [role="button"]:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
	border-radius: 4px;
}

/* ------------------------------------------------------------------ */
/* DESKTOP (>= 1200px)                                                 */
/* ------------------------------------------------------------------ */
@media (min-width: 1200px) {

	/* Header pleine largeur (max 1600px) : logo | menu | icônes, chacun à sa taille naturelle */
	#masthead .header-top .theme-container,
	#masthead .site-header-main.header-fix .header-top .theme-container {
		display: grid;
		grid-template-columns: auto minmax(0, 1fr) auto;
		column-gap: 20px;
		align-items: center;
		width: 100% !important;
		max-width: 1600px !important;
		margin: 0 auto !important;
		padding: 0 24px !important;
		box-sizing: border-box;
	}

	.header-center {
		min-width: 0;
	}

	/* Barre de menu principale */
	.second-menu {
		display: flex;
		align-items: stretch;
		justify-content: space-between;
		gap: 2px;
		height: 60px;
		margin: 0 !important;
		padding: 0;
	}

	.second-menu > li {
		flex: 1 1 0;
		min-width: min-content;
		display: flex;
		align-items: stretch;
		justify-content: center;
		height: 100%;
		padding: 0;
		line-height: 1.3;
	}

	#masthead .second-menu > li > a {
		display: flex !important;
		align-items: center !important;
		justify-content: center !important;
		width: 100%;
		height: 100%;
		margin: 0 !important;
		padding: 0 7px;
		font-size: 11px;
		font-weight: 500;
		line-height: 1.35;
		letter-spacing: .05em;
		text-align: center;
		text-transform: uppercase;
		color: var(--hv2-text);
		text-wrap: balance;
		transition: opacity .15s;
	}

	#masthead .second-menu > li:hover > a,
	#masthead .second-menu > li:focus-within > a {
		color: var(--hv2-text);
		opacity: .7;
	}

	/* Panneau du sous-menu */
	li.has-mega-menu {
		position: relative;
	}

	li.has-mega-menu > .sub-menu {
		display: none;
		position: fixed;
		left: 0;
		right: 0;
		width: 100%;
		box-sizing: border-box;
		margin: 0;
		padding: 24px max(24px, calc((100% - 1450px) / 2)) 28px;
		background: var(--hv2-panel);
		border-top: 1px solid var(--hv2-line);
		box-shadow: 0 24px 40px -24px rgba(0, 0, 0, .7);
		max-height: calc(100vh - 150px);
		max-height: calc(100dvh - 150px);
		overflow-x: hidden;
		overflow-y: auto;
		overscroll-behavior: contain;
		z-index: 100;
		list-style: none;
	}

	/* Pont invisible sous l'entrée survolée : le curseur peut descendre vers le panneau
	   sans quitter le <li> (le panneau a overflow, un pseudo-élément dedans serait rogné). */
	li.has-mega-menu:hover::after {
		content: "";
		position: absolute;
		left: -40px;
		right: -40px;
		top: 100%;
		height: 40px;
		z-index: 99;
	}

	li.has-mega-menu:hover > .sub-menu,
	li.has-mega-menu:focus-within > .sub-menu {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
		gap: 6px 14px;
		align-content: start;
	}

	#masthead li.mega-menu-column {
		display: block !important;
		width: auto !important;
		max-width: none !important;
		min-height: 0;
		padding: 0 !important;
		margin: 0 !important;
		flex: none;
	}

	#masthead li.mega-menu-column > a {
		display: flex !important;
		flex-direction: row !important;
		align-items: center !important;
		justify-content: flex-start !important;
		gap: 14px;
		width: 100% !important;
		height: 64px;
		margin: 0 !important;
		padding: 0 14px !important;
		border: 0;
		border-radius: 10px;
		box-sizing: border-box;
		font-size: 12.5px;
		font-weight: 500;
		line-height: 1.3;
		letter-spacing: .06em;
		text-align: left !important;
		text-transform: uppercase;
		color: var(--hv2-text);
		background: transparent;
		transition: background .15s;
	}

	#masthead li.mega-menu-column > a:hover,
	#masthead li.mega-menu-column > a:focus-visible {
		background: var(--hv2-card);
		color: var(--hv2-text);
	}

	#masthead li.mega-menu-column > a img {
		flex: 0 0 46px;
		width: 46px !important;
		height: 46px !important;
		max-width: 46px;
		margin: 0 !important;
		padding: 0;
		object-fit: contain;
	}

	/* Lien « Tout voir » ajouté par header-v2.js : même grille, même hauteur */
	#masthead li.mega-menu-column.hv2-all > a {
		background: var(--hv2-card);
		border: 1px dashed rgba(255, 255, 255, .28);
		justify-content: center !important;
		gap: 8px;
	}

	#masthead li.mega-menu-column.hv2-all > a::after {
		content: "→";
		font-size: 15px;
	}

	/* Icônes de droite : même taille, même alignement */
	.header-right {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		gap: 4px;
		margin: 0;
		padding-left: 0;
	}

	.header-right .header-search,
	.header-right .topbar-link,
	.header-right .header-cart {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 48px;
		height: 48px;
		position: relative;
	}

	.header-right [role="button"],
	.header-right .header-cart > a {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 48px;
		height: 48px;
		cursor: pointer;
	}

	.header-right .dashicons {
		width: 30px;
		height: 30px;
		font-size: 30px;
	}

	.header-right .header-toggle {
		width: 48px;
		height: 48px;
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
	}
}

/* ------------------------------------------------------------------ */
/* MOBILE + TABLETTE (<= 1199px) : header refait                       */
/* ------------------------------------------------------------------ */
@media (max-width: 1199px) {
	/* Le mini-panier du thème est hors-écran à droite : il ne doit pas élargir la page */
	html,
	body {
		overflow-x: clip;
	}


	/* Header collant, sans le basculement fixe/animé du thème parent */
	#masthead.site-header {
		position: sticky;
		top: 0;
		z-index: 1000;
		min-height: 0 !important;
		background: var(--hv2-bg);
	}

	.admin-bar #masthead.site-header {
		top: var(--wp-admin--admin-bar--height, 0px);
	}

	#masthead .topbar-outer {
		display: none;
	}

	#masthead .site-header-main,
	#masthead .header-main,
	#masthead .sticky-menu .header-main {
		position: static !important;
		margin: 0 !important;
		width: 100%;
		animation: none !important;
		box-shadow: none;
		background: var(--hv2-bg);
	}

	#masthead .header-top,
	#masthead .sticky-menu .header-top {
		display: block;
		padding: 0 !important;
		margin: 0;
		border-bottom: 1px solid var(--hv2-line);
	}

	#masthead .header-top .theme-container,
	#masthead .site-header-main.header-fix .header-top .theme-container {
		display: grid;
		grid-template-columns: 48px minmax(0, 1fr) 48px 48px 48px;
		grid-template-areas: "menu logo search user cart";
		align-items: center;
		width: 100%;
		max-width: none;
		height: 56px;
		box-sizing: border-box;
		margin: 0 !important;
		padding: 0 4px !important;
	}

	/* Logo centré */
	#masthead .header-left,
	#masthead .sticky-menu .header-main .header-left {
		grid-area: logo;
		display: block !important;
		position: static !important;
		float: none;
		margin: 0;
		padding: 0;
		text-align: center;
		min-width: 0;
	}

	#masthead .header-logo {
		display: none;
	}

	#masthead .header-mob-logo {
		display: block;
		margin: 0;
		padding: 0;
	}

	#masthead .header-mob-logo a {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 56px;
	}

	#masthead .header-mob-logo img {
		width: auto;
		max-width: 100%;
		height: auto;
		max-height: 30px;
		margin: 0 auto;
	}

	#masthead .site-description {
		display: none;
	}

	/* Navigation horizontale du desktop : remplacée par le menu catégories */
	#masthead .header-center,
	#masthead .navigation-bar {
		display: none !important;
	}

	/* Icônes : on place chaque bloc dans la grille */
	#masthead .header-right {
		display: contents;
	}

	#masthead .header-search {
		grid-area: search;
	}

	#masthead .topbar-link--account {
		grid-area: user;
	}

	#masthead .topbar-link--menu {
		grid-area: menu;
	}

	#masthead .header-cart {
		grid-area: cart;
	}

	#masthead .header-search,
	#masthead .topbar-link,
	#masthead .header-cart {
		position: static;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 48px;
		height: 48px;
		margin: 0;
		padding: 0;
		float: none;
	}

	#masthead .header-right [role="button"],
	#masthead .header-search .header-toggle,
	#masthead .header-cart > a {
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 48px;
		height: 48px;
		margin: 0;
		padding: 0;
		cursor: pointer;
		-webkit-tap-highlight-color: transparent;
	}

	#masthead .header-right .dashicons {
		width: 28px;
		height: 28px;
		font-size: 28px;
		color: var(--hv2-text);
	}

	#masthead .header-search.active .header-toggle .dashicons,
	#masthead .header-right [role="button"]:active .dashicons {
		color: var(--hv2-muted);
	}

	/* Pastille panier */
	#masthead .cart-items-num {
		position: absolute;
		top: 4px;
		right: 2px;
		width: 18px;
		height: 18px;
		line-height: 18px;
		font-size: 11px;
		font-weight: 600;
		background: var(--hv2-accent);
		color: #fff;
		border-radius: 50%;
		text-align: center;
		margin: 0;
	}

	#masthead .cart-items-num-pos {
		line-height: 18px;
	}

	/* Recherche : barre pleine largeur sous le header */
	#masthead .header-search .search-form {
		position: absolute !important;
		top: 100% !important;
		left: 0 !important;
		right: 0 !important;
		width: auto !important;
		margin: 0;
		padding: 10px 12px 12px;
		box-sizing: border-box;
		background: var(--hv2-panel);
		border-bottom: 1px solid var(--hv2-line);
		box-shadow: 0 16px 24px -16px rgba(0, 0, 0, .6);
		z-index: 1001;
	}

	#masthead .header-search .search-form > div {
		display: flex;
		gap: 8px;
		width: 100%;
	}

	#masthead .header-search .search-form .search-field {
		flex: 1 1 auto;
		min-width: 0;
		height: 44px;
		padding: 0 14px;
		border: 1px solid #555;
		border-radius: 8px;
		background: #fff;
		color: #111;
		font-size: 16px; /* évite le zoom auto d'iOS */
		box-sizing: border-box;
	}

	#masthead .header-search .search-form #searchsubmit {
		position: static;
		flex: 0 0 auto;
		height: 44px;
		min-width: 64px;
		padding: 0 16px;
		border: 0;
		border-radius: 8px;
		background: var(--hv2-accent);
		color: #fff;
		font-size: 14px;
		font-weight: 600;
		cursor: pointer;
	}

	/* Mini-panier du thème : ne déborde pas de l'écran */
	#masthead .header-cart .togg .widget.widget_shopping_cart {
		right: 0;
		max-width: calc(100vw - 16px);
	}

	/* Contenu : plus de décalage dû à l'ancien header */
	.page-title.header {
		margin-top: 0;
	}
}

/* ------------------------------------------------------------------ */
/* MENU CATÉGORIES (volet) — desktop et mobile                         */
/* ------------------------------------------------------------------ */
.jj-slide-in-menu .jj-slide-in-menu-top-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 56px;
	box-sizing: border-box;
	padding: 0 8px 0 16px;
	background: var(--hv2-panel);
	border-bottom: 1px solid var(--hv2-line);
	position: sticky;
	top: 0;
	z-index: 5;
}

.jj-slide-in-menu .jj-slide-in-menu-top-bar::before {
	content: attr(data-title);
	color: var(--hv2-text);
	font-size: 13px;
	font-weight: 600;
	letter-spacing: .1em;
	text-transform: uppercase;
}

.jj-slide-in-menu .jj-slide-in-menu-top-bar .jj-slide-in-menu-top-bar-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	margin: 0;
	padding: 0;
	float: none;
	cursor: pointer;
}

.jj-slide-in-menu .jj-slide-in-menu-top-bar .dashicons {
	width: 32px;
	height: 32px;
	font-size: 32px;
	color: var(--hv2-text);
}

.jj-slide-in-menu.new .jj-slide-in-menu-items {
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 8px;
	padding: 12px;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	padding: 12px 6px 22px;
	font-size: 11px;
	font-weight: 500;
	line-height: 1.3;
	letter-spacing: .05em;
	text-wrap: balance;
	overflow-wrap: anywhere;
	border-radius: 10px;
	border: 1px solid transparent;
	-webkit-tap-highlight-color: transparent;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a .jj-slide-in-menu-item-img {
	flex: 0 0 auto;
	width: min(100%, 72px);
	aspect-ratio: 1 / 1;
	margin: 0 0 10px;
	background-repeat: no-repeat;
	background-position: center;
	background-size: contain;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a.has-children {
	padding-bottom: 26px;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a.has-children::after {
	bottom: 9px;
	transition: transform .2s;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a.has-children.active {
	background-color: #434242;
	border-color: rgba(255, 255, 255, .25);
}

.jj-slide-in-menu.new .jj-slide-in-menu-items a.has-children.active::after {
	transform: translateX(-50%) rotate(180deg);
}

/* Sous-menu du volet : panneau qui s'ouvre sous la rangée */
.jj-slide-in-menu.new .jj-slide-in-menu-items.children {
	padding: 0 12px;
	background: #2a2a2a;
	border-top: 0;
	scroll-margin-top: 64px;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children.active {
	padding: 12px;
	max-height: 4000px;
	border-top: 2px solid var(--hv2-accent);
	border-bottom: 1px solid var(--hv2-line);
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a {
	padding: 10px 6px 12px;
	background: #333;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a:hover,
.jj-slide-in-menu.new .jj-slide-in-menu-items.children a:active {
	background: #484848;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a .jj-slide-in-menu-item-img {
	width: min(100%, 56px);
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a.hv2-head {
	grid-column: 1 / -1;
	flex-direction: row;
	justify-content: center;
	gap: 8px;
	min-height: 44px;
	padding: 10px 12px;
	font-size: 12px;
	font-weight: 600;
	background: var(--hv2-accent);
	text-align: center;
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a.hv2-head::after {
	content: "→";
}

.jj-slide-in-menu.new .jj-slide-in-menu-items.children a.hv2-head:hover,
.jj-slide-in-menu.new .jj-slide-in-menu-items.children a.hv2-head:active {
	background: #c20024;
}

/* Volet fermé : pas d'ombre débordante, hors du parcours clavier / lecteur d'écran */
.jj-slide-in-menu {
	visibility: hidden;
	box-shadow: none;
	transition: right .25s ease, visibility 0s linear .25s;
}

.jj-slide-in-menu.opened {
	visibility: visible;
	box-shadow: 0 0 30px -15px #000;
	transition: right .25s ease, visibility 0s;
}

/* Volet : pleine hauteur ; plein écran sur mobile, panneau de 520px sur tablette */
@media (max-width: 1199px) {
	.jj-slide-in-menu {
		top: 0 !important;
		height: 100vh;
		height: 100dvh;
		max-height: none !important;
		width: min(520px, 100%);
		right: -101%;
		border: 0;
		overscroll-behavior: contain;
		-webkit-overflow-scrolling: touch;
		padding-bottom: env(safe-area-inset-bottom);
	}

	.jj-slide-in-menu.opened {
		right: 0;
	}

	.jj-slide-in-menu .jj-slide-in-menu-top-bar {
		padding-top: env(safe-area-inset-top);
		height: calc(56px + env(safe-area-inset-top));
	}
}

@media (max-width: 599px) {
	.jj-slide-in-menu {
		width: 100%;
	}
}

/* Colonne de 2 sur très petit écran : les libellés restent lisibles */
@media (max-width: 340px) {
	.jj-slide-in-menu.new .jj-slide-in-menu-items {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/* Fond assombri derrière le volet (tablette) ; clic dessus = fermeture (header-v2.js) */
@media (min-width: 600px) and (max-width: 1199px) {
	body.hv2-lock::after {
		content: "";
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, .55);
		z-index: 99999990;
	}
}

@media (min-width: 1200px) {
	.jj-slide-in-menu {
		max-width: 100vw;
	}
}

body.hv2-lock {
	overflow: hidden;
	touch-action: none;
}

@media (prefers-reduced-motion: reduce) {
	.jj-slide-in-menu,
	.jj-slide-in-menu.new .jj-slide-in-menu-items.children,
	.mega-menu-column > a {
		transition: none !important;
	}
}
