/*
 * UAPL Multisearch
 *
 * Restyle by overriding the custom properties below in your theme, e.g.
 *   .uapl-ms { --uapl-ms-accent: #7a1f2b; }
 * Default colours meet WCAG 2.1 AA contrast on a white background.
 */

.uapl-ms {
	--uapl-ms-font-size: 1rem;
	--uapl-ms-gap: 0.75rem;
	--uapl-ms-radius: 4px;
	--uapl-ms-text: #1a1a1a;          /* 17.4:1 on white */
	--uapl-ms-bg: #ffffff;
	--uapl-ms-border: #595959;        /* 7:1 on white (1.4.11 needs 3:1) */
	--uapl-ms-accent: #005a9c;        /* 7.1:1 with white text */
	--uapl-ms-accent-hover: #003f6e;
	--uapl-ms-accent-text: #ffffff;
	--uapl-ms-focus: #005a9c;
	--uapl-ms-error: #b00020;         /* 7.3:1 on white */
	--uapl-ms-option-active-bg: #e6f0f8;
	--uapl-ms-arrow: var(--uapl-ms-text); /* keep at least 3:1 against --uapl-ms-bg */

	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: var(--uapl-ms-gap);
	margin: 0;
	color: var(--uapl-ms-text);
	font-size: var(--uapl-ms-font-size);
}

.uapl-ms__field {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.uapl-ms__field--query {
	flex: 3 1 16rem;
}

.uapl-ms__field--target {
	flex: 1 1 12rem;
}

.uapl-ms__label {
	font-weight: 600;
}

/* The error sits beside the label, so showing it doesn't push the fields out of line. */
.uapl-ms__label-row {
	display: flex;
	flex-wrap: wrap; /* long or translated messages drop below the label */
	align-items: baseline;
	column-gap: 0.75rem;
}

.uapl-ms__combo {
	position: relative;
}

.uapl-ms__input,
.uapl-ms__select,
.uapl-ms__submit {
	box-sizing: border-box;
	min-height: 2.75rem; /* 44px target size */
	margin: 0;
	border-radius: var(--uapl-ms-radius);
	font: inherit;
}

.uapl-ms__input,
.uapl-ms__select {
	width: 100%;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--uapl-ms-border);
	background: var(--uapl-ms-bg);
	color: var(--uapl-ms-text);
}

/*
 * Dropdown arrow. The native <select> is kept (full keyboard and screen reader
 * support); only its arrow is redrawn. Borders become the system text colour in
 * forced-colours mode, so the arrow stays visible there. It is decorative
 * CSS, so screen readers ignore it.
 */
.uapl-ms__select-wrap {
	position: relative;
}

.uapl-ms__select {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	padding-right: 2.5em; /* keep option text clear of the arrow */
}

.uapl-ms__select-wrap::after {
	content: "";
	position: absolute;
	top: 50%;
	right: 1em;
	width: 0.5em;
	height: 0.5em;
	border-right: 2px solid var(--uapl-ms-arrow);
	border-bottom: 2px solid var(--uapl-ms-arrow);
	transform: translateY(-70%) rotate(45deg);
	pointer-events: none; /* clicks go through to the select */
}

.uapl-ms__input[aria-invalid="true"] {
	border-color: var(--uapl-ms-error);
	border-width: 2px;
	padding: calc(0.5rem - 1px) calc(0.75rem - 1px); /* offset the thicker border so the text doesn't move */
}

.uapl-ms__submit {
	padding: 0.5rem 1.5rem;
	border: 2px solid var(--uapl-ms-accent);
	background: var(--uapl-ms-accent);
	color: var(--uapl-ms-accent-text);
	font-weight: 600;
	cursor: pointer;
}

.uapl-ms__submit:hover {
	border-color: var(--uapl-ms-accent-hover);
	background: var(--uapl-ms-accent-hover);
}

.uapl-ms__input:focus-visible,
.uapl-ms__select:focus-visible,
.uapl-ms__submit:focus-visible {
	outline: 3px solid var(--uapl-ms-focus);
	outline-offset: 2px;
}

/* Scoped to .uapl-ms so theme text rules (e.g. .entry-content span) can't add
   spacing that makes the label row taller and pushes the fields down. */
.uapl-ms .uapl-ms__error {
	margin: 0;
	padding: 0;
	color: var(--uapl-ms-error);
	font-size: inherit;
	font-weight: 600;
	line-height: inherit;
}

.uapl-ms .uapl-ms__error[hidden],
.uapl-ms__suggestions[hidden] {
	display: none;
}

.uapl-ms__suggestions {
	position: absolute;
	z-index: 100;
	top: calc(100% + 2px);
	right: 0;
	left: 0;
	max-height: 20rem;
	overflow-y: auto;
	margin: 0;
	padding: 0.25rem 0;
	border: 1px solid var(--uapl-ms-border);
	border-radius: var(--uapl-ms-radius);
	background: var(--uapl-ms-bg);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	list-style: none;
}

.uapl-ms__option {
	margin: 0;
	padding: 0.5rem 0.75rem;
	border-left: 4px solid transparent;
	overflow-wrap: anywhere; /* long unbroken terms wrap instead of scrolling sideways (1.4.10) */
	cursor: pointer;
}

.uapl-ms__option:hover {
	background: var(--uapl-ms-option-active-bg);
}

/* Only the keyboard-active option gets the border, so a resting mouse pointer
   can't make a second option look active (2.4.7). Not colour alone (1.4.1). */
.uapl-ms__option[aria-selected="true"] {
	border-left-color: var(--uapl-ms-accent);
	background: var(--uapl-ms-option-active-bg);
}

.uapl-ms__sr-only {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/* Windows High Contrast / forced colours. Borders are forced to a visible
   colour, even transparent ones, so the options set their own system colours. */
@media (forced-colors: active) {
	.uapl-ms__option,
	.uapl-ms__option:hover {
		forced-color-adjust: none;
		border-left-color: Canvas;
		background: Canvas;
		color: CanvasText;
	}

	.uapl-ms__option:hover {
		text-decoration: underline;
	}

	.uapl-ms__option[aria-selected="true"] {
		border-left-color: Highlight;
		background: Highlight;
		color: HighlightText;
	}
}

/* Stack fields on narrow screens (supports 320px reflow). */
@media (max-width: 30em) {
	.uapl-ms__field,
	.uapl-ms__submit {
		flex-basis: 100%;
	}
}
