/**
 * Learnomy — Catalog stylesheet.
 *
 * Page-specific styles for /courses/ (course-archive.php) and
 * /courses/category/{slug}/ (category-archive.php). Loaded only on
 * those routes via Template_Loader::enqueue_assets() so other pages
 * don't pay for the filter-bar CSS (the view toggle + list view are in
 * shared/course-list-layout.css).
 *
 * Shared primitives consumed but not owned here:
 *   .lrn-course-card*, .lrn-wishlist-btn*, .lrn-empty-state*,
 *   .lrn-grid (base grid utility), .lrn-load-more
 * Those live in learnomy.css because dashboards, single-course, and
 * blocks all render them too.
 *
 * Responsive contract: 1024px (tablet ↔ desktop) and 640px (mobile) only.
 * No intermediate breakpoints. The previous 17-breakpoint sprawl is what
 * this slice is extracting away from. Only a 640px query remains directly
 * in this file (search-suggest tap floor) — the grid's own 1024/1440/640
 * column rules moved to shared/course-list-layout.css (Basecamp
 * 10350179892), which is where My Courses can actually load them too.
 *
 * @package Learnomy
 */

/* ==========================================================================
   Filter bar — search + category + sort + grid/list toggle
   ========================================================================== */

.lrn-filter-bar {
	display:       flex;
	align-items:   center;
	gap:           var(--lrn-sp-3);
	flex-wrap:     wrap;
	margin-bottom: var(--lrn-sp-6);
}

.lrn-filter-bar__form {
	display:     flex;
	align-items: center;
	gap:         var(--lrn-sp-3);
	flex-wrap:   wrap;
	flex:        1;
	margin:      0;
	padding:     0;
}

.lrn-filter-bar__search {
	flex:      1;
	min-width: 180px;
}

.lrn-filter-bar__category,
.lrn-filter-bar__sort {
	flex-shrink: 0;
}

/* The grid/list toggle, the course grid's column rules (--cols-N, the
   height-fill li rules) and the list-view layout all live in
   shared/course-list-layout.css: My Courses uses them too, and that sheet
   is the one both routes load (Basecamp 10350179892 — this file only ever
   loads on catalog/category, so a column rule here could never reach
   /account/courses/). */

/* ── Results header ─────────────────────────────────────────────────────────
   Count on the start edge, grid/list switch on the end edge, right above the
   courses (catalog/partials/results-bar.php, every catalog layout). */
.lrn-catalog-results__bar {
	display:          flex;
	justify-content:  space-between;
	align-items:      center;
	gap:              var(--lrn-sp-3);
	margin-block-end: var(--lrn-sp-4);
}

.lrn-catalog-results__showing {
	margin:    0;
	color:     var(--lrn-text-secondary);
	font-size: var(--lrn-text-sm);
}

/* ── Phone Filters sheet (grid layout) ─────────────────────────────────────
   On desktop and tablet the wrapper steps out of the layout (display:
   contents) so the dropdowns sit in the bar as before, and the button and the
   sheet's own head and foot never show. The phone rules are in the 640px
   block below. */
.lrn-filter-bar__filters {
	display: contents;
}

.lrn-filter-bar__sheet-toggle,
.lrn-filter-bar__sheet-head,
.lrn-filter-bar__sheet-foot {
	display: none;
}

/* ── Top-bar filters (grid layout) ──────────────────────────────────────────
   Each registered facet (Price, Level, Tags...) folds into a native
   <details> dropdown in the filter bar: same options, counts and inputs as
   the sidebar rail (Facet_Renderer), no second renderer, keyboard and screen
   reader behaviour from the browser. */
.lrn-facet-dropdown {
	position:    relative;
	flex-shrink: 0;
}

.lrn-facet-dropdown__toggle {
	display:       inline-flex;
	align-items:   center;
	gap:           var(--lrn-sp-2);
	min-height:    var(--lrn-touch-min, 40px);
	padding-inline: var(--lrn-sp-3);
	border:        1px solid var(--lrn-border);
	border-radius: var(--lrn-radius-md);
	background:    var(--lrn-bg);
	color:         var(--lrn-text);
	font-size:     var(--lrn-text-sm);
	list-style:    none;
	cursor:        pointer;
}

