/*
 * NSWF design system - only what theme.json cannot express.
 *
 * Rules (CLAUDE.md section 3): logical properties only. No left/right in
 * layout CSS, so the same stylesheet serves Arabic RTL and English LTR.
 *
 * Tokens come from theme.json, so editors changing the palette in the Site
 * Editor change these components too.
 */

:root {
	--nswf-header-h: 76px;
	--nswf-shadow: var(--wp--custom--shadow);
	--nswf-ease: var(--wp--custom--ease);
	--nswf-fast: var(--wp--custom--duration--fast);
	--nswf-r-s: var(--wp--custom--radius--s);
	--nswf-r-m: var(--wp--custom--radius--m);
	--nswf-r-l: var(--wp--custom--radius--l);
	--nswf-pill: var(--wp--custom--radius--pill);
	--nswf-on-deep-1: var(--wp--custom--on-deep--one);
	--nswf-on-deep-2: var(--wp--custom--on-deep--two);
	--nswf-on-deep-3: var(--wp--custom--on-deep--three);
	--nswf-on-brand: var(--wp--custom--on-brand);
}

/* --------------------------------------------------------------- base */

body {
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
	text-wrap: balance;
}

p {
	text-wrap: pretty;
}

/* Section 3: Western digits everywhere, and reference/phone numbers always
   read left-to-right even inside Arabic text. */
.nswf-num,
.nswf-tel {
	font-variant-numeric: tabular-nums;
}

.nswf-tel,
.nswf-ref {
	direction: ltr;
	display: inline-block;
	unicode-bidi: isolate;
}

/* ------------------------------------------------------------- focus */

/* Section 12: a visible ring on every interactive element. :focus-visible
   keeps it off mouse clicks but always on for keyboard and screen readers. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 3px solid var(--wp--preset--color--ochre);
	outline-offset: 2px;
	border-radius: var(--nswf-r-s);
}

.nswf-skip-link {
	position: absolute;
	inset-block-start: -100px;
	inset-inline-start: 16px;
	z-index: 100;
	padding: 12px 20px;
	background: var(--wp--preset--color--bg);
	color: var(--wp--preset--color--brand);
	border-radius: 0 0 var(--nswf-r-s) var(--nswf-r-s);
	font-weight: 600;
	transition: inset-block-start var(--nswf-fast) var(--nswf-ease);
}

.nswf-skip-link:focus {
	inset-block-start: 0;
}

/* ------------------------------------------------------------ header */

.nswf-header {
	position: sticky;
	inset-block-start: 0;
	z-index: 50;
	background: color-mix(in srgb, var(--wp--preset--color--bg) 92%, transparent);
	backdrop-filter: saturate(1.4) blur(10px);
	border-block-end: 1px solid var(--wp--preset--color--line);
}

/*
 * Base is the phone. The brand's two lines, the menu toggle, the language
 * pill and the sign-in button do not fit one 375px row, and the block's own
 * `nowrap` made them OVERLAP rather than wrap - the brand ran underneath
 * both the toggle and the pill, which no measurement of scroll width can
 * see. Wrapping puts the actions on a second line instead: nothing hidden,
 * nothing truncated, nothing on top of anything else.
 */
.nswf-header > .wp-block-group {
	min-height: var(--nswf-header-h);
	flex-wrap: wrap;
	row-gap: 6px;
}

/* ------------------------------------------------------------- brand */

.nswf-brand {
	display: flex;
	align-items: center;
	gap: 12px;
	color: var(--wp--preset--color--fg);
	text-decoration: none;
	flex-shrink: 0;
}

.nswf-brand:hover {
	text-decoration: none;
}

.nswf-brand__mark,
.nswf-brand .custom-logo {
	width: 46px;
	height: 46px;
	flex-shrink: 0;
}

.nswf-brand__mark {
	--sym-c: var(--wp--preset--color--brand);
	--sym-d: var(--wp--preset--color--fg);
	--sym-b: var(--wp--preset--color--brand);
}

