/* The facet rail — a drawer on a phone, a column on a desktop.
 *
 * Every value here is a theme token or a plain measurement. No colour literal,
 * no font name, no store: the rail inherits whatever palette the store's
 * global styles set, which is what makes one stylesheet right on fifty stores
 * (PATTERN-RULE.md).
 *
 * The desktop layout is the UA's own `details` rule being overridden, not a
 * script: `.st-facet-drawer:not([open]) > :not(summary)` is an author rule and
 * author rules win. `content-visibility` is set too, because recent Chrome
 * hides a closed `details` with that rather than `display`.
 */

.st-facet-drawer {
	display: block;
	border: 1px solid var(--wp--preset--color--ti-line);
	border-radius: var(--wp--custom--st-radius, 2px);
	background: var(--wp--preset--color--ti-bg-alt);
	margin-bottom: 1.5rem;
}

.st-facet-drawer__summary {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	cursor: pointer;
	list-style: none;
	padding: 0.85rem 1rem;
	font-family: var(--wp--preset--font-family--space-mono);
	font-size: 0.72rem;
	letter-spacing: var(--wp--custom--st-track, 0.12em);
	text-transform: var(--wp--custom--st-case, uppercase);
}

.st-facet-drawer__summary::after {
	content: "+";
	margin-left: auto;
}

.st-facet-drawer[open] > .st-facet-drawer__summary::after {
	content: "\2212";
}

.st-facet-drawer__clear {
	margin: 0;
	padding: 0 1rem 0.5rem;
	font-size: 0.78rem;
}

.st-facet {
	display: block;
	border-top: 1px solid var(--wp--preset--color--ti-line);
}

.st-facet__summary {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	cursor: pointer;
	list-style: none;
	padding: 0.7rem 1rem;
	font-weight: 600;
	font-size: 0.85rem;
}

.st-facet__summary::after {
	content: "+";
	margin-left: auto;
	opacity: 0.6;
}

.st-facet[open] > .st-facet__summary::after {
	content: "\2212";
}

.st-facet__terms {
	list-style: none;
	margin: 0;
	padding: 0 1rem 0.85rem;
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
}

.st-facet__term a {
	display: flex;
	gap: 0.5rem;
	align-items: baseline;
	text-decoration: none;
	font-size: 0.85rem;
	line-height: 1.35;
}

.st-facet__term.is-on a {
	font-weight: 700;
	text-decoration: underline;
}

.st-facet__count {
	margin-left: auto;
	font-family: var(--wp--preset--font-family--space-mono);
	font-size: 0.68rem;
	opacity: 0.65;
}

.st-facet__more {
	padding: 0 1rem 0.85rem;
}

.st-facet__more > summary {
	cursor: pointer;
	font-size: 0.78rem;
	opacity: 0.75;
}

.st-facet__more > .st-facet__terms {
	padding: 0.5rem 0 0;
}

/* Desktop: the drawer is not a drawer. Its own summary goes away and its
   contents are always shown, open or not, so the same markup is a column here
   and a tap target on a phone. */
@media (min-width: 1024px) {
	.st-facet-drawer > .st-facet-drawer__summary {
		display: none;
	}

	.st-facet-drawer:not([open]) > *:not(summary) {
		display: block;
		content-visibility: visible;
	}

	/* Chrome 131+ hides a closed <details> through its `::details-content`
	   slot, not through the children, so the rule above no longer reaches it
	   and the desktop rail rendered as an empty bordered box (measured on the
	   live /products/ in Chrome 141: drawer height 2px, 406px with this). */
	.st-facet-drawer::details-content {
		display: block;
		content-visibility: visible;
	}
}

/* The plugin's own filter column, when the theme rail has replaced it. Belt to
   inc/woocommerce/archive.php's braces: if a store re-enables the widget by
   hand, two rails still do not stack. */
.dtla-shop-archive__filters:has(.st-facet-drawer) .wpc-filters-main-wrap {
	display: none;
}

/* ── Applied filters, as chips · TT-5911 ────────────────────────────────────
   Above the drawer at every width: what is applied, each one a link that
   removes it, then Clear all. The kit's "inline actions". */
.st-facet-chips {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin: 0 0 1rem;
	padding: 0;
	list-style: none;
}

