/**
 * Grid/list view switch and the list-view course layout.
 *
 * Shared by every surface that shows a course grid with a view switch: the
 * catalog and category archive, and My Courses. It lived in catalog.css, which
 * only the catalog loads, so My Courses rendered the same grid with no way to
 * switch it (Basecamp 10346630582). The switch is named for itself
 * (.lrn-view-toggle), not for the catalog filter bar it used to sit in.
 *
 * @package Learnomy
 */

/* Grid/list toggle — a single bordered segmented control so BOTH icons read as
   proper square buttons (not one boxed + one bare), visually consistent with the
   neighbouring select boxes (Basecamp #9972665769). */
.lrn-view-toggle {
	display:       inline-flex;
	gap:           0;
	flex-shrink:   0;
	border:        1px solid var(--lrn-border);
	border-radius: var(--lrn-radius-md);
	overflow:      hidden;
	background:    var(--lrn-bg);
}

/* Each half: icon-only square. Inherits .lrn-btn base; drop its own
   border/radius so the segmented wrapper owns the box. Sized to 40px so the
   1px-bordered wrapper renders at 42px — flush with the neighbouring 42px
   search/category/sort controls (Basecamp #9981880849; the toggle read 46px
   because .lrn-btn's min-height: var(--lrn-touch-min) (~44px) overrode the old
   36px). min-height:0 lets the explicit height win; the ::after extender
   (learnomy.css, inset:-4px) keeps the tap target ≥44px for accessibility. */
.lrn-btn.lrn-view-btn {
	width:           40px;
	height:          40px;
	min-width:       40px;
	min-height:      0;
	padding:         0;
	flex-shrink:     0;
	display:         inline-flex;
	align-items:     center;
	justify-content: center;
	border:          0;
	border-radius:   0;
	background:      transparent;
	color:           var(--lrn-text-secondary);
}

/* Divider between the two halves. */
.lrn-btn.lrn-view-btn + .lrn-view-btn {
	border-inline-start: 1px solid var(--lrn-border);
}

.lrn-view-btn svg {
	width:       18px;
	height:      18px;
	flex-shrink: 0;
}

.lrn-view-btn:hover:not(.is-active) {
	background: var(--lrn-bg-hover);
	color:      var(--lrn-text);
}

.lrn-view-btn.is-active {
	background: var(--lrn-accent-bg);
	color:      var(--lrn-accent-text, var(--lrn-accent));
}

/* ==========================================================================
   Course grid — three explicit tiers (mobile / tablet / desktop)

   Moved from catalog.css (Basecamp 10350179892): the "Catalog columns"
   setting is site-wide by name, so My Courses has to resolve the same
   modifier class AND load the stylesheet that can act on it. catalog.css
   only ever loads on the catalog/category routes; this sheet already
   loads on catalog, category AND account-courses (see the file header),
   so the column rules belong here, not there.

   Below 640px: 1 column (mobile @media at bottom).
   640px-1023px: 2 columns (base).
   1024px+: 3 columns, or the Catalog columns setting as a maximum, with a
   minimum card width (see the 1024px block).
   ========================================================================== */

.lrn-courses-grid {
	grid-template-columns: repeat(2, 1fr);
}

/* The equal-height rule for `.lrn-courses-grid > li` lives in learnomy.css,
   beside `.lrn-grid`: every page that prints a course grid needs it, and this
   sheet only loads on the catalog, category and My Courses routes. */

@media (min-width: 1024px) {
	/* Wide desktop: 3 columns by default. The previous code had a separate
	   1440px breakpoint; consolidating here keeps this on the canonical
	   breakpoint and still gives most laptops the 3-column layout
	   (1280-1440px range). */
	.lrn-courses-grid {
		grid-template-columns: repeat(3, 1fr);
	}

	/* Site-wide "Catalog columns" setting (2-5, default 3), read as a MAXIMUM.
	   Mobile (<=640px) stays 1 column and 640-1024px stays 2 (the responsive
	   contract); this only sets the desktop count.

	   A card never drops below --lrn-course-card-min: when the grid's OWN
	   width cannot fit N cards that wide, it shows fewer. Viewport breakpoints
	   could not see that My Courses sits beside the account sidebar, so 5
	   columns there made 146px cards whose progress label ran under the
	   Start button. The same rule keeps the catalog's tracks equal. */
	.lrn-courses-grid--cols-2 { --lrn-grid-cols: 2; }
	.lrn-courses-grid--cols-3 { --lrn-grid-cols: 3; }
	.lrn-courses-grid--cols-4 { --lrn-grid-cols: 4; }
	.lrn-courses-grid--cols-5 { --lrn-grid-cols: 5; }

	.lrn-courses-grid[class*="lrn-courses-grid--cols-"] {
		--lrn-course-card-min: 190px;
		grid-template-columns: repeat(
			auto-fill,
			minmax(
				max(
					var(--lrn-course-card-min),
					calc( ( 100% - ( var(--lrn-grid-cols) - 1 ) * var(--lrn-sp-6) ) / var(--lrn-grid-cols) )
				),
				1fr
			)
		);
	}
}