.nswf-brand__primary {
	display: block;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.25;
}

/* The secondary line is the name in the OTHER language, so it needs its own
   direction rather than inheriting the page's. */
.nswf-brand__secondary {
	display: block;
	font-size: 10.5px;
	color: var(--wp--preset--color--muted);
	letter-spacing: 0.02em;
	unicode-bidi: isolate;
}

[dir="ltr"] .nswf-brand__secondary {
	font-size: 12px;
	letter-spacing: 0;
}

/* --------------------------------------------------------------- nav */

.nswf-nav .wp-block-navigation__container {
	gap: 4px;
}

.nswf-nav .wp-block-navigation-item__content {
	color: var(--wp--preset--color--fg);
	font-size: 15px;
	padding: 8px 12px;
	white-space: nowrap;
	border-radius: var(--nswf-pill);
	transition: background-color var(--nswf-fast) ease;
}

.nswf-nav .wp-block-navigation-item__content:hover {
	background: var(--wp--preset--color--paper);
	text-decoration: none;
}

.nswf-nav .current-menu-item > .wp-block-navigation-item__content,
.nswf-nav [aria-current="page"] {
	color: var(--wp--preset--color--brand);
	font-weight: 600;
	background: var(--wp--preset--color--tint);
}

/*
 * Submenus. Core ships a square white panel with a hairline border and no
 * shadow, which is its own look rather than this one. Everything here is
 * logical-property only, so the panel hangs from the correct edge in both
 * directions without a second rule.
 *
 * The parent stays a real link - الخدمات الطلابية is a page in its own right
 * - so core renders a separate <button> beside it for the toggle. That is
 * what makes the submenu reachable by keyboard, so it is left alone.
 */
.nswf-nav .wp-block-navigation__submenu-container {
	min-width: 220px;
	padding: 6px;
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--nswf-r-m);
	background: var(--wp--preset--color--bg);
	box-shadow: var(--nswf-shadow);
}

.nswf-nav .wp-block-navigation__submenu-container .wp-block-navigation-item__content {
	display: block;
	padding: 9px 12px;
	border-radius: var(--nswf-r-s);
	white-space: normal; /* a long label wraps inside the panel, not out of it */
}

/* The chevron should not crowd the label it belongs to. */
.nswf-nav .wp-block-navigation__submenu-icon {
	margin-inline-start: 2px;
}

/*
 * Open, the parent reads as active even before you pick a child, so the row
 * does not look as though focus has gone nowhere.
 */
.nswf-nav .wp-block-navigation-submenu:hover > .wp-block-navigation-item__content,
.nswf-nav .wp-block-navigation-submenu:focus-within > .wp-block-navigation-item__content {
	background: var(--wp--preset--color--paper);
}

/* In the overlay there is no panel to float: it is an indented list. */
.nswf-nav .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__submenu-container {
	min-width: 0;
	padding: 0 0 0 0;
	padding-inline-start: 14px;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	background: transparent;
}

/* ------------------------------------------------- language switcher */

.nswf-lang {
	font-size: 13.5px;
	font-weight: 600;
	letter-spacing: 0.04em;
	color: var(--wp--preset--color--muted);
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--nswf-pill);
	padding: 6px 11px;
	text-decoration: none;
	line-height: 1;
	unicode-bidi: isolate;
}

.nswf-lang:hover {
	color: var(--wp--preset--color--brand);
	border-color: var(--wp--preset--color--brand);
	text-decoration: none;
}

/* ----------------------------------------------------------- buttons */

/* Base button styling lives in theme.json elements.button. These are the
   variations registered in inc/block-styles.php. */

/*
 * Every button is a 44px target (section 12). Most already were - the
 * header's, the nav toggle, a form's submit - but the ghost variation came
 * out at 42, and it is the one carrying "create an account" and "sign in"
 * on the two screens a new student starts from.
 */