.st-facet-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	min-block-size: 32px;
	padding: 0 0.6rem;
	font-family: var(--wp--preset--font-family--space-mono);
	font-size: 0.72rem;
	letter-spacing: var(--wp--custom--st-track, 0.08em);
	text-transform: var(--wp--custom--st-case, uppercase);
	text-decoration: none;
	color: inherit;
	border: 1px solid var(--wp--preset--color--ti-fg, currentColor);
	border-radius: var(--wp--custom--st-radius, 2px);
}

.st-facet-chip:hover,
.st-facet-chip:focus-visible {
	color: var(--wp--preset--color--ti-bg, #fff);
	background: var(--wp--preset--color--ti-fg, currentColor);
}

.st-facet-chip__x {
	font-size: 1rem;
	line-height: 1;
}

.st-facet-chips__clear {
	font-size: 0.78rem;
	text-decoration: underline;
	text-underline-offset: 0.2em;
	color: inherit;
}

.st-facet-chip .screen-reader-text {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* ── The trigger row names every facet, as the kit's does ─────────────────── */
.st-facet-drawer__label {
	flex-shrink: 0;
}

.st-facet-drawer__names {
	flex: 1 1 auto;
	min-inline-size: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	font-family: inherit;
	letter-spacing: 0;
	text-transform: none;
	opacity: 0.65;
}

/* The panel's own head (title + close) exists only in panel mode. `!important`
   from `desktop` up because the rule that re-shows the drawer's contents there
   (`.st-facet-drawer:not([open]) > *:not(summary)`) outranks a single class. */
.st-facet-drawer__head {
	display: none;
}

@media (min-width: 1024px) {
	.st-facet-drawer > .st-facet-drawer__head {
		display: none !important;
	}
}

/* ── Below `desktop`: the open drawer is a panel over the page ──────────────
   The contents slide in from the right; the summary's ::before is a fixed
   backdrop, and because it belongs to the summary, tapping it closes the
   drawer with no script. Behind @supports: a browser without ::details-content
   keeps the drawer opening in place, as it always did. */
@media (max-width: 1023.98px) {
	@supports selector(::details-content) {
		/* Open only: a closed slot hides its contents (content-visibility) but
		   not its own box, so a fixed panel on the closed slot would cover the
		   page empty. */
		.st-facet-drawer[open]::details-content {
			position: fixed;
			inset-block: 0;
			inset-inline-end: 0;
			z-index: 100001;
			inline-size: min(22rem, 88vw);
			overflow-y: auto;
			overscroll-behavior: contain;
			padding-block-end: 2rem;
			background: var(--wp--preset--color--ti-bg, #fff);
			box-shadow: -16px 0 40px -24px rgba(0, 0, 0, 0.45);
		}

		.st-facet-drawer[open]::details-content {
			animation: st-facet-slide-in 280ms cubic-bezier(0.22, 1, 0.36, 1);
		}

		.st-facet-drawer[open] > .st-facet-drawer__summary::before {
			content: "";
			position: fixed;
			inset: 0;
			z-index: 100000;
			background: rgba(0, 0, 0, 0.35);
			cursor: default;
		}

		.st-facet-drawer[open] .st-facet-drawer__head {
			display: flex;
			align-items: center;
			justify-content: space-between;
			gap: 1rem;
			padding: 0.75rem 1rem;
			border-block-end: 1px solid var(--wp--preset--color--ti-line);
		}

		.st-facet-drawer__title {
			margin: 0;
			font-family: var(--wp--preset--font-family--space-mono);
			font-size: 0.72rem;
			letter-spacing: var(--wp--custom--st-track, 0.12em);
			text-transform: var(--wp--custom--st-case, uppercase);
		}

		.st-facet-drawer__close {
			display: inline-flex;
			align-items: center;
			justify-content: center;
			inline-size: 44px;
			block-size: 44px;
			margin-inline-end: -0.5rem;
			padding: 0;
			font-size: 1.5rem;
			line-height: 1;
			color: inherit;
			background: transparent;
			border: 0;
			cursor: pointer;
		}

		.st-facet-drawer__close[hidden] {
			display: none;
		}

		/* The drawer's first facet and its Clear all, inside the panel. */
		.st-facet-drawer .st-facet:first-of-type {
			border-top: 0;
		}
	}
}

@keyframes st-facet-slide-in {
	from {
		transform: translateX(100%);
	}

	to {
		transform: translateX(0);
	}
}

@media (prefers-reduced-motion: reduce) {
	.st-facet-drawer[open]::details-content {
		animation: none;
	}
}

/* The page behind the open panel does not scroll (assets/st-facets.js). */
html.st-facets-open,
html.st-facets-open body {
	overflow: hidden;
}
