/*
 * Canadensys global header (Theme Builder layout 48), as the v6.5 prototype:
 * bar, nav spacing, chevrons, divider, language item, dropdown panels and the
 * theme toggle (pixel plan chunk 02, 2026-11-13). Loaded on every front-end
 * page and in the Visual Builder (functions.php).
 * Divi limitations: the Menu module has no setting for the space between
 * items, the chevron's shape, the dropdown's width, padding, borders, row
 * hover band or open animation, a divider, or an extra button.
 * The prototype hard-codes the header colours and keeps the header dark in
 * both themes (GLOBAL-42), so the values below are literal and the same in
 * both themes. The section carries cds-always-dark (Divi CSS Class field), so
 * cds-* variables used in the header (focus ring, mobile menu, skip link) keep
 * their dark values in light mode.
 */
.et-l--header {
	--cds-hdr-text: var(--gcid-cds-header-text); /* nav labels and toggle icon (Divi colour, printed by layout 48) */
	--cds-hdr-hover: #9AA7F2;                  /* hover colour */
	--cds-hdr-lang: #B9BABE;                   /* language item */
	--cds-hdr-ring: #3A3B3F;                   /* theme toggle ring */
	--cds-hdr-divider: #4A5CD0;                /* divider before the language item; toggle hover ring */
	--cds-hdr-rule: rgba(91, 110, 214, 0.35);  /* dropdown panel border */
	--cds-hdr-band: rgba(91, 110, 214, 0.08);  /* dropdown row hover band */
	--cds-hdr-gap: 30px;                       /* space between top-level items */
	--cds-hdr-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1 L5 5 L9 1' fill='none' stroke='black' stroke-width='1.4'/%3E%3C/svg%3E");
}

/* Narrow desktops: the prototype's 30px gaps need 1310px (English) and 1372px (French). */
@media (min-width: 1280px) and (max-width: 1319px) {
	.et-l--header {
		--cds-hdr-gap: 26px;
	}
}

@media (min-width: 1280px) and (max-width: 1379px) {
	html[lang^="fr"] .et-l--header {
		--cds-hdr-gap: 19px;
	}
}

/* Top-level items: no side padding, one gap between them (Divi pads each item 11px a side). */
@media (min-width: 1280px) {
	/* Keep the bar on one row while web fonts load: the logo, nav and toggle share one flex row that may shrink instead of wrapping the toggle. */
	.et-l--header .et_pb_menu__wrap:has(.cds-theme-toggle) {
		flex-wrap: nowrap;
	}

	.et-l--header .et_pb_menu__menu {
		min-width: 0;
	}

	.et-l--header .et_pb_menu .et-menu-nav > ul.et-menu {
		flex-wrap: nowrap;
		column-gap: var(--cds-hdr-gap);
		margin-left: 0;
		margin-right: 0;
	}

	.et-l--header .et_pb_menu .et-menu-nav > ul.et-menu > li {
		padding-left: 0;
		padding-right: 0;
	}

	/* Chevron: the prototype's 9x6 stroked SVG, 5px after the label (Divi: a 16px icon-font "3" in a 20px slot). */
	.et-l--header .et_pb_menu .et-menu > li.menu-item-has-children > a:first-child {
		position: relative;
		padding-right: 14px;
	}

	.et-l--header .et_pb_menu .et-menu > li.menu-item-has-children > a:first-child::after {
		content: "";
		position: absolute;
		top: 50%;
		right: 0;
		width: 9px;
		height: 6px;
		margin-top: -3px;
		font-size: 0;
		line-height: 0;
		background-color: currentColor;
		-webkit-mask: var(--cds-hdr-chevron) no-repeat center / 9px 6px;
		mask: var(--cds-hdr-chevron) no-repeat center / 9px 6px;
	}

	/* Divider before the language item: 1x16px, one gap each side. */
	.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher {
		margin-left: calc(var(--cds-hdr-gap) + 1px);
	}

	.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher::before {
		content: "";
		position: absolute;
		top: 50%;
		left: calc(-1 * (var(--cds-hdr-gap) + 1px));
		width: 1px;
		height: 16px;
		margin-top: -8px;
		background-color: var(--cds-hdr-divider);
	}
}

/*
 * Language item ("EN", the current language, with "FR" in its panel): dimmer
 * than the nav and no hover change, as the prototype. !important: Divi prints
 * the current-item colour with !important, and this item is the current page.
 */
.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher > a,
.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher > a:hover {
	color: var(--cds-hdr-lang) !important;
}

/*
 * A current section's top-level label rests at the nav colour. Divi 5.19 prints the
 * menu and dropdown "active link colour" settings with the same selector
 * (`ul li.current-menu-ancestor > a`, !important) and the dropdown value (cds-header-item) wins, which would dim About, Exploration, Missions and Capabilities on their
 * own pages. (0,5,2) beats Divi's (0,3,3); the hover rule below, at (0,6,2), still beats this.
 */
.et-l--header .et_pb_menu .et-menu > li:is(.current-menu-item, .current-menu-ancestor, .current-menu-parent, .current_page_ancestor):not(.menu-item-object-language_switcher) > a {
	color: var(--cds-hdr-text) !important;
}

/* A current item still answers hover (Divi's current-item colour is !important). */
.et-l--header .et_pb_menu .et-menu > li:is(.current-menu-item, .current-menu-ancestor, .current-menu-parent, .current_page_ancestor):not(.menu-item-object-language_switcher) > a:hover,
.et-l--header .et_pb_menu .nav li ul.sub-menu li.current-menu-item > a:hover {
	color: var(--cds-hdr-hover) !important;
}

