/*
 * Top bar, sticky header (main row + categories row), search, actions and the categories row.
 *
 * Structure: .cw-header > .cw-header__main (84px, z 2) + .cw-header__categories (56px, absolute under the
 * main row, z 1). A .cw-header__spacer of the same height follows the header in the flow, so the document
 * height never changes when the categories row hides (that would loop the scroll handler and flicker).
 * One 140px brand-to-bg gradient is split between both rows (background-position on the second).
 * Scroll state classes on .cw-header (set by assets/js/header.js): is-scrolled, is-categories-hidden.
 */
.cw-topbar {
	background: var(--cw-color-brand);
	color: var(--cw-color-brand-ink);
}

.cw-topbar__row {
	display: flex;
	min-height: var(--cw-topbar-h);
	align-items: center;
	justify-content: space-between;
	gap: 24px;
}

.cw-topbar__text {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	font-size: 13px;
	font-weight: 700;
	line-height: 1.3;
}

.cw-topbar__link {
	color: inherit;
	text-decoration: none;
}

.cw-topbar__link:hover,
.cw-topbar__link:focus-visible {
	text-decoration: underline;
	text-underline-offset: 4px;
}

.cw-topbar__star {
	color: var(--cw-color-accent);
	font-size: 14px;
	line-height: 1;
}

.cw-topbar__nav {
	margin-left: auto;
}

.cw-topbar__menu {
	display: flex;
	align-items: center;
	gap: 24px;
	margin: 0;
	padding: 0;
	font-size: 13px;
	font-weight: 500;
	list-style: none;
}

.cw-topbar__menu a {
	color: inherit;
	text-decoration: none;
}

.cw-topbar__menu a:hover,
.cw-topbar__menu a:focus-visible {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 4px;
}

.cw-header {
	--cw-header-main-h: 84px;
	--cw-header-categories-h: 56px;
	--cw-header-gradient-h: 140px;
	--cw-header-shadow: 0 8px 24px color-mix(in srgb, var(--cw-color-ink) 10%, transparent);
	--cw-header-glass: color-mix(in srgb, var(--cw-color-surface) 75%, transparent);
	--cw-header-hairline: color-mix(in srgb, var(--cw-color-ink) 8%, transparent);
	position: sticky;
	z-index: var(--cw-z-header);
	top: var(--cw-admin-bar-offset);
	width: 100%;
	color: var(--cw-color-ink);
	font-size: 14px;
	line-height: 1.4;
}

.cw-header a {
	color: inherit;
	text-decoration: none;
}

.cw-header__main,
.cw-header__categories {
	background-color: var(--cw-color-bg);
	background-image: linear-gradient(var(--cw-color-brand), var(--cw-color-bg));
	background-repeat: no-repeat;
	background-size: 100% var(--cw-header-gradient-h);
}

.cw-header__main {
	position: relative;
	z-index: 2;
	transition: box-shadow .2s ease;
}

/* Shadow goes on the main row when the categories row is hidden... */
.cw-header.is-scrolled.is-categories-hidden .cw-header__main {
	box-shadow: var(--cw-header-shadow);
}

.cw-header__row {
	display: grid;
	height: var(--cw-header-main-h);
	grid-template-areas: "logo search actions";
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 28px;
}

.cw-header__menu-button {
	display: none;
	grid-area: menu;
}

.cw-logo {
	display: flex;
	grid-area: logo;
	align-items: center;
	justify-content: flex-start;
}

/* Two classes: must beat `.woocommerce-page img { height: auto; max-width: 100% }` (0,1,1) of woocommerce-layout.css. */
.cw-header .cw-logo__image {
	display: block;
	width: auto;
	max-width: 200px;
	height: 56px;
	object-fit: contain;
}

.cw-logo__text {
	font-size: 19px;
	font-weight: 700;
}

.cw-header__mobile-search {
	display: none;
}

.cw-header__search {
	grid-area: search;
	min-width: 0;
}

