/**
 * Courses catalog styles.
 *
 * Mirrors the programs catalog: a full-width search bar above a two-column
 * layout — filter sidebar (organization checkboxes with counts, collapsible,
 * with an in-group search box and a fixed-height scrolling option list) beside
 * the results (chips, count + sort, card grid). Structural class names are the
 * plugin's stable contract shared with courses-catalog.php and courses.js.
 *
 * Targets Arabic (RTL) pages but uses logical/flex rules. IBM Plex Sans Arabic
 * is enqueued globally as 'tutor-sso-programs-font' (see tutor-sso.php).
 */

.rwaq-courses {
	--rwaq-primary: #565199;
	--rwaq-primary-soft: #EFEEFA;
	--rwaq-text: #242424;
	--rwaq-heading: #242424;
	--rwaq-muted: #616161;
	--rwaq-placeholder: #9E9E9E;
	--rwaq-icon: #616161;
	--rwaq-border: #D1D1D1;
	--rwaq-divider: #EDEDED;

	position: relative;
	margin: 0 0 2rem;
	color: var(--rwaq-text);
	font-family: 'IBM Plex Sans Arabic', sans-serif;
	-webkit-font-smoothing: antialiased;
}

.rwaq-courses *,
.rwaq-courses *::before,
.rwaq-courses *::after {
	box-sizing: border-box;
}

/* Width-constrained wrapper used by the /courses/ archive template
   (templates/archive-course.php). Matches the site's Elementor content width. */
.rwaq-courses-archive {
	max-width: 1280px;
	margin-inline: auto;
	padding: 25px 15px;
}

/* Overlay shown while a search / sort / filter reloads the whole list. */
.rwaq-courses__overlay {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.7);
	backdrop-filter: blur(1px);
}

.rwaq-courses__overlay[hidden] {
	display: none;
}

.rwaq-courses__overlay .rwaq-courses__spinner {
	position: sticky;
	top: 40%;
	width: 2rem;
	height: 2rem;
}

/* ---- Optional header ---- */
.rwaq-courses__header {
	display: flex;
	align-items: center;
	gap: 16px;
	margin-bottom: 22px;
}

.rwaq-courses__title {
	margin: 0;
	font-size: 32px;
	line-height: 40px;
	font-weight: 600;
	color: var(--rwaq-heading);
}

.rwaq-courses__total-badge {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	background: var(--rwaq-primary-soft);
	color: var(--rwaq-primary);
	border-radius: 999px;
	padding: 6px 14px;
	font-size: 14px;
	line-height: 20px;
	font-weight: 600;
	white-space: nowrap;
}

/* ---- Search bar (full width, above the layout) ---- */
.rwaq-courses__searchbar {
	position: relative;
	margin-bottom: 24px;
}

.rwaq-courses__search-icon {
	position: absolute;
	inset-inline-end: 16px; /* left in RTL */
	top: 50%;
	transform: translateY(-50%);
	display: inline-flex;
	color: var(--rwaq-icon);
	pointer-events: none;
}

.rwaq-courses input.rwaq-courses__search-input {
	width: 100%;
	height: 48px;
	border: 1px solid var(--rwaq-border);
	border-radius: 12px;
	outline: none;
	box-shadow: none;
	background: #fff;
	font-family: inherit;
	font-size: 16px;
	font-weight: 400;
	color: var(--rwaq-text);
	padding-inline-start: 16px;
	padding-inline-end: 48px;
	transition: border-color 0.15s;
}

.rwaq-courses input.rwaq-courses__search-input:focus {
	border-color: var(--rwaq-primary);
}

.rwaq-courses__search-input::placeholder {
	color: var(--rwaq-placeholder);
}

.rwaq-courses__search-input::-webkit-search-cancel-button,
.rwaq-courses__search-input::-webkit-search-decoration {
	-webkit-appearance: none;
	appearance: none;
}

/* ---- Layout: filter sidebar + results ---- */
.rwaq-courses__layout {
	display: flex;
	gap: 24px;
	align-items: flex-start;
}

.rwaq-courses__sidebar {
	flex: 0 0 280px;
	width: 280px;
	border: 1px solid var(--rwaq-border);
	border-radius: 18px;
	padding: 22px 22px 26px;
}

.rwaq-courses__main {
	flex: 1 1 auto;
	min-width: 0;
}

/* Sidebar head */
.rwaq-courses__sidebar-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 24px;
}

.rwaq-courses__sidebar-title {
	display: flex;
	align-items: center;
	gap: 9px;
	font-size: 16px;
	line-height: 22px;
	font-weight: 600;
	color: var(--rwaq-text);
}

