/* ==========================================================================
   AJAX Product Filter — frontend
   Override the look from your theme by redefining these variables on :root.
   ========================================================================== */

:root {
	--maf-accent: #1d2327;
	--maf-accent-contrast: #fff;
	--maf-text: #1f2937;
	--maf-muted: #6b7280;
	--maf-border: #e5e7eb;
	--maf-soft: #f4f5f7;
	--maf-star: #f59e0b;
	--maf-radius: 8px;
}

/* --------------------------------------------------------------------------
   Reset: keep theme button/list styles from leaking into the filter
   -------------------------------------------------------------------------- */
.maf-sidebar,
.maf-sidebar *,
.maf-sidebar *::before,
.maf-sidebar *::after,
.maf-toolbar *,
.maf-chips * {
	box-sizing: border-box;
}

.maf-sidebar button,
.maf-toolbar button,
.maf-chips button {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	box-shadow: none;
	font: inherit;
	line-height: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-align: left;
	color: inherit;
	cursor: pointer;
	min-height: 0;
	width: auto;
}

.maf-sidebar button:hover,
.maf-sidebar button:focus,
.maf-sidebar button:active,
.maf-toolbar button:hover,
.maf-toolbar button:focus,
.maf-toolbar button:active,
.maf-chips button:hover,
.maf-chips button:focus,
.maf-chips button:active {
	background: none;
	color: inherit;
	box-shadow: none;
}

.maf-sidebar button:focus-visible,
.maf-toolbar button:focus-visible,
.maf-chips button:focus-visible,
.maf-sidebar input:focus-visible,
.maf-toolbar select:focus-visible {
	outline: 2px solid var(--maf-accent);
	outline-offset: 2px;
}

.maf-sidebar ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

.maf-sidebar li {
	margin: 0;
	padding: 0;
}

.maf-sidebar h3 {
	margin: 0;
	padding: 0;
	font-size: inherit;
	line-height: inherit;
}

/* --------------------------------------------------------------------------
   Sidebar panel
   -------------------------------------------------------------------------- */
.maf-sidebar {
	color: var(--maf-text);
	font-size: 14px;
	line-height: 1.45;
}

.maf-panel__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 0 0 10px;
	border-bottom: 1px solid var(--maf-border);
}

.maf-panel__title {
	display: none;
	font-size: 17px;
	font-weight: 700;
}

.maf-sidebar .maf-link {
	margin-left: auto;
	font-size: 13px;
	color: var(--maf-muted);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.maf-sidebar .maf-link:hover {
	color: var(--maf-accent);
}

.maf-sidebar .maf-close {
	display: none;
	position: relative;
	width: 32px;
	height: 32px;
}

.maf-close::before,
.maf-close::after {
	content: "";
	position: absolute;
	top: 15px;
	left: 7px;
	width: 18px;
	height: 2px;
	background: var(--maf-text);
	transform: rotate(45deg);
}

.maf-close::after {
	transform: rotate(-45deg);
}

/* --------------------------------------------------------------------------
   Collapsible sections
   -------------------------------------------------------------------------- */
.maf-section {
	border-bottom: 1px solid var(--maf-border);
}

.maf-sidebar .maf-section__toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 14px 0;
	font-size: 14px;
	font-weight: 600;
	color: var(--maf-text);
}

.maf-section__toggle::after {
	content: "";
	flex: none;
	width: 7px;
	height: 7px;
	margin-right: 3px;
	border-right: 2px solid var(--maf-muted);
	border-bottom: 2px solid var(--maf-muted);
	transform: rotate(45deg) translate(-2px, -2px);
	transition: transform 0.2s ease;
}

.maf-section.is-collapsed .maf-section__toggle::after {
	transform: rotate(-45deg);
}

.maf-section__body {
	padding: 0 0 16px;
}

.maf-section__body[hidden] {
	display: none;
}

/* --------------------------------------------------------------------------
   Category tree
   -------------------------------------------------------------------------- */
.maf-tree__row {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 4px 0;
}

.maf-sidebar .maf-tree__link {
	flex: 1;
	min-width: 0;
	padding: 3px 0;
	color: var(--maf-text);
	word-break: break-word;
}