/*
 * Dropdown panels: 235px wide (long labels wrap), 1px accent sides and
 * bottom, no top border, 35px rows across the full width, aligned so the item
 * text sits under the label, and a 6px slide-and-fade over 0.16s. The
 * visibility switch isn't transitioned, so a panel disappears at once on
 * mouse leave, as in the prototype.
 */
.et-l--header .et_pb_menu .et-menu > li > ul.sub-menu {
	top: 100%;
	left: -22px;
	width: 235px;
	min-width: 235px;
	padding: 8px 0 10px;
	border: 1px solid var(--cds-hdr-rule) !important;
	border-top: 0 !important;
	box-shadow: none;
	visibility: hidden;
	opacity: 0;
	transform: translateY(-6px);
	transition: opacity 0.16s ease, transform 0.16s ease;
}

.et-l--header .et_pb_menu .et-menu > li:hover > ul.sub-menu,
.et-l--header .et_pb_menu .et-menu > li.et-touch-hover > ul.sub-menu {
	visibility: visible;
	opacity: 1;
	transform: none;
	transition: opacity 0.16s ease, transform 0.16s ease;
}

/* WCAG 2.1.1 Keyboard: keyboard focus inside an item opens its panel (own rule, so a browser without :has() keeps the hover rule). */
.et-l--header .et_pb_menu .et-menu > li:has(:focus-visible) > ul.sub-menu {
	visibility: visible;
	opacity: 1;
	transform: none;
}

/* Keyboard focus inside an item (header.js adds cds-dd-focus): Chrome checks that the next link in the panel is still focusable after the old focus is removed, and for that instant no :focus-visible element exists, so the panel must stay open on the class, not only on :has(:focus-visible). */
.et-l--header .et_pb_menu .et-menu > li.cds-dd-focus > ul.sub-menu {
	visibility: visible;
	opacity: 1;
	transform: none;
}

/* Closed after an item click until the pointer moves outside the item or keyboard focus comes back into it, and after Escape until focus leaves it (header.js, GLOBAL-N01). After :hover and :has(:focus-visible), same specificity, so it wins. */
.et-l--header .et_pb_menu .et-menu > li.cds-dd-closed > ul.sub-menu {
	visibility: hidden;
	opacity: 0;
	transform: translateY(-6px);
	transition: none;
}

/* Divi's `.et-menu li { display: inline-block }` also matches panel items, so each row would shrink to its text: block makes every row (hover band, click area) the full panel width. */
.et-l--header .et_pb_menu .et-menu > li > ul.sub-menu > li {
	display: block;
	padding: 0;
	line-height: 15px;
}

.et-l--header .et_pb_menu .et-menu-nav li ul.sub-menu a {
	display: block;
	width: auto;
	padding: 10px 22px;
	font-size: 12px;
	line-height: 15px;
	letter-spacing: 1.82px; /* Divi prints the dropdown letter-spacing setting on the ul only; links reset it to 0.14em of their own size */
	white-space: normal;
}

.et-l--header .et_pb_menu .et-menu-nav li ul.sub-menu a:hover {
	background-color: var(--cds-hdr-band);
}

/* The language panel holds one short item: as wide as it is. */
.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher > ul.sub-menu {
	width: auto;
	min-width: 0;
}

.et-l--header .et_pb_menu .et-menu > li.menu-item-object-language_switcher > ul.sub-menu a {
	white-space: nowrap;
}

/*
 * Theme toggle (theme-toggle.js adds the button inside the Menu module; moved
 * here from light.css). 34px with a 15px icon from 1280px, as the prototype;
 * 44px below, where the header is a touch layout with no prototype reference.
 * Instant hover, as the prototype. Focus ring: a11y.css.
 */
.cds-theme-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 44px;
	height: 44px;
	margin: 0 0 0 12px;
	padding: 0;
	border: 1px solid var(--cds-hdr-ring);
	border-radius: var(--gvid-cds-radius-pill, 100px);
	background: transparent;
	color: var(--cds-hdr-text);
	cursor: pointer;
	transition: none;
}

.cds-theme-toggle:hover {
	border-color: var(--cds-hdr-divider);
	color: var(--cds-hdr-hover);
}

.cds-theme-toggle svg {
	width: 18px;
	height: 18px;
	pointer-events: none;
}

/* Show the icon for the theme the button switches to. */
.cds-theme-toggle .cds-icon-moon,
html[data-theme="light"] .cds-theme-toggle .cds-icon-sun {
	display: none;
}

html[data-theme="light"] .cds-theme-toggle .cds-icon-moon {
	display: block;
}

/* Keep the menu, the toggle and the hamburger on one line. */
.et-l--header .et_pb_menu__wrap:has(.cds-theme-toggle) {
	display: flex;
	align-items: center;
}

@media (min-width: 1280px) {
	.cds-theme-toggle {
		width: 34px;
		height: 34px;
		margin-left: var(--cds-hdr-gap);
	}

	.cds-theme-toggle svg {
		width: 15px;
		height: 15px;
	}
}

/* Reduced motion: panels appear without the slide (site motion §6). */
@media (prefers-reduced-motion: reduce) {
	.et-l--header .et_pb_menu .et-menu > li > ul.sub-menu {
		transform: none !important;
		transition: none !important;
	}
}
