/**
 * TC Searchbar — frontend styles.
 *
 * Themable via CSS custom properties (override them on .tc-searchbar or
 * any ancestor). Layout follows the design direction: a large rounded
 * white pill with a query field, a vertical divider, a taxonomy select
 * and a green pill-shaped submit button.
 *
 * Sizing strategy (Automatic.css friendly):
 *  - Font sizes and spacing prefer ACSS variables (--text-*, --space-*)
 *    and fall back to em values on sites without ACSS.
 *  - No raw rem values: themes that rescale the root font size (e.g.
 *    ACSS sites where 1rem ≈ 10px) would shrink the component. The em
 *    fallbacks track the component font size instead.
 *  - No max-width: the bar fills its container — wrap the shortcode in
 *    your own wrapper/section to constrain it.
 */

.tc-searchbar {
	/* Public theming API — see docs/SHORTCODE.md. */
	--tc-searchbar-bg: #ffffff;
	--tc-searchbar-text: #1a2330;
	--tc-searchbar-muted: #8a94a6;
	--tc-searchbar-border: #e4e8ee;
	--tc-searchbar-accent: #00d563;
	--tc-searchbar-accent-text: #0b1220;
	--tc-searchbar-radius: 999px;
	--tc-searchbar-shadow: 0 10px 30px rgba(10, 20, 40, 0.12);
	--tc-searchbar-font-size: var(--text-m, 1em);
	--tc-searchbar-gap: var(--space-xs, 0.5em);

	/* Internal knobs (override only if needed). */
	--tc-searchbar-panel-radius: 1.25em;
	--tc-searchbar-focus-ring: 0 0 0 3px rgba(0, 213, 99, 0.35);

	position: relative;
	width: 100%;
	margin: 0;
	font-size: var(--tc-searchbar-font-size);
	color: var(--tc-searchbar-text);
}

.tc-searchbar *,
.tc-searchbar *::before,
.tc-searchbar *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------------
 * The bar
 * ------------------------------------------------------------------ */

.tc-searchbar__bar {
	display: flex;
	align-items: center;
	gap: var(--tc-searchbar-gap);
	padding: 0.3em;
	background: var(--tc-searchbar-bg);
	border: 1px solid var(--tc-searchbar-border);
	border-radius: var(--tc-searchbar-radius);
	box-shadow: var(--tc-searchbar-shadow);
}

.tc-searchbar__field {
	display: flex;
	align-items: center;
	gap: var(--space-xs, 0.625em);
	min-width: 0;
}

.tc-searchbar__field--query {
	flex: 1 1 60%;
}

.tc-searchbar__field--filter {
	flex: 0 1 auto;
	padding-right: 0.25em;
}

.tc-searchbar__icon {
	display: inline-flex;
	flex: 0 0 auto;
	color: var(--tc-searchbar-muted);
}

.tc-searchbar__icon svg {
	display: block;
	width: 1.25em;
	height: 1.25em;
}

.tc-searchbar__divider {
	flex: 0 0 auto;
	align-self: stretch;
	width: 1px;
	margin: 0.375em 0.25em;
	background: var(--tc-searchbar-border);
}

/* Input — strip theme styling so the pill stays clean. */
.tc-searchbar__input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 0.75em 0;
	border: 0;
	background: transparent;
	font: inherit;
	font-size: var(--text-s, 0.875em);
	color: inherit;
	outline: none;
	box-shadow: none;
}

.tc-searchbar__input::placeholder {
	color: var(--tc-searchbar-muted);
	opacity: 1;
}

.tc-searchbar__input::-webkit-search-cancel-button,
.tc-searchbar__input::-webkit-search-decoration {
	-webkit-appearance: none;
	appearance: none;
}

.tc-searchbar__select {
	max-width: 14em;
	padding: 0.75em 1.75em 0.75em 0;
	border: 0;
	background-color: transparent;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.25em center;
	background-size: 1em;
	font: inherit;
	/* Match the enhanced toggle's text size so there is no layout/text
	   shift (CLS) when frontend.js swaps the native select for the styled
	   dropdown after load. Keep in sync with .tc-searchbar__select-value. */
	font-size: calc(var(--text-xs, 0.75em) * 1.2);
	color: inherit;
	outline: none;
	box-shadow: none;
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
}

/* Enhanced taxonomy dropdown — frontend.js visually replaces the native
   select with a toggle button + listbox; the native element stays in the
   DOM (hidden) for no-JS rendering and form submission. */
.tc-searchbar__select--enhanced {
	display: none;
}

.tc-searchbar__select-wrap {
	position: relative;
	display: flex;
	align-items: center;
	min-width: 0;
}

