/* ===================================================================
 * Mega-menu — the Insurance Services panel
 *
 * Measured off "HOMEPAGE - with drop down menu 5 B.pdf", the only artwork
 * that shows the panel open. Its numbers are on an 1822px sheet; everything
 * below is converted to the theme's 1300px sheet with the same 0.7135 factor
 * that reproduces the documented 158px header height.
 *
 *   panel        flush under the header, ~440px tall (content decides)
 *   three blocks Personal / Business / categories, roughly 28% / 48% / 24%
 *   item rhythm  ~20px line box
 *
 * One deliberate departure: the artwork composites the panel as white at 85%
 * over the hero photograph. Here it is opaque. The artwork only ever shows it
 * over a photo, whereas on an inner page it falls across body copy, and a
 * translucent panel makes both unreadable. Change --mega-menu-bg below to
 * rgba(255, 255, 255, 0.85) to get the artwork's version back.
 *
 * Above 1024px the panel is a dropdown; below it, an accordion inside the
 * existing off-canvas. The breakpoint is written literally, per the convention
 * in tokens.css — custom properties do not work inside @media.
 * =================================================================== */

:root {
	--mega-menu-bg: var(--color-bg);
}

/* ===================================================================
 * The trigger beside the link
 * =================================================================== */

.mega-menu__toggle {
	display: inline-flex;
	width: 44px;
	height: 44px;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
}

.mega-menu__caret {
	width: 0;
	height: 0;
	border-top: 5px solid currentColor;
	border-right: 4px solid transparent;
	border-left: 4px solid transparent;
	transition: transform var(--transition-fast);
}

.mega-menu__toggle[aria-expanded="true"] .mega-menu__caret {
	transform: rotate(180deg);
}

.mega-menu__toggle:hover,
.mega-menu__toggle:focus-visible {
	color: var(--color-accent);
}

/* ===================================================================
 * Shared panel content
 * =================================================================== */

.mega-menu__inner {
	display: grid;
	gap: var(--space-8);
}

.mega-menu__group-link,
.mega-menu__category-link {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	text-decoration: none;
}

.mega-menu__group-title,
.mega-menu__category-title {
	color: var(--color-heading);
	font-family: var(--font-display);
	font-size: var(--fs-sm);
	font-weight: var(--fw-bold);
	letter-spacing: var(--ls-wide);
	text-transform: uppercase;
	white-space: nowrap;
}

.mega-menu__group-link:hover .mega-menu__group-title,
.mega-menu__group-link:focus-visible .mega-menu__group-title,
.mega-menu__category-link:hover .mega-menu__category-title,
.mega-menu__category-link:focus-visible .mega-menu__category-title {
	color: var(--color-accent);
}

.mega-menu__icon {
	width: auto;
	height: 34px;
	flex: none;
}

/*
 * The category icons (Life, Health, Disability, Long Term Care) differ in
 * aspect ratio, so at a shared height their widths differ and each label
 * started at a different x. A fixed-width box with the icon pinned to its
 * left edge lines the labels up, left-justified.
 */
.mega-menu__category-link .mega-menu__icon {
	width: 3.4rem;
	object-fit: contain;
	object-position: left center;
}

.mega-menu__list,
.mega-menu__categories {
	margin: 0;
	padding: 0;
	list-style: none;
}

.mega-menu__item {
	margin: 0;
}

/* Beats .site-nav__list a, which styles the top-level items. */
.mega-menu__link {
	display: block;
	padding: var(--space-1) 0;
	color: var(--color-text);
	font-size: var(--fs-sm);
	font-weight: var(--fw-regular);
	line-height: var(--lh-tight);
	text-decoration: none;
	white-space: normal;
}

.mega-menu__link:hover,
.mega-menu__link:focus-visible {
	color: var(--color-accent);
	text-decoration: underline;
}

.mega-menu .mega-menu__link[aria-current="page"],
.mega-menu .mega-menu__group-link[aria-current="page"] .mega-menu__group-title,
.mega-menu .mega-menu__category-link[aria-current="page"] .mega-menu__category-title {
	color: var(--color-primary);
	font-weight: var(--fw-bold);
}

/* ===================================================================
 * Below 1024px — an accordion inside the off-canvas panel
 * =================================================================== */

