/**
 * Site header (redesign 2026), Figma 1328:22573 (desktop) and the 1024/390 frames (hamburger).
 * One row from 80rem; below that a toggle opens the menu as a panel under the header.
 */

.c-site-header {
	position: relative;
	z-index: 100;
	background: var(--color-surface);
	color: var(--color-dark-green);
	font-family: var(--font-sans);
	font-size: var(--font-size-body);
	line-height: var(--line-height-body);
	letter-spacing: var(--letter-spacing-body);

	& :where(nav, ul, li) {
		margin: 0;
		padding: 0;
	}

	& :where(ul) {
		list-style: none;
	}

	& :where(a:not(.c-button)) {
		color: inherit;
		text-decoration: none;
	}

	& :where(a, button):focus-visible {
		outline: 3px solid var(--color-focus);
		outline-offset: 3px;
	}

	/* app.css rings every focused button, also on mouse click */
	& :where(button):focus:not(:focus-visible) {
		outline: none;
	}
}

.c-site-header__inner {
	box-sizing: content-box;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	max-inline-size: var(--container-max);
	margin-inline: auto;
	padding-inline: var(--gutter);
}

.c-site-header__logo {
	display: inline-block;
	color: var(--color-dark-green);

	& svg {
		display: block;
		inline-size: clamp(5.75rem, 5.2rem + 1.2vw, 6.8125rem); /* 92 → 109 */
		block-size: auto;
	}
}

.c-site-header__toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 2.75rem;
	block-size: 2.75rem;
	margin-inline-end: -0.625rem; /* icon lines up with the gutter */
	padding: 0;
	border: 0;
	border-radius: var(--radius-sm);
	background: none;
	color: var(--color-ink);
	cursor: pointer;

	& .c-icon {
		inline-size: 1.75rem;
		block-size: 1.75rem;
	}

	&[hidden],
	&[aria-expanded="false"] .c-icon:last-of-type,
	&[aria-expanded="true"] .c-icon:first-of-type {
		display: none;
	}
}

/* Icons drawn with mask, so JS-built buttons and WP menu links need no SVG markup.
   Figma arrow-right (18), plus/minus (20) and the filled chevron (10). */
.c-site-header {
	--icon-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M3.75 9h10.5M9 14.25 14.25 9 9 3.75' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	--icon-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4.17 10h11.66M10 4.17v11.66' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
	--icon-minus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4.17 10h11.66' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
	--icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M4.67 7.45.87 3.65a.47.47 0 0 1 0-.66l.44-.44a.47.47 0 0 1 .66 0L5 5.56l3.02-3.01a.47.47 0 0 1 .66 0l.44.44a.47.47 0 0 1 0 .66l-3.8 3.8a.47.47 0 0 1-.65 0Z'/%3E%3C/svg%3E");
	--header-radius: 0.5rem; /* Figma radius/md 8 */
}

.c-site-header__list a,
.c-site-header__parent {
	display: flex;
	align-items: center;
	font-weight: var(--font-weight-semibold);
}

.c-site-header__list a:hover,
.c-site-header__list a[aria-current="page"] {
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-underline-offset: 0.3em;
}

.c-site-header__parent {
	gap: var(--space-xs);
	inline-size: 100%;
	border: 0;
	background: none;
	color: inherit;
	font-family: inherit;
	letter-spacing: inherit;
	text-align: start;
	cursor: pointer;

	&::after {
		content: "";
		flex: none;
		background: currentColor;
		mask: var(--icon-chevron) center / contain no-repeat;
	}
}

/* JS-built disclosures: closed means hidden (also for assistive tech) */
.c-site-header.is-enhanced .c-site-header__parent[aria-expanded="false"] + .sub-menu {
	display: none;
}

/* Languages: a "Svenska / English" row below 80rem and without JS,
   a "globe SV" button with a panel from 80rem (Figma 1881:11092) */
.c-lang__toggle,
.c-lang__label,
.c-lang__link .c-icon,
.c-lang__code {
	display: none;
}

.c-lang__list {
	display: flex;
	justify-content: center;
	gap: var(--space-sm);
	font-size: var(--font-size-body-sm);
	line-height: var(--line-height-body-sm);
	letter-spacing: var(--letter-spacing-body-sm);

	& li + li::before {
		content: "/" / "";
		margin-inline-end: var(--space-sm);
		color: var(--color-neutral-600);
	}
}