@media (max-width: 640px) {
	/* Mobile: single column. Filter bar stays as flex-wrap, so the
	   search input takes the full row and category/sort/toggle wrap
	   beneath it. */
	.lrn-courses-grid {
		grid-template-columns: 1fr;
	}
}

/* ==========================================================================
   List view — toggled by the grid/list switch.

   Compound selector .lrn-courses-grid.lrn-list-layout intentionally
   wins specificity over the 1440px @media that forces 3 columns. Each
   course renders as a full-width horizontal row: image left (280px),
   content right (flex 1), price pinned to the bottom of the row.
   Mobile collapses back to vertical stack — 280px thumbnails leave no
   room for content on a phone.
   ========================================================================== */

.lrn-courses-grid.lrn-list-layout {
	grid-template-columns: 1fr;
	gap:                   var(--lrn-sp-2);
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card {
	flex-direction: row;
	align-items:    stretch;
	min-height:     0;
}

/* The cover fills its row, whatever the row's height. It used to keep a fixed
   16:9 box at the top of a link that stretched to the row, and the link's
   background showed as a light strip under the cover on any row taller than
   the image: a two-line title, a description, a progress bar (QA note on
   Basecamp 10437552436). The link is now a flex box, so the cover stretches to
   the row and the image crops into it (object-fit: cover, learnomy.css). Its
   16:9 aspect-ratio stays as the MINIMUM height, so a short row still shows
   the whole cover rather than a letterbox. */
.lrn-courses-grid.lrn-list-layout .lrn-course-card__thumbnail-link {
	flex:       0 0 13.5rem;
	display:    flex;
	align-self: stretch;
	/* Without it the cover's aspect-ratio widens the column on a taller row,
	   and the text column starts at a different x on every row. */
	min-width:  0;
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__thumbnail {
	flex:         1 1 auto;
	width:        100%;
	min-width:    0;
	height:       auto;
	aspect-ratio: 16 / 9;
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__info {
	flex:    1 1 auto;
	padding: var(--lrn-sp-3) var(--lrn-sp-4);
	gap:     var(--lrn-sp-1);
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__title {
	font-size: var(--lrn-text-lg);
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__footer {
	margin-top:  auto;
	padding-top: var(--lrn-sp-1);
}

/* Title and facts on the left, the price or next step on the right, so a row is
   about 120px and 12 of them take less room than a page of cards. */
.lrn-courses-grid.lrn-list-layout .lrn-course-card__info {
	display:               grid;
	grid-template-columns: minmax(0, 1fr) auto;
	column-gap:            var(--lrn-sp-4);
	align-content:         center;
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__info > * {
	grid-column: 1;
}

/* Price, action and the wishlist heart share the right-hand column: the heart
   at its top, price and action at its foot, aligned row to row so prices
   compare down the list. It spans every row the left column can have (title,
   instructor, description, facts, stats). */
.lrn-courses-grid.lrn-list-layout .lrn-course-card__info > .lrn-course-card__footer {
	grid-column:     2;
	grid-row:        1 / span 8;
	align-self:      end;
	flex-direction:  column;
	align-items:     flex-end;
	justify-content: flex-end;
	min-width:       9rem;
	margin:          0;
	padding:         var(--lrn-sp-8) 0 0;
	border:          0;
	gap:             var(--lrn-sp-2);
	text-align:      end;
}

/* The category chips wait for the course page; the short description stays,
   clamped to two lines, because the row has the width for it. */
.lrn-courses-grid.lrn-list-layout .lrn-course-card__badges {
	display: none;
}

.lrn-courses-grid.lrn-list-layout .lrn-course-card__excerpt {
	display:            -webkit-box;
	overflow:           hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

/* Wishlist heart at the top of the right-hand column, with the price and
   action below it. */
.lrn-courses-grid.lrn-list-layout .lrn-wishlist-btn {
	top:   var(--lrn-sp-3);
	inset-inline-end: var(--lrn-sp-4);
}

/* My Courses: the tab strip and the switch share one toolbar row. The
   bottom rule moves from the strip to the row so it spans both; the strip
   aligns to the row's bottom so each tab's 2px active underline still sits on
   that rule. min-width: 0 lets the scrolling strip shrink instead of pushing
   the switch off the end on a phone. */
.lrn-courses-toolbar {
	display:          flex;
	align-items:      flex-end;
	gap:              var(--lrn-sp-3);
	border-bottom:    1px solid var(--lrn-border);
	margin-block-end: var(--lrn-sp-6);
}

.lrn-courses-toolbar > .lrn-tab-nav {
	flex:          1 1 auto;
	min-width:     0;
	border-bottom: 0;
	margin-bottom: 0;
}

.lrn-courses-toolbar > .lrn-view-toggle {
	flex:             0 0 auto;
	align-self:       center;
}

@media (max-width: 640px) {

	/* List view and grid are the same compact card below 640px, so the switch
	   has nothing to switch and is hidden. */
	.lrn-view-toggle {
		display: none;
	}

	/* The phone's card list breathes a little more than the row list. (A
	   container cannot style itself, so this one stays on the viewport.) */
	.lrn-courses-grid.lrn-list-layout {
		gap: var(--lrn-sp-3);
	}
}

/* The list row needs about 36rem: a 13.5rem cover, the title and facts, and the
   price column. Narrower than that, it is the grid card (cover on top at its
   own 16:9, text below). This follows the GRID's width, not the viewport, so a
   Course catalog block in a page's content column, or beside the catalog
   sidebar, gets the card too instead of a row whose text column is squeezed to
   a few words a line and whose cover is cropped to a tall sliver (the light
   strip QA saw under those covers was the same squeeze; Basecamp 10437552436).
   A phone (<= 640px viewport) always lands here. */
.lrn-courses-grid.lrn-list-layout {
	container: lrn-course-list / inline-size;
}

@container lrn-course-list (max-width: 36rem) {

	/* List view on a phone is the grid card: cover on top at its own 16:9, text
	   below. A 7.5rem side cover left most of its column empty and put the Edit
	   pill and the heart over a 72px image (Basecamp 10472638760, QA round 5). */
	.lrn-courses-grid.lrn-list-layout .lrn-course-card {
		flex-direction: column;
		align-items:    stretch;
		min-height:     0;
	}

	.lrn-courses-grid.lrn-list-layout .lrn-course-card__thumbnail-link {
		flex:       0 0 auto;
		display:    block;
		width:      100%;
		align-self: auto;
	}

	.lrn-courses-grid.lrn-list-layout .lrn-course-card__thumbnail {
		aspect-ratio: 16 / 9;
		height:       auto;
	}

	/* The wide list's two columns have no room here. */
	.lrn-courses-grid.lrn-list-layout .lrn-course-card__info {
		display:        flex;
		flex-direction: column;
		min-width:      0;
		padding:        var(--lrn-sp-4);
		gap:            var(--lrn-sp-2);
		align-content:  normal;
	}

	.lrn-courses-grid.lrn-list-layout .lrn-course-card__title {
		font-size: var(--lrn-text-lg);
	}

	.lrn-courses-grid.lrn-list-layout .lrn-course-card__info > .lrn-course-card__footer {
		grid-column:     auto;
		grid-row:        auto;
		align-self:      stretch;
		flex-direction:  row;
		align-items:     center;
		justify-content: space-between;
		min-width:       0;
		margin-top:      auto;
		padding-top:     var(--lrn-sp-2);
		flex-wrap:       wrap;
		text-align:      start;
	}

	/* The phone card is the grid card (cover on top, approved 1 Nov): no
	   description there either. */
	.lrn-courses-grid.lrn-list-layout .lrn-course-card__excerpt {
		display: none;
	}

	/* The heart sits over the cover, as on the grid card, so it never covers the title. */
	.lrn-courses-grid.lrn-list-layout .lrn-wishlist-btn {
		top:              var(--lrn-sp-2);
		inset-inline-end: var(--lrn-sp-2);
	}
}