.wp-element-button,
.wp-block-button__link {
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Without this, a button set to width:100% adds its own padding on top
	   and breaks out of whatever card it sits in. */
	box-sizing: border-box;
}

.wp-block-button.is-style-nswf-ghost .wp-block-button__link {
	background: transparent;
	color: var(--wp--preset--color--fg);
	border: 1px solid var(--wp--preset--color--line);
}

/*
 * The same variation on a bare anchor or button. The rule above only
 * matches inside a `.wp-block-button` wrapper, which an element written in
 * PHP does not have - so `is-style-nswf-ghost` was being ignored and those
 * controls rendered as solid primary buttons. The copy and sign-out buttons
 * were the <button> half of that.
 */
a.wp-element-button.is-style-nswf-ghost,
button.wp-element-button.is-style-nswf-ghost {
	background: transparent;
	color: var(--wp--preset--color--fg);
	border: 1px solid var(--wp--preset--color--line);
}

a.wp-element-button.is-style-nswf-ghost:hover,
button.wp-element-button.is-style-nswf-ghost:hover {
	background: var(--wp--preset--color--paper);
	color: var(--wp--preset--color--fg);
}

.wp-block-button.is-style-nswf-ghost .wp-block-button__link:hover {
	background: var(--wp--preset--color--paper);
	color: var(--wp--preset--color--fg);
}

.wp-block-button.is-style-nswf-light .wp-block-button__link {
	background: #fff;
	color: var(--wp--preset--color--deep);
}

.wp-block-button.is-style-nswf-light .wp-block-button__link:hover {
	background: var(--wp--preset--color--tint);
	color: var(--wp--preset--color--deep);
}

.wp-block-button.is-style-nswf-small .wp-block-button__link {
	padding: 8px 16px;
	font-size: 14px;
}

.wp-block-button__link {
	transition: transform var(--nswf-fast) var(--nswf-ease),
		background-color var(--nswf-fast) ease,
		box-shadow var(--nswf-fast) ease;
}

.wp-block-button__link:active {
	transform: scale(0.97);
}

/* ----------------------------------------------------------- lattice */

/* Nubian lattice: a diamond grid masked over a flat colour, used at low
   opacity on dark bands. Applied as a block style to Group/Cover. */
.is-style-nswf-lattice {
	position: relative;
	isolation: isolate;
}

.is-style-nswf-lattice::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	opacity: 0.12;
	background-color: var(--wp--preset--color--bright);
	-webkit-mask-image: var(--nswf-lattice-mask);
	mask-image: var(--nswf-lattice-mask);
	-webkit-mask-size: var(--wp--custom--lattice--size) var(--wp--custom--lattice--size);
	mask-size: var(--wp--custom--lattice--size) var(--wp--custom--lattice--size);
}

:root {
	--nswf-lattice-mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20width%3D%2756%27%20height%3D%2756%27%3E%3Cpath%20d%3D%27M28%2014%20L42%2028%20L28%2042%20L14%2028%20Z%20M0%20-14%20L14%200%20L0%2014%20L-14%200%20Z%20M56%20-14%20L70%200%20L56%2014%20L42%200%20Z%20M0%2042%20L14%2056%20L0%2070%20L-14%2056%20Z%20M56%2042%20L70%2056%20L56%2070%20L42%2056%20Z%27%20fill%3D%27none%27%20stroke%3D%27%23fff%27%20stroke-width%3D%272%27/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------ footer */

.nswf-footer {
	background: var(--wp--preset--color--deep);
	color: var(--nswf-on-deep-2);
	font-size: 15px;
}

.nswf-footer h2,
.nswf-footer h3,
.nswf-footer h4 {
	color: #fff;
	font-size: 15px;
}

.nswf-footer a {
	color: var(--nswf-on-deep-2);
}

.nswf-footer a:hover {
	color: #fff;
}

.nswf-footer .nswf-brand {
	color: #fff;
}

.nswf-footer .nswf-brand__mark {
	--sym-c: var(--wp--preset--color--bright);
	--sym-d: #fff;
	--sym-b: var(--wp--preset--color--bright);
}

.nswf-footer .nswf-brand__secondary {
	color: var(--nswf-on-deep-3);
}

.nswf-footer__legal {
	border-block-start: 1px solid rgba(255, 255, 255, 0.12);
	padding-block-start: 20px;
	font-size: 13px;
	color: var(--nswf-on-deep-3);
}

.nswf-footer ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 8px;
}

