/*
 * Card Slider
 *
 * Shared Slick Slider styling for the Card Row blocks (Profile, Selected Courses,
 * Selected Pages, Selected Posts) and the Super Block. See assets/js/card-slider.js.
 *
 * Selectors are deliberately specific (and use !important where needed) as .card-row-grid
 * is also styled globally as a CSS grid for the archives, search, etc.
 */

/*
 * Once Slick initialises, its track is as wide as every slide combined. Inside a flex or
 * grid parent (e.g. a vertical Group block, which shrink-wraps its children), that width
 * can stretch the whole slider, which then measures itself as wider and shows too many
 * slides. Keep the slider within its parent's width instead.
 */
.card-slider-wrap {
	min-width: 0;
	max-width: 100%;
}

/* Header: title on the left, arrows on the right */
.card-slider-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1.25rem;
	margin-bottom: 1.25rem;
}

.card-slider-header .card-slider-title {
	margin: 0;
}

.card-slider-header--controls-only {
	justify-content: flex-end;
}

.card-slider-wrap:not(.card-slider-has-nav) .card-slider-header--controls-only {
	display: none;
}

.card-slider-controls {
	display: flex;
	align-items: center;
	gap: 1.25rem;
	margin-right: 1rem;
}

.card-slider-wrap:not(.card-slider-has-nav) .card-slider-controls {
	display: none;
}

/* Reset the theme's global button styling (e.g. OPEN's filled orange buttons) */
.card-slider-controls .slick-arrow,
.card-slider-container .slick-dots li button {
	background: transparent !important;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	padding: 0 !important;
	min-width: 0 !important;
	min-height: 0 !important;
}

.card-slider-controls .slick-arrow {
	position: unset !important;
	/* Slick's theme centres its overlaid arrows with translate(0, -50%), which would lift these up out of line */
	transform: none !important;
	width: 22px !important;
	height: 22px !important;
}

.card-slider-controls .slick-arrow :is(.slick-prev-icon, .slick-next-icon) {
	color: var(--contrast, #000);
}

.card-slider-container {
	position: relative;
}

.card-slider-container .slick-dots li {
	display: inline-block;
	width: auto;
	margin: 0 5px;
	padding: 0;
}

.card-slider-container .slick-dots li button {
	width: 24px !important;
	height: 24px !important;
}

.card-slider-controls .slick-arrow :is(.slick-prev-icon, .slick-next-icon)::before {
	content: "" !important;
}

.card-slider-controls .slick-arrow:focus :is(.slick-prev-icon, .slick-next-icon) {
	font-size: 24px !important;
	margin: 0 !important;
}

/*
 * Before Slick initialises (and in the block editor preview): a plain 1/2/3 column grid
 * showing only the first row of cards. The stack layout (below) uses this grid too.
 */
.card-slider-wrap .card-slider-container .card-slider:not(.slick-initialized) {
	display: grid !important;
	grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
	gap: 1.25rem;
}

.card-slider-wrap:not(.card-slider-wrap--stack) .card-slider-container .card-slider:not(.slick-initialized) > :nth-child(n + 4) {
	display: none;
}

@media screen and (max-width: 1023px) {
	.card-slider-wrap:not(.card-slider-wrap--stack) .card-slider-container .card-slider:not(.slick-initialized) > :nth-child(3) {
		display: none;
	}
}

@media screen and (max-width: 599px) {
	.card-slider-wrap:not(.card-slider-wrap--stack) .card-slider-container .card-slider:not(.slick-initialized) > :nth-child(2) {
		display: none;
	}
}

@media screen and (min-width: 600px) {
	.card-slider-wrap:not(.card-slider-wrap--stack) .card-slider-container .card-slider:not(.slick-initialized) {
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
	}
}

@media screen and (min-width: 1024px) {
	.card-slider-wrap:not(.card-slider-wrap--stack) .card-slider-container .card-slider:not(.slick-initialized) {
		grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
	}
}

/*
 * Stack layout: every card in a 1/2/3 column grid, with no Slick (so no arrows, dots or
 * peeking cards). The columns follow the slider's slidesToShow (assets/js/card-slider.js),
 * which goes off the container's width rather than the window's, so a stack in a narrow
 * column (e.g. the single-course layout) gets fewer columns, just like a slider would.
 */
.card-slider-wrap--stack .card-slider-container {
	container-type: inline-size;
}

/* :not(.slick-initialized) only so these outrank the base grid rule above */
@container (min-width: 600px) {
	.card-slider-wrap--stack .card-slider-container .card-slider:not(.slick-initialized) {
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
	}
}

@container (min-width: 1024px) {
	.card-slider-wrap--stack .card-slider-container .card-slider:not(.slick-initialized) {
		grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
	}
}

/* Once Slick has initialised */
.card-slider-wrap .card-slider-container .card-slider.slick-initialized {
	display: block !important;
	margin-left: 0;
	margin-right: 0;
}

.card-slider-wrap .card-slider.slick-slider:not(.slick-dotted) {
	margin-bottom: 0;
}

.card-slider-wrap .card-slider .slick-list {
	margin: 0 -0.625rem;
	overflow: visible;
}

.card-slider-wrap .card-slider .slick-track {
	display: flex;
	margin-left: unset !important;
	margin-right: unset !important;
}

.card-slider-wrap .card-slider .slick-slide {
	margin: 0 0.625rem;
	display: flex;
	height: auto;
}

.card-slider-wrap .card-slider .slick-slide > div,
.card-slider-wrap .card-slider .slick-slide > div > * {
	width: 100%;
	height: 100%;
}

/*
 * Clip the slick "peek" overflow at the window's edges. This is on the body rather than
 * .site, as .site stops at 1920px wide (.grid-container), which would cut the peek off
 * short of the window's edges on larger screens. `clip` rather than `hidden`, as it
 * doesn't stop position: sticky working for descendants (e.g. the single-course sidebar).
 *
 * It's on html too, as otherwise the body's overflow is handed up to the browser window,
 * which mobile browsers don't clip (they zoom out to fit the overflow instead). With html's
 * overflow set, the body keeps its own and clips like any other element.
 * Mirrors the Testimonies block.
 */
html,
body {
	overflow-x: clip;
}

/*
 * Single-course sliders mostly sit inside coloured boxes (e.g. Upcoming Courses, Related
 * Testimonials), where the peek would spill past the box's edges, so clip at every width.
 */
body.single-course .card-slider-wrap .card-slider .slick-list {
	overflow: hidden;
}
