/**
 * Site-wide responsive layout tweaks for the theme's header and patterns.
 */

.solshow-metric {
	color: var(--wp--preset--color--primary);
	font-weight: bold;
}

.solshow-counter-mobile {
	display: none !important;
}

/*
 * Let a featured image fill a stretched column (event cards). Core puts the
 * block's Height setting on the <img> only, so the <figure> needs a height
 * for that 100% to resolve against.
 */
.wp-block-column > .wp-block-post-featured-image {
	height: 100%;
}

/*
 * Brand button for non-block buttons (form inputs, popup links). Mirrors the
 * Site Editor "brand" button style, whose CSS WordPress only outputs per
 * Button block instance, so it can't be applied by class name.
 */
.bsc-btn-brand,
.bsc-btn-brand:visited,
.bsc-btn-brand:hover,
.bsc-btn-brand:focus {
	background-color: var(--wp--preset--color--primary);
	/* !important beats link colours like Leaflet's `.leaflet-container a`. */
	color: var(--wp--preset--color--main) !important;
	font-family: var(--wp--preset--font-family--alata);
	font-weight: 400;
	border: 0;
	cursor: pointer;
	display: inline-block;
	text-decoration: none;
}

/*
 * The purple alt version of the brand button, e.g. a Contact Form 7 submit.
 * Pair it with wp-element-button for the theme's button padding and corners;
 * !important on the colours beats that class's default button colours.
 */
.bsc-btn-brand-alt,
.bsc-btn-brand-alt:visited,
.bsc-btn-brand-alt:hover,
.bsc-btn-brand-alt:focus {
	background-color: var(--wp--preset--color--primary-alt) !important;
	color: var(--wp--preset--color--tertiary) !important;
	font-family: var(--wp--preset--font-family--alata);
	font-weight: 400;
	border: 0;
	cursor: pointer;
	display: inline-block;
	text-decoration: none;
}

.bsc-btn-brand:hover,
.bsc-btn-brand:focus,
.bsc-btn-brand-alt:hover,
.bsc-btn-brand-alt:focus {
	filter: brightness(0.95);
}

/* CF7 fields default to size="40"; let them fill the space available instead. */
.wpcf7 input:not([type="submit"]):not([type="hidden"]),
.wpcf7 textarea,
.wpcf7 select {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
}

/*
 * Header: drop the Solshow counter first, then collapse the menu. Once it's
 * collapsed, search and the Invest button move into the hamburger overlay
 * as copies inside the Navigation block, marked bsc-menu-only.
 *
 * The mobile counter strip takes over from the inline header counter at the
 * same width, so exactly one counter shows at every screen size.
 */
@media screen and (max-width: 1200px) {
	.bsc-header-counter {
		display: none !important;
	}

	.solshow-counter-mobile {
		display: flex !important;
	}
}

/*
 * Collapse the header menu into its hamburger at 1024px instead of core's
 * fixed 600px. These mirror (and reverse) core's min-width: 600px rules.
 */
@media screen and (min-width: 600px) and (max-width: 1024px) {
	header.wp-block-template-part .wp-block-navigation__responsive-container-open:not(.always-shown) {
		display: flex;
	}

	header.wp-block-template-part .wp-block-navigation__responsive-container:not(.hidden-by-default):not(.is-menu-open) {
		display: none;
	}
}

@media screen and (max-width: 1024px) {
	/* Search and Invest are in the menu at this width, so hide the header copies. */
	.bsc-header-extras {
		display: none !important;
	}
}

/* Menu-only items (Invest, search) appear only inside the open hamburger overlay. */
.wp-block-navigation__responsive-container:not(.is-menu-open) .bsc-menu-only {
	display: none;
}

@media screen and (max-width: 700px) {
	/* Widen both sizes together, so Wide-aligned blocks line up with normal content. */
	:root {
		--wp--style--global--content-size: 90%;
		--wp--style--global--wide-size: 90%;
	}
}

/**
 * Search bar styling
 *
 * Opening the header search lays a white panel over the whole header bar,
 * with a search field across the header's content width, the search icon at
 * the field's right-hand end and a close (×) beyond it. All of these are
 * positioned against the header, so percentages below are of its width.
 */
header.wp-block-template-part {
	position: relative;
	/* Header edge to content edge, so the search lines up with the logo. */
	--bsc-header-gutter: max(1rem, calc((100% - var(--wp--style--global--wide-size)) / 2));
}

/* Panel covering the header while the search is open. */
.bsc-header-extras .wp-block-search:not(.wp-block-search__searchfield-hidden)::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 99;
	background: var(--wp--preset--color--base);
}

/*
 * The field. It stays out of flow in both states, because core's closed state
 * animates the width back to 0 in flow, which shoves the nav sideways on
 * close. The right padding leaves room for the search icon inside it.
 */
.bsc-header-extras .wp-block-search .wp-block-search__input {
	position: absolute;
	top: 50%;
	left: var(--bsc-header-gutter);
	right: calc(var(--bsc-header-gutter) + 3rem);
	z-index: 100;
	box-sizing: border-box;
	width: auto;
	max-width: none;
	height: 3rem;
	margin: 0;
	padding: 0 3.5rem 0 1.25rem;
	transform: translateY(-50%);
	font-size: 1.125rem;
	background: var(--wp--preset--color--tertiary);
	border: 1px solid var(--wp--preset--color--main);
	border-radius: var(--wp--preset--border-radius--sm, 0.5rem);
	transition: none;
}

/* Brand-yellow focus ring in place of the browser's default outline. */
.bsc-header-extras .wp-block-search .wp-block-search__input:focus {
	outline: none;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp--preset--color--primary) 60%, transparent);
}

/* Above the panel and field in both states, so it can open and then submit. */
.bsc-header-extras .wp-block-search__button {
	position: relative;
	z-index: 101;
}

/* While open, move the search icon into the right-hand end of the field. */
.bsc-header-extras .wp-block-search:not(.wp-block-search__searchfield-hidden) .wp-block-search__button {
	position: absolute;
	top: 50%;
	right: calc(var(--bsc-header-gutter) + 3.25rem);
	transform: translateY(-50%);
}

/*
 * Close (×) for the open search, beyond the field at the right edge of the
 * header content. Core's Search block closes itself when focus leaves it (and
 * on Escape), so clicking this non-focusable mark, which takes focus off the
 * input, is all it needs to close; no script required.
 */
.bsc-header-extras .wp-block-search:not(.wp-block-search__searchfield-hidden)::after {
	content: "\00d7";
	position: absolute;
	top: 50%;
	right: var(--bsc-header-gutter);
	z-index: 101;
	width: 2.5rem;
	transform: translateY(-50%);
	font-size: 2rem;
	line-height: 1;
	text-align: center;
	color: var(--wp--preset--color--main);
	cursor: pointer;
}

.bsc-header-extras .wp-block-search__searchfield-hidden .wp-block-search__input {
	visibility: hidden;
}

/* Core's search icon is a filled path, so thicken it with a matching stroke. */
.bsc-header-extras .wp-block-search__button .search-icon path {
	stroke: currentColor;
	stroke-width: 1;
}
