/* ==========================================================================
   Cars for sale — filter panel, toolbar.
   Loaded on the vehicle archive only. The page hero itself moved to
   components.css — every page wants it, not just this one.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Archive layout

   One filter form, one node in the DOM. Below 1024px it is a bottom sheet;
   above, it is a sticky sidebar. Rendering it twice would put two copies of
   every input name in the same form and break the no-JS submit.
   -------------------------------------------------------------------------- */

.pm-archive {
	padding-block: 2rem 4rem;
}

@media (min-width: 1024px) {
	.pm-archive {
		display: grid;
		grid-template-columns: 260px minmax(0, 1fr);
		gap: 2.5rem;
		align-items: start;
		padding-block: 3rem 5rem;
	}

	/* The empty-inventory panel is the archive's only child; let it span. */
	.pm-archive > .pm-empty {
		grid-column: 1 / -1;
	}
}

.pm-archive__backdrop {
	position: fixed;
	inset: 0;
	z-index: 50;
	background-color: rgba(0, 0, 0, 0.7);
	opacity: 0;
	transition: opacity 0.25s var(--ease);
}

.pm-archive__backdrop.is-open {
	opacity: 1;
}

.pm-archive__backdrop[hidden] {
	display: none;
}

/* --------------------------------------------------------------------------
   Filter panel — bottom sheet on phones
   -------------------------------------------------------------------------- */

.pm-filters {
	position: fixed;
	inset-inline: 0;
	bottom: 0;
	z-index: 51;
	max-height: 85vh;
	max-height: 85dvh;
	display: flex;
	flex-direction: column;
	background-color: var(--bg-base);
	border-top: 1px solid var(--border);
	border-radius: var(--radius-lg) var(--radius-lg) 0 0;
	transform: translateY(100%);
	transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.pm-filters.is-open {
	transform: translateY(0);
}

/* A closed sheet must not sit over the page catching taps.
   Scoped to the sheet's own breakpoint on purpose: as an unscoped rule its
   specificity (0,3,1) beat the desktop `.pm-filters` override (0,1,0) — media
   queries add none — and the sidebar rendered invisible on desktop while still
   occupying its grid column. */
@media (max-width: 1023px) {
	html.pm-js .pm-filters:not(.is-open) {
		visibility: hidden;
		pointer-events: none;
	}
}

/* Without JavaScript there is no sheet at all — the panel is a plain block
   above the grid, so every control stays reachable. */

html:not(.pm-js) .pm-filters {
	position: static;
	transform: none;
	max-height: none;
	visibility: visible;
	margin-bottom: 2rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
}

/* Both of these only ever close the sheet, and without the script there is no
   sheet to close. The <noscript> submit button is the one control that
   applies a filter here, so it should be the only one offered. */
html:not(.pm-js) .pm-filters__close,
html:not(.pm-js) .pm-filters__apply {
	display: none;
}

.pm-filters__form {
	display: flex;
	flex-direction: column;
	min-height: 0;
	padding: 1.25rem;
}

.pm-filters__head {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 1.25rem;
}

.pm-filters__title {
	flex: 1;
	font-family: var(--font-display);
	font-size: 1.125rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-primary);
	margin: 0;
}

.pm-filters__clear {
	display: inline-flex;
	align-items: center;
	min-height: 36px;
	padding-inline: 0.75rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	font-family: var(--font-display);
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-secondary);
	transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.pm-filters__clear:hover {
	border-color: var(--accent);
	color: var(--accent-text);
}

/* Nothing selected — the control stays in place so the header does not jump,
   but reads as unavailable. */
.pm-filters__clear.is-disabled {
	opacity: 0.4;
	pointer-events: none;
}

.pm-filters__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin-right: -0.5rem;
	color: var(--text-secondary);
}

.pm-filters__body {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	overflow-y: auto;
	min-height: 0;
	/* Room for the sticky apply button that overlays the scroll area. */
	padding-bottom: 0.5rem;
	-webkit-overflow-scrolling: touch;
}

.pm-filters__apply {
	margin-top: 1rem;
	flex-shrink: 0;
}

.pm-filters__submit {
	margin-top: 1rem;
}

