/*
 * Categories mega menu (desktop). Printed inside the categories row of the header (template-parts/header/mega-menu.php),
 * right under it. Columns: 280px category list | subcategory panels | optional promo (300px).
 * Behavior: assets/js/header.js.
 */
.cw-mega-menu {
	position: absolute;
	z-index: 3;
	top: calc(100% - 2px);
	right: 0;
	left: 0;
	/* The full-width wrapper is transparent: only the panel receives pointer events, so clicks beside it reach the page. */
	pointer-events: none;
}

.cw-mega-menu[hidden] {
	display: none;
}

.cw-mega-menu__panel {
	display: grid;
	/* Fits the viewport even at scroll 0 (topbar + main row + categories row above it); columns scroll inside. */
	max-height: calc(100vh - var(--cw-topbar-h) - var(--cw-header-main-h) - var(--cw-header-categories-h) - var(--cw-admin-bar-offset) - 16px);
	grid-template-columns: 280px minmax(0, 1fr) 300px;
	grid-template-rows: minmax(0, 1fr);
	overflow: hidden;
	pointer-events: auto;
	border: 1px solid var(--cw-color-line);
	border-radius: var(--cw-radius);
	background: var(--cw-color-surface);
	box-shadow: var(--cw-shadow-lg);
}

.cw-mega-menu__panel--no-promo {
	grid-template-columns: 280px minmax(0, 1fr);
}

.cw-mega-menu:not([hidden]) .cw-mega-menu__panel {
	animation: cw-mega-menu-in .18s ease both;
}

@keyframes cw-mega-menu-in {
	from {
		opacity: 0;
		transform: translateY(-6px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

.cw-mega-menu :focus-visible {
	outline-offset: -3px;
}

/* Column 1: categories. The list scrolls; "Ver todas las categorías" stays pinned at the bottom of the column. */
.cw-mega-menu__nav {
	display: flex;
	min-height: 0;
	flex-direction: column;
	overflow: hidden;
	border-right: 1px solid var(--cw-color-line-soft);
}

.cw-mega-menu__list {
	display: flex;
	min-height: 0;
	flex: 1 1 auto;
	flex-direction: column;
	gap: 2px;
	margin: 0;
	padding: 14px;
	overflow-y: auto;
	list-style: none;
}

.cw-mega-menu__item {
	display: flex;
	width: 100%;
	align-items: center;
	gap: 12px;
	margin: 0;
	padding: 10px 12px;
	border: 0;
	border-radius: var(--cw-radius);
	background: transparent;
	color: var(--cw-color-ink);
	cursor: pointer;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
	text-align: left;
}

.cw-mega-menu__item:hover {
	background: var(--cw-color-bg);
}

.cw-mega-menu__item.is-active {
	background: var(--cw-color-brand-soft);
}

.cw-mega-menu__icon {
	display: grid;
	width: 36px;
	height: 36px;
	flex: 0 0 auto;
	place-items: center;
	border-radius: var(--cw-radius);
	background: var(--cw-color-subtle);
}

.cw-mega-menu__item.is-active .cw-mega-menu__icon {
	background: var(--cw-color-surface);
}

.cw-mega-menu__icon .cw-icon {
	width: 18px;
	height: 18px;
	color: var(--cw-color-text-body);
}

/* Image rules use two classes to beat `.woocommerce-page img` (0,1,1) of woocommerce-layout.css. */
.cw-mega-menu .cw-mega-menu__thumb {
	display: block;
	width: 24px;
	height: 24px;
	object-fit: contain;
}

.cw-mega-menu__name {
	min-width: 0;
	flex: 1;
}

.cw-mega-menu__chevron {
	width: 16px;
	height: 16px;
	color: var(--cw-color-muted);
}

.cw-header .cw-mega-menu__all {
	display: block;
	flex: 0 0 auto;
	margin: 0;
	padding: 14px 26px;
	border-top: 1px solid var(--cw-color-line-soft);
	background: var(--cw-color-surface);
	font-size: 14px;
	font-weight: 600;
}

.cw-header .cw-mega-menu__all:hover,
.cw-header .cw-mega-menu__all:focus-visible {
	text-decoration: underline;
	text-underline-offset: 4px;
}

/* Column 2: subcategories of the active category + frequent searches. */
.cw-mega-menu__content {
	display: flex;
	min-width: 0;
	min-height: 0;
	flex-direction: column;
	gap: 14px;
	padding: 26px 30px;
	overflow-y: auto;
}

.cw-mega-menu__section {
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.cw-mega-menu__section[hidden] {
	display: none;
}

.cw-mega-menu__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 16px;
}

.cw-mega-menu__title {
	margin: 0;
	font-size: 20px;
	letter-spacing: -.01em;
}

.cw-header .cw-mega-menu__see-all {
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
}

.cw-header .cw-mega-menu__see-all:hover,
.cw-header .cw-mega-menu__see-all:focus-visible {
	text-decoration: underline;
	text-underline-offset: 4px;
}

.cw-mega-menu__children {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 2px 24px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cw-mega-menu__children a {
	display: block;
	padding: 6px 0;
	color: var(--cw-color-text-2);
	font-size: 14px;
}

.cw-header .cw-mega-menu__children a:hover,
.cw-header .cw-mega-menu__children a:focus-visible {
	color: var(--cw-color-ink);
	text-decoration: underline;
	text-underline-offset: 4px;
}

.cw-mega-menu__frequent {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-top: auto;
}

.cw-mega-menu__frequent-label {
	color: var(--cw-color-muted);
	font-size: 13px;
}

.cw-mega-menu__frequent .cw-chip {
	height: 32px;
	font-size: 13px;
}

/* Column 3: promo card. */
.cw-mega-menu__promo {
	position: relative;
	display: flex;
	margin: 14px;
	padding: 22px;
	flex-direction: column;
	align-items: flex-start;
	gap: 8px;
	overflow: hidden;
	border-radius: var(--cw-radius);
	background: var(--cw-color-brand-soft);
}

.cw-mega-menu__promo-title {
	max-width: 170px;
	color: var(--cw-color-ink);
	font-family: var(--cw-font-heading);
	font-size: 20px;
	font-weight: var(--cw-font-weight-heading);
	line-height: 1.15;
}

.cw-mega-menu__promo-cta {
	margin-top: auto;
	color: var(--cw-color-ink);
	font-size: 14px;
	font-weight: 700;
}

a.cw-mega-menu__promo:hover .cw-mega-menu__promo-cta,
a.cw-mega-menu__promo:focus-visible .cw-mega-menu__promo-cta {
	text-decoration: underline;
	text-underline-offset: 4px;
}

.cw-mega-menu .cw-mega-menu__promo-image {
	position: absolute;
	right: -20px;
	bottom: -20px;
	width: 150px;
	height: 150px;
	object-fit: contain;
	pointer-events: none;
}

@media (max-width: 899px) {
	.cw-mega-menu {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-mega-menu:not([hidden]) .cw-mega-menu__panel {
		animation: none;
	}
}
