/* ── Country search ────────────────────────────────────────────────────────── */
/* A filterable list of countries (blocks/country-search).

   The field starts hidden and view.js reveals it by adding .is-enhanced to the
   root. The no-JS state is the full list on its own. */

/* The surface the field and its dropdown panel share. Declared once here so the
   panel can never drift from the input it hangs off — they are one control as
   far as a visitor is concerned. If a background picker is ever added, it only
   has to override this property in render.php and the panel follows. */
.aa-country-search {
	--aa-cs-surface: var(--wp--preset--color--base, #fff);
	--aa-cs-line: var(--aa-cs-input-border-color, var(--wp--preset--color--neutral, #6b6b6b));
}

/* Hidden until view.js adds .is-enhanced — the controls, not their container.

   Hiding .aa-country-search__field wholesale would be the obvious way to write
   this and it is wrong: Only the parts that genuinely need script are hidden here. */
.aa-country-search__label,
.aa-country-search__input,
.aa-country-search__hint {
	display: none;
}

.aa-country-search.is-enhanced .aa-country-search__label,
.aa-country-search.is-enhanced .aa-country-search__input,
.aa-country-search.is-enhanced .aa-country-search__hint {
	display: block;
}

/* No max-width: the field fills whatever contains it, so its width is set by the
   group it sits in rather than by a number here. That makes it content width
   inside a constrained group, and narrower inside a column or on a small screen,
   without a breakpoint — the input is width:100% of this box. */
.aa-country-search.is-enhanced .aa-country-search__field {
	margin-block-end: var(--wp--preset--spacing--small, 1.5rem);
}

/* No display here: this rule sits after the hide rule above and matches with the
   same specificity, so a `display: block` would win and leak the label onto the
   page without its field. Visibility is the is-enhanced rule's job alone. */
.aa-country-search__label {
	margin-block-end: 0.5rem;
	font-weight: 600;
}

/* The four --aa-cs-input-* properties come from the block's own attributes, set
   on the wrapper in render.php. Each keeps a fallback here so the input is still
   styled if a property is absent — an older saved block, or the editor preview
   before an attribute is touched. */
.aa-country-search__input {
	box-sizing: border-box;
	width: 100%;
	padding: 0.6rem 0.75rem;
	font-family: inherit;
	font-size: 1rem;
	color: var(--aa-cs-input-color, inherit);
	background: var(--aa-cs-surface);
	border-style: solid;
	border-width: var(--aa-cs-input-border-width, 1px);
	border-color: var(--aa-cs-line);
	border-radius: var(--aa-cs-input-radius, var(--border-radius-default, 4px));
}

.aa-country-search__input:focus-visible {
	/* outline: 2px solid var(--wp--preset--color--primary, #003057);
	outline-offset: 1px; */
}

.aa-country-search__hint {
	margin-block: 0.5rem 0;
	font-size: 0.875rem;
	opacity: 0.7;
}

/* Holds its line once it has text, so the list doesn't jiggle as the wording
   changes between keystrokes. */
.aa-country-search__status {
	min-height: 1.5em;
	margin-block: 0 var(--wp--preset--spacing--small, 1.5rem);
	font-weight: 600;
	padding: 1em;
  border: 2px solid;
}

/* Collapsed until there is something to say — most visitors never type, and a
   permanently reserved blank line just reads as a hole above the list.

   Collapsed, not display:none: an aria-live region has to be in the
   accessibility tree before its text arrives, or the first message goes
   unannounced. */
.aa-country-search__status:empty {
	min-height: 0;
	margin-block-end: 0;
	padding: 0;
	border: 0;
}

/* A country's link and image, cloned into the message by view.js once a search
   lands on it. Structure only — colour, weight and font come from the message
   and the theme's own link styles, so a group's colour choices still apply. */
.aa-country-search__detail {
	display: block;
	margin-block-start: 0.5rem;
}

/* The second sentence of the message. */
.aa-country-search__tagline {
	display: block;
	margin-block-start: 0.5rem;
}

/* The link takes the colour of the text around it, never the theme's global
   link colour. Inside an accordion panel that global colour is often the
   panel's own background — a navy link on navy — and the link vanishes.
   Inheriting gives it the colour already proven readable in that context:
   --aa-acc-fg in a panel, the group's text colour anywhere else.

   Two classes deep on purpose. theme.json emits its link colour as
   `:root :where(a:not(.wp-element-button))`, which weighs the same as a single
   class, so a one-class rule here would be a tie decided by stylesheet order. */
.aa-country-search .aa-country-search__link {
	color: inherit;

	/* Colour no longer sets the link apart from its sentence, so the underline
	   has to carry that on its own. */
	text-decoration: underline;
}

/* Hover uses the theme's house hover colour, same as every other link on the
   site. It has to be restated here rather than left to style.css's `a:hover`,
   because the inherit rule above is two classes deep and would otherwise win on
   hover too.

   One placement to watch: this colour is the yellow preset, so on a yellow
   accordion panel the hover state matches the background. Set
   --aa-cs-link-hover on that panel to give it a different hover colour. */
.aa-country-search .aa-country-search__link:hover,
.aa-country-search .aa-country-search__link:focus {
	color: var(--aa-cs-link-hover, var(--wp--preset--color--yellow));
}

/* Height-led so a flag keeps its 3:2 and a portrait keeps its shape — cropping
   to a square would cut the edges off most flags. */
.aa-country-search__thumb {
	display: block;
	width: auto;
	height: 3rem;
}

.aa-country-search__list {
	margin: 0;
	padding: 0;
	list-style: none;
	column-gap: var(--wp--preset--spacing--medium, 2rem);
}

.aa-country-search__item {
	padding-block: 0.35rem;
	break-inside: avoid;
}

.aa-country-search__item[hidden] {
	display: none;
}

/* Columns are a class rather than an inline custom property so the breakpoints
   below can override them — an inline style would outrank both. */
.aa-country-search--cols-1 .aa-country-search__list { columns: 1; }
.aa-country-search--cols-2 .aa-country-search__list { columns: 2; }
.aa-country-search--cols-3 .aa-country-search__list { columns: 3; }
.aa-country-search--cols-4 .aa-country-search__list { columns: 4; }

@media (max-width: 900px) {
	.aa-country-search--cols-3 .aa-country-search__list,
	.aa-country-search--cols-4 .aa-country-search__list {
		columns: 2;
	}
}

@media (max-width: 600px) {
	.aa-country-search--cols-2 .aa-country-search__list,
	.aa-country-search--cols-3 .aa-country-search__list,
	.aa-country-search--cols-4 .aa-country-search__list {
		columns: 1;
	}
}


/* ── Dropdown mode ─────────────────────────────────────────────────────────── */
/* The list is rendered in full either way; here script folds it into a panel.
   Every rule below is gated on .is-enhanced, so without JavaScript the list
   stays an ordinary list in the flow rather than a panel that can never open. */

.aa-country-search--dropdown .aa-country-search__control {
	position: relative;
}

.aa-country-search--dropdown.is-enhanced .aa-country-search__list {
	position: absolute;
	z-index: 20;
	inset-inline: 0;
	top: 100%;
	max-height: 18rem;
	margin-block-start: 0.25rem;

	/* No horizontal padding: it would inset every option, so a highlighted row
	   would stop short of the panel edge and read as narrower than the field
	   above it. The options carry their own inset instead — see below. */
	padding: 0.25rem 0;
	overflow-y: auto;

	/* Reserve the scrollbar gutter whether or not it scrolls, so options keep
	   the same width as the visitor filters the list. No effect where scrollbars
	   are overlays. */
	scrollbar-gutter: stable;

	/* Stops the page from scrolling on once the panel hits its end. */
	overscroll-behavior: contain;

	/* `auto`, not `1`. The --cols-N rules above make this a multi-column
	   container, and a multicol box with a constrained height does not scroll
	   its overflow — it fragments into further columns laid out sideways. With
	   `columns: 1` the panel was 2500px wide and scrolled horizontally. Both
	   column-count and column-width have to be auto to leave multicol layout
	   entirely and get an ordinary scrolling block back. */
	columns: auto;

	/* Background, text and border all come from the field above, so the panel
	   reads as the same control rather than a system menu that happens to be
	   nearby. The border keeps its own 1px: matching the input's width would
	   make an 8px field hang a slab under itself. */
	color: var(--aa-cs-input-color, inherit);
	background: var(--aa-cs-surface);
	border: 1px solid var(--aa-cs-line);
	border-radius: var(--aa-cs-input-radius, var(--border-radius-default, 4px));
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.aa-country-search--dropdown.is-enhanced:not(.is-open) .aa-country-search__list {
	display: none;
}

.aa-country-search--dropdown.is-enhanced .aa-country-search__item {
	padding-block: 0.45rem;

	/* Puts each option's text on the same vertical line as the text in the field
	   above. The input insets its text by its own border plus 0.75rem; an option
	   sits inside the panel's fixed 1px border, so it needs that much less.
	   Written in terms of the border-width property rather than a fixed number
	   so the two stay aligned across the 0–8px the editor can choose. */
	padding-inline: calc(var(--aa-cs-input-border-width, 1px) + 0.75rem - 1px);

	/* No radius: the highlight is a full-width band, and rounded ends would pull
	   it visibly in from the panel edge again. The panel's own overflow clips the
	   first and last rows to its corners. */
	cursor: pointer;
}

/* Keyboard and pointer highlights are the same state deliberately: the arrow
   keys move aria-activedescendant, and the option under it should look exactly
   like the one under the mouse. */
.aa-country-search--dropdown.is-enhanced .aa-country-search__item.is-active,
.aa-country-search--dropdown.is-enhanced .aa-country-search__item:hover {
	/* Derived from the panel's own two colours, so the highlight keeps a gentle
	   contrast whatever the field is set to instead of always being grey.
	   The flat fallback comes first: engines without color-mix ignore the second
	   declaration and keep it. Firefox is the one that lagged here, and it has
	   supported color-mix since 113. */
	background: var(--wp--preset--color--light, #e0e1dd);
	background: color-mix(in srgb, var(--aa-cs-input-color, currentColor) 12%, var(--aa-cs-surface));
}