.tc-searchbar__select-toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	max-width: 14em;
	padding: 0.75em 0.25em 0.75em 0;
	border: 0;
	background: transparent;
	font: inherit;
	font-size: var(--text-s, 0.875em);
	color: inherit;
	cursor: pointer;
}

.tc-searchbar__select-value {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	/* Keep in sync with the native .tc-searchbar__select font-size above so
	   the displayed term does not change size on JS enhancement. */
	font-size: calc(var(--text-xs, 0.75em) * 1.2);
}

.tc-searchbar__select-caret {
	flex: 0 0 auto;
	width: 1em;
	height: 1em;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 1em;
	transition: transform 0.15s ease;
}

.tc-searchbar__select-toggle[aria-expanded="true"] .tc-searchbar__select-caret {
	transform: rotate(180deg);
}

.tc-searchbar__select-toggle:focus-visible {
	outline: none;
	box-shadow: var(--tc-searchbar-focus-ring);
	border-radius: 0.5em;
}

.tc-searchbar__select-list {
	position: absolute;
	top: calc(100% + 0.875em);
	right: -0.5em;
	z-index: 10000;
	min-width: 13em;
	max-height: 19em;
	overflow-y: auto;
	margin: 0;
	padding: 0.375em;
	list-style: none;
	font-size: var(--text-s, 0.875em);
	background: var(--tc-searchbar-bg);
	border: 1px solid var(--tc-searchbar-border);
	border-radius: 1em;
	box-shadow: var(--tc-searchbar-shadow);
}

.tc-searchbar__select-list[hidden] {
	display: none;
}

.tc-searchbar__select-list:focus {
	outline: none;
}

.tc-searchbar__select-option {
	margin: 0;
	padding: 0.55em 2.25em 0.55em 0.875em;
	border-radius: 0.625em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	cursor: pointer;
}

.tc-searchbar__select-option.is-active {
	background: rgba(0, 213, 99, 0.1);
}

.tc-searchbar__select-option[aria-selected="true"] {
	font-weight: 600;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2300d563' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75em center;
	background-size: 1em;
}

/* Button — green pill, dark text, icon on the right. */
.tc-searchbar__button {
	display: inline-flex;
	flex: 0 0 auto;
	align-items: center;
	gap: var(--space-xs, 0.5em);
	padding: 0.875em var(--space-m, 1.75em);
	border: 0;
	border-radius: var(--tc-searchbar-radius);
	background: var(--tc-searchbar-accent);
	color: var(--tc-searchbar-accent-text);
	font: inherit;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	transition: filter 0.15s ease, transform 0.15s ease;
}

.tc-searchbar__button .tc-searchbar__icon {
	color: inherit;
}

.tc-searchbar__button-text {
	font-size: var(--text-s, 0.875em);
}

.tc-searchbar__button:hover {
	filter: brightness(0.94);
}

.tc-searchbar__button:active {
	transform: scale(0.98);
}

/* Focus states: the whole bar lights up while the input has focus;
   select/button keep their own visible rings for keyboard users. */
.tc-searchbar__bar:focus-within {
	border-color: var(--tc-searchbar-accent);
}

.tc-searchbar__input:focus,
.tc-searchbar__input:focus-visible {
	outline: none;
	box-shadow: none;
}

.tc-searchbar__select:focus-visible,
.tc-searchbar__button:focus-visible {
	outline: none;
	box-shadow: var(--tc-searchbar-focus-ring);
	border-radius: 0.5em;
}

.tc-searchbar__button:focus-visible {
	border-radius: var(--tc-searchbar-radius);
}

/* ---------------------------------------------------------------------
 * Results panel
 * ------------------------------------------------------------------ */

.tc-searchbar__panel {
	position: absolute;
	top: calc(100% + var(--space-xs, 0.5em));
	left: 0;
	right: 0;
	z-index: 9999;
	overflow: hidden;
	background: var(--tc-searchbar-bg);
	border: 1px solid var(--tc-searchbar-border);
	border-radius: var(--tc-searchbar-panel-radius);
	box-shadow: var(--tc-searchbar-shadow);
}

.tc-searchbar__panel[hidden] {
	display: none;
}

/* Host-cascade resilience.
 *
 * The bar is embedded in arbitrary themes and page builders (Bricks,
 * Oxygen, Elementor…). Some of them set `position: relative`/`static` on
 * structural elements with rules that out-weigh a single BEM class. If the
 * panel loses `position: absolute` it drops into normal flow: the section
 * stretches to fit it and its z-index is ignored (z-index only applies to
 * positioned boxes), so it ends up overlapped by the section below — no
 * matter how high the value is raised.
 *
 * Pin the panel as an overlay with selectors specific enough to win that
 * cascade. These only restate the layout already declared above; they add
 * no new behaviour. The form is kept as the panel's positioning context so
 * the overlay always anchors to the bar. */
