/**
 * Recipe WP — filter bar and "browse by" tiles.
 *
 * Shares the card's custom properties (--rwp-accent, --rwp-border…)
 * so a theme that restyles the card restyles these too.
 */

:where(.rwp-filters, .rwp-tiles) {
	--rwp-bg: #ffffff;
	--rwp-text: inherit;
	--rwp-muted: #6b6b6b;
	--rwp-border: #dcdcdc;
	--rwp-accent: #b5401f;
	--rwp-accent-text: #ffffff;
	--rwp-chip-bg: #f6f4f0;
	--rwp-radius: 8px;
	--rwp-panel-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.3);
}

.rwp-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Bar ---------- */

.rwp-filters {
	margin: 0 0 1.5em;
}

.rwp-filters__bar {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: flex-start;
}

.rwp-facet {
	position: relative;
}

.rwp-facet__toggle {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 14px;
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.3;
	color: var(--rwp-text);
	list-style: none;
	cursor: pointer;
	background: var(--rwp-bg);
	border: 1px solid var(--rwp-border);
	border-radius: 999px;
	user-select: none;
}

.rwp-facet__toggle::-webkit-details-marker {
	display: none;
}

/* Little arrow that flips when open. */
.rwp-facet__toggle::after {
	content: "";
	width: 6px;
	height: 6px;
	margin-left: 2px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: translateY(-2px) rotate(45deg);
	transition: transform 0.15s;
}

.rwp-facet[open] > .rwp-facet__toggle::after {
	transform: translateY(1px) rotate(225deg);
}

.rwp-facet[open] > .rwp-facet__toggle,
.rwp-facet__toggle:hover {
	border-color: var(--rwp-accent);
}

.rwp-facet__toggle:focus-visible {
	outline: 2px solid var(--rwp-accent);
	outline-offset: 2px;
}

.rwp-facet__badge {
	min-width: 1.4em;
	padding: 1px 6px;
	font-size: 0.75em;
	text-align: center;
	color: var(--rwp-accent-text);
	background: var(--rwp-accent);
	border-radius: 999px;
}

/* ---------- Dropdown panel ---------- */

.rwp-facet__panel {
	position: absolute;
	z-index: 50;
	top: calc(100% + 6px);
	left: 0;
	width: max-content;
	min-width: 220px;
	max-width: min(560px, 90vw);
	max-height: 70vh;
	overflow: auto;
	padding: 14px;
	color: var(--rwp-text);
	background: var(--rwp-bg);
	border: 1px solid var(--rwp-border);
	border-radius: var(--rwp-radius);
	box-shadow: var(--rwp-panel-shadow);
}

.rwp-facet__panel fieldset {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0;
	padding: 0;
	border: 0;
}

/* Families (e.g. Tubes) each get their own row with their shapes beneath. */
.rwp-facet__group {
	display: contents;
}

.rwp-facet__group:has(.rwp-facet__children) {
	display: block;
	flex-basis: 100%;
}

.rwp-facet__children {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 6px 0 10px 14px;
	padding-left: 10px;
	border-left: 2px solid var(--rwp-border);
}

/* ---------- Chips ---------- */

.rwp-chip {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 11px;
	font-size: 0.875rem;
	line-height: 1.3;
	cursor: pointer;
	background: var(--rwp-chip-bg);
	border: 1px solid transparent;
	border-radius: 999px;
}

.rwp-chip input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.rwp-chip .rwp-icon {
	width: 22px;
	height: 22px;
	margin: -3px 0;
}

.rwp-chip--family {
	font-weight: 700;
}

.rwp-chip__count {
	font-size: 0.8em;
	color: var(--rwp-muted);
}

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

.rwp-chip:has(input:checked) {
	color: var(--rwp-accent-text);
	background: var(--rwp-accent);
}

.rwp-chip:has(input:checked) .rwp-chip__count {
	color: inherit;
	opacity: 0.85;
}

.rwp-chip:has(input:focus-visible) {
	outline: 2px solid var(--rwp-accent);
	outline-offset: 2px;
}

.rwp-facet__apply,
.rwp-filters__submit {
	margin-top: 12px;
	padding: 7px 16px;
	font: inherit;
	font-size: 0.875rem;
	font-weight: 700;
	color: var(--rwp-accent-text);
	cursor: pointer;
	background: var(--rwp-accent);
	border: 0;
	border-radius: 999px;
}

/* With JavaScript, dropdowns apply themselves when closed. */
.rwp-js .rwp-filters__submit {
	display: none;
}

.rwp-filters__submit {
	margin-top: 0;
}

/* ---------- Status line: count + active pills ---------- */

.rwp-filters__status {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-top: 12px;
	font-size: 0.875rem;
}

.rwp-filters__total {
	margin-right: 4px;
	font-weight: 700;
}

.rwp-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 3px 10px;
	color: var(--rwp-text);
	text-decoration: none;
	border: 1px solid var(--rwp-border);
	border-radius: 999px;
}

.rwp-pill:hover {
	border-color: var(--rwp-accent);
	color: var(--rwp-accent);
}

.rwp-filters__clear {
	color: var(--rwp-muted);
}

.rwp-filters.is-loading {
	opacity: 0.6;
	pointer-events: none;
}

/* ---------- Phones: panels drop in below the bar instead of floating ---------- */

@media (max-width: 600px) {
	.rwp-facet[open] {
		flex-basis: 100%;
	}

	.rwp-facet__panel {
		position: static;
		width: auto;
		max-width: none;
		margin-top: 8px;
		box-shadow: none;
	}
}

/* ---------- "Browse by" tiles ---------- */

.rwp-tiles {
	/* Flex (not grid) so a short row centers instead of hugging the left. */
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 14px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rwp-tiles > li {
	flex: 0 1 140px;
}

.rwp-tile {
	box-sizing: border-box; /* Padding stays inside the 100% height. */
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	height: 100%;
	padding: 16px 10px 14px;
	color: var(--rwp-text);
	text-align: center;
	text-decoration: none;
	background: var(--rwp-bg);
	border: 1px solid var(--rwp-border);
	border-radius: var(--rwp-radius);
	transition: transform 0.15s, border-color 0.15s;
}

.rwp-tile:hover,
.rwp-tile:focus-visible {
	color: var(--rwp-accent);
	border-color: var(--rwp-accent);
	transform: translateY(-2px);
}

.rwp-tile__icon {
	width: 56px;
	height: 56px;
}

.rwp-tile__name {
	font-weight: 700;
	line-height: 1.2;
}

.rwp-tile__count {
	font-size: 0.8rem;
	color: var(--rwp-muted);
}

@media (prefers-reduced-motion: reduce) {
	.rwp-tile {
		transition: none;
	}

	.rwp-tile:hover {
		transform: none;
	}
}
