/**
 * Brands index (/brand/) — directory grid + sticky search/alphabet bar.
 *
 * All color / radius / shadow / spacing values come from theme.json tokens so
 * the page stays in lockstep with the rest of the theme. Mobile-first.
 *
 * Layout model:
 *   - ONE continuous grid holds every card; letters are full-width dividers,
 *     so rows stay tight across the whole page (no per-letter half-empty grids).
 *   - The header (title + count + search + alphabet) is a SOLID sticky bar so
 *     nothing floats transparently over the cards. Desktop sticks the whole
 *     header; mobile sticks only the inner search+alphabet bar.
 *   - --rh-header-height is measured + set by brands.js so the sticky offset
 *     sits exactly under the site header (falls back to 64px before JS runs).
 */

.rh-brands-main {
	max-width: var(--wp--style--global--wide-size, 1200px);
	margin-inline: auto;
	padding: 0 var(--wp--preset--spacing--30, 1rem) var(--wp--preset--spacing--60, 4rem);
}

.rh-brands {
	--rh-brands-top: var(--rh-header-height, 64px);
}

/* ── Header (sticky on desktop) ─────────────────────────────────────────── */
.rh-brands__header {
	position: sticky;
	top: var(--rh-brands-top);
	z-index: 5;
	background: var(--wp--preset--color--base, #fff);
	padding-top: var(--wp--preset--spacing--40, 1.5rem);
	margin-bottom: var(--wp--preset--spacing--40, 1.5rem);
	border-bottom: 1px solid var(--wp--preset--color--border, #e2e4e9);
}

.rh-brands__intro { padding-bottom: 12px; }
.rh-brands__title {
	margin: 0;
	font-size: var(--wp--preset--font-size--2xl, 1.875rem);
	font-weight: var(--wp--custom--fw--strong);
	line-height: 1.4;
}
.rh-brands__sub {
	margin: 4px 0 0;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
}

/* Inner bar — search + alphabet. Solid background. */
.rh-brands__bar {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding-bottom: 12px;
	background: var(--wp--preset--color--base, #fff);
}

/* ── Search ─────────────────────────────────────────────────────────────── */
.rh-brands__search {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0 14px;
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: var(--wp--custom--radius--pill, 9999px);
	box-shadow: var(--wp--preset--shadow--xs, 0 1px 2px rgba(15, 17, 21, 0.06));
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.rh-brands__search:focus-within {
	border-color: var(--wp--preset--color--primary, #0a66c2);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp--preset--color--primary, #0a66c2) 12%, transparent);
}
.rh-brands__search-icon {
	flex: none;
	color: var(--wp--preset--color--text-muted, #5b6271);
}
.rh-brands__search-input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 12px 6px;
	border: 0;
	background: transparent;
	font: inherit;
	font-size: var(--wp--preset--font-size--md, 1.125rem);
	color: var(--wp--preset--color--text, #1a1d23);
	outline: none;
}
.rh-brands__search-input::placeholder { color: var(--wp--preset--color--text-muted, #5b6271); }
.rh-brands__search-input::-webkit-search-cancel-button { display: none; }
.rh-brands__search-clear {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: var(--wp--custom--radius--pill, 9999px);
	background: var(--wp--preset--color--muted, #eceef1);
	color: var(--wp--preset--color--text, #1a1d23);
	cursor: pointer;
}
.rh-brands__search-clear[hidden] { display: none; }

/* ── Alphabet rail (solid row, horizontal scroll) ───────────────────────── */
.rh-brands__alpha {
	display: flex;
	gap: 4px;
	overflow-x: auto;
	scrollbar-width: none;
	padding: 2px;
	margin: 0 -2px;
}
.rh-brands__alpha::-webkit-scrollbar { display: none; }
.rh-brands__alpha-link {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 30px;
	height: 30px;
	padding: 0 6px;
	border-radius: var(--wp--custom--radius--md, 0.5rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	font-weight: var(--wp--custom--fw--strong);
	text-decoration: none;
	line-height: 1;
	transition: background-color 0.12s ease, color 0.12s ease;
}
.rh-brands__alpha-link:hover {
	background: var(--wp--preset--color--surface, #f7f7f8);
	color: var(--wp--preset--color--text, #1a1d23);
}
.rh-brands__alpha-link.is-active {
	background: var(--wp--preset--color--primary, #0a66c2);
	color: #fff;
}
.rh-brands__alpha-link.is-empty {
	opacity: 0.3;
	pointer-events: none;
}

/* Mobile: the whole header stays sticky (search + alphabet always reachable).
 * It must remain a direct child of the tall .rh-brands so its sticky container
 * spans the full list — making only the inner bar sticky fails because its
 * container (the short header) scrolls away with it. Just tighten spacing. */
@media (max-width: 900px) {
	.rh-brands__header {
		padding-top: var(--wp--preset--spacing--30, 1rem);
		margin-bottom: var(--wp--preset--spacing--30, 1rem);
	}
	.rh-brands__intro { padding-bottom: 8px; }
	.rh-brands__title { font-size: var(--wp--preset--font-size--xl, 1.5rem); }
}

/* ── Grid (one continuous grid; dividers span full width) ───────────────── */
.rh-brands__grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--wp--preset--spacing--30, 1rem);
}
@media (min-width: 540px)  { .rh-brands__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 768px)  { .rh-brands__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .rh-brands__grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .rh-brands__grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.rh-brands__divider {
	grid-column: 1 / -1;
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 10px 0 0;
	/* Land the letter just below the sticky stack. --rh-brands-jump is measured
	   in JS (site header + whichever brands bar is sticky); the calc() is the
	   pre-JS fallback. */
	scroll-margin-top: var(--rh-brands-jump, calc(var(--rh-brands-top) + 124px));
	color: var(--wp--preset--color--primary, #0a66c2);
	font-size: var(--wp--preset--font-size--lg, 1.25rem);
	font-weight: var(--wp--custom--fw--strong);
	line-height: 1;
}
.rh-brands__divider:first-child { margin-top: 0; }
.rh-brands__divider[hidden] { display: none; }
.rh-brands__divider::after {
	content: "";
	flex: 1 1 auto;
	height: 1px;
	background: var(--wp--preset--color--border, #e2e4e9);
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.rh-brand-card {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	min-width: 0;
	padding: 16px 12px;
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: var(--wp--custom--radius--lg, 0.75rem);
	color: inherit;
	text-decoration: none;
	text-align: center;
	transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.rh-brand-card[hidden] { display: none; }
.rh-brand-card:hover {
	transform: translateY(-3px);
	border-color: color-mix(in srgb, var(--wp--preset--color--primary, #0a66c2) 40%, var(--wp--preset--color--border, #e2e4e9));
	box-shadow: var(--wp--preset--shadow--md, 0 8px 24px rgba(15, 17, 21, 0.10));
}

.rh-brand-card__logo {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 1 / 1;
	padding: 12px; /* breathing room so logos never touch the edges */
	border-radius: var(--wp--custom--radius--md, 0.5rem);
	background: var(--wp--preset--color--surface, #f7f7f8);
	overflow: hidden;
}
.rh-brand-card__img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain; /* show the WHOLE logo, never crop */
}
.rh-brand-card__logo--mono {
	padding: 0;
	font-size: clamp(1.75rem, 6vw, 2.5rem);
	font-weight: var(--wp--custom--fw--strong);
	color: var(--wp--preset--color--primary, #0a66c2);
}

.rh-brand-card__name {
	width: 100%;
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	font-weight: var(--wp--custom--fw--strong);
	line-height: 1.5;
	color: var(--wp--preset--color--text, #1a1d23);
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.rh-brand-card__count {
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
}

/* ── Empty / no-results states ──────────────────────────────────────────── */
.rh-brands__noresults,
.rh-brands__blank {
	margin-top: var(--wp--preset--spacing--50, 3rem);
	padding: var(--wp--preset--spacing--50, 3rem) var(--wp--preset--spacing--30, 1rem);
	text-align: center;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--md, 1.125rem);
}
.rh-brands__noresults[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
	.rh-brand-card { transition: none; }
	.rh-brand-card:hover { transform: none; }
}
