/*
 * Header actions: search, cart and account icons next to the navigation
 * (inc/header-actions.php). Scoped to .best-header-actions / .best-header-search.
 */

.best-header-actions {
	flex-shrink: 0;
}

/*
 * Phones: the header row (site title, menu button, these icons) must fit the
 * screen. While the navigation is a menu button (below 600 px) a long site
 * title gets shorter with an ellipsis instead of pushing the icons past the
 * right edge. The ellipsis sits on the link, so its focus ring is not clipped.
 */
@media (max-width: 599.98px) {

	.wp-block-group:has(> .best-header-actions) > .wp-block-site-title,
	.wp-block-group:has(> .best-header-actions) > .wp-block-site-logo {
		flex-shrink: 1;
		min-width: 0;
	}

	.wp-block-group:has(> .best-header-actions) > .wp-block-site-title a {
		display: block;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/* A visible search field (always shown, or the expand search when open) gives way as well. */
	.wp-block-group.best-header-actions:has(> .best-header-search--field),
	.wp-block-group.best-header-actions:has(> .best-header-search--expand:not(.wp-block-search__searchfield-hidden)) {
		flex-shrink: 1;
		min-width: 0;
	}

	.best-header-actions > .best-header-search--field,
	.best-header-actions > .best-header-search--expand:not(.wp-block-search__searchfield-hidden) {
		flex: 0 1 auto;
		min-width: 0;
	}

	.best-header-actions > .best-header-search--field .wp-block-search__inside-wrapper,
	.best-header-actions > .best-header-search--expand .wp-block-search__inside-wrapper {
		max-width: 100%;
	}

	.best-header-actions > .best-header-search--field .wp-block-search__input,
	.best-header-actions > .best-header-search--expand .wp-block-search__input {
		min-width: 0;
	}
}

/*
 * Phones up to 480 px (360, 375, 390, 430 px): tighter gaps, so a normal site
 * title stays whole and the icons keep clear of the page padding.
 */
@media (max-width: 479.98px) {

	.wp-block-group:has(> .best-header-actions) {
		gap: var(--wp--preset--spacing--20, 0.5rem);
	}

	.wp-block-group.best-header-actions {
		gap: 0;
	}

	.best-header-actions .best-header-icon {
		width: 2.5rem;
	}
}

.best-header-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 0;
	border-radius: 0.5rem;
	background: transparent;
	color: inherit;
	cursor: pointer;
	text-decoration: none;
}

.best-header-icon:hover {
	background: color-mix(in srgb, currentcolor 10%, transparent);
}

.best-header-icon:focus-visible {
	outline: var(--wp--custom--focus--width, 3px) solid var(--wp--preset--color--primary, currentColor);
	outline-offset: var(--wp--custom--focus--offset, 2px);
}

/* The core search block expands in place; keep it from pushing the logo around. */
.best-header-search--expand .wp-block-search__inside-wrapper {
	align-items: center;
}

.best-header-search--field {
	margin: 0;
}

/* ---- Modal ---------------------------------------------------------------- */

.best-header-search__dialog {
	width: min(40rem, 92vw);
	max-height: 80vh;
	margin: 12vh auto auto;
	padding: 0;
	border: 1px solid var(--wp--preset--color--outline, currentColor);
	border-radius: var(--wp--custom--radius--md, 0.75rem);
	background: var(--wp--preset--color--surface, #fff);
	color: var(--wp--preset--color--on-surface, inherit);
	overflow: visible;
}

.best-header-search__dialog::backdrop {
	background: color-mix(in srgb, var(--wp--preset--color--on-surface, #000) 55%, transparent);
}

.best-header-search__panel {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 1rem;
}

.best-header-search__panel .wp-block-search {
	flex: 1 1 auto;
	margin: 0;
}

/* Suggestions dropdown must stay inside the viewport on small screens. */
.best-header-search__dialog .wp-block-search__input {
	min-width: 0;
}

/* Cart and account blocks follow the header's text colour. */
.best-header-actions a,
.best-header-actions .wc-block-mini-cart__button,
.best-header-actions .wc-block-customer-account__link {
	color: inherit;
}

@media (prefers-reduced-motion: no-preference) {

	.best-header-icon {
		transition: background-color 120ms ease;
	}
}

/* ---- Language switcher ------------------------------------------------------ */

.best-header-lang ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.best-header-lang a,
.best-header-lang summary {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	min-height: 2.75rem;
	padding: 0 0.6rem;
	border-radius: 0.5rem;
	color: inherit;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}

.best-header-lang a:hover,
.best-header-lang summary:hover {
	background: color-mix(in srgb, currentcolor 10%, transparent);
}

.best-header-lang a:focus-visible,
.best-header-lang summary:focus-visible {
	outline: var(--wp--custom--focus--width, 3px) solid var(--wp--preset--color--primary, currentColor);
	outline-offset: var(--wp--custom--focus--offset, 2px);
}

.best-header-lang--inline ul {
	display: flex;
	gap: 0.1rem;
}

.best-header-lang--inline [aria-current] {
	text-decoration: underline;
	text-underline-offset: 0.3em;
}

.best-header-lang summary {
	list-style: none;
}

.best-header-lang summary::-webkit-details-marker {
	display: none;
}

.best-header-lang details {
	position: relative;
}

.best-header-lang details[open] .best-header-lang__caret {
	transform: rotate(180deg);
}

.best-header-lang--dropdown ul {
	position: absolute;
	z-index: 20;
	top: 100%;
	right: 0;
	min-width: 100%;
	padding: 0.25rem;
	border: 1px solid var(--wp--preset--color--outline, currentColor);
	border-radius: var(--wp--custom--radius--md, 0.75rem);
	background: var(--wp--preset--color--surface, #fff);
	color: var(--wp--preset--color--on-surface, inherit);
	white-space: nowrap;
}

.best-header-lang--dropdown li.is-current a {
	font-weight: 800;
}

.best-header-lang__flag {
	display: block;
	width: 18px;
	height: auto;
	border-radius: 2px;
}

/* Language switch as a menu entry (block style "Language switch"): flag next to the label. */
.best-lang-menu .wp-block-navigation-item__content {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
}