/* ------------------------------------------------------- mobile menu */

/*
 * Mobile-first menu (Phase 6B section 4.1).
 *
 * The overlay is the DEFAULT, and the inline navigation is added back at
 * 1240px. Core switches to its overlay at 600px and renders it as a
 * full-screen dialog; we keep core's markup and keyboard handling and only
 * move the breakpoint and re-position the open panel below the header.
 */
.nswf-nav .wp-block-navigation__responsive-container-open:not(.always-shown) {
	display: flex;
}

.nswf-nav .wp-block-navigation__responsive-container:not(.is-menu-open) {
	display: none;
}

.nswf-nav .wp-block-navigation__responsive-container.is-menu-open {
	position: fixed;
	inset-block-start: var(--nswf-header-h);
	inset-block-end: auto;
	inset-inline: 0;
	padding: 12px 20px 20px;
	background: var(--wp--preset--color--bg);
	border-block-end: 1px solid var(--wp--preset--color--line);
	box-shadow: var(--nswf-shadow);
	align-items: stretch;
}

.nswf-nav .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-content {
	padding: 0;
}

.nswf-nav .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__container {
	flex-direction: column;
	gap: 2px;
	align-items: stretch;
}

.nswf-nav .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item__content {
	font-size: 17px;
	padding: 12px 14px;
}

/*
 * «قدّم الآن» waits for room; signing in does not.
 *
 * Both used to be hidden on a phone, and sign-in did not come back until
 * 1240px - so a student on a phone, which is most of them, had no way into
 * their account at all, and a tablet offered "apply" without offering the
 * account that applying now requires. Sign-in is the way in, so it shows at
 * every width and apply is the one that waits.
 */
.nswf-header .nswf-apply-link {
	display: none;
}

.nswf-brand__secondary {
	display: none;
}

/* Compact by default; loosened at 1400px. */
.nswf-header .nswf-nav .wp-block-navigation-item__content {
	padding-inline: 8px;
	font-size: 14.5px;
}

.nswf-header .wp-block-button__link {
	padding-inline: 16px;
}

/*
 * Section 4: the menu opens BELOW the header under 1240px.
 *
 * Core's Navigation block switches to an overlay at 600px and renders it as a
 * full-screen dialog. We keep core's markup and keyboard handling - which is
 * accessible and already translated - and only move the breakpoint up and
 * re-position the open panel.
 */


/* --------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {

	*,
	*::before,
	*::after {
		animation-duration: 1ms !important;
		animation-delay: 0ms !important;
		transition-duration: 1ms !important;
		scroll-behavior: auto !important;
	}
}

/* ------------------------------------------------- shortcode slots */

/* core/shortcode pipes output through wpautop, so the brand and the language
   switcher return block-level wrappers to avoid a stray <p>. These keep them
   behaving as plain flex items. */
.nswf-brand-slot,
.nswf-lang-slot {
	display: flex;
	align-items: center;
	gap: 8px;
}

/* The shortcode block itself should not introduce spacing in the header row. */
.nswf-header .wp-block-shortcode,
.nswf-footer .wp-block-shortcode {
	margin: 0;
}

/* ------------------------------------------------- footer columns */

/* Prototype proportions: the brand column is wider than the three link
   columns. Core's Grid block only emits equal columns, so the template is
   set here. */
/*
 * Core's Grid block emits `grid-template-columns: repeat(4, minmax(0,1fr))`
 * with no media query, so without this the footer stays four cramped columns
 * on a phone. Two classes beats core's single-class rule, so no !important.
 */