/* Search form (also used on the 404 page). */
.cw-search {
	position: relative;
	min-width: 0;
}

.cw-search__input {
	width: 100%;
	height: 50px;
	margin: 0;
	padding: 0 60px 0 18px;
	border: 1px solid color-mix(in srgb, var(--cw-color-ink) 8%, transparent);
	border-radius: var(--cw-radius-lg);
	background: var(--cw-color-surface);
	box-shadow: 0 4px 14px color-mix(in srgb, var(--cw-color-ink) 6%, transparent);
	color: var(--cw-color-ink);
	font-size: 15px;
	font-weight: 500;
	-webkit-appearance: none;
	appearance: none;
}

.cw-search__input::placeholder {
	color: var(--cw-color-muted);
	opacity: 1;
}

.cw-search__submit {
	position: absolute;
	top: 5px;
	right: 5px;
	display: grid;
	width: 44px;
	height: 40px;
	margin: 0;
	padding: 0;
	place-items: center;
	border: 0;
	border-radius: calc(var(--cw-radius-lg) - 4px);
	background: var(--cw-color-button);
	color: var(--cw-color-button-ink);
	cursor: pointer;
	transition: filter .15s ease;
}

.cw-search__submit:hover,
.cw-search__submit:focus-visible {
	filter: brightness(.94);
}

.cw-search__submit .cw-icon {
	width: 20px;
	height: 20px;
	stroke-width: 2;
}

.cw-header__actions {
	display: flex;
	grid-area: actions;
	align-items: center;
	justify-content: flex-end;
	gap: 18px;
}

.cw-header__quote {
	display: inline-flex;
	height: 46px;
	align-items: center;
	gap: 8px;
	padding: 0 16px;
	border: 1px solid var(--cw-header-hairline);
	border-radius: var(--cw-radius-lg);
	background: var(--cw-header-glass);
	font-size: 14px;
	font-weight: 700;
	transition: filter .15s ease;
}

.cw-header__quote .cw-icon {
	width: 18px;
	height: 18px;
}

.cw-header .cw-header__quote:hover,
.cw-header .cw-header__quote:focus-visible {
	filter: brightness(.97);
}

.cw-account {
	position: relative;
}

.cw-account__link {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 46px;
}

.cw-account__text {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
	white-space: nowrap;
}

.cw-account__greeting {
	max-width: 130px;
	overflow: hidden;
	color: var(--cw-color-muted);
	font-size: 12px;
	text-overflow: ellipsis;
}

.cw-account__label {
	font-size: 14px;
	font-weight: 700;
}

.cw-account__menu {
	position: absolute;
	z-index: 20;
	top: calc(100% + 10px);
	right: 0;
	display: grid;
	visibility: hidden;
	width: 190px;
	padding: 8px;
	border: 1px solid var(--cw-color-line);
	border-radius: var(--cw-radius);
	background: var(--cw-color-surface);
	box-shadow: var(--cw-shadow-md);
	opacity: 0;
	transform: translateY(-4px);
	transition: opacity .15s ease, transform .15s ease, visibility .15s;
}

/* Invisible bridge so the menu does not close while the pointer crosses the gap. */
.cw-account__menu::before {
	position: absolute;
	right: 0;
	bottom: 100%;
	left: 0;
	height: 12px;
	content: "";
}

.cw-account:hover .cw-account__menu,
.cw-account:focus-within .cw-account__menu {
	visibility: visible;
	opacity: 1;
	transform: none;
}

.cw-account__item {
	padding: 9px 10px;
	border-radius: var(--cw-radius);
}

.cw-account__item:hover {
	background: var(--cw-color-bg);
}

/* Cart button: 46px box with the counter, then "Tu carrito" and the subtotal. */
.cw-header__cart {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--cw-color-ink);
	cursor: pointer;
	text-align: left;
}

.cw-header__cart-box {
	position: relative;
	display: grid;
	width: 46px;
	height: 46px;
	flex: 0 0 auto;
	place-items: center;
	border-radius: var(--cw-radius);
	background: var(--cw-header-glass);
}

