/**
 * Ajax Product Filter styles.
 *
 * Conventions:
 *  - Everything is namespaced under .apf-* to avoid clashing with the theme.
 *  - Themeable values are CSS custom properties (set by Elementor style
 *    controls); override --apf-accent etc. to restyle.
 *  - Layout uses logical properties (margin-inline, inset-inline …) so the
 *    component is RTL-aware out of the box. A couple of [dir="rtl"] overrides
 *    handle the few cases logical properties can't express.
 */

/* -------------------------------------------------------------------------
 * Tokens / theme variables
 * ---------------------------------------------------------------------- */
.apf-filter {
	--apf-accent: #ef4444;
	--apf-text: #1f2937;
	--apf-muted: #6b7280;
	--apf-panel-bg: #ffffff;
	--apf-control-bg: #f3f4f6;
	--apf-border: #e5e7eb;
	--apf-radius: 12px;

	color: var(--apf-text);
	background: var(--apf-panel-bg);
	border: 1px solid var(--apf-border);
	border-radius: var(--apf-radius);
	padding: 16px;
	box-sizing: border-box;
}

.apf-filter *,
.apf-filter *::before,
.apf-filter *::after {
	box-sizing: border-box;
}

/* -------------------------------------------------------------------------
 * Top bar
 * ---------------------------------------------------------------------- */
.apf-filter__bar {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin-block-end: 12px;
}

.apf-filter__title {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.2;
}

.apf-filter__count {
	font-size: 0.85rem;
	color: var(--apf-muted);
}

.apf-filter__clear {
	margin-inline-start: auto;
	padding: 0;
	border: 0;
	background: none;
	color: var(--apf-accent);
	font-size: 0.85rem;
	font-weight: 600;
	cursor: pointer;
}

.apf-filter__clear:hover {
	text-decoration: underline;
}

.apf-filter__clear[hidden] {
	display: none;
}

/* -------------------------------------------------------------------------
 * Active filter chips
 * ---------------------------------------------------------------------- */
.apf-filter__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-block-end: 14px;
}

.apf-filter__chips:empty {
	display: none;
}

.apf-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 6px 4px 12px;
	border-radius: 999px;
	background: var(--apf-control-bg);
	font-size: 0.8rem;
	line-height: 1.4;
}

.apf-chip__remove {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 18px;
	block-size: 18px;
	border: 0;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.08);
	color: inherit;
	font-size: 0.8rem;
	line-height: 1;
	cursor: pointer;
}

.apf-chip__remove:hover {
	background: var(--apf-accent);
	color: #fff;
}

/* -------------------------------------------------------------------------
 * Sections / accordions
 * ---------------------------------------------------------------------- */
.apf-section {
	border-block-start: 1px solid var(--apf-border);
	padding-block: 14px;
}

.apf-section:first-child {
	border-block-start: 0;
	padding-block-start: 0;
}

.apf-section__heading {
	margin: 0 0 10px;
	font-size: 0.95rem;
	font-weight: 600;
}

