/* WP Enhanced Search — shared look of the Accordion Search and Docs Search
 * blocks, plus the Docs Search results list (end of file).
 *
 * Text color, background and typography come from the block's Color and
 * Typography settings (applied to the wrapper and inherited by everything
 * inside). The accent, border color and corner radii come from the block's
 * Style settings as custom properties. Font sizes are in em so they scale
 * with the block's font size.
 */

.wpea-search {
	--wpea-search-accent: #5a78ff;
	--wpea-search-field-radius: 12px;
	--wpea-search-filter-radius: 12px;

	/* Strengths (set per block from "Fill strength" and "Border strength";
	 * these defaults match the accordion items). */
	--wpea-search-fill: 7.5%;
	--wpea-search-fill-end: 2.4%;
	--wpea-search-border-pct: 28%;
	--wpea-search-border-hover-pct: 40%;
	--wpea-search-filter-border-pct: 16%;
	--wpea-search-filter-hover-pct: 28%;
	--wpea-search-selected-border-pct: 60%;
	--wpea-search-selected-tint: 16%;

	/* Colors built from the accent and strengths. */
	--wpea-search-fill-bg: linear-gradient(145deg, color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-fill), transparent), color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-fill-end), transparent));
	--wpea-search-border: color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-border-pct), transparent);
	--wpea-search-border-hover: color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-border-hover-pct), transparent);
	--wpea-search-filter-border: color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-filter-border-pct), transparent);
	--wpea-search-filter-border-hover: color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-filter-hover-pct), transparent);
	--wpea-search-selected-border: color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-selected-border-pct), transparent);
	--wpea-search-selected-bg: linear-gradient(color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-selected-tint), transparent), color-mix(in srgb, var(--wpea-search-accent) var(--wpea-search-selected-tint), transparent));

	/* Same soft shadows as closed and open accordion items. */
	--wpea-search-shadow: 0 8px 26px rgba(0, 0, 0, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.05);
	--wpea-search-shadow-raised: 0 12px 30px rgba(0, 0, 0, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.06);
	margin-bottom: 1.5em;
}

/* Browsers from before 2023 without color-mix(): fixed accordion-blue values. */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {

	.wpea-search {
		--wpea-search-fill-bg: linear-gradient(145deg, rgba(90, 120, 255, 0.075), rgba(90, 120, 255, 0.024));
		--wpea-search-border: rgba(90, 120, 255, 0.28);
		--wpea-search-border-hover: rgba(90, 120, 255, 0.4);
		--wpea-search-filter-border: rgba(90, 120, 255, 0.16);
		--wpea-search-filter-border-hover: rgba(90, 120, 255, 0.28);
		--wpea-search-selected-border: rgba(90, 120, 255, 0.6);
		--wpea-search-selected-bg: linear-gradient(rgba(90, 120, 255, 0.16), rgba(90, 120, 255, 0.16));
	}
}

/* White text by default; a text color chosen in the block's Color settings
 * (which adds .has-text-color) takes over. */
.wpea-search:not(.has-text-color) {
	color: #fff;
}

.wpea-search[hidden] {
	display: none !important;
}

.wpea-search .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.wpea-search__field {
	position: relative;
	display: flex;
	align-items: center;
}

.wpea-search__icon {
	position: absolute;
	left: 14px;
	width: 1.25em;
	height: 1.25em;
	opacity: 0.7;
	pointer-events: none;
}

.wpea-search .wpea-search__input {
	box-sizing: border-box;
	width: 100%;
	height: auto;
	min-height: 48px;
	margin: 0;
	padding: 10px 44px 10px calc(1.25em + 24px);
	border: 1px solid var(--wpea-search-border);
	border-radius: var(--wpea-search-field-radius);
	background-color: transparent;
	background-image: var(--wpea-search-fill-bg);
	color: inherit;
	font: inherit;
	font-size: 1em;
	line-height: inherit;
	letter-spacing: inherit;
	text-transform: none;
	box-shadow: var(--wpea-search-shadow);
	transition: border-color 0.2s, box-shadow 0.2s;
	appearance: none;
	-webkit-appearance: none;
}

.wpea-search .wpea-search__input:hover {
	border-color: var(--wpea-search-border-hover);
	box-shadow: var(--wpea-search-shadow-raised);
}