.lrn-facet-dropdown__toggle::-webkit-details-marker {
	display: none;
}

.lrn-facet-dropdown__toggle svg {
	width:  var(--lrn-icon-sm);
	height: var(--lrn-icon-sm);
	transition: transform var(--lrn-dur) var(--lrn-ease);
}

.lrn-facet-dropdown[open] .lrn-facet-dropdown__toggle svg {
	transform: rotate(180deg);
}

.lrn-facet-dropdown[data-active] .lrn-facet-dropdown__toggle {
	border-color: var(--lrn-accent);
}

.lrn-facet-dropdown__toggle:focus-visible {
	outline:        3px solid var(--lrn-focus-ring);
	outline-offset: 2px;
}

.lrn-facet-dropdown__panel {
	position:      absolute;
	inset-block-start: calc(100% + var(--lrn-sp-1));
	inset-inline-start: 0;
	z-index:       var(--lrn-z-dropdown);
	min-width:     14rem;
	max-height:    20rem;
	overflow-y:    auto;
	padding:       var(--lrn-sp-3);
	border:        1px solid var(--lrn-border);
	border-radius: var(--lrn-radius-md);
	background:    var(--lrn-bg);
	box-shadow:    var(--lrn-shadow-md);
}

/* The toggle already names the facet. */
.lrn-facet-dropdown__panel .lrn-catalog-filters__heading {
	position: absolute;
	width:    1px;
	height:   1px;
	overflow: hidden;
	clip:     rect(0, 0, 0, 0);
	white-space: nowrap;
}

.lrn-facet-dropdown__panel .lrn-catalog-facet {
	margin:  0;
	padding: 0;
	border:  0;
}

.lrn-facet-dropdown__panel .lrn-catalog-facet__list {
	margin:     0;
	padding:    0;
	list-style: none;
}

.lrn-facet-dropdown__panel .lrn-catalog-facet__row {
	display:     flex;
	align-items: center;
	gap:         var(--lrn-sp-2);
	min-height:  var(--lrn-touch-min, 40px);
	cursor:      pointer;
}

.lrn-facet-dropdown__panel .lrn-catalog-facet__label {
	flex: 1;
}

.lrn-facet-dropdown__panel .lrn-catalog-facet__count {
	color:     var(--lrn-text-secondary);
	font-size: var(--lrn-text-xs);
	font-variant-numeric: tabular-nums;
}

/* ── Search autocomplete dropdown (BC #10043289391) ─────────────────────── */
.lrn-search-suggest-wrap {
	position: relative;
}

.lrn-search-suggest {
	position: absolute;
	inset-inline: 0;
	top: calc(100% + var(--lrn-sp-2));
	z-index: 20;
	background: var(--lrn-bg);
	border: 1px solid var(--lrn-border);
	border-radius: var(--lrn-radius-md);
	box-shadow: 0 6px 24px color-mix(in srgb, var(--lrn-text) 14%, transparent);
	max-height: 320px;
	overflow-y: auto;
}

.lrn-search-suggest[hidden] {
	display: none;
}

.lrn-search-suggest__item {
	display: block;
	padding: var(--lrn-sp-2) var(--lrn-sp-3);
	color: var(--lrn-text);
	text-decoration: none;
	border-bottom: 1px solid color-mix(in srgb, var(--lrn-border) 60%, transparent);
}

.lrn-search-suggest__item:last-child {
	border-bottom: 0;
}

.lrn-search-suggest__item:hover,
.lrn-search-suggest__item:focus,
.lrn-search-suggest__item.is-active {
	background: var(--lrn-bg-hover);
	color: var(--lrn-accent-text, var(--lrn-accent));
}

.lrn-search-suggest__empty {
	margin: 0;
	padding: var(--lrn-sp-3);
	color: var(--lrn-text-secondary);
}

.lrn-search-suggest__empty[hidden] {
	display: none;
}

