/*
 * Site chrome: header, navigation, skip link, footer and partners band.
 *
 * Mirrors src/components/layout/Header.astro, Footer.astro,
 * src/components/sections/PartnersSection.astro, the skip link of
 * src/layouts/BaseLayout.astro and the header rules of
 * src/styles/global.css. Loaded on the front end and in the editor by
 * inc/header.php. What the blocks store (colours, sizes, gaps, column
 * widths, line heights) stays in their attributes; these rules hold what
 * blocks cannot express.
 *
 * Breakpoints are Astro's: sm 40rem, md 48rem, lg 64rem.
 *
 * The navigation is a core navigation block with the `credi-site-nav`
 * class, no overlay and no submenu buttons. Core copies the block's
 * classes onto its inner list, so rules for the panel itself name `nav`. Core's own rules hide a
 * submenu until :hover or :focus-within; the rules below take over that
 * state machine (higher specificity than core's, so the order the
 * stylesheets load in does not matter). Below 64rem the layout depends on
 * `credi-js`, which the `credi-nf-scripted` mark the navigation script
 * depends on sets before first paint (inc/_helpers.php): with it the
 * navigation is a panel below the header behind the "Menu" toggle that
 * assets/js/header-nav.js adds; without it every link stays in the page,
 * submenus open, as on a scriptless Astro page.
 */

/* ------------------------------------------------------------------
 * Skip link: sr-only until focused, then a brand pill 24px from the top
 * left (BaseLayout.astro).
 * ------------------------------------------------------------------ */
