/**
 * Site header and footer.
 *
 * These are theme templates rather than Elementor Theme Builder templates,
 * because Theme Builder is Elementor Pro only. Menus come from WordPress
 * menu locations, and the logo/CTA come from the Customizer — so the parts
 * an editor realistically needs to change are still editable without code.
 */

/* --- Header ---------------------------------------------------------- */
.damf-header {
	position: relative;
	z-index: 50;
	background: var(--damf-white);
	border-block-end: 2px solid var(--damf-navy);
}

/* 84px tall, logo left / nav centre / actions right — the proportions of the
   header in the redesign prototype. */
.damf-header__inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--damf-space-6);
	min-block-size: 84px;
}

/* --- Logo lockup ----------------------------------------------------- */
.damf-lockup {
	display: flex;
	align-items: center;
	gap: var(--damf-space-4);
	text-decoration: none;
	/* Must be allowed to shrink: the full wordmark plus the Arabic name is
	   wider than a phone, and a flex item defaults to min-width:auto, which
	   would push the header past the viewport. */
	min-inline-size: 0;
}

.damf-lockup__text {
	min-inline-size: 0;
}

.damf-lockup__mark {
	inline-size: clamp(3rem, 5vw, 4.75rem);
	block-size: auto;
	object-fit: contain;
}

/* A complete horizontal lockup: sized by height so it sits on the header's
   optical baseline whatever its width, and capped so a very wide file cannot
   crowd out the navigation. */
.damf-lockup--full .damf-lockup__image {
	inline-size: auto;
	block-size: clamp(2.25rem, 3.4vw, 3.25rem);
	max-inline-size: min(22rem, 42vw);
	object-fit: contain;
}

.damf-lockup__ar {
	display: block;
	margin-block-end: var(--damf-space-1);
	font-family: var(--damf-font-arabic);
	font-weight: 500;
	font-size: 1.3125rem;
	line-height: 1.2;
	color: var(--damf-text-muted);
}

.damf-lockup__en {
	display: block;
	font-family: var(--damf-font-heading);
	font-weight: 700;
	font-size: 1.0625rem;
	line-height: 1.2;
	letter-spacing: var(--damf-tracking-wordmark);
	color: var(--damf-navy);
}

.damf-lockup__en span {
	color: var(--damf-text-faint);
}

/* --- Primary nav ----------------------------------------------------- */
.damf-nav ul {
	display: flex;
	align-items: center;
	gap: var(--damf-space-6);
	margin: 0;
	padding: 0;
	list-style: none;
}

.damf-nav li {
	position: relative;
	margin: 0;
}

.damf-nav a {
	display: block;
	padding-block: var(--damf-space-2);
	font-size: 0.9375rem;
	font-weight: 600;
	color: var(--damf-navy);
	text-decoration: none;
	white-space: nowrap;
}

/*
 * The submenu toggle button is for touch and keyboard only. On desktop the
 * submenu already opens on hover and focus-within, and showing the button
 * there put a 36px control inside the list item — which wrapped onto a second
 * line and made the whole navigation two rows tall with the dropdown items
 * sitting lower than the plain ones. The "▾" in the link text is the desktop
 * affordance; the button is the mobile one, and they are never both visible.
 *
 * Scoped to .damf-nav because the button also carries .damf-icon-button,
 * which sets display:inline-flex and is declared later in this file — a bare
 * .damf-nav__toggle rule would lose the tie on source order.
 */
.damf-nav .damf-nav__toggle {
	display: none;
}

.damf-nav .current-menu-item > a,
.damf-nav .current-menu-ancestor > a,
.damf-nav .current_page_item > a {
	color: var(--damf-red);
}

/* Submenus. Kept CSS-first so they work without JS, with a JS toggle
   layered on for keyboard and touch (see assets/js/navigation.js). */