.apf-section--toggles .apf-section__body {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.apf-accordion__header {
	display: flex;
	align-items: center;
	inline-size: 100%;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	cursor: pointer;
}

.apf-accordion__chevron {
	margin-inline-start: auto;
	inline-size: 10px;
	block-size: 10px;
	border-inline-end: 2px solid currentColor;
	border-block-end: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.2s ease;
}

.apf-section--accordion.is-open .apf-accordion__chevron {
	transform: rotate(-135deg);
}

.apf-accordion__body {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-block-start: 12px;
}

.apf-accordion__body[hidden] {
	display: none;
}

/* -------------------------------------------------------------------------
 * Checkboxes
 * ---------------------------------------------------------------------- */
.apf-check {
	display: flex;
	align-items: center;
	gap: 10px;
	cursor: pointer;
	font-size: 0.9rem;
	user-select: none;
}

.apf-check__input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.apf-check__box {
	flex: 0 0 auto;
	inline-size: 20px;
	block-size: 20px;
	border: 2px solid var(--apf-border);
	border-radius: 6px;
	background: var(--apf-panel-bg);
	transition: background 0.15s ease, border-color 0.15s ease;
	position: relative;
}

.apf-check__input:checked + .apf-check__box {
	background: var(--apf-accent);
	border-color: var(--apf-accent);
}

.apf-check__input:checked + .apf-check__box::after {
	content: "";
	position: absolute;
	inset-block-start: 2px;
	inset-inline-start: 6px;
	inline-size: 5px;
	block-size: 10px;
	border-inline-end: 2px solid #fff;
	border-block-end: 2px solid #fff;
	transform: rotate(45deg);
}

.apf-check__input:focus-visible + .apf-check__box {
	outline: 2px solid var(--apf-accent);
	outline-offset: 2px;
}

.apf-check__label {
	flex: 1 1 auto;
}

.apf-check__count {
	color: var(--apf-muted);
	font-size: 0.8rem;
}

/* -------------------------------------------------------------------------
 * iOS-style toggle switches
 * ---------------------------------------------------------------------- */
.apf-toggle {
	display: flex;
	align-items: center;
	gap: 12px;
	cursor: pointer;
	font-size: 0.9rem;
	user-select: none;
}

.apf-toggle__label {
	flex: 1 1 auto;
}

.apf-toggle__count {
	color: var(--apf-muted);
	font-size: 0.8rem;
}

.apf-toggle__input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.apf-toggle__track {
	flex: 0 0 auto;
	inline-size: 44px;
	block-size: 26px;
	border-radius: 999px;
	background: #d1d5db;
	transition: background 0.2s ease;
	position: relative;
}

.apf-toggle__thumb {
	position: absolute;
	inset-block-start: 3px;
	inset-inline-start: 3px;
	inline-size: 20px;
	block-size: 20px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
	transition: transform 0.2s ease;
}

.apf-toggle__input:checked + .apf-toggle__track {
	background: var(--apf-accent);
}

.apf-toggle__input:checked + .apf-toggle__track .apf-toggle__thumb {
	transform: translateX(18px);
}

.apf-toggle__input:focus-visible + .apf-toggle__track {
	outline: 2px solid var(--apf-accent);
	outline-offset: 2px;
}

/* Toggle thumb travels the other way in RTL. */
[dir="rtl"] .apf-toggle__input:checked + .apf-toggle__track .apf-toggle__thumb {
	transform: translateX(-18px);
}

/* -------------------------------------------------------------------------
 * Results grid + states
 * ---------------------------------------------------------------------- */
.apf-results {
	position: relative;
}

/* Drive the WooCommerce loop columns via our custom property. */
.apf-results ul.products {
	display: grid;
	grid-template-columns: repeat(var(--apf-columns, 3), minmax(0, 1fr));
	gap: var(--apf-grid-gap, 24px);
	margin: 0;
	padding: 0;
	list-style: none;
}

/*
 * The Elementor Loop Template path reuses the same `ul.products > li.product`
 * structure (with extra .apf-loop / .apf-loop__item classes), so all of the
 * grid, column and gap rules below apply to it unchanged.
 */

/* Neutralise the theme's float-based columns so the grid wins. */
.apf-results ul.products li.product {
	inline-size: auto !important;
	margin: 0 !important;
	float: none !important;
	clear: none !important;
}

.apf-results ul.products::before,
.apf-results ul.products::after {
	content: none !important;
}

.apf-results__inner {
	transition: opacity 0.2s ease;
}

/* Dim + block interaction while loading. */
.apf-results.is-loading .apf-results__inner {
	opacity: 0.45;
	pointer-events: none;
}

.apf-results__loader {
	position: absolute;
	inset: 0;
	display: none;
	align-items: flex-start;
	justify-content: center;
	padding-block-start: 80px;
}

.apf-results.is-loading .apf-results__loader {
	display: flex;
}

.apf-spinner {
	inline-size: 40px;
	block-size: 40px;
	border: 4px solid var(--apf-border, #e5e7eb);
	border-top-color: var(--apf-accent, #ef4444);
	border-radius: 50%;
	animation: apf-spin 0.8s linear infinite;
}

@keyframes apf-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.apf-spinner {
		animation-duration: 2s;
	}
}

/* -------------------------------------------------------------------------
 * Empty state
 * ---------------------------------------------------------------------- */
.apf-no-products {
	text-align: center;
	padding: 48px 16px;
	color: var(--apf-muted, #6b7280);
}

.apf-no-products p {
	margin: 0 0 6px;
}

.apf-no-products__hint {
	font-size: 0.85rem;
}

/* -------------------------------------------------------------------------
 * Pagination
 * ---------------------------------------------------------------------- */
.apf-pagination {
	margin-block-start: 28px;
}

.apf-pagination__list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	margin: 0;
	padding: 0;
	list-style: none;
}

.apf-pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-inline-size: 38px;
	block-size: 38px;
	padding-inline: 8px;
	border: 1px solid var(--apf-border, #e5e7eb);
	border-radius: 8px;
	text-decoration: none;
	color: inherit;
	line-height: 1;
}

.apf-pagination .page-numbers.current {
	background: var(--apf-accent, #ef4444);
	border-color: var(--apf-accent, #ef4444);
	color: #fff;
}

.apf-pagination .page-numbers.dots {
	border-color: transparent;
}

/* Flip the prev/next arrows in RTL. */
[dir="rtl"] .apf-pagination .prev,
[dir="rtl"] .apf-pagination .next {
	transform: scaleX(-1);
}

/*
 * Note: responsive columns are handled by the Results widget's responsive
 * "Columns" control, which updates --apf-columns per breakpoint. No extra
 * media queries are needed here.
 */

/* -------------------------------------------------------------------------
 * Price range (min–max dual slider)
 *
 * Two stacked native range inputs over one rail. The inputs are transparent
 * and ignore pointer events; only their thumbs are interactive, so either
 * thumb can be grabbed even where the inputs overlap.
 * ---------------------------------------------------------------------- */
.apf-price {
	padding-block-start: 2px;
}

.apf-price__display {
	font-weight: 700;
	margin-block-end: 10px;
}

.apf-price__sliders {
	position: relative;
	block-size: 22px;
}

.apf-price__rail,
.apf-price__fill {
	position: absolute;
	inset-block-start: 50%;
	transform: translateY(-50%);
	block-size: 4px;
	border-radius: 999px;
	pointer-events: none;
}

.apf-price__rail {
	inset-inline: 0;
	background: #e5e7eb;
}

.apf-price__fill {
	background: var(--apf-accent, #ef4444);
}

.apf-price__input {
	position: absolute;
	inset-inline: 0;
	inset-block-start: 0;
	inline-size: 100%;
	block-size: 22px;
	margin: 0;
	background: transparent;
	-webkit-appearance: none;
	appearance: none;
	pointer-events: none; /* thumbs re-enable below */
}

.apf-price__input:focus {
	outline: none;
}

.apf-price__input::-webkit-slider-runnable-track {
	background: transparent;
	border: 0;
}

.apf-price__input::-moz-range-track {
	background: transparent;
	border: 0;
}

.apf-price__input::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	pointer-events: auto;
	inline-size: 18px;
	block-size: 18px;
	margin-block-start: 2px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--apf-accent, #ef4444);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
	cursor: pointer;
}

.apf-price__input::-moz-range-thumb {
	pointer-events: auto;
	inline-size: 14px;
	block-size: 14px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--apf-accent, #ef4444);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
	cursor: pointer;
}

.apf-price__input:focus-visible::-webkit-slider-thumb {
	outline: 2px solid var(--apf-accent, #ef4444);
	outline-offset: 2px;
}

.apf-price__input:focus-visible::-moz-range-thumb {
	outline: 2px solid var(--apf-accent, #ef4444);
	outline-offset: 2px;
}

/* The max input sits on top; both thumbs stay reachable via pointer-events. */
.apf-price__input--max {
	z-index: 2;
}

.apf-price__scale {
	display: flex;
	justify-content: space-between;
	margin-block-start: 6px;
	font-size: 0.8rem;
	color: #6b7280;
}