.c-lang__link {
	color: var(--color-neutral-600);

	&:hover {
		text-decoration: underline;
		text-underline-offset: 0.2em;
	}

	&[aria-current="true"] {
		color: var(--color-dark-green);
		font-weight: var(--font-weight-semibold);
	}
}

/* Panel below 80rem, Figma 1881:11151 */
@media (max-width: 79.999rem) {
	.c-site-header {
		border-block-end: 1px solid var(--color-grey);
	}

	/* Padding, not min-height: the open panel wraps onto a second flex line */
	.c-site-header__inner {
		padding-block: 1.375rem; /* 22 + 44 toggle + 22 = 88 */
	}

	.c-site-header__menu {
		display: flex;
		flex-direction: column;
		gap: var(--space-lg);
		/* + both gutters: negative margins only shift a fixed-basis flex item, they don't widen it */
		flex-basis: calc(100% + 2 * var(--gutter));
		/* The same line as under the closed header, full width across the gutter */
		margin-block-start: 1.375rem;
		margin-inline: calc(-1 * var(--gutter));
		padding: var(--space-md) var(--gutter) var(--space-xl);
		border-block-start: 1px solid var(--color-grey);
	}

	/* header.js adds .is-enhanced; without JS the panel stays open */
	.c-site-header.is-enhanced:not(.is-open) .c-site-header__menu {
		display: none;
	}

	/* CTA and languages above the links (Figma 390 frame); the DOM keeps nav first for desktop */
	.c-site-header__nav {
		order: 1;
	}

	.c-site-header__list {
		display: grid;
		gap: var(--space-xs);

		& a,
		& .c-site-header__parent {
			justify-content: space-between;
			gap: var(--space-md);
			min-block-size: 3.5rem; /* 56 */
			padding: 0 var(--space-md);
			font-size: var(--font-size-h5);
			font-weight: var(--font-weight-h5);
			line-height: var(--line-height-h5);
			letter-spacing: var(--letter-spacing-h5);

			&::after {
				content: "";
				flex: none;
				inline-size: 1.125rem;
				block-size: 1.125rem;
				background: currentColor;
				mask: var(--icon-arrow) center / contain no-repeat;
			}
		}

		& .c-site-header__parent::after {
			inline-size: 1.25rem;
			block-size: 1.25rem;
			mask-image: var(--icon-plus);
		}

		& .c-site-header__parent[aria-expanded="true"]::after {
			mask-image: var(--icon-minus);
		}

		& .sub-menu {
			margin-block-start: var(--space-2xs);
			padding: var(--space-2xs);
			border: 1px solid var(--color-grey);
			border-radius: var(--header-radius);
			background: var(--color-white);

			& a {
				min-block-size: 3.25rem; /* 52 */
				font-size: var(--font-size-body);
				font-weight: var(--font-weight-body);
				line-height: var(--line-height-body);
				letter-spacing: var(--letter-spacing-body);
			}
		}
	}

	.c-site-header__cta {
		margin-inline: var(--space-xs);
	}
}

