/*
 * Header layer: top header, sticky header, mega menu, dropdown, icons and the
 * mobile drawer. Numbers come from .scratch/header-polish/spec.md and are
 * checked by `make test-header`; the class names in the templates are the ones
 * that test selects, so renaming one means updating tests/visual/header.spec.mjs.
 * Mobile first: base styles are the compact header, min-width queries add the
 * desktop tiers.
 */

/* Tier variables. The top header, the sticky header and the drawer read the same names. */
.main-header,
.fixed-header,
.st-menu {
	--band: 8px;
	--band-solid: 3px;
	--bar: 60px;
	--logo: 36px;
	--gutter: 16px;
	--hit: 44px;
	--circle: 36px;
	--glyph: 14px;
	--icon-gap: 0px;
	--item-gap: 16px;
	--group-gap: 24px;
	/* Visible space between the Search circle and the hamburger bars. */
	--cluster-gap: 8px;
}

/* Bar -------------------------------------------------------------------- */

.header-wrapper {
	position: absolute;
	inset: 0 0 auto;
	z-index: 1000;
}

.main-header,
.fixed-header {
	position: relative;
	height: calc(var(--band) + var(--bar));
	padding-top: var(--band);
}

.main-header {
	background: rgb(255 255 255 / 0.75);
}

.fixed-header {
	background: var(--sm-surface);
}

/* Scallop band. It sits inside the padding, so it never pushes content down. */
.main-header::before,
.fixed-header::before {
	content: "";
	position: absolute;
	inset: 0 0 auto;
	height: var(--band);
	background: var(--sm-pink);
	-webkit-mask:
		linear-gradient(#000 0 0) top left / 100% var(--band-solid) no-repeat,
		url(../images/header/scallop.svg) left calc(var(--band-solid) - 0.5px) / 14px 5px repeat-x;
	mask:
		linear-gradient(#000 0 0) top left / 100% var(--band-solid) no-repeat,
		url(../images/header/scallop.svg) left calc(var(--band-solid) - 0.5px) / 14px 5px repeat-x;
	pointer-events: none;
}

:is(.main-header, .fixed-header) > .container {
	display: flex;
	align-items: center;
	column-gap: var(--group-gap);
	max-width: 1440px;
	height: 100%;
	margin: 0 auto;
	padding-inline: var(--gutter);
	font-family: var(--sm-font);
}

/* Logo */
.header-logo,
.sm-drawer-logo {
	flex: none;
	margin-right: auto;
	line-height: 0;
}

.site-logo {
	display: block;
	color: var(--sm-ink);
	line-height: 1.2;
	text-decoration: none;
}

.header-logo img {
	display: block;
	width: auto;
	max-width: none;
	height: var(--logo);
}

/* Hamburger */
#st-trigger-effects {
	flex: none;
	width: var(--hit);
	height: var(--hit);
	/* The row's group gap separates this from the icons. Pull it back so the bars sit
	   --cluster-gap from the Search circle, the same space as between the two circles. */
	margin-left: calc(
		-1 * var(--group-gap) + var(--cluster-gap)
		- (var(--hit) - 20px) / 2
		- (var(--hit) - var(--circle)) / 2
	);
}

#st-trigger-effects .menu-icon {
	display: block;
	width: var(--hit);
	height: var(--hit);
	margin: 0;
	padding: 0;
	border: 0;
	background:
		linear-gradient(var(--sm-pink) 0 0) center calc(50% - 6px) / 20px 2px no-repeat,
		linear-gradient(var(--sm-pink) 0 0) center / 20px 2px no-repeat,
		linear-gradient(var(--sm-pink) 0 0) center calc(50% + 6px) / 20px 2px no-repeat;
	cursor: pointer;
}

#st-trigger-effects .menu-icon:focus-visible,
.sm-drawer-close:focus-visible,
.st-menu a:focus-visible,
.st-menu .open-child:focus-visible {
	outline: 2px solid var(--sm-pink);
	outline-offset: -2px;
}

/* Menu ------------------------------------------------------------------- */

/* The menu shows from the first desktop tier up. */
.navbar-collapse {
	display: none;
}

.navbar-collapse ul.menu {
	display: flex;
	align-items: stretch;
	column-gap: var(--item-gap);
	height: 100%;
	margin: 0;
	padding: 0;
	list-style: none;
}

.navbar-collapse ul.menu > li {
	position: relative;
	display: flex;
	align-items: center;
	margin: 0;
	padding: 0;
}

