/**
 * Schmetti Product Filter: frontend styles.
 *
 * Class selectors only (never element or id selectors), so nothing leaks into the theme. Customise the look
 * through the custom properties on .spf, e.g. `.spf { --spf-accent: #c00; }` in the theme's CSS.
 *
 * Themes style lists in content areas. Divi 4 sets `list-style-type: disc; padding: 0 0 23px 1em;
 * line-height: 26px` on `.entry-content ul`, `.et-l--body ul` (Theme Builder layouts) and `#left-area ul`,
 * `padding: 2px 0 2px 20px` on nested lists, and `padding: 0 !important` in its sidebar module. So the list
 * resets below are scoped with `.spf` (beats the class rules), bullets are removed on the list items (their
 * own value beats the inherited one), the list padding reset is `!important` (beats the id rule), and the
 * child indent is a margin (the sidebar's `!important` padding cannot remove it).
 *
 * Collapsible blocks and subtrees are native details/summary; the server renders the open state. Sides use
 * logical properties, so the layout mirrors in right-to-left languages.
 *
 * @package Schmetti\ProductFilter
 */

.spf {
	--spf-gap: 1rem;
	--spf-gap-small: 0.375rem;
	--spf-text: inherit;
	--spf-muted: #5f5f5f;
	--spf-border: #c8c8c8;
	--spf-background: #fff;
	--spf-accent: #1e1e1e;
	--spf-accent-text: #fff;
	--spf-chip-background: #f0f0f0;
	--spf-chip-text: inherit;
	--spf-focus: #2271b1;
	--spf-radius: 4px;
	--spf-indent: 1.25rem;
	--spf-track: #c8c8c8;
	--spf-thumb: var(--spf-accent);
	--spf-thumb-size: 1.125rem;
	--spf-subtree-toggle-size: max(24px, 1.5rem);
	--spf-notice-text: #1e1e1e;
	--spf-notice-background: #f0f0f0;
	--spf-notice-border: var(--spf-accent);

	box-sizing: border-box;
	margin: 0 0 var(--spf-gap);
	color: var(--spf-text);
}

/* Visually hidden, still announced by screen readers. */
.spf-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.spf-title {
	margin: 0 0 var(--spf-gap-small);
}

/* Form and blocks */
.spf-form {
	margin: 0;
}

.spf-block {
	min-width: 0;
	margin: 0 0 var(--spf-gap);
	padding: 0;
	border: 0;
}

.spf-block__title {
	margin: 0 0 var(--spf-gap-small);
	padding: 0;
	font-weight: 600;
}

/* Collapsible block: details.spf-block > summary.spf-block__summary, then fieldset.spf-block__group with a
   visually hidden legend (the options keep their group name). The row is at least 2.75rem high. The summary
   and subtree rules are scoped with .spf, so theme rules for summary and details do not reach them. */