/* Typed text and the blinking cursor always use the block's text color.
 * Themes often recolor focused search fields (e.g. Argent sets
 * input[type="search"]:focus { color: #111 }), which made typing invisible
 * on dark backgrounds, so every state is covered with higher specificity. */
.wpea-search .wpea-search__input,
.wpea-search .wpea-search__input:hover,
.wpea-search .wpea-search__input:focus,
.wpea-search .wpea-search__input:active {
	color: inherit;
	-webkit-text-fill-color: currentcolor;
	caret-color: currentcolor;
	background-color: transparent;
}

/* Same protection for the buttons, whose colors themes also restyle.
 * Hovered, focused and selected filters use the full text color. */
.wpea-search .wpea-search__filter.is-active,
.wpea-search .wpea-search__filter:hover,
.wpea-search .wpea-search__filter:focus,
.wpea-search .wpea-search__filter:active,
.wpea-search .wpea-search__clear:focus,
.wpea-search .wpea-search__clear:active {
	color: inherit;
}

.wpea-search .wpea-search__input::placeholder {
	color: inherit;
	-webkit-text-fill-color: currentcolor;
	opacity: 0.75;
}

.wpea-search .wpea-search__input::-webkit-search-cancel-button {
	display: none;
}

.wpea-search .wpea-search__input:focus {
	outline: 2px solid var(--wpea-search-accent);
	outline-offset: 1px;
	border-color: var(--wpea-search-accent);
}

/* Phones zoom in on inputs under 16px; never go below it there. */
@media (max-width: 600px) {

	.wpea-search .wpea-search__input {
		font-size: max(16px, 1em);
	}
}

.wpea-search .wpea-search__clear {
	position: absolute;
	right: 6px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: inherit;
	opacity: 0.7;
	cursor: pointer;
}

.wpea-search .wpea-search__clear[hidden] {
	display: none;
}

.wpea-search .wpea-search__clear:hover,
.wpea-search .wpea-search__clear:focus-visible {
	opacity: 1;
	background: rgba(127, 127, 127, 0.18);
}

/* Buttons for sections the page doesn't have are hidden by the script.
 * !important because themes often set display on all buttons. */
.wpea-search .wpea-search__filter[hidden],
.wpea-search .wpea-search__filters[hidden] {
	display: none !important;
}

.wpea-search__filters {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 12px;
}

.wpea-search .wpea-search__filter {
	margin: 0;
	padding: 0.4em 1em;
	border: 1px solid var(--wpea-search-filter-border);
	border-radius: var(--wpea-search-filter-radius);
	background-color: transparent;
	background-image: var(--wpea-search-fill-bg);
	/* Unselected buttons are slightly dimmer, like closed accordions. */
	color: inherit;
	color: color-mix(in srgb, currentcolor 80%, transparent);
	font: inherit; /* Weight follows the block's Typography setting. */
	font-size: 0.875em;
	line-height: 1.4;
	letter-spacing: inherit;
	text-transform: inherit;
	height: auto;
	min-height: 0;
	box-shadow: var(--wpea-search-shadow);
	cursor: pointer;
	transition: border-color 0.2s, box-shadow 0.2s, color 0.2s;
}

.wpea-search .wpea-search__filter:hover {
	border-color: var(--wpea-search-filter-border-hover);
	box-shadow: var(--wpea-search-shadow-raised);
}

.wpea-search .wpea-search__filter.is-active {
	border-color: var(--wpea-search-selected-border);
	background-image: var(--wpea-search-selected-bg), var(--wpea-search-fill-bg);
	box-shadow: var(--wpea-search-shadow-raised);
	color: inherit;
}

.wpea-search .wpea-search__filter:focus-visible {
	outline: 2px solid var(--wpea-search-accent);
	outline-offset: 2px;
}

/* Phones: one row of filter buttons that scrolls sideways, with taller
 * buttons for thumbs and a fade on the edge that has more buttons. */
@media (max-width: 600px) {

	.wpea-search__filters {
		flex-wrap: nowrap;
		overflow-x: auto;
		margin-right: -4px;
		margin-left: -4px;
		padding: 4px;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
	}

	.wpea-search__filters::-webkit-scrollbar {
		display: none;
	}

	.wpea-search__filters.has-more-end {
		-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
		mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
	}

	.wpea-search__filters.has-more-start {
		-webkit-mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
		mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
	}

	.wpea-search__filters.has-more-start.has-more-end {
		-webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
		mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
	}

	.wpea-search .wpea-search__filter {
		flex: 0 0 auto;
		min-height: 40px;
		white-space: nowrap;
	}
}