.damf-nav .sub-menu {
	position: absolute;
	inset-block-start: 100%;
	inset-inline-start: calc(var(--damf-space-4) * -1);
	z-index: 20;
	display: block;
	inline-size: 13rem;
	padding-block: var(--damf-space-2);
	background: var(--damf-white);
	border: var(--damf-border);
	border-radius: var(--damf-radius);
	box-shadow: var(--damf-shadow-md);
	opacity: 0;
	visibility: hidden;
	transform: translateY(-0.35rem);
	transition: opacity var(--damf-transition), transform var(--damf-transition),
		visibility var(--damf-transition);
}

.damf-nav li:hover > .sub-menu,
.damf-nav li:focus-within > .sub-menu,
.damf-nav li[data-open="true"] > .sub-menu {
	opacity: 1;
	visibility: visible;
	transform: none;
}

.damf-nav .sub-menu a {
	padding: var(--damf-space-2) var(--damf-space-5);
	font-weight: 400;
	white-space: normal;
}

.damf-nav .sub-menu a:hover,
.damf-nav .sub-menu a:focus-visible {
	background: var(--damf-tint);
	color: var(--damf-red);
}

.damf-nav__toggle-icon {
	margin-inline-start: 0.35em;
	font-size: 0.7em;
	vertical-align: middle;
}

/* --- Header actions -------------------------------------------------- */
.damf-header__actions {
	display: flex;
	align-items: center;
	gap: var(--damf-space-5);
	flex-shrink: 0;
}

/* Below the desktop breakpoint the actions drop to their own full-width row
   rather than being crushed against the lockup. Search keeps working on
   phones instead of being hidden, which is where it is most used. */
@media (max-width: 1080px) {
	.damf-header__inner {
		flex-wrap: wrap;
	}

	.damf-header__actions {
		order: 3;
		inline-size: 100%;
		flex-shrink: 1;
		justify-content: space-between;
		gap: var(--damf-space-3);
		padding-block-end: var(--damf-space-3);
	}

	.damf-header__actions .damf-search {
		flex: 1 1 auto;
		min-inline-size: 0;
	}

	/* Element selector needed here too, to out-specify the base input rule. */
	.damf-header .damf-search input.damf-search__field {
		inline-size: 100%;
		padding-inline: var(--damf-space-3);
		border-color: var(--damf-lavender);
		background: var(--damf-white);
	}
}

@media (max-width: 600px) {
	/* 14px: at 16px the Arabic name is 209px wide against 201px of room on
	   a 360px phone, and wraps onto a second line. */
	.damf-lockup__ar {
		font-size: 0.875rem;
	}

	.damf-lockup__en {
		font-size: 0.8125rem;
	}

	/* "MATERIAL FACTORY L.L.C." takes its own line rather than being hidden:
	   the phone header row holds only the lockup and the menu button, and
	   the full name does not fit on one line at 360px. */
	.damf-lockup__en span {
		display: block;
	}

	.damf-header__actions .damf-button {
		padding-inline: var(--damf-space-4);
		font-size: var(--damf-text-sm);
	}
}

.damf-icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	position: relative;
	inline-size: 2.25rem;
	block-size: 2.25rem;
	border: 0;
	background: none;
	color: var(--damf-navy);
	cursor: pointer;
	border-radius: var(--damf-radius);
}

.damf-icon-button:hover,
.damf-icon-button:focus-visible {
	color: var(--damf-red);
}

/* Quote-basket count bubble. Hidden at zero rather than showing "0". */
.damf-quote-count {
	position: absolute;
	inset-block-start: 0;
	inset-inline-end: 0;
	min-inline-size: 1.15rem;
	padding: 0 0.25rem;
	background: var(--damf-red);
	color: var(--damf-white);
	border-radius: 999px;
	font-size: 0.6875rem;
	font-weight: 700;
	line-height: 1.15rem;
	text-align: center;
}

.damf-quote-count[hidden] {
	display: none;
}

/* --- Mobile ---------------------------------------------------------- */
.damf-header__burger {
	display: none;
}