/* Stays transparent on hover / focus (override theme / Elementor button styles). */
.rwaq-courses .rwaq-courses__clear,
.rwaq-courses .rwaq-courses__clear:hover,
.rwaq-courses .rwaq-courses__clear:focus {
	background: none !important;
	border: none !important;
	box-shadow: none !important;
	color: var(--rwaq-primary) !important;
	font-family: inherit;
	font-size: 14px;
	line-height: 20px;
	font-weight: 600;
	cursor: pointer;
	padding: 0;
}

/* ---- Filter groups ---- */
.rwaq-courses__filter-group {
	margin-top: 17px;
	padding-top: 17px;
	border-top: 1px solid var(--rwaq-divider);
}

.rwaq-courses__filter-title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 0;
	font-size: 14px;
	font-weight: 600;
	line-height: 20px;
	color: var(--rwaq-text);
	cursor: pointer;
	user-select: none;
}

.rwaq-courses__filter-chevron {
	display: inline-flex;
	color: var(--rwaq-text);
	transition: transform 0.18s ease;
}

/* Collapsed state: hide the search box and options, flip the chevron. */
.rwaq-courses__filter-group.is-collapsed .rwaq-courses__filter-search,
.rwaq-courses__filter-group.is-collapsed .rwaq-courses__filter-options {
	display: none;
}

.rwaq-courses__filter-group.is-collapsed .rwaq-courses__filter-chevron {
	transform: rotate(180deg);
}

/* In-group search for long option lists (organizations). */
.rwaq-courses__filter-search {
	position: relative;
	margin-top: 14px;
}

.rwaq-courses__filter-search-icon {
	position: absolute;
	inset-inline-end: 12px; /* left in RTL */
	top: 50%;
	transform: translateY(-50%);
	display: inline-flex;
	color: var(--rwaq-icon);
	pointer-events: none;
}

.rwaq-courses input.rwaq-courses__filter-search-input {
	width: 100%;
	height: 40px;
	border: 1px solid var(--rwaq-border);
	border-radius: 10px;
	outline: none;
	box-shadow: none;
	background: #fff;
	font-family: inherit;
	font-size: 14px;
	color: var(--rwaq-text);
	padding-inline-start: 12px;
	padding-inline-end: 40px;
	transition: border-color 0.15s;
}

.rwaq-courses input.rwaq-courses__filter-search-input:focus {
	border-color: var(--rwaq-primary);
}

.rwaq-courses__filter-search-input::placeholder {
	color: var(--rwaq-placeholder);
}

.rwaq-courses__filter-search-input::-webkit-search-cancel-button,
.rwaq-courses__filter-search-input::-webkit-search-decoration {
	-webkit-appearance: none;
	appearance: none;
}

/* "No organizations match" message (toggled by the in-group search). */
.rwaq-courses__filter-empty {
	padding: 4px 0;
	font-size: 13px;
	color: var(--rwaq-muted);
}

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

/* Fixed-height scroll area: the sidebar stays the same height no matter how many
   organizations the API returns (the search box narrows a long list).

   Inline spacing does two jobs: the negative margin with matching start padding
   keeps the checkbox focus ring from being clipped by `overflow`, and the larger
   end padding keeps the course-count numbers clear of the scrollbar (which sits
   on the inline-end edge — the left in RTL). `scrollbar-gutter` reserves that
   space up front so the rows don't shift when the scrollbar appears. */
.rwaq-courses__filter-options {
	display: flex;
	flex-direction: column;
	gap: 14px;
	margin-top: 14px;
	max-height: 280px;
	overflow-y: auto;
	overscroll-behavior: contain;
	margin-inline: -4px;
	padding-inline-start: 4px;
	padding-inline-end: 14px;
	scrollbar-width: thin;
	scrollbar-gutter: stable;
}

.rwaq-courses__filter-options:focus-visible {
	outline: 2px solid var(--rwaq-primary);
	outline-offset: 2px;
}

/* Slim scrollbar on WebKit/Blink (Firefox uses scrollbar-width above). */
.rwaq-courses__filter-options::-webkit-scrollbar {
	width: 6px;
}

.rwaq-courses__filter-options::-webkit-scrollbar-thumb {
	background: var(--rwaq-border);
	border-radius: 3px;
}

.rwaq-courses__filter-option {
	display: flex;
	align-items: center;
	gap: 11px;
	font-size: 14px;
	font-weight: 400;
	line-height: 22px;
	color: var(--rwaq-text);
	cursor: pointer;
}

/* Honor the `hidden` attribute on overflow options — the class's display:flex
   otherwise overrides the browser's built-in [hidden] { display: none } rule.
   `is-filtered-out` is the in-group search's own hiding mechanism, kept separate
   so it composes with the overflow state instead of fighting it. */