.wpea-search__status {
	margin: 10px 0 0;
	font-size: 0.875em;
	opacity: 0.8;
}

.wpea-search__status:empty {
	display: none;
}

/* Applied to accordions, items, sections and entries that don't match. */
.wpea-search-hide {
	display: none !important;
}

mark.wpea-search-mark {
	padding: 0 1px;
	border-radius: 2px;
	background: rgba(90, 120, 255, 0.4);
	background: color-mix(in srgb, var(--wpea-search-accent, #5a78ff) 40%, transparent);
	color: inherit;
}

/* Editor preview: the bar is shown but not interactive. */
.wpea-search--preview .wpea-search__input,
.wpea-search--preview .wpea-search__filter {
	pointer-events: none;
}

/* ------------------------------------------------------------------------
 * Docs Search: results list shown in place of the index while searching.
 * Results are cards styled like closed accordion items; hovered or focused
 * they look like an open one.
 * --------------------------------------------------------------------- */

.wpes-docs-search {
	--wpes-result-radius: 12px;
}

.wpes-docs-search .wpes-results {
	display: grid;
	gap: 10px;
	margin: 16px 0 0;
	padding: 0;
	list-style: none;
}

.wpes-docs-search .wpes-results[hidden] {
	display: none;
}

.wpes-docs-search .wpes-results > li {
	margin: 0;
	padding: 0;
	list-style: none;
}

.wpes-docs-search .wpes-results > li::before,
.wpes-docs-search .wpes-results > li::marker {
	content: none;
}

.wpes-docs-search a.wpes-result,
.wpes-docs-search a.wpes-result:visited,
.wpes-docs-search a.wpes-result:hover,
.wpes-docs-search a.wpes-result:focus,
.wpes-docs-search a.wpes-result:active {
	display: block;
	padding: 14px 18px;
	border: 1px solid var(--wpea-search-filter-border);
	border-radius: var(--wpes-result-radius);
	background-color: transparent;
	background-image: var(--wpea-search-fill-bg);
	box-shadow: var(--wpea-search-shadow);
	color: inherit;
	text-decoration: none;
	transition: border-color 0.2s, box-shadow 0.2s;
}

.wpes-docs-search a.wpes-result:hover,
.wpes-docs-search a.wpes-result:focus-visible {
	border-color: var(--wpea-search-filter-border-hover);
	box-shadow: var(--wpea-search-shadow-raised);
}

.wpes-docs-search a.wpes-result:focus-visible {
	outline: 2px solid var(--wpea-search-accent);
	outline-offset: 2px;
}

.wpes-result__title {
	display: block;
	font-weight: 600;
	line-height: 1.4;
}

.wpes-result__meta {
	display: block;
	margin-top: 2px;
	font-size: 0.8em;
	opacity: 0.7;
}

.wpes-result__snippet {
	display: block;
	margin-top: 6px;
	font-size: 0.9em;
	line-height: 1.55;
	opacity: 0.85;
}

.wpes-result__snippet:empty {
	display: none;
}

/* Content after the block is hidden while a search is showing results. */
.wpes-docs-hidden {
	display: none !important;
}

/* "Did you mean …?" under the search box. */
.wpea-search__suggest {
	margin: 6px 0 0;
	font-size: 0.875em;
}

.wpea-search__suggest[hidden] {
	display: none;
}

.wpea-search .wpea-search__suggest-button {
	display: inline;
	min-height: 0;
	height: auto;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-weight: 600;
	letter-spacing: inherit;
	text-transform: none;
	text-decoration: underline;
	text-decoration-color: var(--wpea-search-accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 3px;
	box-shadow: none;
	cursor: pointer;
}

.wpea-search .wpea-search__suggest-button:hover,
.wpea-search .wpea-search__suggest-button:focus,
.wpea-search .wpea-search__suggest-button:active {
	color: inherit;
	background: none;
}

.wpea-search .wpea-search__suggest-button:focus-visible {
	outline: 2px solid var(--wpea-search-accent);
	outline-offset: 2px;
	border-radius: 2px;
}
