/*
 * The filter bar, result count and empty state on the Campaign Options page.
 * WordPress loads this file only on pages that contain the r2s/mechanics-browser block.
 * The tiles themselves are in tiles.css.
 */

.r2s-browser {
	/* The height the search row needs on a phone, used to let it scroll away below. */
	--r2s-search-row: 4rem;
}

/* ---------- Filter bar ---------- */

/*
 * On a phone the search row scrolls away and only the chips stay pinned, so the bar never
 * takes over the small screen. The negative top value is what does this.
 */
.r2s-filters {
	position: sticky;
	top: calc(var(--wp-admin--admin-bar--height, 0px) - var(--r2s-search-row));
	z-index: 5;
	display: grid;
	gap: var(--wp--preset--spacing--10);
	padding-block: var(--wp--preset--spacing--20) var(--wp--preset--spacing--10);
	background: var(--wp--preset--color--background);
	border-block-end: 1px solid var(--wp--preset--color--line);
}

.r2s-filters__top {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--30);
	min-height: calc(var(--r2s-search-row) - var(--wp--preset--spacing--20) - var(--wp--preset--spacing--10));
}

.r2s-filters__search {
	flex: 1 1 auto;
	min-width: 0;
}

.r2s-filters__search input {
	width: 100%;
	min-height: 44px;
	padding-inline: var(--wp--preset--spacing--20);
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--muted);
	border-radius: var(--wp--custom--radius--control);
	color: var(--wp--preset--color--ink);
	font: inherit;
}

.r2s-filters__search input::placeholder {
	color: var(--wp--preset--color--muted);
	opacity: 1;
}

.r2s-filters__clear {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	white-space: nowrap;
}

.r2s-filters__clear[hidden] {
	display: none;
}

.r2s-filters__groups {
	display: grid;
	gap: var(--wp--preset--spacing--10);
	min-width: 0;
}

/* A row of chips scrolls sideways on a phone. It runs to the screen edge to show there is more. */
.r2s-chip-group {
	display: flex;
	align-items: center;
	gap: var(--wp--preset--spacing--10);
	margin-inline: calc(clamp(1rem, 4vw, 2.5rem) * -1);
	padding: 4px clamp(1rem, 4vw, 2.5rem);
	overflow-x: auto;
	scrollbar-width: none;
}

.r2s-chip-group::-webkit-scrollbar {
	display: none;
}

.r2s-chip-group__label {
	flex: none;
	min-width: 4rem;
	font-weight: 650;
}

.r2s-chip {
	display: inline-flex;
	flex: none;
	align-items: center;
	min-height: 44px;
	padding-inline: var(--wp--preset--spacing--30);
	border: 1px solid color-mix(in srgb, var(--wp--preset--color--ink) 22%, transparent);
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--ink);
	text-decoration: none;
	white-space: nowrap;
	transition:
		background-color var(--wp--custom--motion--fast),
		border-color var(--wp--custom--motion--fast),
		color var(--wp--custom--motion--fast);
}

a.r2s-chip:hover {
	border-color: var(--wp--preset--color--ink);
	text-decoration: none;
}

a.r2s-chip[aria-current="true"] {
	background: var(--wp--preset--color--ink);
	border-color: var(--wp--preset--color--ink);
	color: var(--wp--preset--color--background);
	font-weight: 650;
}

/* How many cards the chip would show. */
.r2s-chip__count {
	display: inline-grid;
	place-items: center;
	min-width: 1.6rem;
	min-height: 1.6rem;
	margin-inline-start: 0.5rem;
	padding-inline: 0.4rem;
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--color--line);
	color: var(--wp--preset--color--ink);
	font-size: 1rem;
	font-weight: 600;
	line-height: 1;
}

a.r2s-chip[aria-current="true"] .r2s-chip__count {
	background: var(--wp--preset--color--accent);
	color: var(--wp--custom--on-accent);
}

/* A chip that would show no cards with the other filters: switched off. */
.r2s-chip[aria-disabled="true"] {
	border-style: dashed;
	border-color: var(--wp--preset--color--line);
	color: var(--wp--preset--color--muted);
	cursor: not-allowed;
}

.r2s-chip[aria-disabled="true"] .r2s-chip__count {
	background: transparent;
	color: inherit;
}

.r2s-browser__status {
	margin-block: var(--wp--preset--spacing--30);
	color: var(--wp--preset--color--muted);
}

.r2s-browser__status:focus-visible {
	outline-offset: 4px;
}

/* ---------- Empty state ---------- */

.r2s-empty {
	padding: var(--wp--preset--spacing--60) var(--wp--preset--spacing--40);
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--tile);
}

