/**
 * Proactive Enhanced Search — front-end styles.
 *
 * Neutral and theme-friendly: inherits the surrounding font, uses currentColor
 * and a single accent custom property so it sits naturally inside the theme's
 * search overlay. Override --pes-accent from the theme to recolour.
 */

/*
 * The toggle lives inside the theme's search form, which often applies large,
 * high-specificity styles to its labels and inputs. We use fixed units and
 * !important on the layout-critical properties so the control stays a small,
 * consistent pill regardless of the surrounding theme.
 */
.proactive-es-toggle {

	/* Inherit the theme's accent (block themes expose the palette as
	   --wp--preset--color--*); fall back through primary, then currentColor. */
	--pes-accent: var(--wp--preset--color--secondary, var(--wp--preset--color--primary, currentColor));
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	width: auto !important;
	margin: 0 0 0 8px !important;
	padding: 0;
	border: 0 !important;
	background: none !important;
	border-radius: 999px !important;
	line-height: 1 !important;
	cursor: pointer;

	/* Force the accent colour — the theme tends to set a white label colour in
	   the search overlay, which would make the icon invisible. Opacity signals
	   the on/off state. */
	color: var(--pes-accent) !important;
	opacity: 0.3;
	vertical-align: middle;
	transition: opacity 0.15s ease;
	user-select: none;
}

.proactive-es-toggle:hover {
	opacity: 0.8;
}

/* Screen-reader-only label (in case the theme doesn't define this class). */
.proactive-es-toggle__text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Visually hidden but still operable (the wrapping label toggles it). */
.proactive-es-toggle__input {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	border: 0 !important;
	opacity: 0 !important;
	overflow: hidden;
	clip: rect(0 0 0 0);
	pointer-events: none;
	appearance: none !important;
}

.proactive-es-toggle__icon {
	display: inline-flex;
	width: 30px;
}

.proactive-es-toggle__icon svg {
	display: block;
}

/* Active state — full-strength accent icon. */
.proactive-es-on .proactive-es-toggle {
	opacity: 1 !important;
}

.proactive-es-toggle__input:focus-visible + .proactive-es-toggle__icon {
	outline: 2px solid var(--pes-accent);
	outline-offset: 2px;
	border-radius: 2px;
}

/* Server-rendered results in "page" mode — reuses the inner result/chip styles
   without the overlay panel's height cap or fade. */
.proactive-es-page-results {
	--pes-accent: var(--wp--preset--color--secondary, var(--wp--preset--color--primary, currentColor));
	margin: 1.5rem 0;
}

/* Results panel */
.proactive-es-panel {
	--pes-accent: var(--wp--preset--color--secondary, var(--wp--preset--color--primary, currentColor));
	margin-top: 1.25rem;
	max-width: 60ch;
	width: 100%;
	text-align: left;
	animation: pes-fade 0.2s ease;

	/* Cap the height and scroll when there are many results. */
	max-height: min(55vh, 600px);
	overflow-y: auto;
	overscroll-behavior: contain;
	padding-right: 10px;

	/* Firefox scrollbar */
	scrollbar-width: thin;
	scrollbar-color: color-mix(in srgb, var(--pes-accent) 55%, transparent) transparent;
}

/* Soft fade at the bottom while there's more to scroll. */
.proactive-es-panel.pes-has-overflow {
	-webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 48px), transparent);
	mask-image: linear-gradient(to bottom, #000 calc(100% - 48px), transparent);
}

/* Remove the fade once scrolled to the bottom so the last item is crisp. */
.proactive-es-panel.pes-has-overflow.pes-at-bottom {
	-webkit-mask-image: none;
	mask-image: none;
}

/* WebKit/Blink scrollbar */
.proactive-es-panel::-webkit-scrollbar {
	width: 8px;
}

.proactive-es-panel::-webkit-scrollbar-track {
	background: transparent;
}

.proactive-es-panel::-webkit-scrollbar-thumb {
	background-color: color-mix(in srgb, currentcolor 22%, transparent);
	border-radius: 999px;
	transition: background-color 0.15s ease;
}

.proactive-es-panel::-webkit-scrollbar-thumb:hover {
	background-color: color-mix(in srgb, var(--pes-accent) 60%, transparent);
}

