/*
 * Search block, "button only" mode: a navy magnifier that opens the field.
 * functions.php adds a close button and the Search button's word
 * (sutherland_search_buttons()).
 *
 * Loaded with the Search block (functions.php).
 */

.wp-block-search__button-only {
	display: flex;
	align-items: center;
}

.wp-block-search__button-only .wp-block-search__button {
	margin: 0;
	padding: 6px;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--navy);
}

.wp-block-search__button-only .wp-block-search__button svg {
	width: 24px;
	height: 24px;
	fill: currentcolor;
}

/*
 * The close button, shown while the field is open: the mobile menu's (crimson,
 * 32px), in a box of the magnifier's size, 36px.
 */
.sutherland-search__close {
	display: none;
	flex-shrink: 0;
	margin: 0;
	padding: 2px;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--crimson);
	cursor: pointer;
}

.wp-block-search:not(.wp-block-search__searchfield-hidden) .sutherland-search__close {
	display: block;
}

.sutherland-search__close svg {
	display: block;
	width: 32px;
	height: 32px;
	fill: currentcolor;
}

.sutherland-search__close:focus-visible {
	outline: 2px solid var(--wp--custom--color--focus);
	outline-offset: 2px;
}

/* The Search button's word, beside an icon: only where the header asks. */
.wp-block-search__button.has-icon .sutherland-search__label {
	display: none;
}

/*
 * In the header the field opens in a panel that slides down from under the
 * header: the dropdowns' panel (white, a crimson rule on top) with the site's
 * field (48px, 16px text, up to 560px) and the Search button beside it. The
 * close button takes the magnifier's place, and the menu stays.
 *
 * The panel, the field and the button are three boxes hung from the header's
 * bottom edge, and move as one. They are drawn behind a copy of the header's
 * background (the header's ::before), so they come out from under it.
 */
.sutherland-header {
	--sutherland-search-edge: 30px;
	--sutherland-search-space: var(--wp--preset--spacing--30);
	--sutherland-search-button: 120px;
	--sutherland-search-row: min(100% - 2 * var(--sutherland-search-edge), 560px + var(--wp--preset--spacing--10) + var(--sutherland-search-button));
	--sutherland-search-top: calc(100% + 3px + var(--sutherland-search-space));
	--sutherland-search-height: calc(51px + 2 * var(--sutherland-search-space));
	--sutherland-search-in: 0.25s;
	--sutherland-search-out: 0.2s;
}

.sutherland-header::before {
	content: "";
	position: absolute;
	z-index: -1;
	inset: 0;
	background: inherit;
}

.sutherland-header .wp-block-search__button-only::before {
	content: "";
	position: absolute;
	z-index: -2;
	inset: 100% 0 auto;
	box-sizing: border-box;
	height: var(--sutherland-search-height);
	border-top: 3px solid var(--wp--preset--color--crimson);
	background: var(--wp--preset--color--white);
	box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
	transition: translate var(--sutherland-search-in) ease-out;
}

/* Closing: the field and the button go at once, the empty panel slides back. */
.sutherland-header .wp-block-search__searchfield-hidden::before {
	visibility: hidden;
	translate: 0 calc(-1 * var(--sutherland-search-height));
	transition: translate var(--sutherland-search-out) ease-in, visibility 0s var(--sutherland-search-out);
}

/*
 * The field. Core gives a closed field no width, padding or side borders, and
 * an open one a width, all with !important or inline.
 */
.sutherland-header .wp-block-search.wp-block-search__button-only .wp-block-search__inside-wrapper .wp-block-search__input {
	position: absolute;
	z-index: -2;
	top: var(--sutherland-search-top);
	left: calc((100% - var(--sutherland-search-row)) / 2);
	box-sizing: border-box;
	width: calc(var(--sutherland-search-row) - var(--sutherland-search-button) - var(--wp--preset--spacing--10)) !important;
	height: 48px;
	margin: 0;
	padding: 11px 16px !important;
	border: 1px solid var(--wp--preset--color--muted) !important;
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--heading);
	font-size: var(--wp--preset--font-size--medium);
	line-height: 1.5;
	transition: translate var(--sutherland-search-in) ease-out;
}