/* The mega menu spans the header, so its parent must not be the containing block. */
.navbar-collapse ul.menu > li.menu-full-width {
	position: static;
}

.navbar-collapse ul.menu > li > a {
	position: relative;
	display: inline-flex;
	align-items: center;
	height: 44px;
	margin: 0;
	padding: 0;
	color: var(--sm-ink);
	font-family: var(--sm-font);
	font-size: 13px;
	font-weight: 400;
	line-height: 18px;
	letter-spacing: normal;
	text-transform: uppercase;
	text-decoration: none;
	white-space: nowrap;
	transition: color var(--sm-transition);
}

.navbar-collapse ul.menu > li > a:focus-visible {
	outline: 2px solid var(--sm-pink);
	outline-offset: 4px;
}

/* Caret after MENU and ABOUT */
.navbar-collapse ul.menu > li.menu-item-has-children > a::before {
	content: "";
	order: 1;
	flex: none;
	width: 8px;
	height: 8px;
	margin: 0 0 0 6px;
	background: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 2.5 4 5.5 7 2.5' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 2.5 4 5.5 7 2.5' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Active swirl: 15px, 5px left of the label, centred on the text.
   It hangs in the item gap (at least 20px) so the label does not move. */
.navbar-collapse ul.menu > li > a::after {
	content: "";
	position: absolute;
	top: 50%;
	right: calc(100% + 5px);
	width: 15px;
	height: 15px;
	margin: -7.5px 0 0;
	background: url(../images/header/swirl.png) center / 15px 15px no-repeat;
	opacity: 0;
	pointer-events: none;
	transition: opacity var(--sm-transition);
}

.navbar-collapse ul.menu > li > a:hover::after,
.navbar-collapse ul.menu > li:is(.current-menu-item, .current-menu-ancestor, .current-menu-parent) > a::after {
	opacity: 1;
}

/* Icons ------------------------------------------------------------------ */

.sm-header-icons {
	position: relative;
	z-index: 1;
	display: flex;
	flex: none;
	align-items: center;
	column-gap: var(--icon-gap);
}

.sm-icon {
	position: relative;
	display: block;
	flex: none;
	width: var(--hit);
	height: var(--hit);
	text-decoration: none;
}

/* Circle. The 1px #eddad3 ring is a box-shadow so it stays round. */
.sm-icon::after {
	content: "";
	position: absolute;
	inset: 0;
	width: var(--circle);
	height: var(--circle);
	margin: auto;
	border: 3px solid var(--sm-icon-line);
	border-radius: 50%;
	background: var(--sm-icon-fill);
	box-shadow: 0 0 0 1px var(--sm-icon-fill);
	transition: background-color var(--sm-transition);
}

/* Glyph, drawn with a mask so the whole set changes colour together. */
.sm-icon::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	width: var(--glyph);
	height: var(--glyph);
	margin: auto;
	background: #fff;
	-webkit-mask: var(--sm-glyph) center / contain no-repeat;
	mask: var(--sm-glyph) center / contain no-repeat;
}

.sm-icon:hover::after,
.sm-icon:focus-visible::after {
	background: var(--sm-icon-hover);
}

.fixed-header .sm-icon::after,
.st-menu .sm-icon::after {
	border-color: #fff;
}

.sm-icon:focus-visible {
	outline: 2px solid var(--sm-pink);
	outline-offset: 2px;
	border-radius: 50%;
}

.sm-icon--facebook { --sm-glyph: url(../images/header/icons/facebook.svg); }
.sm-icon--instagram { --sm-glyph: url(../images/header/icons/instagram.svg); }
.sm-icon--email { --sm-glyph: url(../images/header/icons/email.svg); }
.sm-icon--youtube { --sm-glyph: url(../images/header/icons/youtube.svg); }
.sm-icon--shopee { --sm-glyph: url(../images/header/icons/shopee.svg); }
.sm-icon--line { --sm-glyph: url(../images/header/icons/line.svg); }
.sm-icon--search { --sm-glyph: url(../images/header/icons/search.svg); }

/* The compact bar shows LINE and Search only; the drawer shows all of them. */
:is(.main-header, .fixed-header) .sm-icon:not(.sm-icon--line, .sm-icon--search) {
	display: none;
}

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

.fixed-header-area {
	position: fixed;
	inset: 0 0 auto;
	z-index: 10001;
	transform: translateY(-100%);
	visibility: hidden;
	transition: transform 200ms, visibility 0s 200ms;
}