.r2s-empty[hidden] {
	display: none;
}

.r2s-empty__title {
	margin-block: 0 var(--wp--preset--spacing--20);
	font-size: var(--wp--preset--font-size--large);
}

.r2s-empty p {
	margin-block: 0 var(--wp--preset--spacing--40);
	color: var(--wp--preset--color--muted);
}

.r2s-empty__list {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* ---------- Desktop: everything fits, so the whole bar stays pinned ---------- */

@media (min-width: 1000px) {
	.r2s-browser {
		--r2s-search-row: 0rem;
	}

	/* Search on top, then the three chip rows at full width, so each row fits on one line. */
	.r2s-filters {
		padding-block-end: var(--wp--preset--spacing--20);
	}

	.r2s-filters__search {
		flex: 0 1 22rem;
	}

	.r2s-chip-group {
		margin-inline: 0;
		padding-inline: 0;
		overflow: visible;
		flex-wrap: wrap;
	}
}

/* Three filter rows are too tall to pin on a phone, so there the bar scrolls with the page. */
@media (max-width: 699px) {
	.r2s-filters {
		position: static;
	}
}

/* The row labels line up: "Goal", "Channels", "Product type". */
@media (min-width: 700px) {
	.r2s-chip-group__label {
		min-width: 7.5rem;
	}
}

/* ---------- "Browse by" switcher: Products, Objectives, Objectives & channels ---------- */

.r2s-views {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem;
	width: fit-content;
	max-width: 100%;
	margin-block-end: var(--wp--preset--spacing--30);
	padding: 0.25rem;
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--color--surface);
}

.r2s-views__link {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding-inline: var(--wp--preset--spacing--30);
	border-radius: var(--wp--custom--radius--pill);
	color: var(--wp--preset--color--ink);
	font-weight: 600;
	text-decoration: none;
	white-space: nowrap;
}

/* On a phone the three buttons share the width equally; long labels wrap inside their button. */
@media (max-width: 599px) {
	.r2s-views {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		width: 100%;
		box-sizing: border-box;
		border-radius: var(--wp--custom--radius--card);
	}

	.r2s-views__link {
		justify-content: center;
		padding-inline: 0.5rem;
		border-radius: var(--wp--custom--radius--control);
		line-height: 1.2;
		text-align: center;
		white-space: normal;
	}
}

.r2s-views__link:hover {
	background: var(--wp--preset--color--background);
}

.r2s-views__link[aria-current="true"] {
	background: var(--wp--preset--color--ink);
	color: var(--wp--preset--color--background);
}

.r2s-view[hidden],
.r2s-pgroup[hidden],
.r2s-matrix__row[hidden],
.r2s-browser [data-r2s-item][hidden] {
	display: none;
}

/* ---------- A section of products with its heading ---------- */

.r2s-pgroup + .r2s-pgroup {
	margin-block-start: var(--wp--preset--spacing--60);
}

.r2s-pgroup__title {
	margin-block: 0 var(--wp--preset--spacing--30);
	font-size: var(--wp--preset--font-size--large);
}

/* ---------- Objectives view: small text cards ---------- */

.r2s-minis {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
	gap: var(--wp--preset--spacing--20);
	margin: 0;
	padding: 0;
	list-style: none;
}

.r2s-mini a {
	display: grid;
	gap: 0.3rem;
	height: 100%;
	box-sizing: border-box;
	padding: var(--wp--preset--spacing--30);
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--card);
	background: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--ink);
	text-decoration: none;
	transition: border-color var(--wp--custom--motion--fast);
}

.r2s-mini a:hover {
	border-color: var(--wp--preset--color--ink);
}

.r2s-mini__title {
	font-weight: 700;
}

.r2s-mini__pitch {
	color: var(--wp--preset--color--muted);
}

.r2s-mini__group {
	color: var(--wp--preset--color--accent-ink);
	font-weight: 600;
}

/* ---------- Objectives & channels view: a row of products per channel ---------- */

.r2s-matrix {
	display: grid;
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--card);
	background: var(--wp--preset--color--surface);
}

.r2s-matrix__row {
	display: grid;
	gap: 0.5rem;
	padding: var(--wp--preset--spacing--30);
}

.r2s-matrix__row:not([hidden]) ~ .r2s-matrix__row:not([hidden]) {
	border-block-start: 1px solid var(--wp--preset--color--line);
}

.r2s-matrix__label {
	margin: 0;
	font-size: var(--wp--preset--font-size--base);
}

.r2s-matrix__pills {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (min-width: 700px) {
	.r2s-matrix__row {
		grid-template-columns: 9rem minmax(0, 1fr);
		align-items: center;
	}
}