.nswf-footer .nswf-footer__cols {
	grid-template-columns: 1fr;
	gap: 32px;
}

@media (min-width: 600px) {

	.nswf-footer .nswf-footer__cols {
		grid-template-columns: 1fr 1fr;
	}
}

@media (min-width: 1024px) {

	.nswf-footer .nswf-footer__cols {
		grid-template-columns: 1.4fr 1fr 1fr 1fr;
	}
}

/* Footer links are plain until hovered, as in the prototype. */
.nswf-footer a {
	text-decoration: none;
}

.nswf-footer a:hover {
	text-decoration: underline;
	text-underline-offset: 4px;
}

/* --------------------------------------------- header row fitting */

/*
 * The prototype pushes the nav away from the brand with margin-inline-start:
 * auto, so brand sits at the start and nav + actions sit together at the end.
 * space-between would instead strand the nav in the middle.
 */
.nswf-header .nswf-nav {
	margin-inline-start: auto;
}

/* Nothing in the header bar may wrap to a second line: the nav list, the
   button labels, or the row itself. */
.nswf-header .wp-block-navigation__container {
	flex-wrap: nowrap;
}

.wp-block-button__link {
	white-space: nowrap;
}

.nswf-header__actions {
	flex-shrink: 0;
}

/* ------------------------------------------- header fit at mid widths */

/*
 * English labels are longer than Arabic, and the prototype itself overflows
 * at 1280px in English ("Apply now" ends up off-screen). Rather than copy
 * that, the bar tightens its own spacing before it would overflow. Section 12
 * requires no horizontal scroll at any width.
 */
.nswf-header .alignwide,
.nswf-header .nswf-nav,
.nswf-header .wp-block-navigation {
	min-width: 0;
}


/*
 * English runs about 100px wider than Arabic in the same bar, which is what
 * pushes the language pill into the last nav item. With the real seven-item
 * menu in place (menus.php) the English bar cannot hold the ghost "track"
 * button at ANY width: the header is capped at the 1200px container, so a
 * wider screen adds no room. It is therefore restored for Arabic only, and
 * English reaches tracking from the home page task card and the footer.
 *
 * The earlier rules were measured against WordPress's fallback menu, which
 * listed all twelve pages and WRAPPED rather than overflowing, so this
 * collision never showed up. [dir="ltr"] is a reliable hook because English
 * is the only LTR language on the site.
 */

/* ===================================================================
 * Header breakpoints (Phase 6B section 4.1), min-width only.
 *
 * The 360px case is the default: the overlay menu is on, the brand's
 * second line and the two call-to-action buttons are hidden, and the
 * nav is compact. Each step below adds room rather than taking it away.
 * =================================================================== */

/* Phones get the apply button back as soon as there is room for it. */
@media (min-width: 600px) {

	/* One row again: from here everything fits beside the brand. */
	.nswf-header > .wp-block-group {
		flex-wrap: nowrap;
	}

	.nswf-header .nswf-apply-link {
		display: inline-block;
	}

	.nswf-brand__secondary {
		display: block;
	}
}

/* Desktop: the inline navigation replaces the overlay. */
@media (min-width: 1240px) {

	.nswf-nav .wp-block-navigation__responsive-container-open:not(.always-shown) {
		display: none;
	}

	.nswf-nav .wp-block-navigation__responsive-container:not(.is-menu-open) {
		display: flex;
	}

}

/*
 * Widest screens.
 *
 * The nav spacing is deliberately NOT loosened here. The header content is
 * capped at the 1200px container, so a 1920px screen gives it no more room
 * than 1280 does - and with the longer English labels the roomier spacing
 * pushed the navigation into the language pill, which WCAG 2.2's target-size
 * rule flags as overlapping hit areas. Nothing comes back here but the gap.
 */
@media (min-width: 1400px) {

	.nswf-header .alignwide {
		gap: 24px;
	}
}