/* Tap floor (technique 1, see "Tap targets" in learnomy.css). A suggestion row
   is 8px of padding around 14px text, so it renders ~37px. It sits at the end
   of the file rather than in the 640px block above because the component's own
   `display: block` is declared later and would otherwise win on source order. */
@media (max-width: 640px) {
	.lrn-search-suggest__item {
		display:     flex;
		align-items: center;
		min-height:  var(--lrn-touch-min);
	}

	/* Category and sort each take a full row on a phone; at content width
	   they sat as two odd-length boxes under the search field. */
	.lrn-filter-bar__category,
	.lrn-filter-bar__sort {
		flex: 1 1 100%;
	}

	/* Search and sort stay on the first screen; the filters fold behind one
	   Filters button and open as a sheet from the bottom of the screen. */
	.lrn-btn.lrn-filter-bar__sheet-toggle {
		display:         inline-flex;
		align-items:     center;
		justify-content: center;
		gap:             var(--lrn-sp-2);
		flex:            1 1 100%;
	}

	.lrn-filter-bar__sheet-toggle svg {
		width:  var(--lrn-icon-sm);
		height: var(--lrn-icon-sm);
	}

	.lrn-filter-bar__filters {
		display: none;
	}

	.lrn-filter-bar__filters.is-open {
		position:        fixed;
		inset-inline:    0;
		inset-block-end: 0;
		z-index:         var(--lrn-z-modal);
		display:         flex;
		flex-direction:  column;
		gap:             var(--lrn-sp-2);
		max-height:      85vh;
		overflow-y:      auto;
		padding:         var(--lrn-sp-4) var(--lrn-sp-4) 0;
		border-start-start-radius: var(--lrn-radius-lg);
		border-start-end-radius:   var(--lrn-radius-lg);
		background:      var(--lrn-bg);
		/* The page behind dims, so the sheet reads as on top of it. */
		box-shadow:      var(--lrn-shadow-overlay), 0 0 0 100vmax rgba(0, 0, 0, 0.4);
		box-shadow:      var(--lrn-shadow-overlay), 0 0 0 100vmax color-mix(in srgb, var(--lrn-text) 40%, transparent);
	}

	.lrn-filter-bar__filters.is-open .lrn-filter-bar__sheet-head {
		display:         flex;
		align-items:     center;
		justify-content: space-between;
	}

	.lrn-filter-bar__sheet-title {
		margin:      0;
		font-size:   var(--lrn-text-lg);
		font-weight: var(--lrn-weight-semibold);
	}

	.lrn-filter-bar__sheet-close svg {
		width:  var(--lrn-icon-md);
		height: var(--lrn-icon-md);
	}

	/* The close-and-see-results button stays in reach while the list scrolls. */
	.lrn-filter-bar__filters.is-open .lrn-filter-bar__sheet-foot {
		display:            block;
		position:           sticky;
		inset-block-end:    0;
		margin-block-start: auto;
		padding-block:      var(--lrn-sp-3) var(--lrn-sp-4);
		background:         var(--lrn-bg);
	}

	.lrn-filter-bar__sheet-foot .lrn-btn {
		width: 100%;
	}

	/* Inside the sheet each filter is a full-width row that opens in place. */
	.lrn-facet-dropdown {
		position: static;
	}

	.lrn-facet-dropdown__toggle {
		width:           100%;
		justify-content: space-between;
	}

	.lrn-facet-dropdown__panel {
		position:           static;
		min-width:          0;
		max-height:         none;
		margin-block-start: var(--lrn-sp-1);
		box-shadow:         none;
	}
}

/*
 * Catalog search submit.
 *
 * The grid layout shipped without one: its only buttons were the view
 * toggles, so Enter was the sole way to run a search and nothing said so
 * (Basecamp 10171341067). Typing deliberately does not live-filter, since a
 * debounced reload used to eat characters mid-word (10042899710), which makes
 * a visible control the only honest affordance.
 */
.lrn-filter-bar__submit {
	flex-shrink: 0;
}
