/* e-Products — stacked filter drawer (PROTOTYPE, gated by body.ep-sf-on) */

/* ---------- 0. re-assert the drawer above the theme breakpoint ----------
   The block renders is-mobile-overlay, whose desktop rules turn the overlay back into
   an inline sidebar and hide the trigger. Woo re-adds that class on every re-render, so
   the drawer is re-asserted in CSS (a JS class-removal loses that race) — this is the
   same geometry the block emits for overlayMode:"always". */
@media (min-width: 782px) {
	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay {
		display: block;
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__overlay {
		position: fixed;
		inset: 0;
		z-index: 9999;
		pointer-events: none;
		visibility: hidden;
		background: transparent;
		color: inherit;
		flex-grow: 0;
		transition: background-color .25s, visibility 0s .3s;
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay.is-overlay-opened .wc-block-product-filters__overlay {
		pointer-events: auto;
		visibility: visible;
		background-color: rgba(20, 16, 12, .34);
		transition-delay: 0s;
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__overlay-wrapper {
		width: 100%;
		height: 100%;
	}

	/* slide in from the right — the reference's edge — whatever the block's own setting is */
	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__overlay-dialog {
		position: absolute;
		inset: 0 0 0 auto;
		width: min(100%, 480px);
		max-height: 100%;
		transform: translateX(100%);
		transition: transform .38s cubic-bezier(.22, .61, .36, 1);
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay.is-overlay-opened .wc-block-product-filters__overlay-dialog {
		transform: translateX(0);
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__overlay-header {
		display: flex;
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__open-overlay {
		display: inline-flex;
	}

	body.ep-sf-on .wc-block-product-filters.is-mobile-overlay .wc-block-product-filters__overlay-footer {
		display: block;
	}
}

/* ---------- 1. drawer surface: reference palette ---------- */
body.ep-sf-on .wc-block-product-filters__overlay-dialog {
	--ep-sf-panel: #f0ece6;
	--ep-sf-ink: #1a1714;
	--ep-sf-muted: #6b645c;
	--ep-sf-line: rgba(26, 23, 20, .12);
	--ep-sf-shade: 70, 52, 31;
	background: var(--ep-sf-panel);
	color: var(--ep-sf-ink);
	box-shadow: -24px 0 60px rgba(20, 16, 12, .18);
}

body.ep-sf-on .wc-block-product-filters__overlay-header {
	position: relative;
	z-index: 30;
	background: var(--ep-sf-panel);
}

body.ep-sf-on .wc-block-product-filters__close-overlay {
	border: 0;
	border-radius: 999px;
	background: #12100e;
	color: #fff;
	padding: 6px 14px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	cursor: pointer;
}

body.ep-sf-on .wc-block-product-filters__close-overlay svg {
	width: 18px;
	height: 18px;
}

body.ep-sf-on .wc-block-product-filters__overlay-content {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow-y: auto;
	padding: calc(var(--ep-sf-head, 56px) + 4px) 24px calc(var(--ep-sf-foot, 64px) + 8px);
	scrollbar-width: thin;
}

body.ep-sf-on .wc-block-product-filters__overlay-footer {
	position: relative;
	z-index: 30;
	margin-top: auto; /* the content is out of flow, so the bar must be pushed down */
	margin-inline-start: var(--ep-sf-inset, 0px);
	transition: margin-inline-start .38s cubic-bezier(.22, .61, .36, 1);
	background: var(--ep-sf-panel);
	box-shadow: 0 -1px 0 var(--ep-sf-line);
}

body.ep-sf-on .wc-block-product-filters__apply {
	background: #12100e;
	color: #fff;
	border-radius: 8px;
	padding: 12px 16px;
	font-weight: 600;
	cursor: pointer;
}

/* ---------- 2. the trigger, when the block sits in its own full-width row ---------- */
@media (min-width: 782px) {
	/* classes come from the script: :has() lost the cascade against the theme's own column rules */
	body.ep-sf-on .ep-sf-cols {
		flex-direction: column;
		gap: 1.25rem;
	}

	body.ep-sf-on .ep-sf-cols > .wp-block-column {
		flex-basis: 100% !important;
		width: 100%;
	}

	body.ep-sf-on .ep-sf-cols > .ep-sf-col--filters {
		order: -1;
		padding-left: 0 !important;   /* line the trigger up with the grid's left edge */
	}

	body.ep-sf-on .wc-block-product-filters__open-overlay {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		background: var(--wp--preset--color--primary, #2f2f5b);
		color: #fff;
		border: 0;
		border-radius: 999px;
		padding: 10px 18px;
		font-size: 15px;
		font-weight: 600;
		cursor: pointer;
	}

	body.ep-sf-on .wc-block-product-filters__open-overlay svg {
		width: 18px;
		height: 18px;
	}
}

/* ---------- 3. root menu: one stacked row per filter group ---------- */
body.ep-sf-on .ep-sf__menu {
	display: flex;
	flex-direction: column;
	border-top: 1px solid var(--ep-sf-line);
}

body.ep-sf-on .ep-sf__row {
	display: grid;
	grid-template-columns: 1fr auto 20px;
	align-items: center;
	gap: 12px;
	width: 100%;
	padding: 22px 2px;
	background: none;
	border: 0;
	border-bottom: 1px solid var(--ep-sf-line);
	color: inherit;
	text-align: left;
	cursor: pointer;
	font: inherit;
}

body.ep-sf-on .ep-sf__row:hover .ep-sf__row-label,
body.ep-sf-on .ep-sf__row:focus-visible .ep-sf__row-label {
	transform: translateX(4px);
}

body.ep-sf-on .ep-sf__row-label {
	font-size: 24px;
	font-weight: 500;
	letter-spacing: -.01em;
	transition: transform .25s ease;
}

body.ep-sf-on .ep-sf__row-meta {
	font-size: 13px;
	color: var(--ep-sf-muted);
	font-variant-numeric: tabular-nums;
}

body.ep-sf-on .ep-sf__chev,
body.ep-sf-on .ep-sf__back {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--ep-sf-muted);
}

body.ep-sf-on .ep-sf__chev svg,
body.ep-sf-on .ep-sf__back svg {
	width: 18px;
	height: 18px;
}

/* ---------- 4. layers: the active panel is POSITIONED over the menu, inset 56px ---------- */
body.ep-sf-on .ep-sf__panel {
	display: none !important;
}

body.ep-sf-on .ep-sf__panel.is-layer {
	display: block !important;
	position: absolute;
	inset: 0 0 0 56px;
	z-index: 3;
	overflow-y: auto;
	padding: calc(var(--ep-sf-head, 56px) + 4px) 24px calc(var(--ep-sf-foot, 64px) + 12px);
	background: var(--ep-sf-panel);
	border-inline-start: 1px solid rgba(26, 23, 20, .14);
	box-shadow: -18px 0 40px rgba(20, 16, 12, .12);
	scrollbar-width: thin;
}

/* the panel's own h3 is replaced by the layer header */
body.ep-sf-on .ep-sf__panel.is-layer > h3,
body.ep-sf-on .ep-sf__panel.is-layer > .wp-block-heading:first-child {
	display: none;
}

body.ep-sf-on .ep-sf__layer-head {
	position: sticky;
	top: calc(-1 * (var(--ep-sf-head, 56px) + 4px));
	z-index: 2;
	display: flex;
	align-items: center;
	gap: 10px;
	margin: calc(-1 * (var(--ep-sf-head, 56px) + 4px)) -24px 14px;
	padding: calc(var(--ep-sf-head, 56px) + 4px) 16px 14px 10px;
	background: var(--ep-sf-panel);
	border-bottom: 1px solid var(--ep-sf-line);
}

body.ep-sf-on .ep-sf__layer-head .ep-sf__back {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background: none;
	border-radius: 999px;
	padding: 6px;
	color: var(--ep-sf-ink);
	cursor: pointer;
}

body.ep-sf-on .ep-sf__layer-head .ep-sf__back:hover {
	background: rgba(26, 23, 20, .06);
}

body.ep-sf-on .ep-sf__layer-title {
	font-size: 20px;
	font-weight: 600;
	letter-spacing: -.01em;
}

body.ep-sf-on .ep-sf__shade {
	position: absolute;
	inset: 0;
	z-index: 2;
	background: rgb(var(--ep-sf-shade));
	opacity: 0;
	pointer-events: none;
	transition: opacity .28s ease;
	mix-blend-mode: multiply;
}

body.ep-sf-on .ep-sf__shade.is-on {
	opacity: .26;
	pointer-events: auto;
}

body.ep-sf-on .ep-sf__hidden {
	display: none !important;
}

/* ---------- 5. native panel furniture, restyled to match ---------- */
body.ep-sf-on .wc-block-product-filter-checkbox-list__text,
body.ep-sf-on .wc-block-product-filter-chips__label {
	font-size: 16px;
}

body.ep-sf-on .ep-sf__in-layer .wc-block-product-filter-chips__item {
	border-radius: 999px;
}


/* ---------- 6. closed-state summary: trigger + active filter pills ---------- */
@media (min-width: 782px) {
	body.ep-sf-on .wc-block-product-filters {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 10px 12px;
	}
}

body.ep-sf-on .ep-sf__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

body.ep-sf-on .ep-sf__bar[hidden] {
	display: none;
}

body.ep-sf-on .ep-sf__pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	border: 1px solid rgba(26, 23, 20, .18);
	border-radius: 999px;
	padding: 6px 8px 6px 13px;
	font-size: 14px;
	line-height: 1.2;
	background: #fff;
	color: #1a1714;
}

body.ep-sf-on .ep-sf__pill-x {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background: none;
	padding: 2px;
	border-radius: 999px;
	color: inherit;
	cursor: pointer;
}

body.ep-sf-on .ep-sf__pill-x:hover {
	background: rgba(26, 23, 20, .08);
}

body.ep-sf-on .ep-sf__pill-x svg {
	width: 14px;
	height: 14px;
}

body.ep-sf-on .ep-sf__clear {
	border: 0;
	background: none;
	padding: 6px 4px;
	font-size: 14px;
	color: #4a443d;
	text-decoration: underline;
	cursor: pointer;
}

body.ep-sf-on .ep-sf__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	margin-inline-start: 8px;
	padding: 0 6px;
	border-radius: 999px;
	background: #fff;
	color: var(--wp--preset--color--primary, #2f2f5b);
	font-size: 12px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

body.ep-sf-on .ep-sf__badge[hidden] {
	display: none;
}


/* ---------- 6b. mobile: trigger on its own row, chips scroll sideways ----------
   At 390 px the block is inline-flex with nowrap, so trigger + summary bar share one
   line: the trigger squeezes to ~60 px and wraps "Suodata tuotteita" character by
   character, while the bar pushes the whole block to ~700 px and the page scrolls
   sideways. Below the drawer breakpoint, stack the trigger above a single-line,
   horizontally scrollable chip row. Desktop rules above are untouched. */
@media (max-width: 781px) {
	/* The page template stores `flex-basis:20%` inline on this column. Combined with
	   the block's width:100% that becomes a cyclic constraint and the column grows to
	   the chip row's min-content (~457px), taking the page with it. Pin the basis. */
	body.ep-sf-on .ep-sf-col--filters {
		flex: 1 1 0% !important;
		width: 100%;
		max-width: 100%;
	}

	body.ep-sf-on .wc-block-product-filters {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 8px 10px;
		width: 100%;
		max-width: 100%;
		/* a flex item's automatic minimum is min-content: without this the
		   nowrap chip row stretches the column to ~457px and the page scrolls */
		min-width: 0;
	}

	body.ep-sf-on .wc-block-product-filters__open-overlay {
		flex: 0 0 auto;
		white-space: nowrap;
	}

	body.ep-sf-on .ep-sf__bar {
		flex: 1 0 100%;
		flex-wrap: nowrap;
		align-items: center;
		max-width: 100%;
		min-width: 0;
		gap: 6px;
		padding: 2px 0 4px;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}

	body.ep-sf-on .ep-sf__bar::-webkit-scrollbar {
		display: none;
	}

	body.ep-sf-on .ep-sf__pill {
		flex: 0 0 auto;
		white-space: nowrap;
		font-size: 13px;
		padding: 5px 6px 5px 11px;
	}

	body.ep-sf-on .ep-sf__clear {
		flex: 0 0 auto;
		white-space: nowrap;
		padding: 6px 2px;
	}
}


/* ---------- 7. grid density comparison (?ep_cols=N) ---------- */
@media (min-width: 1200px) {
	body.ep-cols-5 .wc-block-product-template {
		grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
	}

	body.ep-cols-6 .wc-block-product-template {
		grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	body.ep-sf-on .ep-sf__layer,
	body.ep-sf-on .ep-sf__shade,
	body.ep-sf-on .ep-sf__row-label {
		transition: none !important;
	}
}