.maf-sidebar .maf-tree__link:hover {
	color: var(--maf-accent);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.maf-sidebar .maf-tree__link.is-active {
	font-weight: 700;
	color: var(--maf-accent);
}

.maf-tree__toggle,
.maf-tree__spacer {
	flex: none;
	width: 22px;
	height: 22px;
}

.maf-sidebar .maf-tree__toggle {
	position: relative;
	border-radius: 6px;
}

.maf-sidebar .maf-tree__toggle:hover {
	background: var(--maf-soft);
}

.maf-tree__toggle::before {
	content: "";
	position: absolute;
	top: 7px;
	left: 6px;
	width: 6px;
	height: 6px;
	border-right: 2px solid var(--maf-muted);
	border-top: 2px solid var(--maf-muted);
	transform: rotate(45deg);
	transition: transform 0.2s ease;
}

.maf-tree__item.is-open > .maf-tree__row .maf-tree__toggle::before {
	transform: rotate(135deg);
	top: 5px;
}

.maf-tree__children {
	margin-left: 6px;
	padding-left: 12px;
	border-left: 1px solid var(--maf-border);
}

.maf-tree__children[hidden] {
	display: none;
}

/* --------------------------------------------------------------------------
   Checkbox lists (brand, attributes, availability)
   -------------------------------------------------------------------------- */
.maf-sidebar .maf-check-list {
	max-height: 260px;
	overflow-y: auto;
}

.maf-check {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 5px 0;
	margin: 0;
	cursor: pointer;
}

.maf-sidebar .maf-check input[type="checkbox"] {
	flex: none;
	width: 16px;
	height: 16px;
	margin: 0;
	accent-color: var(--maf-accent);
	cursor: pointer;
}

.maf-check__label {
	flex: 1;
	min-width: 0;
}

.maf-badge {
	flex: none;
	min-width: 24px;
	padding: 1px 7px;
	border-radius: 999px;
	background: var(--maf-soft);
	font-size: 12px;
	color: var(--maf-muted);
	text-align: center;
}

/* --------------------------------------------------------------------------
   Price range (two native range inputs on one track)
   -------------------------------------------------------------------------- */
.maf-price {
	padding: 4px 4px 0;
}

.maf-range {
	position: relative;
	height: 24px;
}

.maf-range__track {
	position: absolute;
	top: 50%;
	left: 0;
	right: 0;
	height: 4px;
	margin-top: -2px;
	border-radius: 4px;
	background: var(--maf-border);
}

.maf-range__fill {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--maf-from, 0%);
	right: calc(100% - var(--maf-to, 100%));
	background: var(--maf-accent);
}

.maf-range input[type="range"] {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 24px;
	margin: 0;
	padding: 0;
	background: none;
	pointer-events: none;
	-webkit-appearance: none;
	appearance: none;
}

.maf-range input[type="range"]::-webkit-slider-runnable-track {
	background: none;
	height: 24px;
}

.maf-range input[type="range"]::-moz-range-track {
	background: none;
}

.maf-range input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 20px;
	height: 20px;
	margin-top: 2px;
	border-radius: 50%;
	border: 2px solid var(--maf-accent);
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
	pointer-events: auto;
	cursor: grab;
}

.maf-range input[type="range"]::-moz-range-thumb {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	border: 2px solid var(--maf-accent);
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
	pointer-events: auto;
	cursor: grab;
}

.maf-range input[type="range"]:focus-visible::-webkit-slider-thumb {
	outline: 2px solid var(--maf-accent);
	outline-offset: 2px;
}

.maf-price__values {
	display: flex;
	justify-content: space-between;
	margin-top: 8px;
	font-size: 13px;
	font-weight: 600;
}

/* --------------------------------------------------------------------------
   Rating
   -------------------------------------------------------------------------- */
.maf-rating {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.maf-sidebar .maf-rating__btn {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 6px 8px;
	border: 1px solid transparent;
	border-radius: var(--maf-radius);
}

.maf-sidebar .maf-rating__btn:hover {
	background: var(--maf-soft);
}

.maf-sidebar .maf-rating__btn.is-active {
	border-color: var(--maf-accent);
	background: var(--maf-soft);
}

.maf-rating__stars {
	color: var(--maf-star);
	letter-spacing: 1px;
}

.maf-rating__text {
	font-size: 13px;
	color: var(--maf-muted);
}

/* --------------------------------------------------------------------------
   Drawer footer (mobile only)
   -------------------------------------------------------------------------- */
.maf-drawer-footer {
	display: none;
}

/* --------------------------------------------------------------------------
   Toolbar, active-filter chips, product grid, pagination
   -------------------------------------------------------------------------- */
.maf-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin: 0 0 14px;
}

.maf-toolbar__count {
	flex: 1;
	margin: 0;
	font-size: 14px;
	color: var(--maf-muted);
}

.maf-toolbar__sort {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 14px;
}

.maf-toolbar__sort label {
	margin: 0;
	color: var(--maf-muted);
}

.maf-toolbar select {
	width: auto;
	min-width: 170px;
	height: auto;
	margin: 0;
	padding: 8px 12px;
	border: 1px solid var(--maf-border);
	border-radius: var(--maf-radius);
	background-color: #fff;
	font-size: 14px;
	color: var(--maf-text);
	cursor: pointer;
}

.maf-toolbar .maf-open-filters {
	display: none;
	align-items: center;
	gap: 8px;
	padding: 8px 14px;
	border: 1px solid var(--maf-border);
	border-radius: var(--maf-radius);
	font-size: 14px;
	font-weight: 600;
	background: #fff;
}