@media (min-width: 1024px) {
	.pm-filters {
		position: sticky;
		/* Clears the fixed header. */
		top: calc(var(--header-h) + 1.5rem);
		inset-inline: auto;
		bottom: auto;
		z-index: 1;
		max-height: calc(100vh - var(--header-h) - 3rem);
		transform: none;
		visibility: visible;
		pointer-events: auto;
		background-color: transparent;
		border: 0;
		border-radius: 0;
	}

	.pm-filters__form {
		padding: 0;
		overflow: hidden;
	}

	.pm-filters__close,
	.pm-filters__apply {
		display: none;
	}
}

/* --------------------------------------------------------------------------
   Filter groups
   -------------------------------------------------------------------------- */

/*
 * The fieldset itself carries no styling. A <legend> is laid out inside its
 * parent's border by definition, so a bordered fieldset put the group title
 * through the panel edge and left a gap beneath it. The panel is drawn on an
 * inner element instead, which keeps the fieldset/legend semantics without
 * fighting their rendering.
 */
.pm-filter-group {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

.pm-filter-group__panel {
	padding: 1rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	background-color: var(--bg-elevated);
}

.pm-filter-group__title {
	padding: 0;
	font-family: var(--font-display);
	font-size: 0.875rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-primary);
	margin-bottom: 0.75rem;
}

.pm-filter-group__options {
	display: grid;
	/* Two columns on a phone keeps the seventeen makes from becoming a
	   seventeen-row scroll before anything else is reachable. */
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.25rem 0.75rem;
}

@media (min-width: 1024px) {
	.pm-filter-group__options {
		grid-template-columns: 1fr;
		gap: 0.125rem;
	}
}

.pm-check {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	/* 40px rows so a mis-aimed thumb still lands on the right make. */
	min-height: 40px;
	font-size: 0.875rem;
	color: var(--text-secondary);
	cursor: pointer;
	transition: color 0.2s var(--ease);
}

.pm-check:hover {
	color: var(--text-primary);
}

.pm-check input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.pm-check__box {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
	flex-shrink: 0;
	border: 1px solid var(--border-strong);
	border-radius: 4px;
	background-color: var(--bg-card);
	color: var(--text-on-accent);
	transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.pm-check__box svg {
	opacity: 0;
	transition: opacity 0.15s var(--ease);
}

.pm-check input:checked + .pm-check__box {
	background-color: var(--accent);
	border-color: var(--accent);
}

.pm-check input:checked + .pm-check__box svg {
	opacity: 1;
}

.pm-check input:focus-visible + .pm-check__box {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.pm-check input:checked ~ .pm-check__label {
	color: var(--text-primary);
}

.pm-check__label {
	line-height: 1.3;
}

/* --------------------------------------------------------------------------
   Range controls
   -------------------------------------------------------------------------- */

.pm-range__labels {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 1rem;
	font-size: 0.75rem;
	color: var(--text-secondary);
}

.pm-range__value {
	color: var(--accent-text);
	font-weight: 500;
}

/* --------------------------------------------------------------------------
   Toolbar
   -------------------------------------------------------------------------- */

.pm-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin-bottom: 1.5rem;
}

.pm-toolbar__count {
	font-size: 0.875rem;
	color: var(--text-secondary);
}

.pm-toolbar__count strong {
	color: var(--text-primary);
	font-weight: 500;
}

.pm-toolbar__controls {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.pm-toolbar__filters {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
	padding-inline: 0.875rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background-color: var(--bg-elevated);
	font-size: 0.875rem;
	color: var(--text-primary);
}

.pm-toolbar__filters .pm-icon {
	color: var(--accent-text);
}

.pm-toolbar__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding-inline: 0.25rem;
	border-radius: 999px;
	background-color: var(--accent);
	color: var(--text-on-accent);
	font-size: 0.6875rem;
	font-weight: 700;
	line-height: 1;
}

.pm-toolbar__badge[hidden] {
	display: none;
}

/* The sheet trigger is meaningless where the sidebar is always visible, and
   equally meaningless without the script that opens it. */
@media (min-width: 1024px) {
	.pm-toolbar__filters {
		display: none;
	}
}

html:not(.pm-js) .pm-toolbar__filters {
	display: none;
}

.pm-select {
	min-height: 44px;
	padding: 0 2.25rem 0 0.875rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background-color: var(--bg-elevated);
	color: var(--text-primary);
	font-size: 0.875rem;
	appearance: none;
	-webkit-appearance: none;
	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='%23a0a0b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75rem center;
	cursor: pointer;
	transition: border-color 0.2s var(--ease);
}

.pm-select:focus {
	border-color: var(--accent);
	outline: none;
}

.pm-empty[hidden] {
	display: none;
}