.spf-block__group {
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.spf .spf-block__summary {
	display: block;
	position: relative;
	box-sizing: border-box;
	min-height: 2.75rem;
	margin: 0;
	padding: 0;
	padding-block: max(0.25rem, (2.75rem - 1.5em) / 2);
	padding-inline: 0.25rem 2rem;
	list-style: none;
	line-height: 1.5;
	font-weight: 600;
	cursor: pointer;
}

.spf-block[open] > .spf-block__summary {
	margin-block-end: var(--spf-gap-small);
}

/* No theme or browser marker; each vendor pseudo-element in its own rule (an unknown one voids a list). */
.spf .spf-block__summary::before,
.spf .spf-subtree__toggle::before {
	content: none;
}

.spf .spf-block__summary::-webkit-details-marker {
	display: none;
}

.spf .spf-subtree__toggle::-webkit-details-marker {
	display: none;
}

/* "+" while closed, a minus sign while open, in the text colour. Decorative: an empty alternative text keeps
   it out of the accessibility tree (the summary itself is announced as expanded or collapsed). */
.spf .spf-block__summary::after,
.spf .spf-subtree__toggle::after {
	content: "+";
	content: "+" / "";
}

.spf-block[open] > .spf-block__summary::after,
.spf-subtree[open] > .spf-subtree__toggle::after {
	content: "\2212";
	content: "\2212" / "";
}

/* As wide as a subtree toggle, so the glyphs of a block and of its first level line up. */
.spf .spf-block__summary::after {
	position: absolute;
	top: 50%;
	inset-inline-end: 0;
	width: var(--spf-subtree-toggle-size);
	margin-top: -0.5em;
	font-size: 1.25em;
	font-weight: 400;
	line-height: 1;
	text-align: center;
}

.spf .spf-options {
	margin: 0;
	padding: 0 !important;
	list-style: none;
	line-height: inherit;
}

.spf .spf-options--children {
	margin-block: 0.25rem 0;
	margin-inline: var(--spf-indent) 0;
}

.spf .spf-option {
	margin: 0 0 0.25rem;
	padding: 0;
	list-style: none;
	line-height: 1.4;
}

/* Subtree: li.spf-option--collapsible > details.spf-subtree > summary.spf-subtree__toggle. The toggle sits at
   the end of the parent's row, after its checkbox in both visual and focus order. */
.spf .spf-option--collapsible {
	position: relative;
	padding-inline-end: calc(var(--spf-subtree-toggle-size) + 0.25rem);
}

.spf .spf-subtree {
	margin: 0;
	padding: 0;
	border: 0;
}

.spf .spf-subtree__toggle {
	display: block;
	position: absolute;
	top: 0;
	inset-inline-end: 0;
	box-sizing: border-box;
	width: var(--spf-subtree-toggle-size);
	height: var(--spf-subtree-toggle-size);
	margin: 0;
	padding: 0;
	list-style: none;
	line-height: var(--spf-subtree-toggle-size);
	text-align: center;
	cursor: pointer;
}

.spf-option::before,
.spf-option::after {
	content: none;
}

.spf-option__input {
	width: 1.125rem;
	height: 1.125rem;
	margin: 0;
	margin-inline-end: 0.5em;
	vertical-align: middle;
	accent-color: var(--spf-accent);
}

/* The label is the main click target: at least 24px high (WCAG 2.2, 2.5.8), more on touch screens. */
.spf-option__label {
	display: inline-block;
	min-height: 1.5rem;
	line-height: 1.5rem;
	cursor: pointer;
	vertical-align: middle;
}

@media (pointer: coarse) {

	.spf {
		--spf-subtree-toggle-size: max(24px, 2rem);
	}

	.spf-option__label {
		min-height: 2rem;
		line-height: 2rem;
	}
}

.spf-option--empty > .spf-option__label {
	color: var(--spf-muted);
}

.spf-count {
	color: var(--spf-muted);
	font-size: 0.875em;
}

.spf-count__value::before {
	content: "(";
}

.spf-count__value::after {
	content: ")";
}

/* Price */
.spf-price__fields {
	display: flex;
	flex-wrap: wrap;
	gap: var(--spf-gap-small) var(--spf-gap);
}

.spf-price__field {
	flex: 1 1 6rem;
	min-width: 0;
}

.spf-price__label {
	display: block;
	margin: 0 0 0.25rem;
	font-size: 0.875em;
}

.spf-price__currency {
	color: var(--spf-muted);
}

.spf-price__input {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	min-height: 2.5rem;
	margin: 0;
	padding: 0.375rem 0.5rem;
	border: 1px solid var(--spf-border);
	border-radius: var(--spf-radius);
	background: var(--spf-background);
	color: inherit;
	font: inherit;
}

.spf-price__slider {
	position: relative;
	height: 2rem;
	margin: var(--spf-gap-small) calc(var(--spf-thumb-size) / 2) 0;
}

.spf-price__slider::before {
	content: "";
	position: absolute;
	top: 50%;
	right: 0;
	left: 0;
	height: 4px;
	margin-top: -2px;
	border-radius: 2px;
	background: var(--spf-track);
}

.spf-price__range {
	position: absolute;
	top: 0;
	left: calc(var(--spf-thumb-size) / -2);
	width: calc(100% + var(--spf-thumb-size));
	height: 2rem;
	margin: 0;
	padding: 0;
	background: transparent;
	pointer-events: none;
	-webkit-appearance: none;
	appearance: none;
}

/* The later (max) input lies on top; the script raises the min input while its thumb is in the upper half, so a
   min thumb pushed onto the max thumb at the right end can still be dragged back. */
.spf-price__range--top {
	z-index: 1;
}

.spf-price__range::-webkit-slider-runnable-track {
	height: 2rem;
	background: transparent;
	border: 0;
}

.spf-price__range::-moz-range-track {
	height: 2rem;
	background: transparent;
	border: 0;
}

.spf-price__range::-webkit-slider-thumb {
	width: var(--spf-thumb-size);
	height: var(--spf-thumb-size);
	margin-top: calc((2rem - var(--spf-thumb-size)) / 2);
	border: 2px solid var(--spf-background);
	border-radius: 50%;
	background: var(--spf-thumb);
	cursor: pointer;
	pointer-events: auto;
	-webkit-appearance: none;
	appearance: none;
}

.spf-price__range::-moz-range-thumb {
	width: var(--spf-thumb-size);
	height: var(--spf-thumb-size);
	border: 2px solid var(--spf-background);
	border-radius: 50%;
	background: var(--spf-thumb);
	cursor: pointer;
	pointer-events: auto;
}

/* Buttons and links */
.spf-actions {
	margin: 0;
}

.spf-submit,
.spf-toggle {
	box-sizing: border-box;
	min-height: 2.75rem;
	margin: 0;
	padding: 0.5rem 1rem;
	border: 1px solid var(--spf-accent);
	border-radius: var(--spf-radius);
	background: var(--spf-accent);
	color: var(--spf-accent-text);
	font: inherit;
	line-height: 1.2;
	cursor: pointer;
}

.spf-toggle {
	display: none;
	align-items: center;
	gap: 0.5em;
	margin: 0 0 var(--spf-gap-small);
	border-color: var(--spf-border);
	background: var(--spf-background);
	color: inherit;
}

.spf-toggle__count {
	min-width: 1.5em;
	padding: 0 0.375em;
	border-radius: 1em;
	background: var(--spf-accent);
	color: var(--spf-accent-text);
	font-size: 0.875em;
	text-align: center;
}

.spf-active-filters {
	margin: var(--spf-gap) 0 0;
}

.spf--active-only > .spf-active-filters {
	margin-top: 0;
}

.spf .spf-active {
	display: flex;
	flex-wrap: wrap;
	gap: var(--spf-gap-small);
	margin: 0 0 var(--spf-gap-small);
	padding: 0 !important;
	list-style: none;
	line-height: inherit;
}

.spf .spf-active__item {
	margin: 0;
	padding: 0;
	list-style: none;
	line-height: 1.4;
}

.spf-active__item::before,
.spf-active__item::after {
	content: none;
}

.spf-chip {
	display: inline-flex;
	align-items: center;
	gap: 0.375em;
	min-height: 2rem;
	padding: 0.25rem 0.625rem;
	border-radius: 1rem;
	background: var(--spf-chip-background);
	color: var(--spf-chip-text);
	text-decoration: none;
}

.spf-chip::after {
	content: "\00D7";
	/* Decorative: an empty alternative text keeps it out of the accessibility tree (the link has its own text). */
	content: "\00D7" / "";
	font-size: 1.125em;
	line-height: 1;
}

.spf-chip:hover .spf-chip__text {
	text-decoration: line-through;
}

.spf-reset {
	color: inherit;
	font-size: 0.875em;
}

.spf-empty {
	margin: 0;
	color: var(--spf-muted);
}

.spf-note {
	margin: 0 0 var(--spf-gap-small);
	color: var(--spf-muted);
	font-size: 0.875em;
}

/* Empty result: p.spf-no-results[role=status] outside the form, so it stays visible while the mobile toggle
   hides the form. The text carries the meaning; the default colours have a contrast of at least 4.5:1. */
.spf .spf-no-results {
	margin: 0 0 var(--spf-gap-small);
	padding: 0.5rem 0.75rem;
	border: 0;
	border-inline-start: 4px solid var(--spf-notice-border);
	border-radius: var(--spf-radius);
	background: var(--spf-notice-background);
	color: var(--spf-notice-text);
}

/* Scoped like the box: a theme content-link rule such as .entry-content a would otherwise set a colour that
   the notice background was not chosen for. */
.spf .spf-no-results__reset {
	color: inherit;
	text-decoration: underline;
}

/* Keyboard focus */
.spf-option__input:focus-visible,
.spf-price__input:focus-visible,
.spf-submit:focus-visible,
.spf-toggle:focus-visible,
.spf-chip:focus-visible,
.spf-reset:focus-visible,
.spf-no-results__reset:focus-visible,
.spf-block__summary:focus-visible,
.spf-subtree__toggle:focus-visible {
	outline: 2px solid var(--spf-focus);
	outline-offset: 2px;
}

/* Inset, so a container with overflow: hidden cannot clip the outline at the edge of the row. The block
   summary keeps 0.25rem of inline-start padding, so the ring does not run through the first letter. */
.spf-block__summary:focus-visible,
.spf-subtree__toggle:focus-visible {
	outline-offset: -2px;
}

/* Hidden until the script enhances them (author styles would otherwise override [hidden]). */
.spf-toggle[hidden],
.spf-price__slider[hidden],
.spf-note[hidden] {
	display: none;
}

/* Small screens: the script reveals the toggle button and collapses the form. */
@media (max-width: 767.98px) {

	.spf--js .spf-toggle:not([hidden]) {
		display: inline-flex;
	}

	.spf--js.spf--collapsed .spf-form {
		display: none;
	}

	.spf-submit {
		width: 100%;
	}
}

/* Motion only for visitors who have not asked to reduce it. Opening and closing blocks is not animated. */
@media (prefers-reduced-motion: no-preference) {

	.spf-chip {
		transition: background-color 0.15s ease-in-out;
	}
}

.spf-chip:hover {
	background: var(--spf-border);
}

/* Print: the chips are the record of the applied filters; controls and links that only work on screen go. */
@media print {

	.spf-toggle,
	.spf-form,
	.spf-reset,
	.spf-no-results__reset {
		display: none !important;
	}

	.spf-chip::after {
		content: none;
	}
}