@media (max-width: 1023px) {
	.site-nav__item.has-mega-menu {
		display: grid;
		grid-template-columns: 1fr auto;
		align-items: center;
	}

	/*
	 * The client found the bare triangle too subtle to notice on a phone, so
	 * here the trigger is drawn as a button: a burgundy ring with a heavier
	 * chevron, filled when the accordion is open. Desktop hides it entirely.
	 */
	.mega-menu__toggle {
		margin-right: var(--space-2);
		border: 2px solid currentColor;
		border-radius: 50%;
		color: var(--color-nav);
		transition:
			background-color var(--transition-fast),
			color var(--transition-fast);
	}

	.mega-menu__caret {
		width: 10px;
		height: 10px;
		margin-top: -4px;
		border: 0;
		border-right: 2.5px solid currentColor;
		border-bottom: 2.5px solid currentColor;
		transform: rotate(45deg);
	}

	.mega-menu__toggle[aria-expanded="true"] {
		background-color: var(--color-nav);
		color: var(--color-bg);
	}

	.mega-menu__toggle[aria-expanded="true"] .mega-menu__caret {
		margin-top: 4px;
		transform: rotate(-135deg);
	}

	.mega-menu__toggle[aria-expanded="true"]:hover,
	.mega-menu__toggle[aria-expanded="true"]:focus-visible {
		background-color: var(--color-accent);
		color: var(--color-bg);
	}

	.site-nav__item.has-mega-menu > .mega-menu {
		display: none;
		grid-column: 1 / -1;
	}

	.site-nav__item.has-mega-menu > .mega-menu.is-open {
		display: block;
	}

	/*
	 * .container is on the inner element for the desktop dropdown's sake; inside
	 * a 22rem drawer its page gutter only eats width, so it is dropped here.
	 */
	.mega-menu__inner {
		max-width: none;
		gap: var(--space-6);
		padding: var(--space-2) 0 var(--space-4);
	}

	.mega-menu__group-link {
		margin-bottom: var(--space-2);
	}

	.mega-menu__icon {
		height: 28px;
	}

	.mega-menu__category-link .mega-menu__icon {
		width: 2.8rem;
	}

	.mega-menu__categories {
		display: grid;
		gap: var(--space-2);
		border-top: 1px solid var(--color-border);
		padding-top: var(--space-4);
	}
}

/* ===================================================================
 * 1024px and up — the dropdown from the design
 * =================================================================== */

@media (min-width: 1024px) {
	.site-nav__item.has-mega-menu {
		position: static;
	}

	.mega-menu {
		position: absolute;
		z-index: var(--z-dropdown);
		top: 100%;
		right: 0;
		left: 0;
		/*
		 * The header stays on screen (Task 016), so the panel has to as well:
		 * on a short laptop it scrolls inside instead of running off the
		 * bottom. --header-h is the live header height, from main.js.
		 */
		max-height: calc(100dvh - var(--header-h, 160px) - var(--wp-admin--admin-bar--height, 0px));
		overflow-y: auto;
		overscroll-behavior: contain;
		border-top: 2px solid var(--color-accent);
		background-color: var(--mega-menu-bg);
		box-shadow: var(--shadow-md);
		opacity: 0;
		transition:
			opacity var(--transition-base),
			transform var(--transition-base),
			visibility var(--transition-base);
		transform: translateY(-8px);
		visibility: hidden;
	}

	/*
	 * Hover is driven from main.js rather than from a :hover rule here, so that
	 * the toggle can actually close the panel: a CSS :hover would hold it open
	 * under the pointer and make the button look broken. :focus-within stays as
	 * the rule, so the panel is still reachable by keyboard if the script fails.
	 */
	.site-nav__item.has-mega-menu:focus-within > .mega-menu,
	.mega-menu.is-open {
		opacity: 1;
		transform: translateY(0);
		visibility: visible;
	}

	.mega-menu__inner {
		grid-template-columns: 28fr 48fr 24fr;
		align-items: start;
		gap: var(--space-8);
		padding-top: var(--space-8);
		padding-bottom: var(--space-8);
	}

	/* The design centres each heading over its own pair of columns. */
	.mega-menu__group-link {
		justify-content: center;
		margin-bottom: var(--space-6);
	}

	.mega-menu__categories {
		display: grid;
		gap: var(--space-4);
		border-left: 1px solid var(--color-border);
		padding-left: var(--space-8);
	}

	/*
	 * The artwork's nav carries no disclosure arrow: the five items sit on one
	 * baseline and the panel opens on hover. Hiding the button restores both.
	 * It was also what broke the alignment — the <a> is display:block, so the
	 * button fell onto a second line and made this <li> taller than its
	 * siblings, which align-items:center then centred, lifting the label.
	 * main.js binds hover and focus to the <li>, not to the button, so nothing
	 * depends on it being visible here; the accordion below 1024px keeps it.
	 */
	.mega-menu__toggle {
		display: none;
	}

	/*
	 * Two columns, balanced by the browser. The artwork cuts Personal 6/8 and
	 * Business 11/12 — not down the middle, but wherever the two sides come out
	 * the same height, which depends on how many labels wrap. Only the renderer
	 * knows that, so the list is emitted whole and CSS does the balancing; it
	 * also stays right as lines are added or hidden.
	 */
	.mega-menu__list {
		columns: 2;
		column-gap: var(--space-6);
	}

	.mega-menu__item {
		break-inside: avoid;
	}
}

/*
 * Between 1024 and 1199px the category column never narrows below its own
 * labels: they are nowrap, and a plain 24fr cut LONG TERM CARE off at the
 * screen edge (and scrolled the page sideways by 7px even with the panel
 * closed). Not applied from 1200px up, where it would move the Business
 * column split that was matched against the art (Task011).
 */
@media (min-width: 1024px) and (max-width: 1199px) {
	.mega-menu__inner {
		grid-template-columns: 28fr 48fr minmax(max-content, 24fr);
	}
}