/* ------------------------------------------------- notched phones */

/*
 * Safe areas (Phase 6B section 4.1).
 *
 * On a notched phone in landscape the inset can be 44px or more, so content
 * pinned to the edge ends up under the rounded corner. These widen the
 * gutters only where the device reports an inset; max() means nothing
 * changes on a device without one.
 */
.wp-site-blocks > * {
	padding-inline-start: max(0px, env(safe-area-inset-left));
	padding-inline-end: max(0px, env(safe-area-inset-right));
}

.nswf-header > .wp-block-group,
.nswf-footer > .wp-block-group {
	padding-inline-start: max(0px, env(safe-area-inset-left));
	padding-inline-end: max(0px, env(safe-area-inset-right));
}

/* The open mobile menu reaches the bottom of the screen. */
.nswf-nav .wp-block-navigation__responsive-container.is-menu-open {
	padding-block-end: max(20px, env(safe-area-inset-bottom));
}

/* ------------------------------------------------- long-word wrap */

/*
 * Long Arabic compounds, URLs and English headings must not force the page
 * sideways on a 360px screen (section 4.1).
 */
body,
.nswf-card,
.nswf-task,
.nswf-news-item,
.nswf-svc,
.nswf-type {
	overflow-wrap: anywhere;
}

/* A URL in body copy is the usual culprit. */
a {
	overflow-wrap: anywhere;
}

/* ------------------------------------------------------ wide content */

/*
 * Tables scroll inside their own box rather than widening the page
 * (section 4.1).
 */
.wp-block-table,
.nswf-review {
	display: block;
	max-width: 100%;
	overflow-x: auto;
}

.wp-block-table table,
.nswf-review table {
	min-width: 100%;
}

/* ------------------------------------------------- touch targets */

/*
 * At least 44x44 with space between (section 4.1 and section 12).
 */
@media (pointer: coarse) {

	.nswf-tab,
	.nswf-lang,
	.nswf-seg button,
	.wp-block-navigation-item__content,
	.nswf-header .wp-block-button__link,
	.nswf-btn {
		min-height: 44px;
		display: inline-flex;
		align-items: center;
	}

	.nswf-tabs,
	.nswf-filters {
		gap: 8px;
	}
}

/*
 * The menu toggle is the ONLY way into the navigation on a phone, and core
 * ships it at the icon's own size - 24x24, well under the 44 section 12 asks
 * for. It is sized here rather than in the `pointer: coarse` block below
 * because a 24px target is awkward with a trackpad too.
 */
.nswf-nav .wp-block-navigation__responsive-container-open,
.nswf-nav .wp-block-navigation__responsive-container-close {
	min-width: 44px;
	min-height: 44px;
	align-items: center;
	justify-content: center;
}

/* ------------------------------------------------ target size (2.5.8) */

/*
 * WCAG 2.2 AA asks for 24x24 CSS px on anything you have to hit. Footer and
 * list links were 19px tall - fine to click, awkward to tap. The rule is
 * unconditional rather than behind `pointer: coarse`, because a target that
 * small is hard for anyone with a tremor or a trackpad, not only on a phone.
 *
 * Links inline in a sentence are exempt from 2.5.8 and are left alone.
 */
.nswf-footer a,
.nswf-list a,
.nswf-timeline a,
.nswf-partners a,
.nswf-card__foot a,
.nswf-crumbs a {
	display: inline-block;
	min-height: 24px;
	padding-block: 3px;
}

/* Footer columns need a little more room once the links are taller. */
.nswf-footer ul {
	gap: 6px;
}

/*
 * The language pill sat flush against the last navigation item. Both are
 * comfortably over 24px, but WCAG 2.2's target-size rule also cares about
 * the space between adjacent targets - two touching hit areas are easy to
 * mis-tap. A real gap separates the navigation from the header actions.
 */
.nswf-header__actions {
	margin-inline-start: 12px;
}

.nswf-lang-slot {
	margin-inline-end: 4px;
}
