/*
 * Best Before theme · "All categories" drawer (template-parts/global/drawer.php,
 * assets/js/catdrawer.js). One component on every width: a full-height panel
 * that slides in from the left over a dimmed backdrop.
 *
 * Every selector is scoped to .bb-catdrawer (the <dialog>) and doubles up with
 * .bb-dialog.bb-drawer where it has to beat the generic dialog rules in main.css.
 * <ul> rules carry the .bb-catdrawer prefix to beat main.css's ul[class] reset.
 *
 * Geometry (left edge of panel = 0):
 *   16px side padding · 40px thumbnail (16-56) · 12px gap · name text at 68px.
 *   Child guide line at 36px (under the thumbnail centre); child text at 68px,
 *   so subcategory names line up exactly with their parent's name.
 */

/* ---------- Dialog shell ---------- */
.bb-dialog.bb-drawer {
	position: fixed;
	inset: 0 auto 0 0;
	width: min(400px, 92vw);
	max-width: none;
	height: 100%;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0 var(--bb-r-panel) var(--bb-r-panel) 0;
	background: var(--bb-surface);
	color: var(--bb-ink-2);
	box-shadow: 12px 0 48px -16px rgba(17, 17, 17, .35);
	overflow: hidden;
	overflow: clip; /* not even programmatically scrollable: the panel never shifts */
}
.bb-dialog.bb-drawer:not([open]) { display: none; }
.bb-dialog.bb-drawer[open] { display: flex; animation: bbCatdrawerIn 220ms var(--bb-ease); }
.bb-dialog.bb-drawer::backdrop { background: rgba(17, 17, 17, .5); animation: bbCatdrawerFade 220ms ease-out; }
@keyframes bbCatdrawerIn { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes bbCatdrawerFade { from { opacity: 0; } to { opacity: 1; } }

/* Page behind the open drawer doesn't scroll (JS adds the class as a fallback for :has()). */
html:has(#bb-drawer[open]), html.bb-catdrawer-lock { overflow: hidden; }

.bb-catdrawer__panel { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; overflow: hidden; overflow: clip; }

/* ---------- Header row ---------- */
.bb-catdrawer__head {
	flex: none;
	display: flex; align-items: center; justify-content: space-between; gap: 12px;
	min-height: 64px; padding: 10px 8px 10px 20px;
}
.bb-catdrawer__title { margin: 0; font: 800 1.25rem/1.2 var(--bb-font-display); letter-spacing: -.01em; color: var(--bb-ink); }
.bb-catdrawer__close {
	flex: none; display: grid; place-items: center;
	width: 44px; height: 44px; padding: 0;
	border: 0; border-radius: var(--bb-r-control);
	background: transparent; color: var(--bb-ink); cursor: pointer;
	transition: background-color .15s var(--bb-ease);
}
.bb-catdrawer__close:focus-visible { outline: 2px solid var(--bb-ink); outline-offset: 2px; }

/* ---------- Search (pinned under the header; the list scrolls beneath it) ---------- */
.bb-catdrawer__search {
	flex: none; position: relative;
	padding: 0 16px 12px;
	border-bottom: 1px solid var(--bb-border);
}
.bb-catdrawer__searchicon {
	position: absolute; left: 30px; top: 22px; /* 16px pad + 14px inset; 22 = half the 44px field */
	display: grid; place-items: center; width: 18px; height: 18px;
	transform: translateY(-50%);
	color: var(--bb-muted); pointer-events: none;
}
.bb-catdrawer .bb-catdrawer__input[type="search"] {
	display: block; width: 100%; height: 44px; min-height: 44px; margin: 0;
	padding: 0 44px 0 42px;
	border: 1.5px solid #d6d5cf; border-radius: var(--bb-r-control);
	background: var(--bb-ground); color: var(--bb-ink);
	font-size: 1rem; line-height: 1; /* 16px: no iOS zoom on focus */
	-webkit-appearance: none; appearance: none;
	transition: border-color .15s var(--bb-ease), background-color .15s var(--bb-ease), box-shadow .15s var(--bb-ease);
}
.bb-catdrawer .bb-catdrawer__input[type="search"]:focus { outline: none; border-color: var(--bb-ink); background: var(--bb-surface); box-shadow: 0 0 0 3px rgba(255, 207, 2, .55); }
.bb-catdrawer__input::-webkit-search-cancel-button,
.bb-catdrawer__input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.bb-catdrawer__clear {
	position: absolute; right: 16px; top: 0;
	display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
	border: 0; border-radius: var(--bb-r-control);
	background: transparent; color: var(--bb-muted); cursor: pointer;
}
.bb-catdrawer__clear[hidden] { display: none; }
.bb-catdrawer__clear .bb-icon { width: 16px; height: 16px; }

/* ---------- Scroll area ---------- */
.bb-catdrawer__scroll {
	flex: 1; min-height: 0;
	overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* ---------- Quick chips (horizontal scroll) ---------- */
.bb-catdrawer .bb-catdrawer__chips {
	display: flex; gap: 8px;
	margin: 0; padding: 12px 16px; list-style: none;
	overflow-x: auto; scrollbar-width: none; scroll-padding-inline: 16px;
}
.bb-catdrawer__chips::-webkit-scrollbar { display: none; }
.bb-catdrawer__chips > li { flex: none; }
.bb-catdrawer__chip {
	display: inline-flex; align-items: center; gap: 6px;
	height: 40px; padding: 0 14px;
	border: 1px solid var(--bb-border); border-radius: var(--bb-r-pill);
	background: var(--bb-surface); color: var(--bb-ink);
	font-size: .875rem; font-weight: 600; white-space: nowrap; text-decoration: none;
	transition: border-color .15s var(--bb-ease), background-color .15s var(--bb-ease);
}
.bb-catdrawer__chip .bb-icon { flex: none; }
.bb-catdrawer__chip--yellow { background: var(--bb-yellow); border-color: var(--bb-yellow); font-weight: 700; }
.bb-catdrawer__chips + .bb-catdrawer__nav { border-top: 1px solid var(--bb-border); }
.bb-catdrawer__chip:focus-visible,
.bb-catdrawer__row:focus-visible,
.bb-catdrawer__kid a:focus-visible,
.bb-catdrawer__links a:focus-visible { outline: 2px solid var(--bb-ink); outline-offset: -2px; }

/* ---------- Category list ---------- */
.bb-catdrawer .bb-catdrawer__list { margin: 0; padding: 0; list-style: none; }
.bb-catdrawer__item[hidden] { display: none; }
.bb-catdrawer__item + .bb-catdrawer__item { border-top: 1px solid var(--bb-border); }

/* Parent row: a <button> (has subcategories) or an <a> (leaf), same look. */
.bb-catdrawer__row {
	display: flex; align-items: center; gap: 12px;
	width: 100%; min-height: 56px; margin: 0;
	padding: 8px 6px 8px 16px;
	border: 0; border-radius: 0;
	background: transparent; color: var(--bb-ink);
	font: inherit; font-size: .9375rem; text-align: left; text-decoration: none;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color .15s var(--bb-ease);
}
.bb-catdrawer__row:active { background: var(--bb-border); }
/* Leaf rows end in a muted right arrow ("opens") where parents have the down
   chevron ("expands"), so counts line up in one column on every row. */
.bb-catdrawer__go { color: var(--bb-muted); }
.bb-catdrawer__go .bb-icon { transform: rotate(-90deg); }

.bb-catdrawer__thumb {
	flex: none; display: grid; place-items: center;
	width: 40px; height: 40px; overflow: hidden;
	border-radius: var(--bb-r-small);
	background: var(--bb-soft-yellow); color: var(--bb-ink);
	font: 800 1rem/1 var(--bb-font-display);
	box-shadow: inset 0 0 0 1px rgba(17, 17, 17, .06);
}
.bb-catdrawer__thumb img { width: 100%; height: 100%; object-fit: cover; }

.bb-catdrawer__name {
	flex: 1; min-width: 0;
	font-weight: 600; line-height: 1.3;
	overflow-wrap: anywhere;
}
.bb-catdrawer__count {
	flex: none; margin-left: auto;
	color: var(--bb-muted); font-size: .8125rem; font-weight: 500;
	font-variant-numeric: tabular-nums;
}
.bb-catdrawer__chev {
	flex: none; display: grid; place-items: center;
	width: 44px; height: 44px; margin-left: -4px;
	color: var(--bb-ink);
	transition: transform 220ms var(--bb-ease);
}
.bb-catdrawer__row[aria-expanded="true"] { background: var(--bb-ground); }
.bb-catdrawer__row[aria-expanded="true"] .bb-catdrawer__chev { transform: rotate(180deg); }

/* ---------- Subcategories (height animates via grid rows 0fr -> 1fr) ---------- */
.bb-catdrawer__kids {
	display: grid; grid-template-rows: 0fr;
	visibility: hidden; /* collapsed links are out of the tab order and the a11y tree */
	transition: grid-template-rows 220ms var(--bb-ease), visibility 0s linear 220ms;
}
.bb-catdrawer__kids.is-open {
	grid-template-rows: 1fr; visibility: visible;
	transition: grid-template-rows 220ms var(--bb-ease), visibility 0s linear 0s;
}
.bb-catdrawer .bb-catdrawer__kidlist {
	min-height: 0; overflow: hidden;
	margin: 0 0 0 36px; padding: 0; list-style: none; /* guide line at 36px = thumbnail centre */
	border-left: 1px solid var(--bb-border);
}
/* Spacing as child margins (inside the overflow box) so a collapsed list is truly 0px tall. */
.bb-catdrawer__kidlist > li:first-child { margin-top: 4px; }
.bb-catdrawer__kidlist > li:last-child { margin-bottom: 10px; }
.bb-catdrawer__kid[hidden] { display: none; }
.bb-catdrawer__kid a {
	display: flex; align-items: center; gap: 12px;
	min-height: 44px; padding: 10px 58px 10px 31px; /* left: 36 + 1 + 31 = 68px = parent name; right: counts in the parents' count column */
	color: var(--bb-ink-2); font-size: .9375rem; font-weight: 400; line-height: 1.3;
	text-decoration: none;
	transition: background-color .15s var(--bb-ease);
}
.bb-catdrawer__kid a:active { background: var(--bb-border); }
.bb-catdrawer__kidname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.bb-catdrawer__kid--all a { font-weight: 600; color: var(--bb-ink); }

/* Live-filter highlight + empty state. */
.bb-catdrawer mark { background: var(--bb-soft-yellow); color: inherit; border-radius: 3px; box-shadow: 0 0 0 1px var(--bb-soft-yellow); }
.bb-catdrawer__empty { margin: 0; padding: 20px 16px; color: var(--bb-muted); font-size: .9375rem; line-height: 1.5; }
.bb-catdrawer__empty[hidden] { display: none; }
.bb-catdrawer__empty a { color: var(--bb-ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* While searching, only results show: the quick chips step aside. */
.bb-catdrawer.is-searching .bb-catdrawer__chips { display: none; }
.bb-catdrawer.is-searching .bb-catdrawer__nav { border-top: 0; }

/* ---------- Footer links ---------- */
.bb-catdrawer__more { margin-top: 8px; padding: 8px 0 0; border-top: 1px solid var(--bb-border); }
.bb-catdrawer .bb-catdrawer__links { margin: 0; padding: 0; list-style: none; }
.bb-catdrawer__links a {
	display: flex; align-items: center;
	min-height: 44px; padding: 0 16px;
	color: var(--bb-ink-2); font-size: .9375rem; font-weight: 500; text-decoration: none;
	transition: background-color .15s var(--bb-ease);
}
.bb-catdrawer__more + .bb-catdrawer__more { margin-top: 0; }

/* ---------- Hover (pointer devices only; avoids sticky hover after a tap) ---------- */
@media (hover: hover) {
	.bb-catdrawer__close:hover { background: var(--bb-ground); }
	.bb-catdrawer .bb-catdrawer__input[type="search"]:hover { border-color: #b4b3ad; }
	.bb-catdrawer__clear:hover { color: var(--bb-ink); }
	.bb-catdrawer__chip:hover { border-color: var(--bb-ink); }
	.bb-catdrawer__chip--yellow:hover { border-color: var(--bb-ink); }
	.bb-catdrawer__row:hover { background: var(--bb-ground); }
	.bb-catdrawer__kid a:hover { background: var(--bb-ground); }
	.bb-catdrawer__links a:hover { background: var(--bb-ground); color: var(--bb-ink); }
}

/* ---------- Reduced motion: no slide, no height animation ---------- */
@media (prefers-reduced-motion: reduce) {
	.bb-dialog.bb-drawer[open], .bb-dialog.bb-drawer::backdrop { animation: none; }
	.bb-catdrawer__kids, .bb-catdrawer__kids.is-open, .bb-catdrawer__chev { transition: none; }
}