.credi-skip-link {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.credi-skip-link:focus {
	left: 1.5rem;
	top: 1.5rem;
	z-index: 50;
	width: auto;
	height: auto;
	margin: 0;
	padding: 0.75rem 1.5rem;
	overflow: visible;
	clip-path: none;
	white-space: normal;
	border-radius: var(--wp--custom--radius--pill);
	background-color: var(--wp--preset--color--brand);
	color: var(--wp--preset--color--white);
	font-size: var(--wp--preset--font-size--body-sm);
	font-weight: 600;
	line-height: 1.4375rem;
	letter-spacing: normal;
	text-decoration: none;
}

/* ------------------------------------------------------------------
 * Header (Header.astro: relative z-30, border-b, py-4).
 * ------------------------------------------------------------------ */
.credi-site-header {
	position: relative;
	z-index: 30;
	border-bottom: 1px solid var(--wp--custom--color--navy-hairline);
}

/* h-11 sm:h-14 lg:h-[72px]: the logo steps down on narrow screens so the
   menu toggle never overhangs the gutter at 320px. */
.credi-logo img {
	width: auto;
	height: 2.75rem;
}

@media (min-width: 40rem) {
	.credi-logo img {
		height: 3.5rem;
	}
}

@media (min-width: 64rem) {
	.credi-logo img {
		height: 4.5rem;
	}
}

/* Top-level links: py-2, a flex row so a parent's chevron sits 8px after
   its label (flex items-center gap-2). Size, weight, colour, line height
   and tracking come from theme.json (core/navigation). */
.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .wp-block-navigation-item > .wp-block-navigation-item__content {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.5rem 0;
}

/* Submenu items: text-body-sm font-medium text-navy-800 (the colour is the
   navigation's "Submenu & overlay text" setting). No underline on hover:
   the tint marks it. */
.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__submenu-container > .wp-block-navigation-item > .wp-block-navigation-item__content {
	display: block;
	padding: 0.5rem 0;
	font-weight: 500;
	text-decoration: none;
}

/* The "Menu" toggle and the submenu toggles that header-nav.js adds. */
.credi-nav-toggle,
.credi-subnav-toggle {
	margin: 0;
	border: 0;
	background: none;
	color: var(--wp--preset--color--brand);
	font: inherit;
	letter-spacing: normal;
	cursor: pointer;
}

.credi-nav-toggle svg,
.credi-subnav-toggle svg {
	display: block;
	flex-shrink: 0;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
}

/* inline-flex items-center gap-2 rounded-pill border border-navy-hairline
   px-4 py-2 text-body-sm font-semibold text-brand */
.credi-nav-toggle {
	display: inline-flex;
	flex-shrink: 0;
	align-items: center;
	gap: 0.5rem;
	padding: 0.5rem 1rem;
	border: 1px solid var(--wp--custom--color--navy-hairline);
	border-radius: var(--wp--custom--radius--pill);
	font-size: var(--wp--preset--font-size--body-sm);
	font-weight: 600;
	line-height: 1.4375rem;
}

/* shrink-0 rounded-sm p-2 text-brand */
.credi-subnav-toggle {
	flex-shrink: 0;
	padding: 0.5rem;
	border-radius: 0.25rem;
	line-height: 1;
}

/* ------------------------------------------------------------------
 * Below 64rem: one column, submenus in flow (border-l pl-4), the button
 * last (mt-3 self-start).
 * ------------------------------------------------------------------ */
@media (max-width: 63.999rem) {
	.credi-site-header nav.credi-site-nav.wp-block-navigation {
		flex-direction: column;
		flex-wrap: nowrap;
		align-items: stretch;
		justify-content: flex-start;
		gap: 0.25rem;
		padding-block: 1rem;
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container {
		flex-direction: column;
		align-items: stretch;
		gap: 0.25rem;
	}

	/* The link and its toggle share the first line (justify-between
	   gap-2); the submenu takes the line below. */
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .wp-block-navigation-item {
		flex-wrap: wrap;
		justify-content: space-between;
		column-gap: 0.5rem;
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child > .wp-block-navigation__submenu-container.wp-block-navigation-submenu {
		position: static;
		flex-basis: 100%;
		width: auto;
		min-width: 0;
		height: auto;
		overflow: visible;
		visibility: visible;
		opacity: 1;
		padding: 0 0 0 1rem;
		border: 0;
		border-left: 1px solid var(--wp--custom--color--navy-hairline);
		box-shadow: none;
		transition: none;
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child > .wp-block-navigation__submenu-container.wp-block-navigation-submenu[data-open="false"] {
		display: none;
	}

	.credi-site-header nav.credi-site-nav.wp-block-navigation > .wp-block-buttons {
		align-self: flex-start;
		margin-top: 0.75rem;
	}

	/* With JavaScript: a panel below the header (absolute left-0 right-0
	   top-full border-b bg-white px-gutter py-4 shadow-figure), shown while
	   the toggle is expanded. */
	.credi-js .credi-site-header nav.credi-site-nav.wp-block-navigation {
		position: absolute;
		top: 100%;
		right: 0;
		left: 0;
		padding-inline: var(--wp--style--root--padding-left) var(--wp--style--root--padding-right);
		border-bottom: 1px solid var(--wp--custom--color--navy-hairline);
		background-color: var(--wp--preset--color--white);
		box-shadow: var(--wp--preset--shadow--figure);
	}

	.credi-js .credi-site-header nav.credi-site-nav.wp-block-navigation[data-open="false"] {
		display: none;
	}

	/* Without JavaScript the header grows to hold every link, logo first. */
	html:not(.credi-js) .credi-site-header__inner {
		flex-direction: column;
		align-items: flex-start;
	}

	html:not(.credi-js) .credi-site-header nav.credi-site-nav.wp-block-navigation {
		width: 100%;
	}
}

/* ------------------------------------------------------------------
 * 64rem and up: one row; submenus are panels (w-72, hairline border, py-2,
 * shadow-figure) that open on hover and :focus-within, and close on
 * Escape until the pointer or focus enters again (header-nav.js marks the
 * item).
 * ------------------------------------------------------------------ */
@media (min-width: 64rem) {
	.credi-nav-toggle,
	.credi-subnav-toggle {
		display: none;
	}

	/* -mb-1 pb-1: the panel opens 4px below the link and the pointer
	   crosses the gap without leaving the item. */
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .wp-block-navigation-item {
		margin-bottom: -0.25rem;
		padding-bottom: 0.25rem;
	}

	/* The decorative chevron of a link with a submenu (11x7, stroke 2),
	   flipped while the submenu is open. */
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .has-child > .wp-block-navigation-item__content::after {
		content: "";
		flex-shrink: 0;
		width: 11px;
		height: 7px;
		background-color: currentColor;
		-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
		mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
		transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .has-child:hover > .wp-block-navigation-item__content::after,
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .has-child:focus-within > .wp-block-navigation-item__content::after {
		transform: scaleY(-1);
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child > .wp-block-navigation__submenu-container.wp-block-navigation-submenu {
		top: 100%;
		right: auto;
		left: 0;
		z-index: 20;
		width: 18rem;
		min-width: 0;
		height: auto;
		overflow: visible;
		padding: 0.5rem 0;
		border: 1px solid var(--wp--custom--color--navy-hairline);
		box-shadow: var(--wp--preset--shadow--figure);
		visibility: hidden;
		opacity: 0;
		transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1), visibility 150ms cubic-bezier(0.4, 0, 0.2, 1);
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child:hover > .wp-block-navigation__submenu-container.wp-block-navigation-submenu,
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child:focus-within > .wp-block-navigation__submenu-container.wp-block-navigation-submenu {
		visibility: visible;
		opacity: 1;
	}

	/* After Escape: closed despite hover or focus, until a new entry. */
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation-item.has-child[data-subnav-dismissed="true"] > .wp-block-navigation__submenu-container.wp-block-navigation-submenu {
		visibility: hidden;
		opacity: 0;
	}

	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__container > .has-child[data-subnav-dismissed="true"] > .wp-block-navigation-item__content::after {
		transform: none;
	}

	/* lg:px-5 lg:py-3, hover:bg-navy-800/5 */
	.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__submenu-container > .wp-block-navigation-item > .wp-block-navigation-item__content {
		padding: 0.75rem 1.25rem;
	}
}

.credi-site-header .credi-site-nav.wp-block-navigation .wp-block-navigation__submenu-container > .wp-block-navigation-item > .wp-block-navigation-item__content:hover {
	background-color: color-mix(in srgb, var(--wp--preset--color--navy-800) 5%, transparent);
	text-decoration: none;
}

/* ------------------------------------------------------------------
 * Footer (Footer.astro). Columns, gaps, widths, heading line height and
 * link colours are block attributes in patterns/footer.php; this holds
 * the md breakpoint and the 24px link targets.
 * ------------------------------------------------------------------ */
.credi-footer-logo img {
	width: auto;
	height: 5.5rem;
}

.credi-footer-menu {
	list-style: none;
	padding-left: 0;
}

/* inline-flex min-h-6 items-center: 24px targets for WCAG 2.2 target size. */
.credi-site-footer a {
	display: inline-flex;
	align-items: center;
	min-height: 1.5rem;
	text-decoration: none;
}

/* On Astro each menu link sits on the 16px / 1.5 line of its list item,
   which makes the row of a link that wraps (md widths) 2px taller than the
   link. This empty inline box is that line; the link keeps the list's font
   size, so the size stays an editor choice. */
.credi-site-footer .credi-footer-menu > li::before {
	content: "";
	font-size: 1rem;
	line-height: 1.5;
}

.credi-site-footer a:hover {
	text-decoration: underline;
}

/* flex-col below md, a row from md (48rem); core columns would wait for
   782px, so the pattern turns its stacking off and this stacks them. */
@media (max-width: 47.999rem) {
	.credi-site-footer .wp-block-columns.is-not-stacked-on-mobile {
		flex-wrap: wrap !important;
	}

	.credi-site-footer .wp-block-columns.is-not-stacked-on-mobile > .wp-block-column {
		flex-basis: 100% !important;
	}
}

/* ------------------------------------------------------------------
 * Partners band (PartnersSection.astro).
 * ------------------------------------------------------------------ */
.credi-partners figure {
	margin: 0;
	max-width: 100%;
}

/* display:block, as Tailwind's preflight sets on every img: an inline logo
   sits on its figure's line box, which made the shortest mark (HEC
   Montréal, 25.4px) a 26px row and the band 0.6px taller than Astro's. */
.credi-partners img {
	display: block;
	max-width: 100%;
	height: auto;
}

/* mt-2 h-[104px] w-auto object-contain: the funders' mark keeps its height
   when the column is narrower than it, as on Astro. */
.credi-partners .wp-block-group > .credi-partners__funders {
	margin-top: 0.5rem;
}

.credi-partners .credi-partners__funders img {
	height: 6.5rem;
	object-fit: contain;
}

/* Hairline width="short" (w-full max-w-100), mt-4, and the mt-2 of the
   label after it. */
.wp-block-separator.credi-hairline-short {
	width: 100%;
	max-width: 25rem;
	margin: 1rem 0 0.5rem;
	border: 0;
	border-top: 1px solid var(--wp--custom--color--navy-hairline);
	opacity: 1;
}