.cw-header__cart-count {
	position: absolute;
	top: -6px;
	right: -8px;
	display: grid;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	place-items: center;
	border: 2px solid var(--cw-color-surface);
	border-radius: var(--cw-radius-pill);
	background: var(--cw-color-accent);
	color: var(--cw-color-accent-ink);
	font-size: 12px;
	font-weight: 800;
	line-height: 1;
}

.cw-header__cart-count[hidden] {
	display: none;
}

.cw-header__cart-text {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
	white-space: nowrap;
}

.cw-header__cart-label {
	color: var(--cw-color-muted);
	font-size: 12px;
}

.cw-header__cart-subtotal {
	font-size: 14px;
	font-weight: 800;
}

.cw-header__cart-subtotal:empty {
	display: none;
}

/*
 * Categories row. Hidden state: slides up behind the main row (transform only, so the layout does not move)
 * and fades out. `visibility: hidden` is applied when the transition ends, which removes its links from the
 * tab order and from the accessibility tree: they never receive focus while the row is out of sight.
 */
.cw-header__categories {
	position: absolute;
	z-index: 1;
	top: 100%;
	right: 0;
	left: 0;
	height: var(--cw-header-categories-h);
	background-position: 0 calc(-1 * var(--cw-header-main-h));
	transition: transform .25s ease, opacity .2s ease, box-shadow .2s ease, visibility 0s;
}

/* ...and on the categories row while it is visible. */
.cw-header.is-scrolled:not(.is-categories-hidden) .cw-header__categories {
	box-shadow: var(--cw-header-shadow);
}

.cw-header.is-categories-hidden .cw-header__categories {
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
	transform: translateY(-100%);
	transition: transform .25s ease, opacity .2s ease, box-shadow .2s ease, visibility 0s linear .25s;
}

.cw-header__categories-row {
	display: flex;
	height: 100%;
	align-items: center;
	gap: 28px;
}

.cw-header .cw-header__all {
	min-height: 40px;
	flex: 0 0 auto;
	font-weight: 700;
	box-shadow: var(--cw-shadow-sm);
}

.cw-header__all .cw-icon {
	width: 20px;
	height: 20px;
}

.cw-header__all .cw-header__all-caret {
	width: 16px;
	height: 16px;
	transition: transform .2s ease;
}

.cw-header__all[aria-expanded="true"] .cw-header__all-caret {
	transform: rotate(180deg);
}

.cw-header__featured-nav {
	display: flex;
	min-width: 0;
	flex: 1;
	align-items: center;
	gap: 26px;
}