.tc-searchbar.tc-searchbar {
	position: relative !important;
}

.tc-searchbar .tc-searchbar__panel {
	position: absolute !important;
	top: calc(100% + var(--space-xs, 0.5em)) !important;
	left: 0 !important;
	right: 0 !important;
	z-index: 9999 !important;
}

.tc-searchbar__results {
	list-style: none;
	margin: 0;
	padding: 0.375em;
	max-height: 26em;
	overflow-y: auto;
}

.tc-searchbar__result {
	margin: 0;
}

.tc-searchbar__result-link {
	display: flex;
	align-items: flex-start;
	gap: var(--space-s, 0.875em);
	padding: 0.4em;
	border-radius: 0.875em;
	text-decoration: none;
	color: inherit;
	cursor: pointer;
}

.tc-searchbar__result-link:hover,
.tc-searchbar__result[aria-selected="true"] .tc-searchbar__result-link {
	background: rgba(0, 213, 99, 0.1);
}

.tc-searchbar__result-image {
	flex: 0 0 auto;
	width: 3em;
	height: 3em;
	border-radius: 0.625em;
	object-fit: cover;
	background: var(--tc-searchbar-border);
}

.tc-searchbar__result-body {
	min-width: 0;
}

.tc-searchbar__result-title {
	display: block;
	margin-bottom: 0.2em;
	font-weight: 600;
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.tc-searchbar__result-excerpt {
	display: block;
	margin-top: 0.125em;
	font-size: var(--text-s, 0.875em);
	line-height: 1.4;
	color: var(--base, var(--tc-searchbar-muted));
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.tc-searchbar__result-taxonomy {
	display: inline-block;
	margin-top: 0.375em;
	padding: 0.125em 0.625em;
	border-radius: 999px;
	background: rgba(0, 213, 99, 0.12);
	color: var(--tc-searchbar-text);
	font-size: var(--text-xs, 0.75em);
	font-weight: 600;
}

/* Status row (loading / empty / error) + "view all" link. */
.tc-searchbar__status {
	padding: var(--space-s, 0.875em) var(--space-m, 1.25em);
	font-size: var(--text-s, 0.9em);
	color: var(--tc-searchbar-muted);
}

.tc-searchbar__status:empty {
	display: none;
}

.tc-searchbar__status--error {
	color: #c0392b;
}

.tc-searchbar__view-all {
	display: block;
	padding: var(--space-xs, 0.5em) var(--space-s, 0.875em);
	border-top: 1px solid var(--tc-searchbar-border);
	text-align: center;
	font-size: var(--text-m, 1em);
	font-weight: 600;
	color: var(--tc-searchbar-text);
	text-decoration: none;
}

.tc-searchbar__view-all:hover {
	background: rgba(0, 213, 99, 0.1);
}

/* ---------------------------------------------------------------------
 * Responsive: stack below tablet width.
 * ------------------------------------------------------------------ */

@media (max-width: 700px) {
	.tc-searchbar {
		--tc-searchbar-radius: 1.25em;
	}

	.tc-searchbar__bar {
		flex-wrap: wrap;
		padding: var(--space-xs, 0.625em) var(--space-s, 0.875em);
	}

	.tc-searchbar__field--query {
		flex: 1 1 100%;
		border-bottom: 1px solid var(--tc-searchbar-border);
	}

	.tc-searchbar__divider {
		display: none;
	}

	.tc-searchbar__field--filter {
		flex: 1 1 auto;
	}

	.tc-searchbar__select {
		width: 100%;
		max-width: none;
	}

	.tc-searchbar__select-wrap {
		width: 100%;
	}

	.tc-searchbar__select-toggle {
		width: 100%;
		max-width: none;
		justify-content: space-between;
	}

	.tc-searchbar__select-list {
		left: 0;
		right: 0;
	}

	.tc-searchbar__button {
		flex: 0 0 auto;
		margin-left: auto;
	}
}

@media (max-width: 420px) {
	.tc-searchbar__field--filter {
		flex: 1 1 100%;
		border-bottom: 1px solid var(--tc-searchbar-border);
		padding-right: 0;
	}

	.tc-searchbar__button {
		flex: 1 1 100%;
		justify-content: center;
		margin-top: 0.25em;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tc-searchbar__button,
	.tc-searchbar__select-caret {
		transition: none;
	}
}
