/*
 * EVPL Resource Cards.
 * Uses the theme's --evpl-* colour variables when present, with fallbacks.
 * The grid responds to the width of the column it sits in (container query):
 *   - wide column  -> several cards per row, logo panel on top
 *   - medium       -> one card per row, logo panel on the left
 *   - narrow/phone -> stacked
 * Inside a row, logo / title / description / button line up across cards (subgrid).
 */

.evpl-rc {
	--rc-ink: var(--evpl-g700, #404040);
	--rc-line: #e6e2d9;
	--rc-tint: #f6f4ef;
	--rc-red: var(--evpl-teal, #276171);
	--rc-red-hover: #1c4a58;
	--rc-radius: 10px;
	--rc-gap: 24px;

	container-name: evpl-rc;
	container-type: inline-size;
	margin: 0 0 2rem;
	color: var(--rc-ink);
}

.evpl-rc *,
.evpl-rc *::before,
.evpl-rc *::after {
	box-sizing: border-box;
}

.evpl-rc__heading {
	margin: 0 0 0.35em;
}

.evpl-rc__intro {
	margin: 0 0 1.75rem;
}

.evpl-rc__intro > :last-child {
	margin-bottom: 0;
}

.evpl-rc__empty {
	padding: 1em;
	border: 2px dashed #b9b4a8;
	color: #5f6b73;
}

/* ---------- Grid ---------- */
.evpl-rc__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--rc-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* ---------- Card (default: logo panel on the left, text on the right) ---------- */
.evpl-rc__card {
	position: relative; /* anchors the stretched link */
	display: grid;
	grid-template-columns: 150px minmax(0, 1fr);
	gap: 4px 24px;
	align-items: start;
	margin: 0;
	padding: 22px;
	border: 1px solid var(--rc-line);
	border-radius: var(--rc-radius);
	background: #fff;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
	transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.evpl-rc__card:hover {
	transform: translateY(-3px);
	border-color: #d4cfc3;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), 0 14px 28px rgba(0, 0, 0, 0.12);
}

/* Show the ring only for keyboard focus, not after a mouse click */
.evpl-rc__card:has(.evpl-rc__btn:focus-visible) {
	outline: 3px solid var(--rc-red);
	outline-offset: 2px;
}

.evpl-rc__btn:focus:not(:focus-visible) {
	outline: none;
	box-shadow: none;
}

/* ---------- Logo panel ---------- */
.evpl-rc__media {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	justify-content: center;
	min-height: 170px;
	padding: 14px;
	border-radius: 8px;
	background: var(--rc-tint);
}

.evpl-rc .evpl-rc__img {
	display: block;
	width: auto;
	max-width: 100%;
	height: auto;
	max-height: 130px;
	object-fit: contain;
}

/* Cards without a logo get a quiet monogram so the row still looks finished */
.evpl-rc__media--placeholder span {
	color: #cfc9ba;
	font-size: 2.6rem;
	font-weight: 700;
	line-height: 1;
}

/* ---------- Text ---------- */
.evpl-rc__body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.evpl-rc .evpl-rc__title {
	margin: 0 0 0.45em !important;
	font-size: 19px !important;
	line-height: 1.25 !important;
}

.evpl-rc .evpl-rc__desc {
	margin: 0 0 1.1rem;
	font-size: 15.5px !important;
	line-height: 1.5 !important;
}

.evpl-rc .evpl-rc__desc p,
.evpl-rc .evpl-rc__desc li {
	margin: 0 0 0.6em !important;
	font-size: inherit !important;
	line-height: 1.5 !important;
}

.evpl-rc .evpl-rc__desc > :last-child {
	margin-bottom: 0 !important;
}

/* ---------- Button + stretched link ---------- */
.evpl-rc__btn {
	align-self: flex-start;
	margin-top: auto;
	padding: 0.65em 1.7em;
	border-radius: 999px;
	background: var(--rc-red);
	color: #fff !important; /* some themes restyle links inside content */
	font-size: 14px;
	font-weight: 700;
	letter-spacing: 0.06em;
	line-height: 1.3;
	text-decoration: none !important;
	text-transform: uppercase;
	transition: background-color 0.15s ease;
}

.evpl-rc__btn::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: var(--rc-radius);
}

.evpl-rc__btn:hover,
.evpl-rc__btn:focus {
	background: var(--rc-red-hover);
	color: #fff !important;
}

.evpl-rc__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Wide columns: cards sit side by side, logo panel on top ----------
 * "Auto" fills the available width with as many columns as fit (each at least 300px).
 * 2 and 3 are fixed counts. "One column" keeps the horizontal card above. */
@container evpl-rc (min-width: 680px) {
	.evpl-rc--cols-auto .evpl-rc__grid {
		grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
	}

	.evpl-rc--cols-2 .evpl-rc__grid,
	.evpl-rc--cols-3 .evpl-rc__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	/* Simple version first (works everywhere): stacked card, button pinned to the bottom */
	.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__card {
		display: flex;
		flex-direction: column;
		align-items: stretch;
		gap: 0;
	}

	.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__media {
		margin-bottom: 16px;
	}

	.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__body {
		flex: 1 1 auto;
	}

	/* Better version: every card in a row shares row heights (CSS subgrid), so logo,
	 * title, description and button line up even when text lengths differ. */
	@supports (grid-template-rows: subgrid) {
		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__grid {
			row-gap: 0;
			margin-bottom: calc(var(--rc-gap) * -1); /* cancels the last row's bottom margin */
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__card {
			display: grid;
			grid-row: span 4;
			grid-template-rows: subgrid;
			grid-template-columns: minmax(0, 1fr);
			gap: 0;
			margin-bottom: var(--rc-gap);
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__body {
			display: contents;
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__media {
			grid-row: 1;
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__title {
			grid-row: 2;
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__desc {
			grid-row: 3;
		}

		.evpl-rc:not(.evpl-rc--cols-1):not(.evpl-rc--cols-compact) .evpl-rc__btn {
			grid-row: 4;
			align-self: end;
			justify-self: start;
		}
	}
}

@container evpl-rc (min-width: 1000px) {
	.evpl-rc--cols-3 .evpl-rc__grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

/* ---------- Narrow columns / phones: stack everything ---------- */
@container evpl-rc (max-width: 480px) {
	.evpl-rc__card {
		display: flex;
		flex-direction: column;
		align-items: stretch;
		gap: 0;
		padding: 18px;
	}

	.evpl-rc__media {
		min-height: 150px;
		margin-bottom: 14px;
	}

	.evpl-rc__body {
		flex: 1 1 auto;
	}
}

@media (prefers-reduced-motion: reduce) {
	.evpl-rc__card,
	.evpl-rc__btn {
		transition: none;
	}

	.evpl-rc__card:hover {
		transform: none;
	}
}

/* ---------- Closing links under the cards (Text tab) ---------- */
.evpl-rc-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin: 1.5rem 0 2rem;
}

.evpl-rc-actions a.evpl-rc-link {
	display: inline-block !important;
	padding: 0.65em 1.7em !important;
	border: 2px solid #276171 !important;
	border-radius: 999px !important;
	background: #276171 !important;
	color: #fff !important;
	font-size: 14px !important;
	font-weight: 700 !important;
	letter-spacing: 0.06em !important;
	line-height: 1.3 !important;
	text-decoration: none !important;
	text-transform: uppercase !important;
}

.evpl-rc-actions a.evpl-rc-link:hover,
.evpl-rc-actions a.evpl-rc-link:focus {
	border-color: #1c4a58 !important;
	background: #1c4a58 !important;
}

/* ---------- Back-to-top arrow ---------- */
.evpl-rc-top {
	position: fixed;
	right: 38px; /* centred above the chat button */
	bottom: 128px; /* sits above the chat button, not on it */
	z-index: 999;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: #276171;
	color: #fff !important;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
	text-decoration: none !important;
	transition: background-color 0.15s ease, transform 0.15s ease;
}

.evpl-rc-top[hidden] {
	display: none;
}

.evpl-rc-top:hover,
.evpl-rc-top:focus-visible {
	background: #1c4a58;
	transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
	.evpl-rc-top { transition: none; }
	.evpl-rc-top:hover, .evpl-rc-top:focus-visible { transform: none; }
}

/* ---------- Works on the page's existing closing links, no Text-tab edit needed ---------- */
.evpl-rc ~ p:has(> a[href="#college-amp-careers"]) {
	display: none; /* replaced by the round back-to-top arrow */
}

.evpl-rc ~ p:has(> a[href*="research-home"]) {
	margin: 1.5rem 0 2rem;
}

.evpl-rc ~ p > a[href*="research-home"] {
	display: inline-block !important;
	padding: 0.65em 1.7em !important;
	border: 2px solid #276171 !important;
	border-radius: 999px !important;
	background: #276171 !important;
	color: #fff !important;
	font-size: 14px !important;
	font-weight: 700 !important;
	letter-spacing: 0.06em !important;
	line-height: 1.3 !important;
	text-decoration: none !important;
	text-transform: uppercase !important;
}

.evpl-rc ~ p > a[href*="research-home"]:hover,
.evpl-rc ~ p > a[href*="research-home"]:focus {
	border-color: #1c4a58 !important;
	background: #1c4a58 !important;
}

.evpl-rc ~ p > a[href*="book-a-librarian"] {
	color: #276171 !important;
}

@media (max-width: 600px) {
	.evpl-rc-top {
		right: 22px;
		bottom: 100px;
		width: 44px;
		height: 44px;
	}
}

/* ---------- Compact layout: dense grid of square logo tiles ----------
 * Each tile = logo, title, one full-width START bar. The whole tile is the link. */
.evpl-rc--cols-compact {
	--rc-gap: 18px;
}

.evpl-rc--cols-compact .evpl-rc__grid {
	grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
	gap: var(--rc-gap);
	align-items: stretch;
}

.evpl-rc--cols-compact .evpl-rc__card {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0;
	padding: 0;
	overflow: hidden;
}

.evpl-rc--cols-compact .evpl-rc__media {
	aspect-ratio: 1 / 1;
	min-height: 0;
	margin: 0;
	padding: 12px;
	border-radius: 0;
}

.evpl-rc--cols-compact .evpl-rc__img {
	width: 100%;
	max-width: none;
	height: 100%;
	max-height: none;
	object-fit: contain; /* every logo is scaled to the same square, whatever its original size */
}

.evpl-rc--cols-compact .evpl-rc__media--placeholder span {
	font-size: 3.2rem;
}

.evpl-rc--cols-compact .evpl-rc__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
}

.evpl-rc--cols-compact .evpl-rc__title {
	flex: 0 0 auto;
	margin: 0 !important;
	padding: 14px 14px 6px;
	color: var(--rc-red);
	font-size: 17px !important;
	font-weight: 700 !important;
	line-height: 1.25 !important;
}

.evpl-rc--cols-compact .evpl-rc .evpl-rc__desc,
.evpl-rc--cols-compact .evpl-rc__desc {
	flex: 1 1 auto;
	margin: 0 !important;
	padding: 0 14px;
	border-bottom: 14px solid #fff;
	font-size: 14px !important;
	line-height: 1.45 !important;
}

/* The teaser is clamped on its own box (no padding on it), so a long one can never spill out. */
.evpl-rc--cols-compact .evpl-rc__teaser {
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 4;
	line-clamp: 4;
}

/* Optional second line kept in full, e.g. "Also available in Spanish" */
.evpl-rc--cols-compact .evpl-rc__extra {
	margin-top: 6px;
	font-size: 13px !important;
	line-height: 1.4 !important;
}

.evpl-rc--cols-compact .evpl-rc__extra p {
	margin: 0 !important;
	font-size: inherit !important;
	line-height: inherit !important;
}

.evpl-rc--cols-compact .evpl-rc__extra a {
	color: var(--rc-red);
	font-weight: 600;
	text-decoration: underline;
}

.evpl-rc--cols-compact .evpl-rc__btn {
	/* same pill button as every other layout; only the spacing inside the tile differs */
	display: inline-block;
	align-self: start;
	margin: 4px 14px 16px;
}

/* Rows share heights (subgrid) so tiles, titles and START bars line up across a row */
@supports (grid-template-rows: subgrid) {
	.evpl-rc--cols-compact .evpl-rc__grid {
		row-gap: 0;
		margin-bottom: calc(var(--rc-gap) * -1);
	}

	.evpl-rc--cols-compact .evpl-rc__card {
		display: grid;
		grid-row: span 4;
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: subgrid;
		margin-bottom: var(--rc-gap);
	}

	.evpl-rc--cols-compact .evpl-rc__body {
		display: contents;
	}

	.evpl-rc--cols-compact .evpl-rc__media {
		grid-row: 1;
	}

	.evpl-rc--cols-compact .evpl-rc__title {
		grid-row: 2;
	}

	.evpl-rc--cols-compact .evpl-rc__desc {
		grid-row: 3;
	}

	.evpl-rc--cols-compact .evpl-rc__btn {
		grid-row: 4;
		align-self: end;
		justify-self: start;
	}
}