.rwaq-courses__filter-option[hidden],
.rwaq-courses__filter-option.is-filtered-out {
	display: none;
}

/* Visually hide the native control while keeping it accessible / focusable. */
.rwaq-courses__filter-input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

/* Custom checkbox box */
.rwaq-courses__filter-box {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	border: 1.5px solid var(--rwaq-border);
	border-radius: 6px;
	background: #fff;
	transition: background 0.12s, border-color 0.12s;
}

.rwaq-courses__filter-box svg {
	opacity: 0;
}

.rwaq-courses__filter-input:checked + .rwaq-courses__filter-box {
	background: var(--rwaq-primary);
	border-color: var(--rwaq-primary);
}

.rwaq-courses__filter-input:checked + .rwaq-courses__filter-box svg {
	opacity: 1;
}

/* Focus ring on the custom box when the hidden input is focused via keyboard. */
.rwaq-courses__filter-input:focus-visible + .rwaq-courses__filter-box {
	box-shadow: 0 0 0 3px rgba(86, 81, 153, 0.25);
}

.rwaq-courses__filter-label {
	flex: 1 1 auto;
}

/* Per-organization course count from the filters API. */
.rwaq-courses__filter-count {
	flex: 0 0 auto;
	color: var(--rwaq-muted);
	font-size: 12px;
	line-height: 16px;
	font-weight: 400;
	font-variant-numeric: tabular-nums;
}

/* ---- Active filter chips ---- */
.rwaq-courses__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin-bottom: 4px;
	min-height: 32px;
}

.rwaq-courses__chips:empty {
	display: none;
}

.rwaq-courses .rwaq-courses__chip,
.rwaq-courses .rwaq-courses__chip:hover,
.rwaq-courses .rwaq-courses__chip:focus {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 32px;
	padding: 0 12px;
	background: #fff !important;
	border: 1px solid var(--rwaq-border) !important;
	box-shadow: none !important;
	border-radius: 8px;
	font-family: inherit;
	font-size: 12px;
	font-weight: 600;
	line-height: 20px;
	color: var(--rwaq-muted) !important;
	cursor: pointer;
}

.rwaq-courses__chip-x {
	display: inline-flex;
	color: #6b7280;
	line-height: 1;
}

/* ---- Controls: result count + sort ---- */
.rwaq-courses__controls {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
	margin: 20px 0 24px;
}

.rwaq-courses__result-count {
	font-size: 14px;
	font-weight: 600;
	line-height: 20px;
	color: var(--rwaq-text);
}

/* ---- Sort control (custom dropdown backed by a hidden native <select>) ---- */
.rwaq-courses__sort {
	position: relative;
	flex: 0 0 auto;
}

.rwaq-courses .rwaq-courses__sort-trigger,
.rwaq-courses .rwaq-courses__sort-trigger:hover,
.rwaq-courses .rwaq-courses__sort-trigger:focus {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	height: 44px;
	border: 1px solid var(--rwaq-border) !important;
	box-shadow: none !important;
	border-radius: 12px;
	padding: 0 16px;
	background: #fff !important;
	color: inherit !important;
	font-family: inherit;
	font-size: 14px;
	cursor: pointer;
}

.rwaq-courses__sort-caption {
	color: var(--rwaq-muted);
	font-weight: 400;
}

.rwaq-courses__sort-value {
	min-width: 92px;
	text-align: right;
	font-weight: 600;
	color: var(--rwaq-text);
	white-space: nowrap;
}

.rwaq-courses__sort-chevron {
	display: inline-flex;
	color: var(--rwaq-text);
	transition: transform 0.15s;
}

.rwaq-courses__sort.is-open .rwaq-courses__sort-chevron {
	transform: rotate(180deg);
}