/*
 * Closed, the field is behind the header. Not `visibility: hidden`: core
 * focuses the field before it takes the closed state away, and a hidden field
 * refuses the focus.
 */
.sutherland-header .wp-block-search.wp-block-search__searchfield-hidden .wp-block-search__inside-wrapper .wp-block-search__input {
	opacity: 0;
	pointer-events: none;
	translate: 0 calc(-1 * var(--sutherland-search-height));
	transition: none;
}

.sutherland-header .wp-block-search__input::placeholder,
.sutherland-mobile-menu .wp-block-search__input::placeholder {
	color: var(--wp--preset--color--muted);
	opacity: 1;
}

.sutherland-header .wp-block-search__input:focus-visible,
.sutherland-mobile-menu .wp-block-search__input:focus-visible {
	outline: 2px solid var(--wp--custom--color--focus);
	outline-offset: 2px;
}

/*
 * Once the field is open, the magnifier sends the search, and says so. The
 * button's look is on its word, not on the button: a box that wasn't there
 * before has no colour to fade from as the panel comes down. And the word
 * holds its colour while it comes: the browser still counts the button as
 * hovered for a moment, from the click on the magnifier it was.
 */
.sutherland-header .wp-block-search__button-only:not(.wp-block-search__searchfield-hidden) .wp-block-search__button {
	position: absolute;
	z-index: -2;
	top: var(--sutherland-search-top);
	left: calc((100% + var(--sutherland-search-row)) / 2 - var(--sutherland-search-button));
	box-sizing: border-box;
	width: var(--sutherland-search-button);
	height: 48px;
	padding: 0;
	border-radius: var(--wp--preset--border-radius--small);
	animation: sutherland-search-in var(--sutherland-search-in) ease-out;
}

.sutherland-header .wp-block-search__button-only:not(.wp-block-search__searchfield-hidden) .sutherland-search__label {
	display: flex;
	flex: 1;
	align-items: center;
	align-self: stretch;
	justify-content: center;
	border-radius: inherit;
	background: var(--wp--preset--color--crimson);
	color: var(--wp--preset--color--white);
	font-size: 17px;
	font-weight: 600;
	line-height: 1;
	text-transform: uppercase;
	transition: var(--wp--custom--transition--button);
	animation: sutherland-search-word 0.3s;
}

.sutherland-header .wp-block-search__button-only:not(.wp-block-search__searchfield-hidden) .wp-block-search__button:hover .sutherland-search__label {
	background: var(--wp--preset--color--navy);
}

.sutherland-header .wp-block-search__button-only:not(.wp-block-search__searchfield-hidden) .wp-block-search__button:has(.sutherland-search__label) svg {
	display: none;
}

@keyframes sutherland-search-in {

	from {
		translate: 0 calc(-1 * var(--sutherland-search-height));
	}
}

@keyframes sutherland-search-word {

	from,
	to {
		background: var(--wp--preset--color--crimson);
	}
}

/*
 * In the mobile menu, under Donate: the panel's field and Search button, always
 * open. The header's magnifier shows on desktops only.
 */
.sutherland-mobile-menu .wp-block-search__input {
	box-sizing: border-box;
	height: 48px;
	padding: 11px 16px;
	border: 1px solid var(--wp--preset--color--muted);
	color: var(--wp--preset--color--heading);
	font-size: var(--wp--preset--font-size--medium);
	line-height: 1.5;
	text-transform: none;
}

.sutherland-mobile-menu .wp-block-search__button {
	flex-shrink: 0;
	width: 96px;
	height: 48px;
	margin-inline-start: var(--wp--preset--spacing--10);
	padding: 0;
	font-size: 17px;
	font-weight: 600;
	line-height: 1;
	text-transform: uppercase;
}

@media (prefers-reduced-motion: reduce) {

	.sutherland-header {
		--sutherland-search-in: 0s;
		--sutherland-search-out: 0s;
	}
}
