/*
 * Reign LearnDash Addon: course and group grids and cards (archive, [modern_courses],
 * [modern_groups], the Courses grid block, related courses).
 * Every colour comes from Reign tokens, so light, dark, palettes and RTL follow the theme.
 * Breakpoints: 1025px desktop, 768px tablet, 640px phone (Reign).
 */

.rld-grid {
	--rld-radius: var(--reign-global-border-radius, 8px); /* follows Customizer > Global Border Radius */
	--rld-gap: 1.5rem;
	--rld-star: color-mix(in oklab, orange 80%, yellow);
	--rld-muted: var(--reign-site-alternate-text-color, var(--reign-site-body-text-color));
	display: grid;
	gap: var(--rld-gap);
	margin-block-end: 2rem;
}

/* ## Filter bar */

.rld-filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0.75rem 1rem;
	margin: 0;
	padding: 1rem;
	background: var(--reign-site-sections-bg-color);
	border: 1px solid var(--reign-site-border-color);
	border-radius: var(--rld-radius);
}

.rld-filters__field {
	display: flex;
	flex: 1 1 10rem;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.rld-filters__field--search {
	flex-basis: 14rem;
}

.rld-filters__field label {
	margin: 0;
	color: var(--rld-muted);
	font-size: 0.8125rem;
	font-weight: 600;
}

.rld-filters__field :is(input, select) {
	width: 100%;
	min-height: 44px;
	margin: 0;
}

.rld-filters__actions {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.rld-filters__actions .button {
	min-height: 44px;
	margin: 0;
}

.rld-grid__view {
	display: inline-flex;
	margin-inline-start: auto;
	border: 1px solid var(--reign-site-border-color);
	border-radius: var(--rld-radius);
	overflow: hidden;
}

.rld-grid__view-link {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding-inline: 1rem;
	color: var(--reign-site-body-text-color);
	font-size: 0.875rem;
	font-weight: 600;
	text-decoration: none;
}

.rld-grid__view-link + .rld-grid__view-link {
	border-inline-start: 1px solid var(--reign-site-border-color);
}

.rld-grid__view-link[aria-current="true"] {
	color: var(--reign-site-button-text-color);
	background: var(--reign-site-button-bg-color);
}

.rld-grid__view-link:focus-visible {
	outline: 2px solid var(--reign-colors-theme, var(--reign-site-button-bg-color));
	outline-offset: -2px;
}

/* ## Results */

.rld-grid__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
}

.rld-grid__main {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	min-width: 0;
}

.rld-grid__count {
	margin: 0;
	color: var(--rld-muted);
	font-size: 0.875rem;
}

.rld-grid__items {
	display: grid;
	grid-template-columns: repeat(var(--rld-columns, 3), minmax(0, 1fr));
	gap: var(--rld-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.rld-grid__items > li {
	display: flex;
	margin: 0;
	min-width: 0;
}

.rld-grid__empty {
	padding: 2.5rem 1.5rem;
	border: 1px dashed var(--reign-site-border-color);
	border-radius: var(--rld-radius);
	text-align: center;
}

.rld-grid__empty p {
	margin: 0 0 0.5rem;
	color: var(--reign-site-headings-color);
	font-weight: 600;
}

.rld-grid__pages .nav-links,
.rld-grid__pages {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.5rem;
}

.rld-grid__pages .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	padding-inline: 0.75rem;
	color: var(--reign-site-body-text-color);
	border: 1px solid var(--reign-site-border-color);
	border-radius: var(--rld-radius);
	text-decoration: none;
}

.rld-grid__pages .page-numbers.current {
	color: var(--reign-site-button-text-color);
	background: var(--reign-site-button-bg-color);
	border-color: var(--reign-colors-theme, var(--reign-site-button-bg-color));
}

.rld-grid__pages a.page-numbers:hover,
.rld-grid__pages a.page-numbers:focus-visible {
	border-color: var(--reign-colors-theme, var(--reign-site-button-bg-color));
}

/* ## Card */

.rld-card {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
	overflow: hidden;
	background: var(--reign-site-sections-bg-color);
	border: 1px solid var(--reign-site-border-color);
	border-radius: var(--rld-radius);
	transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.rld-card:hover,
.rld-card:focus-within {
	box-shadow: 0 6px 20px color-mix(in srgb, var(--reign-site-headings-color) 12%, transparent);
}

.rld-card__media {
	position: relative;
	display: block;
	aspect-ratio: 16 / 9;
	max-width: 100%;
	overflow: hidden;
	background: color-mix(in srgb, var(--reign-site-border-color) 60%, transparent);
}

.rld-card__media img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}


.rld-card__badge {
	position: absolute;
	inset-block-start: 0.75rem;
	inset-inline-start: 0.75rem;
	padding: 0.25rem 0.625rem;
	color: var(--reign-site-headings-color);
	background: var(--reign-site-sections-bg-color);
	border-radius: 999px;
	box-shadow: 0 1px 4px color-mix(in srgb, var(--reign-site-headings-color) 20%, transparent);
	font-size: 0.8125rem;
	font-weight: 700;
	line-height: 1.4;
}

.rld-card--enrolled .rld-card__badge,
.rld-card--completed .rld-card__badge {
	color: var(--reign-site-button-text-color);
	background: var(--reign-site-button-bg-color);
}

.rld-card__body {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 0.5rem;
	padding: 1rem 1.125rem 1.125rem;
}

.rld-card__category {
	margin: 0;
	color: var(--rld-muted);
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

.rld-card__title {
	margin: 0;
	font-size: 1.0625rem;
	line-height: 1.35;
}

.rld-grid[data-view="grid"] .rld-card__title {
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}

.rld-card__title a {
	color: var(--reign-site-headings-color);
	text-decoration: none;
}

.rld-card__title a:hover,
.rld-card__title a:focus-visible {
	color: var(--reign-site-link-hover-color, var(--reign-colors-theme, var(--reign-site-button-bg-color)));
}

.rld-card__excerpt {
	display: -webkit-box;
	margin: 0;
	overflow: hidden;
	color: var(--reign-site-body-text-color);
	font-size: 0.875rem;
	line-height: 1.55;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.rld-card__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25rem 1rem;
	margin: 0;
	color: var(--rld-muted);
	font-size: 0.8125rem;
}

.rld-card__rating {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
}

/* Five stars drawn by text, filled to the average with a gradient: no image, no icon font. */
.rld-card__stars::before {
	content: "\2605\2605\2605\2605\2605";
	background: linear-gradient(to right, var(--rld-star) calc(var(--rld-rating, 0) / 5 * 100%), var(--reign-site-border-color) 0);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	letter-spacing: 0.05em;
}

[dir="rtl"] .rld-card__stars::before {
	background: linear-gradient(to left, var(--rld-star) calc(var(--rld-rating, 0) / 5 * 100%), var(--reign-site-border-color) 0);
	-webkit-background-clip: text;
	background-clip: text;
}

.rld-card__instructor {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 0;
	color: var(--reign-site-body-text-color);
	font-size: 0.8125rem;
}

.rld-card__instructor img {
	flex: none;
	width: 28px;
	height: 28px;
	margin: 0;
	border-radius: 50%;
	object-fit: cover;
}

.rld-card__foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 0.75rem;
	margin-block-start: auto;
	padding-block-start: 0.75rem;
	border-block-start: 1px solid var(--reign-site-border-color);
}

/* Nothing to show (button off, no price or progress): no empty strip. */
.rld-card__foot:not(:has(*)) {
	display: none;
}

.rld-card__price {
	color: var(--reign-site-headings-color);
	font-size: 1.0625rem;
	font-weight: 700;
}

.rld-card__progress {
	position: relative;
	flex: 1 1 4rem;
	height: 6px;
	overflow: hidden;
	background: color-mix(in srgb, var(--reign-colors-theme, var(--reign-site-button-bg-color)) 18%, transparent);
	border-radius: 999px;
}

.rld-card__progress > span {
	position: absolute;
	inset-block: 0;
	inset-inline-start: 0;
	background: var(--reign-colors-theme, var(--reign-site-button-bg-color));
}

.rld-card__percent {
	color: var(--reign-site-headings-color);
	font-size: 0.8125rem;
	font-weight: 600;
}

.rld-card__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 40px;
	margin-inline-start: auto;
	padding: 0.5rem 1rem;
	color: var(--reign-site-button-text-color);
	background: var(--reign-site-button-bg-color);
	border-radius: var(--reign-global-button-radius, 6px); /* Customizer > Site Layout > Button Radius Value. */
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	white-space: nowrap;
}

.rld-card__button:hover,
.rld-card__button:focus-visible {
	color: var(--reign-site-button-text-hover-color);
	background: var(--reign-site-button-bg-hover-color);
}

/* With progress the bar takes the row and the button its own line end. */
.rld-card__progress ~ .rld-card__button {
	flex-basis: 100%;
}

/* ## Soft cards: rounder, no outline, tinted footer. */

.rld-grid--soft {
	--rld-radius: 16px;
}

.rld-grid--soft .rld-card {
	border-color: transparent;
	box-shadow: 0 2px 10px color-mix(in srgb, var(--reign-site-headings-color) 8%, transparent);
}

.rld-grid--soft .rld-card__foot {
	margin-inline: -1.125rem;
	margin-block-end: -1.125rem;
	padding: 0.875rem 1.125rem;
	background: color-mix(in srgb, var(--reign-colors-theme, var(--reign-site-button-bg-color)) 6%, var(--reign-site-sections-bg-color));
	border: 0;
}

/* ## List view: image beside the text. Catalog starts here. */

.rld-grid[data-view="list"] .rld-grid__items {
	grid-template-columns: minmax(0, 1fr);
}

.rld-grid[data-view="list"] .rld-card {
	flex-direction: row;
}

.rld-grid[data-view="list"] .rld-card__media {
	flex: none;
	width: min(18rem, 38%);
	aspect-ratio: auto;
	min-height: 11rem;
}

.rld-grid[data-view="list"] .rld-card__excerpt {
	-webkit-line-clamp: 3;
}

/* ## Catalog: filters in a side column. */

@media (min-width: 1025px) {
	.rld-grid--catalog.rld-grid--has-filters {
		grid-template-columns: 16rem minmax(0, 1fr);
		align-items: start;
	}

	.rld-grid--catalog .rld-filters {
		position: sticky;
		top: var(--reign-sticky-top, 1.5rem);
		flex-direction: column;
		align-items: stretch;
	}

	.rld-grid--catalog .rld-filters__field {
		flex: none;
	}

	.rld-grid--catalog .rld-filters__actions .button {
		flex: 1;
	}
}

/* ## Tablet and phone */

@media (max-width: 1024.98px) {
	.rld-grid__items {
		grid-template-columns: repeat(min(var(--rld-columns, 3), 2), minmax(0, 1fr));
	}
}

@media (max-width: 640px) {
	.rld-grid {
		--rld-gap: 1rem;
	}

	.rld-grid__items,
	.rld-grid[data-view="list"] .rld-grid__items {
		grid-template-columns: minmax(0, 1fr);
	}

	.rld-grid[data-view="list"] .rld-card {
		flex-direction: column;
	}

	.rld-grid[data-view="list"] .rld-card__media {
		width: 100%;
		min-height: 0;
		aspect-ratio: 16 / 9;
	}

	.rld-filters__field {
		flex-basis: 100%;
	}

	.rld-filters__actions {
		flex: 1;
	}

	.rld-filters__actions .button {
		flex: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.rld-card {
		transition: none;
	}
}

/* ## Instructor banner (an instructor's courses) */

.rld-instructor {
	display: flex;
	align-items: center;
	gap: 1.25rem;
	margin-block-end: 2rem;
	padding: 1.25rem;
	border: 1px solid var(--reign-site-border-color);
	border-radius: 8px;
	background: var(--reign-site-sections-bg-color, var(--reign-site-body-bg-color));
}

/* The avatar keeps its 96px box however long the bio is (a flex item shrinks by default and squeezed it). */
.rld-instructor__avatar {
	flex-shrink: 0;
}

.rld-instructor__avatar img {
	display: block;
	width: 96px;
	height: 96px;
	border-radius: 50%;
	object-fit: cover;
}

.rld-instructor__bio {
	min-width: 0;
	color: var(--reign-site-body-text-color);
}

.rld-instructor__bio > :last-child {
	margin-block-end: 0;
}

@media (max-width: 640px) {
	.rld-instructor {
		flex-direction: column;
		align-items: flex-start;
	}
}

/* ## Profile Courses tab: Teaching and Learning sections (Reign_LD_Community::profile_content). */
.rld-profile-courses {
	display: grid;
	gap: 1.25rem;
	min-width: 0;
}

/* All / In progress / Completed: the same pills as every Reign LMS add-on. */
.rld-filter {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.rld-filter a {
	padding: 0.375rem 0.875rem;
	border: 1px solid var(--reign-site-border-color);
	border-radius: 999px;
	color: var(--reign-site-body-text-color);
	font-size: 0.875rem;
	line-height: 1.4;
	text-decoration: none;
}

.rld-filter a:is(:hover, :focus-visible) {
	border-color: var(--reign-colors-theme);
	color: var(--reign-colors-theme);
}

.rld-filter a[aria-current="page"] {
	border-color: var(--reign-colors-theme);
	background: var(--reign-colors-theme);
	color: var(--reign-site-button-text-color);
}

@media (max-width: 640px) {
	.rld-filter a {
		display: inline-flex;
		align-items: center;
		min-height: 2.5rem;
	}
}

/* The underline marks it as a link where the link colour matches the text (dark mode); the id beats
   BuddyPress's `body #buddypress * a { text-decoration: none }`. */
#buddypress .rld-profile-courses__browse:is(:link, :visited),
.rld-profile-courses__browse:is(:link, :visited) {
	color: var(--reign-site-link-color);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.rld-profile-courses__browse:is(:hover, :focus-visible) {
	color: var(--reign-site-link-hover-color);
}
