/**
 * PropOffice Property Archive — the four controls.
 *
 * Filters, Sort, Favourites and Show Map, plus the breadcrumb, the page position
 * and the numbered pages that sit with them.
 *
 * Painted entirely in design-system roles (--po-ds-*), never in literal brand
 * colours, so the toolbar takes on the website's brand exactly as every other
 * PropOffice component does. The only literals here are neutral fallbacks for a
 * site that has not run the runtime layer at all.
 *
 * 🚨 NOTHING HERE STYLES A PROPERTY CARD. Not one selector reaches inside
 * `.po-pc`, and the grid the cards sit in is the Property Card's own. The cards
 * were designed before this component existed and are unchanged by it.
 */

.po-archive__breadcrumb,
.po-archive__toolbar,
.po-archive__map,
.po-archive__pagination {
	--po-archive-radius: 8px;
	--po-archive-gap: 12px;
	--po-archive-control-height: 44px;

	box-sizing: border-box;
	color: var(--po-ds-color-text, #0f172a);
	font-family: var(--po-ds-font-family, inherit);
}

.po-archive__breadcrumb *,
.po-archive__toolbar *,
.po-archive__map *,
.po-archive__pagination * {
	box-sizing: inherit;
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */

.po-archive__breadcrumb {
	margin: 0 0 16px;
}

.po-archive__crumbs {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.po-archive__crumb {
	align-items: center;
	display: flex;
	font-size: 14px;
	gap: 6px;
}

.po-archive__crumb-link {
	color: var(--po-ds-color-primary, #1e293b);
	text-decoration: none;
}

.po-archive__crumb-link:hover,
.po-archive__crumb-link:focus-visible {
	text-decoration: underline;
}

.po-archive__crumb-current {
	color: var(--po-ds-color-muted, #64748b);
}

.po-archive__crumb-separator {
	color: var(--po-ds-color-muted, #94a3b8);
	display: inline-flex;
}

/* ── The toolbar ─────────────────────────────────────────────────────────── */

/*
 * Page position on the left, the three controls on the right — the reference's
 * arrangement. `position: relative` because the filter panel is a popover
 * anchored to this bar.
 */
.po-archive__toolbar {
	align-items: center;
	container-type: inline-size;
	display: flex;
	flex-wrap: wrap;
	gap: var(--po-archive-gap);
	justify-content: space-between;
	margin: 0 0 20px;
	position: relative;
}

.po-archive__toolbar-start,
.po-archive__controls {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: var(--po-archive-gap);
}

/*
 * Every control on the bar is the same height and the same shape. Written once
 * here rather than four times below, because "aligned, consistent in height,
 * visually balanced" is one rule and four copies of it drift.
 *
 * 🚨 `box-sizing` is DECLARED here, not inherited. The reset above says
 * `box-sizing: inherit` for everything inside the toolbar, and measured on a
 * real page the `<summary>` did not take it — it computed `content-box` while
 * its own parent computed `border-box`. With `min-height` applying to the
 * CONTENT box the two borders were added on top, and the Filters trigger stood
 * 46px tall in a row of 44px controls.
 *
 * This is the same lesson this codebase has now recorded five times in a
 * slightly different costume: a property is only guaranteed where it is
 * DECLARED. Two pixels is small; a control that is visibly out of line with the
 * three beside it is not.
 */
.po-archive__filter-trigger,
.po-archive__pager,
.po-archive__sort,
.po-archive__favourites,
.po-archive__map-toggle {
	background: var(--po-ds-color-surface, #ffffff);
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: var(--po-archive-radius);
	box-sizing: border-box;
	font-size: 14px;
	min-height: var(--po-archive-control-height);
}

/* Focus is visible on every one of them, and it is the same ring. */
.po-archive__filter-trigger:focus-visible,
.po-archive__sort-select:focus-visible,
.po-archive__favourites:focus-visible,
.po-archive__map-toggle:focus-visible,
.po-archive__page-link:focus-visible,
.po-archive__pager-step:focus-visible,
.po-archive__marker:focus-visible,
.po-archive__apply:focus-visible,
.po-archive__clear:focus-visible {
	outline: 2px solid var(--po-ds-color-accent, #2563eb);
	outline-offset: 2px;
}

/* ── Page position ───────────────────────────────────────────────────────── */

.po-archive__pager {
	align-items: center;
	display: flex;
	gap: 4px;
	padding: 0 4px;
}

.po-archive__pager-label {
	padding: 0 8px;
	white-space: nowrap;
}

.po-archive__pager-current {
	font-weight: 600;
}

.po-archive__pager-step {
	align-items: center;
	border-radius: 6px;
	color: var(--po-ds-color-text, #0f172a);
	display: inline-flex;
	height: 32px;
	justify-content: center;
	text-decoration: none;
	width: 32px;
}

.po-archive__pager-step:hover {
	background: var(--po-ds-color-background, #f1f5f9);
}

/*
 * A step that leads nowhere keeps its space. Removing it would slide the page
 * label sideways between page 1 and page 2, which reads as the toolbar moving
 * about while the visitor pages through.
 */
.po-archive__pager-step.is-disabled {
	color: var(--po-ds-color-muted, #cbd5e1);
	cursor: default;
}

/* ── Filters ─────────────────────────────────────────────────────────────── */

.po-archive__filters {
	position: relative;
}

.po-archive__filter-trigger {
	align-items: center;
	cursor: pointer;
	display: inline-flex;
	gap: 8px;
	list-style: none;
	padding: 0 14px;
	user-select: none;
}

/* Safari draws its own disclosure triangle through a pseudo-element. */
.po-archive__filter-trigger::-webkit-details-marker {
	display: none;
}

.po-archive__filter-trigger::marker {
	content: '';
}

.po-archive__filters[open] > .po-archive__filter-trigger,
.po-archive__filter-trigger:hover {
	border-color: var(--po-ds-color-primary, #0f172a);
}

.po-archive__filter-icon {
	display: inline-flex;
}

.po-archive__filter-count {
	background: var(--po-ds-color-primary, #0f172a);
	border-radius: 999px;
	color: var(--po-ds-color-on-primary, #ffffff);
	font-size: 12px;
	line-height: 18px;
	min-width: 18px;
	padding: 0 5px;
	text-align: center;
}

/*
 * The panel is a popover anchored to the toolbar rather than a page-width band,
 * so opening it does not push the results down the page and make the visitor
 * lose their place.
 */
.po-archive__panel {
	background: var(--po-ds-color-surface, #ffffff);
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: var(--po-archive-radius);
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
	left: 0;
	margin-top: 8px;
	max-width: calc(100vw - 32px);
	min-width: 320px;
	padding: 16px;
	position: absolute;
	top: 100%;
	z-index: 20;
}

.po-archive__panel-groups {
	display: grid;
	gap: 18px;
}

.po-archive__group {
	border: 0;
	margin: 0;
	min-width: 0;
	padding: 0;
}

.po-archive__group-legend {
	display: block;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	margin: 0 0 8px;
	padding: 0;
	text-transform: uppercase;
}

/*
 * 🚨 IT SCROLLS DOWN, NEVER ACROSS (M11).
 *
 * `overflow-y: auto` alone computes `overflow-x` to `auto` as well, so a long
 * option label made the filter panel scroll SIDEWAYS on a phone — and a
 * horizontal scrollbar inside a dropdown is a label a visitor never finds the
 * end of. Found at 768 and 375.
 *
 * `min-width: 0` is the half that matters: a grid item's automatic minimum size
 * is its content, so without it the row refuses to be narrower than its longest
 * word no matter what the label is told to do.
 */
.po-archive__options {
	display: grid;
	gap: 6px;
	max-height: 260px;
	min-width: 0;
	overflow-x: hidden;
	overflow-y: auto;
}

.po-archive__option {
	align-items: center;
	cursor: pointer;
	display: flex;
	gap: 8px;
	font-size: 14px;
	min-width: 0;
}

.po-archive__option-label {
	flex: 1 1 auto;
	min-width: 0;
	overflow-wrap: anywhere;
}

.po-archive__option-count {
	color: var(--po-ds-color-muted, #64748b);
	font-size: 12px;
}

.po-archive__keywords {
	background: var(--po-ds-color-surface, #ffffff);
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: 6px;
	color: inherit;
	font: inherit;
	padding: 0 12px;
	height: 40px;
	width: 100%;
}

.po-archive__panel-actions {
	align-items: center;
	border-top: 1px solid var(--po-ds-color-border, #e2e8f0);
	display: flex;
	gap: 12px;
	justify-content: space-between;
	margin-top: 16px;
	padding-top: 16px;
}

.po-archive__apply {
	background: var(--po-ds-color-primary, #0f172a);
	border: 1px solid var(--po-ds-color-primary, #0f172a);
	border-radius: 6px;
	color: var(--po-ds-color-on-primary, #ffffff);
	cursor: pointer;
	font: var(--po-ds-font-button, inherit);
	font-size: 14px;
	height: 40px;
	padding: 0 18px;
}

.po-archive__clear {
	color: var(--po-ds-color-muted, #64748b);
	font-size: 14px;
	text-decoration: underline;
}

/* ── Sort ────────────────────────────────────────────────────────────────── */

.po-archive__sort {
	align-items: center;
	display: flex;
	gap: 6px;
	padding: 0 12px;
}

.po-archive__sort-label {
	color: var(--po-ds-color-muted, #64748b);
	white-space: nowrap;
}

/*
 * The select carries no border of its own: the wrapper is the control, and a
 * second box inside it would read as two.
 */
/*
 * 🚨 THE SELECT FILLS THE CONTROL IT SITS IN (M11).
 *
 * The wrapper `.po-archive__sort` is 44px tall and looks like the control. The
 * `<select>` inside it was 17px — so a thumb landing anywhere in the other 27px
 * of a control that plainly invites a tap did nothing at all. Measured in a
 * browser; invisible in the markup, and invisible to the eye, because the
 * wrapper's border draws exactly the target a visitor believes is there.
 */
.po-archive__sort-select {
	align-self: stretch;
	background: transparent;
	border: 0;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: 14px;
	max-width: 190px;
	min-height: var(--po-archive-control-height);
	padding: 0 4px 0 0;
}

/*
 * The button is what makes sorting work with JavaScript switched off. The
 * script hides it and submits on change instead — so this is styled for the
 * moment before that happens, and for the visitor for whom it never does.
 */
.po-archive__sort-go {
	background: transparent;
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: 6px;
	color: inherit;
	cursor: pointer;
	font: inherit;
	font-size: 12px;
	padding: 4px 10px;
}

/* ── Favourites and Show Map ─────────────────────────────────────────────── */

.po-archive__favourites,
.po-archive__map-toggle {
	align-items: center;
	color: var(--po-ds-color-text, #0f172a);
	display: inline-flex;
	gap: 8px;
	padding: 0 16px;
	text-decoration: none;
}

.po-archive__favourites:hover,
.po-archive__map-toggle:hover {
	border-color: var(--po-ds-color-primary, #0f172a);
}

/*
 * The active state is a filled control, not a tint. A toggle whose two states
 * differ only by a slightly different grey is a toggle nobody can read.
 */
.po-archive__favourites.is-active,
.po-archive__map-toggle.is-active {
	background: var(--po-ds-color-primary, #0f172a);
	border-color: var(--po-ds-color-primary, #0f172a);
	color: var(--po-ds-color-on-primary, #ffffff);
}

.po-archive__favourites-icon,
.po-archive__map-toggle-icon {
	display: inline-flex;
}

.po-archive__favourites-count {
	background: var(--po-ds-color-background, #f1f5f9);
	border-radius: 999px;
	color: var(--po-ds-color-text, #0f172a);
	font-size: 12px;
	line-height: 18px;
	min-width: 18px;
	padding: 0 5px;
	text-align: center;
}

.po-archive__favourites.is-active .po-archive__favourites-count {
	background: rgba(255, 255, 255, 0.22);
	color: inherit;
}

/* ── The map ─────────────────────────────────────────────────────────────── */

.po-archive__map {
	margin: 0 0 24px;
	position: relative;
}

.po-archive__map-canvas {
	background: var(--po-ds-color-background, #e2e8f0);
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: var(--po-archive-radius);
	cursor: grab;
	height: 420px;
	overflow: hidden;
	position: relative;
	touch-action: none;
	width: 100%;
}

.po-archive__map-canvas.is-dragging {
	cursor: grabbing;
}

.po-archive__map-tiles {
	inset: 0;
	position: absolute;
}

/*
 * The tile element belongs to PropOffice's shared map renderer, which gives it
 * `po-map__tile`. Styled by that name rather than by the Property Location
 * component's, so this component does not reach into another's namespace for a
 * thing they both borrow.
 */
.po-archive__map-canvas .po-map__tile {
	position: absolute;
	height: 256px;
	width: 256px;
	user-select: none;
}

/*
 * A pin. Positioned by the shared renderer, which writes `left` and `top` in
 * pixels — so the transform below is what puts the point of the pin on the
 * coordinate rather than its top-left corner.
 */
.po-archive__marker {
	align-items: center;
	background: var(--po-ds-color-primary, #0f172a);
	border: 2px solid var(--po-ds-color-on-primary, #ffffff);
	border-radius: 999px;
	color: var(--po-ds-color-on-primary, #ffffff);
	cursor: pointer;
	display: flex;
	font-size: 12px;
	font-weight: 600;
	height: 28px;
	justify-content: center;
	line-height: 1;
	padding: 0;
	position: absolute;
	transform: translate(-50%, -50%);
	width: 28px;
	z-index: 2;
}

.po-archive__marker:hover,
.po-archive__marker.is-active {
	background: var(--po-ds-color-accent, #2563eb);
	z-index: 3;
}

.po-archive__map-controls {
	display: flex;
	flex-direction: column;
	gap: 6px;
	position: absolute;
	right: 12px;
	top: 12px;
	z-index: 4;
}

.po-archive__map-control {
	align-items: center;
	background: var(--po-ds-color-surface, #ffffff);
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: 6px;
	color: var(--po-ds-color-text, #0f172a);
	cursor: pointer;
	display: flex;
	font-size: 16px;
	height: 32px;
	justify-content: center;
	line-height: 1;
	padding: 0;
	width: 32px;
}

.po-archive__map-message,
.po-archive__map-note,
.po-archive__map-attribution {
	color: var(--po-ds-color-muted, #64748b);
	font-size: 13px;
	margin: 8px 0 0;
}

.po-archive__map--unavailable,
.po-archive__map--empty {
	background: var(--po-ds-color-background, #f8fafc);
	border: 1px dashed var(--po-ds-color-border, #e2e8f0);
	border-radius: var(--po-archive-radius);
	padding: 24px;
	text-align: center;
}

.po-archive__map--unavailable .po-archive__map-message,
.po-archive__map--empty .po-archive__map-message {
	margin: 0;
}

/*
 * The card a marker points at. A ring around the existing Property Card, drawn
 * on the card's own wrapper rather than by changing anything inside it.
 */
.po-pc.is-po-archive-highlighted,
.is-po-archive-highlighted > .po-pc {
	outline: 3px solid var(--po-ds-color-accent, #2563eb);
	outline-offset: 3px;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */

.po-archive__pagination {
	margin: 24px 0 0;
}

.po-archive__pages {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	list-style: none;
	margin: 0;
	padding: 0;
}

.po-archive__page-link {
	align-items: center;
	border: 1px solid var(--po-ds-color-border, #e2e8f0);
	border-radius: 6px;
	color: var(--po-ds-color-text, #0f172a);
	display: inline-flex;
	font-size: 14px;
	height: 36px;
	justify-content: center;
	min-width: 36px;
	padding: 0 8px;
	text-decoration: none;
}

.po-archive__page-link:hover {
	border-color: var(--po-ds-color-primary, #0f172a);
}

.po-archive__page.is-current .po-archive__page-link {
	background: var(--po-ds-color-primary, #0f172a);
	border-color: var(--po-ds-color-primary, #0f172a);
	color: var(--po-ds-color-on-primary, #ffffff);
}

.po-archive__page--gap {
	color: var(--po-ds-color-muted, #94a3b8);
	padding: 0 4px;
}

/* ── Narrow screens ──────────────────────────────────────────────────────── */

/*
 * 🚨 The panel stops being a popover. At 320px a popover anchored to a control
 * near the right-hand edge either overflows the viewport or is clipped by it,
 * and both are §64's "controls extending beyond viewport". In flow it simply
 * takes the width it has.
 */
/*
 * 🚨 Keyed on the TOOLBAR's own width, not the viewport's.
 *
 * Measured on a real page: a theme whose content column is 645px wide inside a
 * 1280px viewport got the DESKTOP layout in a tablet-sized box, and the two
 * halves of the bar wrapped onto separate lines by accident rather than
 * stacking on purpose. A viewport media query cannot see that, because the
 * viewport was never the constraint — the column was.
 *
 * A container query is the right tool and the fallback is honest: where it is
 * unsupported the bar still wraps rather than overflowing, because it is a
 * `flex-wrap: wrap` row and always was. The media query below covers the
 * remaining case — a genuinely narrow SCREEN — for the same browsers.
 */
@container (max-width: 720px) {
	/*
	 * 🚨 The container itself is NOT styled here, and cannot be: an element is
	 * not matched by its own container query — only its descendants are. A
	 * `flex-direction: column` on `.po-archive__toolbar` in this block would
	 * read as working and do nothing, which is worse than not writing it.
	 *
	 * Stacking is achieved through the two GROUPS instead. Each takes the full
	 * width, so the row they sit in wraps deterministically into two, and each
	 * group spaces its own controls across that row.
	 */
	.po-archive__toolbar-start,
	.po-archive__controls {
		justify-content: space-between;
		width: 100%;
	}

	.po-archive__filters {
		position: static;
	}

	.po-archive__panel {
		left: auto;
		margin-top: 12px;
		max-width: none;
		min-width: 0;
		position: static;
		width: 100%;
	}

	.po-archive__sort {
		flex: 1 1 auto;
	}

	.po-archive__sort-select {
		max-width: none;
		width: 100%;
	}
}

@media (max-width: 782px) {
	.po-archive__toolbar {
		align-items: stretch;
		flex-direction: column;
	}

	.po-archive__toolbar-start,
	.po-archive__controls {
		justify-content: space-between;
		width: 100%;
	}

	.po-archive__filters {
		position: static;
	}

	.po-archive__panel {
		left: auto;
		margin-top: 12px;
		max-width: none;
		min-width: 0;
		position: static;
		width: 100%;
	}

	.po-archive__sort {
		flex: 1 1 auto;
	}

	.po-archive__sort-select {
		max-width: none;
		width: 100%;
	}

	.po-archive__map-canvas {
		height: 320px;
	}
}

@media (max-width: 480px) {
	.po-archive__controls {
		display: grid;
		grid-template-columns: 1fr 1fr;
	}

	.po-archive__sort {
		grid-column: 1 / -1;
	}

	.po-archive__favourites,
	.po-archive__map-toggle {
		justify-content: center;
	}
}

/* A visitor who has asked for less movement gets none of it. */
@media (prefers-reduced-motion: reduce) {
	.po-archive__marker,
	.po-archive__page-link,
	.po-archive__favourites,
	.po-archive__map-toggle {
		transition: none;
	}
}