@keyframes pes-fade {

	from {
		opacity: 0;
		transform: translateY(4px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

.proactive-es-panel.is-loading {
	opacity: 0.7;
}

.proactive-es-summary {
	font-size: 1.05em;
	font-weight: 600;
	margin: 0 0 0.9rem;
	line-height: 1.4;
}

.proactive-es-summary__link {
	color: var(--pes-accent);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.proactive-es-summary__link:hover {
	text-decoration: none;
}

.proactive-es-results {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.proactive-es-result {
	padding: 0.85rem 1rem;
	border: 1px solid color-mix(in srgb, currentcolor 18%, transparent);
	border-radius: 10px;
	background: color-mix(in srgb, currentcolor 4%, transparent);
}

.proactive-es-result__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
}

.proactive-es-result__title {
	font-weight: 600;
	text-decoration: none;
	color: inherit;
}

.proactive-es-result__title:hover {
	text-decoration: underline;
}

.proactive-es-result__date {
	font-size: 0.8em;
	opacity: 0.7;
	white-space: nowrap;
}

/* Live figure card — leads the panel when a query names a market metric. */
.proactive-es-metric {
	margin: 0 0 1rem;
	padding: 0 0 0.9rem;
	border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.proactive-es-metric__label {
	margin: 0;
	font-size: 0.8125em;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	opacity: 0.7;
}

.proactive-es-metric__value {
	margin: 0.15rem 0 0;
	font-size: 1.75em;
	line-height: 1.15;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.proactive-es-metric__change {
	font-size: 0.5em;
	font-weight: 500;
	vertical-align: middle;
}

.proactive-es-metric--up .proactive-es-metric__change {
	color: #1a7f45;
}

.proactive-es-metric--down .proactive-es-metric__change {
	color: #b3261e;
}

.proactive-es-metric__meta {
	margin: 0.4rem 0 0;
	font-size: 0.75em;
	opacity: 0.7;
}

.proactive-es-metric__source {
	color: inherit;
}

/* Direct answer block — the lead element when a question is answered. */
.proactive-es-answer {
	margin: 0 0 1rem;
	padding: 0 0 0.9rem;
	border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.proactive-es-answer__text {
	margin: 0;
	font-size: 1.0625em;
	line-height: 1.5;
	font-weight: 500;
}

.proactive-es-answer__source {
	margin: 0.5rem 0 0;
	font-size: 0.8125em;
	opacity: 0.75;
}

.proactive-es-answer__source-label {
	font-weight: 600;
}

.proactive-es-answer__source-link {
	color: inherit;
}

/* The matched passage, shown under the title. */
.proactive-es-result__snippet {
	margin: 0.35rem 0 0;
	font-size: 0.875em;
	line-height: 1.45;
	opacity: 0.8;
}

/* Data breakdown (numbers/text values) */
.proactive-es-data {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0.15rem 0.9rem;
	margin: 0.6rem 0 0;
}

.proactive-es-data dt {
	font-size: 0.82em;
	opacity: 0.7;
	margin: 0;
}

.proactive-es-data dd {
	font-size: 0.9em;
	font-weight: 600;
	margin: 0;
}

.proactive-es-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-top: 0.6rem;
}

.proactive-es-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	padding: 0.25em 0.6em;
	font-size: 0.78em;
	text-decoration: none;
	color: inherit;
	border: 1px solid color-mix(in srgb, currentcolor 22%, transparent);
	border-radius: 6px;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.proactive-es-chip:hover {
	border-color: var(--pes-accent);
	background-color: color-mix(in srgb, var(--pes-accent) 10%, transparent);
}

.proactive-es-chip__type {
	font-weight: 700;
	font-size: 0.85em;
	letter-spacing: 0.03em;
	color: var(--pes-accent);
}

.proactive-es-chip__size {
	opacity: 0.6;
}

/* Standard page/post matches */
.proactive-es-pages-heading {
	margin: 1.25rem 0 0.5rem;
	font-size: 0.8em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	opacity: 0.6;
}

.proactive-es-pages {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.proactive-es-page__link {
	display: inline-block;
	padding: 0.3rem 0;
	color: inherit;
	text-decoration: none;
	border-bottom: 1px solid transparent;
}

.proactive-es-page__link:hover {
	border-bottom-color: var(--pes-accent);
	color: var(--pes-accent);
}

/* Post type badge and taxonomy terms on a result. */
.proactive-es-result__type {
	font-size: 0.7em;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	white-space: nowrap;
	opacity: 0.65;
}

.proactive-es-result__terms {
	margin: 0.2rem 0 0;
	font-size: 0.75em;
	opacity: 0.7;
}
