/* Keys Experts – AJAX Product Filter */

.ke-af-wrap {
	--ke-af-accent: #1d4ed8;
	--ke-af-accent-soft: rgba(29, 78, 216, 0.12);
	--ke-af-text: #1f2937;
	--ke-af-muted: #6b7280;
	--ke-af-border: #e2e8f0;
	--ke-af-bg: #ffffff;
	--ke-af-panel: #f8fafc;
	--ke-af-track: #e2e8f0;
	--ke-af-radius: 12px;
	--ke-af-radius-sm: 9px;
	--ke-af-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
	color: var(--ke-af-text);
	font-size: 15px;
	line-height: 1.4;
	margin: 0 0 28px;
}

/* On mobile/tablet, JS relocates .ke-af-panel (and everything inside it) to
 * be a direct child of <body> once first opened, to escape ancestor
 * stacking-context/overflow traps (see ke-af-filter.js). CSS custom
 * properties only inherit through actual DOM ancestors, so without its own
 * copy of these tokens the panel loses all its theming — background,
 * accent color, borders — the moment it's no longer nested inside
 * .ke-af-wrap. Keep this in sync with the block above. */
.ke-af-panel {
	--ke-af-accent: #1d4ed8;
	--ke-af-accent-soft: rgba(29, 78, 216, 0.12);
	--ke-af-text: #1f2937;
	--ke-af-muted: #6b7280;
	--ke-af-border: #e2e8f0;
	--ke-af-bg: #ffffff;
	--ke-af-panel: #f8fafc;
	--ke-af-track: #e2e8f0;
	--ke-af-radius: 12px;
	--ke-af-radius-sm: 9px;
	--ke-af-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
	color: var(--ke-af-text);
	font-size: 15px;
	line-height: 1.4;
}

