/**
 * "All Brands" mega menu — trigger lives inline in the category bar (see
 * parts/header.html); the panel is positioned relative to it and shown on
 * hover, keyboard focus, or click/tap (see assets/js/all-brands-menu.js
 * for the click/tap + outside-click + Escape handling).
 */

/*
 * align-items: center on the row (.zozia-bar-inner, see header.css) vertically
 * centers every item against the row's tallest sibling — the "₱99 Sale" pill,
 * whose own padding makes it a few pixels taller than a plain text trigger.
 * That centering leaves a hairline gap between the trigger's own bottom edge
 * and where the panel begins (top: 100%, anchored to the row below, not to
 * the trigger) — nothing bridges it, so a careful mouse moving straight down
 * out of the trigger crosses dead space and the panel's :hover drops before
 * the cursor ever reaches it. align-self: stretch makes .zozia-mega-menu
 * fill the row's full height instead of being centered within it, so its own
 * box bottom lands exactly on the row's bottom edge — flush with the panel's
 * top — with no gap left to cross. align-items: center keeps the trigger's
 * label vertically centered inside that now-taller box.
 */
.zozia-mega-menu {
	position: relative;
	display: inline-flex;
	align-items: center;
	align-self: stretch;
}

.zozia-mega-menu__trigger {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	border: none;
	background: none;
	padding: 0;
	margin: 0;
	font-family: inherit;
	line-height: inherit;
	cursor: pointer;
}

.zozia-mega-menu__trigger:hover,
.zozia-mega-menu.is-open .zozia-mega-menu__trigger {
	color: var(--wp--preset--color--primary);
}

.zozia-mega-menu__trigger-icon {
	width: 12px;
	height: 12px;
	flex-shrink: 0;
	transition: transform 0.15s ease;
}

.zozia-mega-menu:hover .zozia-mega-menu__trigger-icon,
.zozia-mega-menu:focus-within .zozia-mega-menu__trigger-icon,
.zozia-mega-menu.is-open .zozia-mega-menu__trigger-icon {
	transform: rotate(180deg);
}

/*
 * The gap between the trigger and the visible panel has to be part of THIS
 * element's own box, not a margin — a margin renders outside the box, so
 * the cursor crossing it is briefly over neither the trigger nor the panel,
 * :hover on .zozia-mega-menu drops, and the panel hides before the pointer
 * ever reaches a link inside it. padding-top keeps that space inside the
 * (still-hoverable) box while staying visually invisible; the actual
 * background/border/shadow live on .zozia-mega-menu__panel-inner below it.
 */
.zozia-mega-menu__panel {
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	padding-top: 20px;
	z-index: 100;
	width: min(980px, calc(100vw - 32px));
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.15s ease;
}

.zozia-mega-menu:hover .zozia-mega-menu__panel,
.zozia-mega-menu:focus-within .zozia-mega-menu__panel,
.zozia-mega-menu.is-open .zozia-mega-menu__panel {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

/*
 * The panel is up to 980px wide, but the "All Brands" trigger is the last
 * item in the category row, so centring the panel on the trigger pushed its
 * right edge past the viewport. The closed panel is only `visibility: hidden`
 * — it still takes part in layout — so that overflow gave every page a
 * horizontal scrollbar, and the open panel was clipped off-screen too.
 *
 * Anchor it to the row container instead. `.zozia-category-inner` ends on the
 * same bottom edge as the trigger (single- or multi-line), so the hover gap
 * described above still lands exactly where it did, and `width: min(980px,
 * 100%)` keeps both panel edges inside the container at any viewport width.
 */
@media (min-width: 861px) {
	.zozia-mega-menu {
		position: static;
	}

	.zozia-category-inner {
		position: relative;
	}

	.zozia-mega-menu__panel {
		width: min(980px, 100%);
	}
}

.zozia-mega-menu__panel-inner {
	padding: var(--wp--preset--spacing--xl);
	background-color: var(--wp--preset--color--white);
	border: 1px solid var(--wp--preset--color--border-light);
	border-radius: 12px;
	box-shadow: 0 16px 40px rgba(36, 16, 25, 0.14);
}

.zozia-mega-menu__heading {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0 0 var(--wp--preset--spacing--lg);
	font-family: var(--wp--preset--font-family--heading, inherit);
	font-size: var(--wp--preset--font-size--x-large);
	font-weight: 800;
	color: var(--wp--preset--color--ink);
	text-decoration: none;
}

.zozia-mega-menu__heading:hover {
	color: var(--wp--preset--color--primary);
}

.zozia-mega-menu__heading svg {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

.zozia-mega-menu__columns {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--2-xl, 48px);
}

.zozia-mega-menu__column {
	min-width: 160px;
}

.zozia-mega-menu__column--wide {
	flex: 1 1 260px;
}

.zozia-mega-menu__column-title {
	margin: 0 0 var(--wp--preset--spacing--sm);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 700;
	color: var(--wp--preset--color--ink);
}

.zozia-mega-menu__column-divider {
	margin: 0 0 var(--wp--preset--spacing--sm);
	border: none;
	border-top: 1px solid var(--wp--preset--color--border-light);
}

.zozia-mega-menu__empty {
	margin: 0;
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--muted);
}