.maf-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0 0 14px;
}

.maf-chips[hidden] {
	display: none;
}

.maf-chips .maf-chip {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 5px 12px;
	border: 1px solid var(--maf-border);
	border-radius: 999px;
	background: var(--maf-soft);
	font-size: 13px;
	color: var(--maf-text);
}

.maf-chips .maf-chip::after {
	content: "\00d7";
	font-size: 16px;
	line-height: 1;
	color: var(--maf-muted);
}

.maf-chips .maf-chip:hover {
	border-color: var(--maf-accent);
}

.maf-chips .maf-chip--clear {
	border-color: transparent;
	background: none;
	text-decoration: underline;
	text-underline-offset: 3px;
	color: var(--maf-muted);
}

.maf-chips .maf-chip--clear::after {
	content: none;
}

.maf-products {
	position: relative;
	min-height: 160px;
}

.maf-products.is-loading > * {
	opacity: 0.4;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

.maf-products.is-loading::after {
	content: "";
	position: absolute;
	top: 80px;
	left: 50%;
	width: 34px;
	height: 34px;
	margin-left: -17px;
	border: 3px solid rgba(0, 0, 0, 0.1);
	border-top-color: var(--maf-accent);
	border-radius: 50%;
	animation: maf-spin 0.8s linear infinite;
}

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

/* Hide WooCommerce's own pagination once AJAX filtering has taken over. */
body.maf-filtering nav.woocommerce-pagination {
	display: none;
}

.maf-pagination ul {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px;
	margin: 28px 0 0;
	padding: 0;
	list-style: none;
}

.maf-pagination li {
	margin: 0;
	padding: 0;
}

.maf-pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 38px;
	height: 38px;
	padding: 0 8px;
	border: 1px solid var(--maf-border);
	border-radius: var(--maf-radius);
	font-size: 14px;
	font-weight: 600;
	color: var(--maf-text);
	text-decoration: none;
}

.maf-pagination a.page-numbers:hover {
	border-color: var(--maf-accent);
}

.maf-pagination .page-numbers.current {
	border-color: var(--maf-accent);
	background: var(--maf-accent);
	color: var(--maf-accent-contrast);
}

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

/* --------------------------------------------------------------------------
   Mobile: filters become a slide-in drawer
   -------------------------------------------------------------------------- */
.maf-backdrop {
	position: fixed;
	inset: 0;
	z-index: 99998;
	background: rgba(0, 0, 0, 0.45);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.25s ease;
}

@media (max-width: 782px) {
	.maf-toolbar .maf-open-filters {
		display: inline-flex;
	}

	.maf-toolbar__count {
		order: 3;
		flex-basis: 100%;
	}

	.maf-toolbar__sort {
		margin-left: auto;
	}

	.maf-sidebar {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 99999;
		width: min(88vw, 360px);
		padding: 16px 20px 0;
		overflow-y: auto;
		background: #fff;
		visibility: hidden;
		transform: translateX(-102%);
		transition: transform 0.28s ease, visibility 0s linear 0.28s;
	}

	body.maf-drawer-open .maf-sidebar {
		visibility: visible;
		transform: none;
		transition: transform 0.28s ease, visibility 0s;
	}

	body.maf-drawer-open .maf-backdrop {
		opacity: 1;
		pointer-events: auto;
	}

	body.maf-drawer-open {
		overflow: hidden;
	}

	.maf-panel__title {
		display: block;
	}

	.maf-sidebar .maf-link {
		margin-left: 0;
	}

	.maf-panel__head {
		padding-bottom: 12px;
	}

	.maf-panel__title {
		margin-right: auto;
	}

	.maf-sidebar .maf-close {
		display: block;
	}

	.maf-drawer-footer {
		position: sticky;
		bottom: 0;
		display: block;
		padding: 12px 0 16px;
		background: #fff;
	}

	.maf-sidebar .maf-apply {
		width: 100%;
		padding: 12px;
		border-radius: var(--maf-radius);
		background: var(--maf-accent);
		font-weight: 600;
		text-align: center;
		color: var(--maf-accent-contrast);
	}

	.maf-sidebar .maf-apply:hover,
	.maf-sidebar .maf-apply:focus {
		background: var(--maf-accent);
		color: var(--maf-accent-contrast);
	}
}

@media (prefers-reduced-motion: reduce) {
	.maf-sidebar,
	.maf-backdrop,
	.maf-section__toggle::after,
	.maf-tree__toggle::before {
		transition: none;
	}

	.maf-products.is-loading::after {
		animation-duration: 2s;
	}
}

.maf-products .maf-notice {
	padding: 16px;
	border-radius: var(--maf-radius);
	background: var(--maf-soft);
	text-align: center;
	color: var(--maf-muted);
}