/* Mobile/tablet toggle button that opens the filter popup (hidden on desktop). */
.ke-af-toggle {
	display: none;
	width: 100%;
	align-items: center;
	gap: 10px;
	min-height: 48px;
	padding: 12px 16px;
	background: var(--ke-af-accent);
	border: 1px solid var(--ke-af-accent);
	border-radius: var(--ke-af-radius);
	box-shadow: var(--ke-af-shadow);
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	font-family: inherit;
	cursor: pointer;
	text-align: left;
}
.ke-af-toggle:hover { background: #1e40af; border-color: #1e40af; }
.ke-af-toggle-icon { flex: 0 0 auto; color: #fff; }
.ke-af-toggle-label { flex: 1 1 auto; color: #fff; }
.ke-af-toggle-chevron { flex: 0 0 auto; color: #fff; transition: transform 0.2s ease; }
.ke-af-toggle[aria-expanded="true"] .ke-af-toggle-chevron { transform: rotate(180deg); }

/* Backdrop behind the popup (mobile/tablet only, see media query below). */
.ke-af-backdrop {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.3);
	z-index: 99998;
	opacity: 0;
	transition: opacity 0.18s ease;
}

/* Desktop: vertical, sidebar-style panel — one field per row. */
.ke-af-filters {
	display: grid;
	grid-template-columns: 1fr;
	gap: 18px;
	align-items: end;
	margin: 0;
	padding: 20px;
	background: var(--ke-af-panel);
	border: 1px solid var(--ke-af-border);
	border-radius: var(--ke-af-radius);
	box-shadow: var(--ke-af-shadow);
}
.ke-af-field-actions .ke-af-btn { width: 100%; }

.ke-af-field { min-width: 0; }

.ke-af-label {
	display: block;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--ke-af-muted);
	margin: 0 0 8px;
}

/* Search */
.ke-af-search-wrap {
	position: relative;
	display: flex;
	align-items: center;
	background: var(--ke-af-bg);
	border: 1px solid var(--ke-af-border);
	border-radius: var(--ke-af-radius-sm);
	transition: border-color 0.15s;
}
.ke-af-search-wrap:focus-within { border-color: var(--ke-af-accent); }
.ke-af-search-icon {
	position: absolute;
	left: 14px;
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	color: var(--ke-af-muted);
	pointer-events: none;
}
.ke-af-search-input {
	width: 100%;
	min-height: 46px;
	padding: 10px 14px 10px 38px;
	border: 0;
	border-radius: var(--ke-af-radius-sm);
	background: transparent;
	color: var(--ke-af-text);
	font-size: 15px;
	appearance: none;
	-webkit-appearance: none;
}
.ke-af-search-input:focus { outline: none; }
.ke-af-search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.ke-af-search-input::-webkit-search-decoration { -webkit-appearance: none; }

/* Selects */
.ke-af-select-wrap { position: relative; }
.ke-af-select-wrap::after {
	content: "";
	position: absolute;
	right: 14px;
	top: 50%;
	width: 9px;
	height: 9px;
	border-right: 2px solid var(--ke-af-muted);
	border-bottom: 2px solid var(--ke-af-muted);
	transform: translateY(-70%) rotate(45deg);
	pointer-events: none;
}
.ke-af-select {
	width: 100%;
	min-height: 46px;
	padding: 10px 38px 10px 14px;
	border: 1px solid var(--ke-af-border);
	border-radius: var(--ke-af-radius-sm);
	background: var(--ke-af-bg);
	color: var(--ke-af-text);
	font-size: 15px;
	appearance: none;
	-webkit-appearance: none;
	cursor: pointer;
	transition: border-color 0.15s, box-shadow 0.15s;
}
.ke-af-select:hover:not(:disabled) { border-color: #c4ccd8; }
.ke-af-select:focus-visible,
.ke-af-wrap input:focus-visible,
.ke-af-wrap button:focus-visible {
	outline: 2px solid var(--ke-af-accent);
	outline-offset: 2px;
}
.ke-af-select:disabled {
	background: var(--ke-af-panel);
	color: var(--ke-af-muted);
	cursor: not-allowed;
	opacity: 0.75;
}

/* Dual-range slider */
.ke-af-price-slider { position: relative; height: 34px; margin: 4px 12px 2px; }
.ke-af-slider-track {
	position: absolute;
	left: 0;
	right: 0;
	top: 50%;
	height: 6px;
	transform: translateY(-50%);
	background: var(--ke-af-track);
	border-radius: 999px;
}
.ke-af-slider-range {
	position: absolute;
	top: 0;
	bottom: 0;
	background: linear-gradient(90deg, var(--ke-af-accent), #3b82f6);
	border-radius: 999px;
}
.ke-af-range {
	position: absolute;
	left: -12px;
	right: -12px;
	width: calc(100% + 24px);
	top: 50%;
	transform: translateY(-50%);
	height: 34px;
	margin: 0;
	background: transparent;
	-webkit-appearance: none;
	appearance: none;
	pointer-events: none;
}
.ke-af-range::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	pointer-events: auto;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #fff;
	border: 2.5px solid var(--ke-af-accent);
	box-shadow: 0 1px 4px rgba(16, 24, 40, 0.3);
	cursor: grab;
	transition: transform 0.12s;
}
.ke-af-range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.ke-af-range::-webkit-slider-thumb:active { cursor: grabbing; }
.ke-af-range::-moz-range-thumb {
	pointer-events: auto;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #fff;
	border: 2.5px solid var(--ke-af-accent);
	box-shadow: 0 1px 4px rgba(16, 24, 40, 0.3);
	cursor: grab;
}
.ke-af-range::-moz-range-track { background: transparent; }

/* Price inputs */
.ke-af-price-inputs { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.ke-af-price-dash { color: var(--ke-af-muted); flex: 0 0 auto; }
.ke-af-price-box {
	position: relative;
	flex: 1 1 0;
	min-width: 0;
	display: flex;
	align-items: center;
	background: var(--ke-af-bg);
	border: 1px solid var(--ke-af-border);
	border-radius: var(--ke-af-radius-sm);
	transition: border-color 0.15s;
}
.ke-af-price-box:focus-within { border-color: var(--ke-af-accent); }
.ke-af-price-box label {
	position: absolute;
	top: -7px;
	left: 10px;
	padding: 0 4px;
	background: var(--ke-af-bg);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: var(--ke-af-muted);
}
.ke-af-currency { padding-left: 12px; color: var(--ke-af-muted); font-size: 14px; }
.ke-af-price-box input[type="number"] {
	width: 100%;
	min-height: 44px;
	padding: 8px 10px 8px 4px;
	border: 0;
	background: transparent;
	color: var(--ke-af-text);
	font-size: 15px;
	-moz-appearance: textfield;
}
.ke-af-price-box input::-webkit-outer-spin-button,
.ke-af-price-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ke-af-price-box input:focus { outline: none; }
.ke-af-price-readout { margin: 10px 0 0; font-size: 14px; color: var(--ke-af-muted); }

/* Buttons */
.ke-af-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	min-height: 46px;
	padding: 10px 20px;
	border-radius: var(--ke-af-radius-sm);
	border: 1px solid var(--ke-af-accent);
	background: var(--ke-af-accent);
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}
.ke-af-btn:hover:not(:disabled) { background: #1e40af; border-color: #1e40af; color: #fff; }
.ke-af-btn-ghost { background: transparent; color: var(--ke-af-accent); }
.ke-af-btn-ghost:hover:not(:disabled) { background: var(--ke-af-accent-soft); color: var(--ke-af-accent); border-color: var(--ke-af-accent); }
.ke-af-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Error + no results */
.ke-af-error[hidden] { display: none; }
.ke-af-error {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin: 14px 0 0;
	padding: 12px 16px;
	border: 1px solid #fca5a5;
	border-radius: var(--ke-af-radius-sm);
	background: #fef2f2;
	color: #991b1b;
}
li.ke-af-no-results {
	grid-column: 1 / -1;
	width: 100%;
	list-style: none;
	padding: 48px 20px;
	text-align: center;
	border: 1.5px dashed #e2e8f0;
	border-radius: 12px;
	color: #6b7280;
}
li.ke-af-no-results p { margin: 0 0 16px; font-size: 16px; }
li.ke-af-no-results .ke-af-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 46px;
	padding: 10px 20px;
	border-radius: 9px;
	border: 1px solid #1d4ed8;
	background: #1d4ed8;
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}

/* Loading state applied to the page's existing product grid */
ul.products.ke-af-busy {
	opacity: 0.45;
	pointer-events: none;
	transition: opacity 0.15s;
}
.ke-af-grid-spinner {
	position: absolute;
	top: 48px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 9;
	width: 34px;
	height: 34px;
	border: 3px solid #e2e8f0;
	border-top-color: #1d4ed8;
	border-radius: 50%;
	animation: ke-af-spin 0.7s linear infinite;
}
@keyframes ke-af-spin { to { transform: translateX(-50%) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
	.ke-af-grid-spinner { animation: none; }
	.ke-af-range::-webkit-slider-thumb { transition: none; }
}

/* Applied to <html> and <body> while the mobile/tablet popup is open, so the
 * page underneath can't be scrolled with the overlay up. Deliberately just
 * overflow:hidden rather than the position:fixed+negative-top scroll-lock
 * trick — that trick was causing the page to jump to the top on open (it
 * collapses <body> out of flow, which resets real scroll position as a side
 * effect on several browsers). Plain overflow:hidden never touches scroll
 * position, so it cannot cause that jump. */
html.ke-af-scroll-locked,
body.ke-af-scroll-locked { overflow: hidden; }

.ke-af-wrap .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	word-wrap: normal !important;
}

/* Responsive: tablet and mobile collapse the whole filter into a popup that
 * opens below a "Search or Filter" toggle button, closed by default. */
@media (max-width: 1024px) {
	.ke-af-filters { grid-template-columns: 1fr 1fr; }
	.ke-af-field-price { grid-column: 1 / -1; }
	.ke-af-field-actions { grid-column: 1 / -1; justify-self: end; }

	/* Stickiness is applied by JS as an inline position:fixed toggle, not CSS
	 * position:sticky — sticky silently stops working the moment ANY ancestor
	 * sets overflow other than visible (common in page builders, e.g. for
	 * hover-crop image effects), which we confirmed empirically. JS is immune
	 * to that since it measures scroll position directly. See ke-af-filter.js. */
	.ke-af-wrap { margin-bottom: 20px; }
	.ke-af-sticky-placeholder { display: block; }
	.ke-af-toggle { display: flex; }

	/* Positioned via inline top/left/width/max-height set by JS (anchored to
	 * the toggle's current on-screen position). JS also relocates this panel
	 * (and the backdrop) to be a direct child of <body> the first time it
	 * opens — position:fixed alone changes the containing block but NOT the
	 * stacking context, so an ordinary ancestor like a page-builder column
	 * with position:relative;z-index:1 was still capping our z-index below
	 * unrelated page elements (e.g. a site header) despite the huge numbers
	 * here. Selectors below target .ke-af-panel/.ke-af-backdrop directly
	 * (not as .ke-af-wrap descendants) because after that move they no
	 * longer are descendants. */
	.ke-af-panel {
		position: fixed;
		z-index: 99999;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		opacity: 0;
		visibility: hidden;
		transform: translateY(-6px);
		pointer-events: none;
	}
	/* Transition gated by a class only added once JS has run an actual
	 * open/close, so a device rotating/resizing across this breakpoint
	 * before that never animates — only a real toggle-button interaction does. */
	.ke-af-panel.ke-af-can-animate {
		transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
	}
	.ke-af-panel.ke-af-open {
		opacity: 1;
		visibility: visible;
		transform: translateY(0);
		pointer-events: auto;
	}
	.ke-af-panel.ke-af-open.ke-af-can-animate {
		transition: opacity 0.18s ease, transform 0.18s ease;
	}
	.ke-af-backdrop.ke-af-open { display: block; opacity: 1; }
}
@media (max-width: 640px) {
	.ke-af-filters { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
	.ke-af-field-actions { justify-self: stretch; }
	.ke-af-field-actions .ke-af-btn { width: 100%; }
	.ke-af-price-slider { margin: 4px 14px 2px; }
}
@media (prefers-reduced-motion: reduce) {
	.ke-af-panel, .ke-af-toggle-chevron, .ke-af-backdrop { transition: none !important; }
}