.fixed-header-area.fixed-already {
	transform: none;
	visibility: visible;
	transition: transform 200ms;
}

@media (prefers-reduced-motion: reduce) {
	.fixed-header-area,
	.fixed-header-area.fixed-already,
	.st-menu,
	.sm-drawer-backdrop,
	.main-header *,
	.main-header *::before,
	.main-header *::after,
	.fixed-header *,
	.fixed-header *::before,
	.fixed-header *::after,
	.st-menu *,
	.st-menu *::before,
	.st-menu *::after {
		transition: none !important;
	}
}

/* Drawer ----------------------------------------------------------------- */

.sm-drawer-backdrop {
	position: fixed;
	inset: 0;
	z-index: 100000;
	background: rgb(58 46 42 / 0.5);
	opacity: 0;
	visibility: hidden;
	transition: opacity 200ms, visibility 0s 200ms;
}

.st-menu {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: 100001;
	width: min(320px, 85vw);
	overflow-y: auto;
	background: var(--sm-surface);
	font-family: var(--sm-font);
	transform: translateX(100%);
	visibility: hidden;
	transition: transform 200ms, visibility 0s 200ms;
}

.sm-drawer-open {
	overflow: hidden;
}

.sm-drawer-open .st-menu {
	transform: none;
	visibility: visible;
	transition: transform 200ms;
}

.sm-drawer-open .sm-drawer-backdrop {
	opacity: 1;
	visibility: visible;
	transition: opacity 200ms;
}

.sm-drawer-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 60px;
	padding: 0 8px 0 16px;
}

.sm-drawer-logo img {
	display: block;
	width: auto;
	max-width: none;
	height: 36px;
}

.sm-drawer-close {
	position: relative;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
}

.sm-drawer-close::before,
.sm-drawer-close::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 20px;
	height: 2px;
	margin: -1px 0 0 -10px;
	background: var(--sm-pink);
	transform: rotate(45deg);
}

.sm-drawer-close::after {
	transform: rotate(-45deg);
}

.et-mobile-menu,
.et-mobile-menu ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.et-mobile-menu li {
	position: relative;
	margin: 0;
	padding: 0;
}

.et-mobile-menu li > a {
	display: flex;
	align-items: center;
	height: 48px;
	padding: 0 52px 0 16px;
	color: var(--sm-ink);
	font-size: 13px;
	font-weight: 400;
	line-height: 18px;
	text-decoration: none;
	text-transform: uppercase;
}

.et-mobile-menu ul li > a {
	padding-left: 32px;
}

/* Active swirl, left of the text; space is reserved so rows never shift */
.et-mobile-menu li > a::before {
	content: "";
	flex: none;
	width: 15px;
	height: 15px;
	margin-right: 5px;
	background: url(../images/header/swirl.png) center / 15px 15px no-repeat;
	opacity: 0;
}

.et-mobile-menu li:is(.current-menu-item, .current-menu-ancestor, .current-menu-parent) > a::before {
	opacity: 1;
}

.et-mobile-menu .sub-menu {
	display: none;
}

.et-mobile-menu li.over > .sub-menu {
	display: block;
}

.et-mobile-menu .open-child {
	position: absolute;
	top: 0;
	right: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 48px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: var(--sm-ink);
	cursor: pointer;
}

/* Same chevron as the desktop caret; it turns when the submenu is open. */
.et-mobile-menu .open-child::after {
	content: "";
	width: 8px;
	height: 8px;
	background: currentColor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 2.5 4 5.5 7 2.5' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1 2.5 4 5.5 7 2.5' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E") center / contain no-repeat;
}

.et-mobile-menu li.over > .open-child::after {
	transform: rotate(180deg);
}

.st-menu .sm-header-icons {
	display: grid;
	grid-template-columns: repeat(4, var(--hit));
	justify-content: start;
	margin: 16px 0;
	padding: 0 16px;
}

/* Desktop tight ---------------------------------------------------------- */

