/*
 * DW Shop Sidebar
 * Inherits fonts, colours, inputs and buttons from the active theme.
 * Accent/background fall back through Blocksy and block-theme variables;
 * the small script then reads the theme's real button and page colours.
 */

/* ---------- Tokens ---------- */
.dw-ss {
	--dw-ss-accent: var(--theme-palette-color-1, var(--wp--preset--color--primary, var(--wp--preset--color--accent, var(--wp--preset--color--contrast, #2271b1))));
	--dw-ss-accent-text: #fff;
	--dw-ss-bg: var(--theme-palette-color-8, var(--wp--preset--color--base, #fff));
	--dw-ss-line: rgba(128, 128, 128, 0.25);
	--dw-ss-line-strong: rgba(128, 128, 128, 0.45);
	--dw-ss-radius: var(--theme-button-border-radius, var(--wp--custom--border-radius, 6px));
	position: relative;
	color: inherit;
	font: inherit;
}

.dw-ss *,
.dw-ss *::before,
.dw-ss *::after {
	box-sizing: border-box;
}

@supports (color: color-mix(in srgb, red, blue)) {
	.dw-ss {
		--dw-ss-line: color-mix(in srgb, currentColor 14%, transparent);
		--dw-ss-line-strong: color-mix(in srgb, currentColor 30%, transparent);
	}
}

/* ---------- Two-column layout ---------- */
.dw-ss-layout {
	display: grid;
	grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
	gap: clamp(1.5rem, 3vw, 2.75rem);
	align-items: start;
}

.dw-ss-main {
	min-width: 0;
}

.dw-ss-main::after {
	content: "";
	display: table;
	clear: both;
}

/* ---------- Helpers ---------- */
.dw-ss .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Mobile-only controls are hidden on desktop. */
.dw-ss-toggle-input,
.dw-ss-toggle,
.dw-ss-backdrop,
.dw-ss-close {
	display: none;
}

/* ---------- Header ---------- */
.dw-ss-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1rem;
}

.dw-ss .dw-ss-title {
	margin: 0;
	padding: 0;
	font-size: 1.125rem;
	line-height: 1.3;
}

/* ---------- Sections ---------- */
.dw-ss .dw-ss-section {
	min-width: 0;
	margin: 0;
	padding: 1.1rem 0;
	border: 0;
	border-top: 1px solid var(--dw-ss-line);
	background: none;
}

.dw-ss .dw-ss-section:first-of-type {
	padding-top: 0;
	border-top: 0;
}

.dw-ss .dw-ss-legend {
	float: left;
	width: 100%;
	margin: 0 0 0.7rem;
	padding: 0;
	border: 0;
	font-size: 0.95em;
	font-weight: 600;
	line-height: 1.3;
}

.dw-ss .dw-ss-section > :not(legend) {
	clear: both;
}

/* ---------- Categories ---------- */
.dw-ss .dw-ss-cat-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.dw-ss .dw-ss-cats > .dw-ss-cat-list {
	max-height: 24rem;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.dw-ss .dw-ss-cat-list li {
	position: relative;
	margin: 0;
	padding: 0;
	list-style: none;
}

.dw-ss .dw-ss-cat-list li::before {
	content: none;
}

.dw-ss .dw-ss-check {
	display: flex;
	align-items: center;
	gap: 0.6em;
	margin: 0;
	padding: 0.3em 1.9rem 0.3em 0;
	font-weight: inherit;
	line-height: 1.35;
	cursor: pointer;
}

.dw-ss .dw-ss-check input {
	flex: none;
	margin: 0;
	accent-color: var(--dw-ss-accent);
}

.dw-ss .dw-ss-name {
	min-width: 0;
	overflow-wrap: anywhere;
}

.dw-ss .dw-ss-count {
	margin-left: auto;
	font-size: 0.85em;
	font-variant-numeric: tabular-nums;
	opacity: 0.6;
}

.dw-ss .dw-ss-sub > summary {
	position: absolute;
	top: 0.2em;
	right: 0;
	display: grid;
	place-items: center;
	width: 1.6rem;
	height: 1.6rem;
	border-radius: 4px;
	list-style: none;
	cursor: pointer;
}

.dw-ss .dw-ss-sub > summary::-webkit-details-marker {
	display: none;
}

.dw-ss .dw-ss-sub > summary::after {
	content: "";
	width: 0.42em;
	height: 0.42em;
	margin-top: -0.2em;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.2s ease, margin 0.2s ease;
}

.dw-ss .dw-ss-sub[open] > summary::after {
	margin-top: 0.2em;
	transform: rotate(-135deg);
}

.dw-ss .dw-ss-sub > summary:hover {
	background: var(--dw-ss-line);
}

.dw-ss .dw-ss-sub > summary:focus-visible {
	outline: 2px solid var(--dw-ss-accent);
	outline-offset: 1px;
}

.dw-ss .dw-ss-sub > .dw-ss-cat-list {
	padding-left: 1.4em;
}

/* ---------- Price ---------- */
.dw-ss .dw-ss-range {
	display: none; /* shown by the script; number inputs alone work without it */
	position: relative;
	height: 22px;
	margin: 0.2rem 0 0.9rem;
}

.dw-ss .dw-ss-has-slider .dw-ss-range {
	display: block;
}

.dw-ss .dw-ss-range-track {
	position: absolute;
	top: 50%;
	left: 9px;
	right: 9px;
	height: 4px;
	margin-top: -2px;
	border-radius: 2px;
	background: var(--dw-ss-line-strong);
}

.dw-ss .dw-ss-range-fill {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--dw-ss-lo, 0%);
	right: calc(100% - var(--dw-ss-hi, 100%));
	border-radius: inherit;
	background: var(--dw-ss-accent);
}

.dw-ss .dw-ss-range input[type="range"] {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 2;
	width: 100%;
	height: 22px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	outline: none;
	pointer-events: none;
	-webkit-appearance: none;
	appearance: none;
}

.dw-ss .dw-ss-range input[type="range"]::-webkit-slider-runnable-track {
	height: 22px;
	border: 0;
	background: none;
}

.dw-ss .dw-ss-range input[type="range"]::-moz-range-track {
	height: 22px;
	border: 0;
	background: none;
}

.dw-ss .dw-ss-range input[type="range"]::-webkit-slider-thumb {
	width: 18px;
	height: 18px;
	margin-top: 2px;
	border: 2px solid var(--dw-ss-bg);
	border-radius: 50%;
	background: var(--dw-ss-accent);
	box-shadow: 0 0 0 1px var(--dw-ss-accent);
	cursor: grab;
	pointer-events: auto;
	-webkit-appearance: none;
	appearance: none;
}

.dw-ss .dw-ss-range input[type="range"]::-moz-range-thumb {
	box-sizing: border-box;
	width: 18px;
	height: 18px;
	border: 2px solid var(--dw-ss-bg);
	border-radius: 50%;
	background: var(--dw-ss-accent);
	box-shadow: 0 0 0 1px var(--dw-ss-accent);
	cursor: grab;
	pointer-events: auto;
}

.dw-ss .dw-ss-range input[type="range"]:focus-visible::-webkit-slider-thumb {
	box-shadow: 0 0 0 1px var(--dw-ss-accent), 0 0 0 5px var(--dw-ss-line-strong);
}

.dw-ss .dw-ss-range input[type="range"]:focus-visible::-moz-range-thumb {
	box-shadow: 0 0 0 1px var(--dw-ss-accent), 0 0 0 5px var(--dw-ss-line-strong);
}

.dw-ss .dw-ss-price-inputs {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	align-items: center;
	gap: 0.5rem;
}

.dw-ss .dw-ss-price-inputs label {
	display: block;
	min-width: 0;
	margin: 0;
}

.dw-ss .dw-ss-price-inputs input {
	width: 100%;
	min-width: 0;
	margin: 0;
}

.dw-ss .dw-ss-dash {
	opacity: 0.6;
}

/* ---------- On-sale switch ---------- */
.dw-ss .dw-ss-switch-label {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin: 0;
	font-weight: 600;
	font-size: 0.95em;
	cursor: pointer;
}

.dw-ss input.dw-ss-switch[type="checkbox"] {
	position: relative;
	flex: none;
	width: 2.5em;
	min-width: 0;
	height: 1.4em;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: var(--dw-ss-line-strong);
	background-image: none;
	box-shadow: none;
	font-size: 1rem;
	vertical-align: middle;
	cursor: pointer;
	transition: background-color 0.2s ease;
	-webkit-appearance: none;
	appearance: none;
}

.dw-ss input.dw-ss-switch[type="checkbox"]::before {
	content: "";
	position: absolute;
	top: 0.2em;
	left: 0.2em;
	width: 1em;
	height: 1em;
	margin: 0;
	border: 0;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
	opacity: 1;
	transform: none;
	transition: transform 0.2s ease;
	-webkit-mask: none;
	mask: none;
}

.dw-ss input.dw-ss-switch[type="checkbox"]::after {
	display: none;
	content: none;
}

.dw-ss input.dw-ss-switch[type="checkbox"]:checked {
	background: var(--dw-ss-accent);
	background-image: none;
}

.dw-ss input.dw-ss-switch[type="checkbox"]:checked::before {
	transform: translateX(1.1em);
}

.dw-ss input.dw-ss-switch[type="checkbox"]:focus-visible {
	outline: 2px solid var(--dw-ss-accent);
	outline-offset: 2px;
}

/* ---------- Actions ---------- */
.dw-ss .dw-ss-actions {
	display: grid;
	gap: 0.75rem;
	padding-top: 1.1rem;
	border-top: 1px solid var(--dw-ss-line);
}

.dw-ss .dw-ss-apply {
	width: 100%;
	margin: 0;
	justify-content: center;
	text-align: center;
}

.dw-ss .dw-ss-clear {
	justify-self: center;
	color: inherit;
	font-size: 0.9em;
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.dw-ss .dw-ss-clear:hover {
	color: var(--dw-ss-accent);
}

/* ---------- Mobile: "Filters" button + slide-in drawer (pure CSS) ---------- */
@media (max-width: 899px) {
	.dw-ss-layout {
		display: block;
	}

	.dw-ss-sidebar {
		margin-bottom: 1.25rem;
	}

	.dw-ss .dw-ss-toggle-input {
		display: block;
		position: absolute;
		top: 0;
		left: 0;
		width: 1px;
		height: 1px;
		margin: 0;
		opacity: 0;
		pointer-events: none;
	}

	.dw-ss .dw-ss-toggle {
		display: inline-flex;
		align-items: center;
		gap: 0.55em;
		margin: 0;
		padding: 0.65em 1.1em;
		border: 1px solid var(--dw-ss-line-strong);
		border-radius: var(--dw-ss-radius);
		font-weight: 600;
		line-height: 1.2;
		cursor: pointer;
		user-select: none;
		-webkit-tap-highlight-color: transparent;
	}

	.dw-ss .dw-ss-toggle:hover {
		border-color: currentColor;
	}

	.dw-ss .dw-ss-toggle-input:focus-visible + .dw-ss-toggle {
		outline: 2px solid var(--dw-ss-accent);
		outline-offset: 2px;
	}

	.dw-ss .dw-ss-badge {
		display: inline-grid;
		place-items: center;
		min-width: 1.5em;
		height: 1.5em;
		padding: 0 0.4em;
		border-radius: 999px;
		background: var(--dw-ss-accent);
		color: var(--dw-ss-accent-text);
		font-size: 0.75em;
		line-height: 1;
	}

	.dw-ss .dw-ss-backdrop {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 100000;
		margin: 0;
		background: rgba(0, 0, 0, 0.45);
		opacity: 0;
		visibility: hidden;
		cursor: pointer;
		transition: opacity 0.25s ease, visibility 0s linear 0.25s;
	}

	.dw-ss .dw-ss-body {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		z-index: 100001;
		display: flex;
		flex-direction: column;
		width: min(88vw, 380px);
		padding: 1.25rem 1.25rem 0;
		overflow-y: auto;
		overscroll-behavior: contain;
		background: var(--dw-ss-bg);
		box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
		visibility: hidden;
		transform: translateX(-105%);
		transition: transform 0.28s ease, visibility 0s linear 0.28s;
	}

	.dw-ss .dw-ss-toggle-input:checked ~ .dw-ss-backdrop {
		opacity: 1;
		visibility: visible;
		transition: opacity 0.25s ease;
	}

	.dw-ss .dw-ss-toggle-input:checked ~ .dw-ss-body {
		visibility: visible;
		transform: none;
		transition: transform 0.28s ease;
	}

	.dw-ss .dw-ss-close {
		display: grid;
		place-items: center;
		width: 2.5rem;
		height: 2.5rem;
		margin: -0.5rem -0.5rem -0.5rem 0;
		border-radius: 50%;
		cursor: pointer;
	}

	.dw-ss .dw-ss-close:hover {
		background: var(--dw-ss-line);
	}

	.dw-ss .dw-ss-close:focus-visible {
		outline: 2px solid var(--dw-ss-accent);
	}

	.dw-ss .dw-ss-form {
		display: flex;
		flex: 1 0 auto;
		flex-direction: column;
	}

	.dw-ss .dw-ss-cats > .dw-ss-cat-list {
		max-height: none;
		overflow: visible;
	}

	/* Apply / Clear stay reachable at the bottom of the drawer. */
	.dw-ss .dw-ss-actions {
		position: sticky;
		bottom: 0;
		margin-top: auto;
		padding-bottom: 1.25rem;
		background: var(--dw-ss-bg);
	}

	html.dw-ss-locked,
	html.dw-ss-locked body {
		overflow: hidden;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dw-ss *,
	.dw-ss *::before,
	.dw-ss *::after {
		transition: none !important;
	}
}