/* Hidden native <select> — the source of truth behind the custom sort UI. */
.rwaq-courses__sort-select {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.rwaq-courses__sort-menu {
	position: absolute;
	top: calc(100% + 8px);
	inset-inline-start: 0;
	width: 240px;
	max-width: 80vw;
	background: #fff;
	border: 1px solid #e5e5e5;
	border-radius: 12px;
	box-shadow: 0 12px 28px rgba(16, 24, 40, 0.14);
	padding: 8px;
	z-index: 20;
	display: none;
}

.rwaq-courses__sort.is-open .rwaq-courses__sort-menu {
	display: block;
}

.rwaq-courses__sort-option {
	padding: 10px 14px;
	border-radius: 8px;
	font-size: 15px;
	color: var(--rwaq-text);
	text-align: right;
	cursor: pointer;
}

.rwaq-courses__sort-option:hover {
	background: #f4f4f6;
}

.rwaq-courses__sort-option.is-selected {
	font-weight: 700;
	background: #f4f4f6;
}

/* ---- Cards grid (flexbox: N per row, wrapping) ---- */
.rwaq-courses__grid {
	--rwaq-courses-gap: 24px;
	display: flex;
	flex-wrap: wrap;
	gap: var(--rwaq-courses-gap);
}

/* ---- Card ---- */
.rwaq-course-card {
	flex: 0 0 calc(
		(100% - (var(--rwaq-courses-columns, 4) - 1) * var(--rwaq-courses-gap, 24px))
		/ var(--rwaq-courses-columns, 4)
	);
	min-width: 0;
	display: flex;
	flex-direction: column;
	border: 1px solid var(--rwaq-border);
	border-radius: 18px;
	padding: 16px;
	background: #fff;
	box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
	transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.rwaq-course-card:hover {
	box-shadow: 0 8px 22px rgba(16, 24, 40, 0.1);
	transform: translateY(-2px);
}

.rwaq-course-card__media {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 180px;
	border-radius: 12px;
	overflow: hidden;
	/* No background fill, so the empty state renders exactly like a program
	   card's: the 'thumb' icon (tinted by `color`) centered on the card. */
	color: #b6bccb;
}

.rwaq-course-card__image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.rwaq-course-card__placeholder {
	display: inline-flex;
}

.rwaq-course-card__body {
	display: flex;
	flex-direction: column;
	flex: 1;
	padding: 0;
}

.rwaq-course-card__title {
	margin: 16px 0 0;
	font-size: 16px;
	font-weight: 600;
	line-height: 22px;
	color: var(--rwaq-heading);
}

.rwaq-course-card__title a {
	color: inherit;
	text-decoration: none;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.rwaq-course-card__title a:hover {
	color: var(--rwaq-primary);
}

/* Meta list (instructor, start date) */
.rwaq-course-card__meta {
	list-style: none;
	margin: 14px 0 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.rwaq-course-card__meta:empty {
	display: none;
}

/* Typography matches .rwaq-program-card__meta-item exactly. */
.rwaq-course-card__meta-item {
	display: flex;
	align-items: center;
	gap: 9px;
	font-size: 12px;
	font-weight: 400;
	line-height: 16px;
	color: var(--rwaq-muted);
}

.rwaq-course-card__meta-item .rwaq-icon {
	flex: 0 0 auto;
	color: var(--rwaq-placeholder);
}

/* Footer badge (organization), pinned to the card bottom. */
.rwaq-course-card__badges {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: auto;
	padding-top: 16px;
}

.rwaq-course-card__org {
	max-width: 100%;
	border: 1px solid var(--rwaq-border);
	border-radius: 8px;
	padding: 5px 12px;
	background: #fff;
	color: #424242;
	font-size: 12px;
	font-weight: 600;
	line-height: 18px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ---- AJAX loader ---- */
.rwaq-courses__loader {
	display: flex;
	justify-content: center;
	padding: 1.5rem 0;
}

.rwaq-courses__loader[hidden] {
	display: none;
}

.rwaq-courses__spinner {
	width: 2rem;
	height: 2rem;
	fill: var(--rwaq-primary);
	animation: rwaq-courses-spin 0.9s linear infinite;
}

@keyframes rwaq-courses-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.rwaq-courses__spinner {
		animation-duration: 2.4s;
	}
}

.rwaq-courses__sentinel {
	height: 1px;
}

.rwaq-courses__status {
	text-align: center;
	color: #52525b; /* same status grey as the programs catalog */
	font-size: 0.95rem;
	margin-top: 1rem;
}

.rwaq-courses__status:empty {
	display: none;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
	.rwaq-course-card {
		flex: 0 0 calc((100% - var(--rwaq-courses-gap, 24px)) / 2);
	}
}

/* Tablet: stack the filter sidebar above the results. */
@media (max-width: 900px) {
	.rwaq-courses__layout {
		flex-direction: column;
		gap: 24px;
	}

	.rwaq-courses__sidebar {
		flex: 0 0 auto;
		width: 100%;
	}
}

@media (max-width: 680px) {
	.rwaq-courses__header {
		flex-wrap: wrap;
		gap: 12px;
	}

	.rwaq-courses__title {
		font-size: 26px;
	}

	.rwaq-courses__controls {
		flex-direction: column;
		align-items: stretch;
		gap: 14px;
	}

	.rwaq-courses__sort {
		width: 100%;
	}

	.rwaq-courses .rwaq-courses__sort-trigger {
		width: 100%;
		justify-content: flex-start;
	}

	.rwaq-courses__sort-value {
		min-width: 0;
		flex: 1;
		text-align: start;
	}

	.rwaq-courses__sort-menu {
		width: 100%;
		max-width: none;
	}

	.rwaq-course-card {
		flex: 0 0 100%;
	}
}