/* One row from 80rem */
@media (min-width: 80rem) {
	.c-site-header__inner {
		flex-wrap: nowrap;
		min-block-size: 6.875rem; /* 110 */
	}

	.c-site-header__toggle {
		display: none;
	}

	.c-site-header__menu {
		display: flex;
		align-items: center;
	}

	.c-site-header__list {
		display: flex;

		& > li {
			position: relative;
		}

		& a,
		& .c-site-header__parent {
			padding: 0.5625rem 1rem; /* 9 16, 38 px row as in Figma */
			font-size: var(--font-size-body-sm); /* Figma Body Small Bold */
			line-height: var(--line-height-body-sm);
			letter-spacing: var(--letter-spacing-body-sm);
		}

		& .c-site-header__parent {
			gap: var(--space-2xs);
			border-radius: var(--header-radius);

			&::after {
				inline-size: 0.625rem; /* 10 */
				block-size: 0.625rem;
			}

			&:hover,
			&[aria-expanded="true"] {
				background: var(--color-grey-subtle);
			}

			&[aria-expanded="true"]::after {
				rotate: 180deg;
			}
		}

		/* Courses dropdown, Figma 1881:11219 */
		& .sub-menu {
			position: absolute;
			inset-block-start: calc(100% + var(--space-sm));
			inset-inline-start: 0;
			z-index: 1;
			inline-size: 20.75rem; /* 332 */
			padding: var(--space-sm);
			border: 1px solid var(--color-grey);
			border-radius: var(--header-radius);
			background: var(--color-white);
			box-shadow: 0 0.75rem 2rem rgb(17 38 43 / 0.09);

			& a {
				justify-content: space-between;
				gap: var(--space-md);
				min-block-size: 3.25rem; /* 52 */
				padding-block: 0;
				font-size: var(--font-size-body);
				font-weight: var(--font-weight-body);
				line-height: var(--line-height-body);
				letter-spacing: var(--letter-spacing-body);

				&::after {
					content: "";
					flex: none;
					inline-size: 1.125rem;
					block-size: 1.125rem;
					background: currentColor;
					mask: var(--icon-arrow) center / contain no-repeat;
				}
			}
		}
	}

	/* Without JS the sub-menu opens on hover and keyboard focus */
	.c-site-header:not(.is-enhanced) .c-site-header__list > li:not(:hover, :focus-within) > .sub-menu {
		display: none;
	}

	/* Figma 1881:11150: smaller than .c-button, 47 px high */
	.c-site-header__cta {
		margin-inline-start: clamp(1.5rem, -4rem + 6.9vw, 4.8rem); /* 24 → 77 */
		padding: 0.71875rem 1.125rem; /* 11.5 18, plus the 2 px border */
		font-size: var(--font-size-body-sm); /* Figma Body Small Bold */
		line-height: var(--line-height-body-sm);
		letter-spacing: var(--letter-spacing-body-sm);
	}

	.c-lang {
		margin-inline-start: clamp(1.5rem, -1rem + 3.1vw, 3.75rem); /* 24 → 60 */
	}

	.c-site-header.is-enhanced .c-lang {
		position: relative;

		/* The button has [hidden] in the markup until header.js runs */
		& .c-lang__toggle {
			display: inline-flex;
			align-items: center;
			gap: 0.375rem; /* 6 */
			block-size: 2.5rem; /* 40 */
			padding-inline: 0.75rem;
			border: 0;
			border-radius: var(--header-radius);
			background: none;
			color: var(--color-dark-green);
			font-family: inherit;
			font-size: var(--font-size-label-md);
			font-weight: var(--font-weight-label-md);
			line-height: var(--line-height-label-md);
			letter-spacing: var(--letter-spacing-label-md);
			cursor: pointer;

			&:hover,
			&[aria-expanded="true"] {
				background: var(--color-grey-subtle);
			}

			& .c-icon:first-child {
				inline-size: 1.0625rem; /* 17 */
				block-size: 1.0625rem;
			}

			& .c-icon:last-child {
				inline-size: 0.75rem;
				block-size: 0.75rem;
			}

			&[aria-expanded="true"] .c-icon:last-child {
				rotate: 180deg;
			}
		}

		& .c-lang__toggle[aria-expanded="false"] + .c-lang__panel {
			display: none;
		}

		& .c-lang__panel {
			position: absolute;
			inset-block-start: calc(100% + var(--space-xs));
			inset-inline-end: 0;
			z-index: 1;
			display: grid;
			gap: var(--space-2xs);
			inline-size: 15.5rem; /* 248 */
			padding: var(--space-xs);
			border: 1px solid var(--color-grey);
			border-radius: var(--header-radius);
			background: var(--color-white);
			box-shadow: 0 0.5rem 1.5rem rgb(17 38 43 / 0.07);
		}

		& .c-lang__label {
			display: block;
			margin: 0;
			padding: var(--space-xs) var(--space-sm);
			font-size: var(--font-size-label-sm);
			font-weight: var(--font-weight-label-sm);
			line-height: var(--line-height-label-sm);
			letter-spacing: var(--letter-spacing-label-sm);
		}

		& .c-lang__list {
			display: grid;
			justify-content: stretch;
			gap: var(--space-2xs);

			& li + li::before {
				content: none;
			}
		}

		& .c-lang__link {
			display: flex;
			align-items: center;
			justify-content: space-between;
			min-block-size: 2.75rem; /* 44 */
			padding-inline: var(--space-sm);
			border-radius: 0.25rem;
			color: var(--color-dark-green);
			font-size: var(--font-size-label-md);
			font-weight: var(--font-weight-label-md);
			line-height: var(--line-height-label-md);
			letter-spacing: var(--letter-spacing-label-md);

			&:hover,
			&[aria-current="true"] {
				background: var(--color-surface);
				text-decoration: none;
			}

			& .c-icon {
				display: block;
			}
		}

		& .c-lang__code {
			display: inline;
			font-size: var(--font-size-label-sm);
			line-height: var(--line-height-label-sm);
			letter-spacing: var(--letter-spacing-label-sm);
		}
	}
}