.zozia-mega-menu__list {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.zozia-mega-menu__list a {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--ink);
	text-decoration: none;
}

.zozia-mega-menu__list a:hover {
	color: var(--wp--preset--color--primary);
	text-decoration: underline;
}

.zozia-mega-menu__brands {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.zozia-mega-menu__brand-logo {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 64px;
	padding: 8px 16px;
	border: 1px solid var(--wp--preset--color--border-light);
	border-radius: 8px;
	background-color: var(--wp--preset--color--white);
}

.zozia-mega-menu__brand-logo img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

.zozia-mega-menu__alphabet {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 14px 20px;
}

.zozia-mega-menu__letter {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
	color: var(--wp--preset--color--ink);
	text-decoration: none;
}

.zozia-mega-menu__letter:hover {
	color: var(--wp--preset--color--primary);
	text-decoration: underline;
}

.zozia-mega-menu__letter.is-disabled {
	font-weight: 400;
	color: var(--wp--preset--color--muted);
	opacity: 0.45;
	pointer-events: none;
}

/**
 * Below the category bar's own collapse point, the panel drops the
 * floating-overlay treatment and becomes a simple stacked section inside
 * the open mobile menu instead (position: static, full width, columns
 * stacked). Kept hidden until .is-open — hover/focus-within don't apply on
 * touch, so the click handling in assets/js/all-brands-menu.js is what
 * opens it there.
 */
@media (max-width: 860px) {
	.zozia-mega-menu {
		display: block;
		width: 100%;
	}

	/* space-between (not the base rule's inline-flex hugging the label)
	   pushes the chevron to the row's far edge — inside the open mobile
	   menu this trigger sits among plain full-width links (see
	   assets/css/header.css), so a chevron floating right next to the
	   label instead of lining up with the rest of the list read as
	   misaligned. */
	.zozia-mega-menu__trigger {
		display: flex;
		justify-content: space-between;
		width: 100%;
		text-align: left;
	}

	/* `display: none`, not just the shared `visibility: hidden`. As an
	   absolutely-positioned overlay a hidden panel costs no space, but here
	   it is `position: static` and back in the flow — so each closed panel
	   was padding the open mobile menu with ~1000px of blank white before
	   the next category link. */
	.zozia-mega-menu__panel {
		position: static;
		transform: none;
		width: 100%;
		padding-top: 0;
		margin-top: 12px;
		display: none;
	}

	.zozia-mega-menu:hover .zozia-mega-menu__panel,
	.zozia-mega-menu:focus-within .zozia-mega-menu__panel {
		opacity: 0;
		visibility: hidden;
		pointer-events: none;
	}

	/* The chevron has to be reset the same way. Upstream it flips on hover
	   and focus-within because those states open the desktop panel — here
	   only .is-open does, and a tapped button keeps focus (plus a sticky
	   :hover on touch), so the arrow stayed pointing up over a closed panel
	   and never flipped back on subsequent taps. */
	.zozia-mega-menu:hover .zozia-mega-menu__trigger-icon,
	.zozia-mega-menu:focus-within .zozia-mega-menu__trigger-icon {
		transform: none;
	}

	.zozia-mega-menu.is-open .zozia-mega-menu__trigger-icon {
		transform: rotate(180deg);
	}

	.zozia-mega-menu.is-open .zozia-mega-menu__panel {
		display: block;
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
	}

	.zozia-mega-menu__panel-inner {
		padding: var(--wp--preset--spacing--md);
		box-shadow: none;
		border-radius: 8px;
	}

	.zozia-mega-menu__columns {
		flex-direction: column;
		gap: var(--wp--preset--spacing--lg);
	}

	.zozia-mega-menu__alphabet {
		grid-template-columns: repeat(5, 1fr);
	}
}

/**
 * "Makeup" mega menu — same .zozia-mega-menu trigger/panel/hover mechanics
 * as the "All Brands" menu above; these rules only style what's specific
 * to it: a group per Makeup subcategory (icon + title, linking to the
 * subcategory archive) with its own children listed underneath. Column
 * assignment for the 3 groups-per-column split happens in PHP — see
 * zozia_beauty_get_makeup_menu_columns() in blocks/makeup-menu/render.php.
 */
.zozia-makeup-menu__column {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	min-width: 180px;
	gap: var(--wp--preset--spacing--lg);
}

.zozia-makeup-menu__group {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.zozia-makeup-menu__group-heading {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	text-decoration: none;
}

.zozia-makeup-menu__group-icon {
	width: 40px;
	height: 40px;
	flex-shrink: 0;
	object-fit: cover;
	border: 1px solid var(--wp--preset--color--border-light);
	border-radius: 8px;
	background-color: var(--wp--preset--color--white);
}

.zozia-makeup-menu__group-title {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 700;
	color: var(--wp--preset--color--ink);
}

.zozia-makeup-menu__group-heading:hover .zozia-makeup-menu__group-title {
	color: var(--wp--preset--color--primary);
}

/* Indent children past the icon so they align under the group title. */
.zozia-makeup-menu__group-list {
	gap: 8px;
	padding-left: 50px;
}

@media (max-width: 860px) {
	.zozia-makeup-menu__column {
		min-width: 0;
	}

	.zozia-makeup-menu__group-list {
		padding-left: 0;
	}
}