/* wp_nav_menu() markup (or the featured categories fallback). */
.cw-header__featured {
	display: flex;
	align-items: center;
	gap: 26px;
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cw-header__featured a,
.cw-header__offers {
	font-size: 15px;
	font-weight: 500;
	white-space: nowrap;
}

.cw-header__featured a {
	color: var(--cw-color-text-body);
}

.cw-header .cw-header__featured a:hover,
.cw-header .cw-header__featured a:focus-visible,
.cw-header .cw-header__featured .current-menu-item > a {
	color: var(--cw-color-ink);
	text-decoration: underline;
	text-underline-offset: 6px;
}

.cw-header .cw-header__offers {
	color: var(--cw-color-accent);
	font-weight: 700;
}

.cw-header .cw-header__offers:hover,
.cw-header .cw-header__offers:focus-visible {
	text-decoration: underline;
	text-underline-offset: 6px;
}

.cw-header__locations {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin-left: auto;
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
}

.cw-header__locations .cw-icon {
	width: 18px;
	height: 18px;
}

.cw-header__spacer {
	height: var(--cw-header-categories-h, 56px);
}

@media (max-width: 1180px) {
	.cw-header__row {
		gap: 18px;
	}

	.cw-header__featured li:nth-child(n + 5) {
		display: none;
	}
}

@media (max-width: 1060px) {
	.cw-header__quote-label,
	.cw-header__cart-text {
		display: none;
	}

	.cw-header__quote {
		width: 46px;
		justify-content: center;
		padding: 0;
	}

	.cw-header__featured li:nth-child(n + 4) {
		display: none;
	}
}

/*
 * Mobile (< 900px): the sticky header holds ONLY the first row (menu button, logo, cart). The search lives in its
 * own block printed right after the header (.cw-header__mobile-search, header.php), so it scrolls away while the
 * row stays pinned (a negative `top` cannot do it: it would hide the first row, not the search). The desktop search
 * slot of the row is hidden here and the mobile block is hidden on desktop, so there is a single visible input at a
 * time. The categories row, the spacer and the mega menu do not exist. The admin bar offset (--cw-admin-bar-offset)
 * is 0 below 600px, where the admin bar is absolute.
 */
@media (max-width: 899px) {
	/*
	 * On :root (not .cw-header) because the mobile search block is a sibling of the header, not a child.
	 * The brand gradient spans row + search as one band (prototype): the row paints its top part and the
	 * search block continues it from the row height (--cw-header-mobile-main-h).
	 */
	:root {
		--cw-header-mobile-row-h: 44px;
		--cw-header-mobile-pad-y: 6px;
		--cw-header-mobile-search-h: 48px;
		--cw-header-mobile-search-pad-b: 14px;
		--cw-header-mobile-main-h: calc(var(--cw-header-mobile-row-h) + 2 * var(--cw-header-mobile-pad-y));
		--cw-header-mobile-gradient-h: calc(var(--cw-header-mobile-main-h) + var(--cw-header-mobile-search-h) + var(--cw-header-mobile-search-pad-b));
	}

	.cw-header__mobile-search {
		display: block;
		padding-block: 0 var(--cw-header-mobile-search-pad-b);
		background-color: var(--cw-color-bg);
		background-image: linear-gradient(var(--cw-color-brand), var(--cw-color-bg));
		background-position: 0 calc(-1 * var(--cw-header-mobile-main-h));
		background-repeat: no-repeat;
		background-size: 100% var(--cw-header-mobile-gradient-h);
	}

	.cw-header__search {
		display: none;
	}

	.cw-topbar__row {
		min-height: 30px;
		justify-content: center;
	}

	.cw-topbar__text {
		font-size: 12px;
	}

	.cw-topbar__nav {
		display: none;
	}

	.cw-header__main {
		background-size: 100% var(--cw-header-mobile-gradient-h);
	}

	.cw-header__row {
		height: auto;
		grid-template-areas: "menu logo actions";
		grid-template-columns: var(--cw-header-mobile-row-h) 1fr var(--cw-header-mobile-row-h);
		gap: 12px;
		padding-block: var(--cw-header-mobile-pad-y);
	}

	.cw-header__menu-button {
		display: grid;
		border-radius: var(--cw-radius);
		background: var(--cw-header-glass);
	}

	.cw-header__menu-button .cw-icon {
		width: 20px;
		height: 20px;
	}

	.cw-logo {
		justify-content: center;
	}

	.cw-header .cw-logo__image {
		height: var(--cw-header-mobile-row-h);
		max-width: 160px;
	}

	.cw-header__quote,
	.cw-account,
	.cw-header__categories,
	.cw-header__spacer,
	.cw-header__cart-text {
		display: none;
	}

	.cw-header__actions {
		gap: 0;
	}

	.cw-header__cart-box {
		width: var(--cw-header-mobile-row-h);
		height: var(--cw-header-mobile-row-h);
	}

	.cw-header__cart-count {
		top: -5px;
		right: -6px;
		min-width: 20px;
		height: 20px;
		font-size: 11px;
	}

	.cw-search__input {
		height: var(--cw-header-mobile-search-h);
	}

	.cw-search__submit {
		top: 4px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-header__main,
	.cw-header__categories,
	.cw-header.is-categories-hidden .cw-header__categories,
	.cw-header__all .cw-header__all-caret {
		transition: none;
	}
}