@media (max-width: 1080px) {
	.damf-header__burger {
		display: inline-flex;
	}

	.damf-nav {
		position: absolute;
		inset-block-start: 100%;
		inset-inline: 0;
		display: none;
		padding: var(--damf-space-4) var(--damf-gutter) var(--damf-space-8);
		background: var(--damf-white);
		border-block-end: 2px solid var(--damf-navy);
		box-shadow: var(--damf-shadow-md);
	}

	.damf-nav[data-open="true"] {
		display: block;
	}

	.damf-nav ul {
		flex-direction: column;
		align-items: stretch;
		gap: 0;
	}

	.damf-nav > ul > li {
		border-block-end: var(--damf-border);
	}

	/* Parent items become a row: the link navigates, the button discloses. */
	.damf-nav > ul > li.menu-item-has-children {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.damf-nav > ul > li.menu-item-has-children > a {
		flex: 1 1 auto;
	}

	.damf-nav .damf-nav__toggle {
		display: inline-flex;
		flex: 0 0 auto;
	}

	/* The button carries the chevron on mobile, so drop the one in the text. */
	.damf-nav .damf-nav__toggle-icon {
		display: none;
	}

	.damf-nav .sub-menu {
		flex: 1 0 100%;
	}

	.damf-nav a {
		padding-block: var(--damf-space-3);
	}

	/* Submenus become inline disclosure panels rather than overlays. */
	.damf-nav .sub-menu {
		position: static;
		inline-size: auto;
		border: 0;
		box-shadow: none;
		padding-inline-start: var(--damf-space-4);
		display: none;
		opacity: 1;
		visibility: visible;
		transform: none;
	}

	.damf-nav li[data-open="true"] > .sub-menu {
		display: block;
	}
}

/* Phones: one header row — lockup and menu button. Search goes, and the
   header button moves to the foot of the menu panel (added in setup.php).
   The button is hidden at every other width, where the header shows it. */
.damf-nav__cta {
	display: none;
}

@media (max-width: 600px) {
	.damf-header__actions {
		display: none;
	}

	/* Only the lockup and the menu button share the row now, so keep them
	   on it: the lockup shrinks rather than pushing the button underneath. */
	.damf-header__inner {
		flex-wrap: nowrap;
	}

	.damf-lockup {
		gap: var(--damf-space-3);
	}

	.damf-nav > ul > li.damf-nav__cta {
		display: block;
		padding-block-start: var(--damf-space-4);
		border-block-end: 0;
	}

	.damf-nav .damf-nav__cta a,
	.damf-nav .damf-nav__cta a:hover,
	.damf-nav .damf-nav__cta a:focus-visible {
		display: flex;
		justify-content: center;
		padding-block: var(--damf-space-3);
		color: var(--damf-white);
	}
}

/* --- Footer ---------------------------------------------------------- */
.damf-footer {
	background: var(--damf-navy-deep);
	color: var(--damf-lavender);
	padding-block-start: var(--damf-space-14);
}

.damf-footer a {
	color: var(--damf-lavender);
	text-decoration: none;
}

.damf-footer a:hover,
.damf-footer a:focus-visible {
	color: var(--damf-white);
	text-decoration: underline;
}

/*
 * An explicit column count rather than auto-fit. auto-fit collapses the
 * tracks it cannot fill and stretches the rest, which turned a two-column
 * footer into two 650px columns of 13px links.
 */
.damf-footer__columns {
	display: grid;
	gap: var(--damf-space-8);
	grid-template-columns: minmax(0, 1fr);
	padding-block-end: var(--damf-space-10);
	border-block-end: 1px solid rgba(213, 213, 228, 0.2);
}

@media (min-width: 600px) {
	.damf-footer__columns {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 960px) {
	.damf-footer__columns--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.damf-footer__columns--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.damf-footer__columns--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.damf-footer__heading {
	margin-block-end: var(--damf-space-4);
	font-family: var(--damf-font-heading);
	font-size: 0.9375rem;
	color: var(--damf-white);
}

.damf-footer__columns ul {
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.84375rem;
	line-height: var(--damf-leading-loose);
}

.damf-footer__columns li {
	margin: 0;
}

.damf-footer .damf-rule {
	margin-block-start: var(--damf-space-6);
}

.damf-footer__legal {
	padding-block: var(--damf-space-4);
	font-size: var(--damf-text-xs);
	color: var(--damf-text-faint);
	text-align: center;
}