@media (min-width: 1280px) {
	.main-header,
	.fixed-header {
		--band: 12px;
		--band-solid: 7px;
		--bar: 80px;
		--logo: 44px;
		--gutter: 24px;
		--hit: 28px;
		--circle: 28px;
		--icon-gap: 4px;
		--item-gap: 20px;
		--group-gap: 22px;
	}

	.fixed-header {
		--band: 8px;
		--band-solid: 3px;
		--bar: 64px;
		--logo: 40px;
	}

	.header-logo {
		margin-right: 0;
	}

	.navbar-collapse {
		display: flex;
		flex: 1 1 auto;
		justify-content: center;
		align-self: stretch;
	}

	#st-trigger-effects {
		display: none;
	}

	:is(.main-header, .fixed-header) .sm-icon:not(.sm-icon--line, .sm-icon--search) {
		display: block;
	}

	/* Mega menu (MENU) */
	.menu-full-width > .nav-sublist-dropdown {
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		padding: 24px 0;
		background: var(--sm-surface);
		box-shadow: var(--sm-shadow);
		opacity: 0;
		visibility: hidden;
		transition: opacity var(--sm-transition), visibility 0s var(--sm-transition);
	}

	.menu-full-width:is(:hover, :focus-within) > .nav-sublist-dropdown {
		opacity: 1;
		visibility: visible;
		transition: opacity var(--sm-transition);
	}

	.menu-full-width > .nav-sublist-dropdown > .container {
		max-width: 1440px;
		margin: 0 auto;
		padding-inline: var(--gutter);
	}

	.menu-full-width > .nav-sublist-dropdown > .container > ul {
		display: grid;
		grid-template-columns: repeat(8, minmax(0, 1fr));
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.menu-full-width > .nav-sublist-dropdown > .container > ul > li {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 0;
		padding: 0;
	}

	.menu-full-width > .nav-sublist-dropdown > .container > ul > li > a {
		display: block;
		line-height: 0;
	}

	.nav-item-image {
		display: block;
		width: 104px;
		height: 104px;
		border-radius: 50%;
		background: var(--sm-icon-fill);
		overflow: hidden;
	}

	.nav-item-image img {
		display: block;
		width: 100%;
		height: 100%;
		object-fit: cover;
	}

	/* Label: 12px below the picture, two lines high, every first line on one baseline. */
	.menu-full-width > .nav-sublist-dropdown > .container > ul > li > ul {
		width: 100%;
		height: 36px;
		margin: 12px 0 0;
		padding: 0;
		list-style: none;
		overflow: hidden;
	}

	.menu-full-width .item-link {
		display: block;
		padding: 0 8px;
		color: var(--sm-ink);
		font-family: var(--sm-font);
		font-size: 13px;
		line-height: 18px;
		text-align: center;
		text-decoration: none;
		text-transform: uppercase;
	}

	.menu-full-width .item-link:focus-visible {
		outline: 2px solid var(--sm-pink);
		outline-offset: -2px;
	}

	/* Dropdown (ABOUT) */
	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown {
		position: absolute;
		top: 100%;
		left: 0;
		min-width: 220px;
		padding: 8px 0;
		background: var(--sm-surface);
		box-shadow: var(--sm-shadow);
		opacity: 0;
		visibility: hidden;
		transition: opacity var(--sm-transition), visibility 0s var(--sm-transition);
	}

	.menu > li:not(.menu-full-width):is(:hover, :focus-within) > .nav-sublist-dropdown {
		opacity: 1;
		visibility: visible;
		transition: opacity var(--sm-transition);
	}

	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown ul {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown li > a {
		display: flex;
		align-items: center;
		height: 40px;
		padding: 0 20px;
		color: var(--sm-ink);
		font-family: var(--sm-font);
		font-size: 13px;
		font-weight: 400;
		line-height: 18px;
		text-decoration: none;
		text-transform: uppercase;
		white-space: nowrap;
	}

	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown li > a:focus-visible {
		outline: 2px solid var(--sm-pink);
		outline-offset: -2px;
	}

	/* Same left swirl as the horizontal menu; space is reserved so rows do not shift. */
	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown li > a::before {
		content: "";
		flex: none;
		width: 15px;
		height: 15px;
		margin-right: 5px;
		background: url(../images/header/swirl.png) center / 15px 15px no-repeat;
		opacity: 0;
	}

	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown li:is(.current-menu-item, .current-menu-ancestor) > a::before,
	.menu > li:not(.menu-full-width) > .nav-sublist-dropdown li > a:hover::before {
		opacity: 1;
	}
}

/* Desktop full ----------------------------------------------------------- */

@media (min-width: 1440px) {
	.main-header,
	.fixed-header {
		--bar: 88px;
		--logo: 52px;
		--hit: 36px;
		--circle: 36px;
		--item-gap: 28px;
		--group-gap: 28px;
	}

	.fixed-header {
		--bar: 64px;
		--logo: 40px;
	}

	.nav-item-image {
		width: 120px;
		height: 120px;
	}
}
