/*
 * ReCODE+ Resource Library
 * Styled after the Apollo Health portal style guide (Figma: "Style Guide").
 * Picks up the recode-plus theme's tokens when present; falls back to the same
 * values so the shortcode still looks right in another theme.
 */

.rl {
	--rl-bg: var(--portal-bg, #d0e1e7);
	--rl-surface: var(--surface, #ffffff);
	--rl-surface-2: var(--surface-2, #f1f1f1);
	--rl-heading: var(--heading, #13374b);
	--rl-text: var(--text, #373232);
	--rl-muted: var(--muted, #4a4a4a);
	--rl-action: var(--action, #0b7ba5);
	--rl-on-action: var(--on-action, #ffffff);
	--rl-primary: var(--primary, #13374b);
	--rl-on-primary: var(--on-primary, #ffffff);
	--rl-line: var(--line, #e0e0e0);
	--rl-field-line: var(--field-line, #bdbdbd);
	--rl-track: var(--track, #e0e0e0);
	--rl-focus: var(--focus, #f5aa00);
	--rl-mark: var(--mark, #fff1c7);
	--rl-shadow: var(--card-shadow, 0 2px 8px rgba(19, 55, 75, 0.12));
	--rl-font: var(--font-sans, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
	--rl-radius: 10px;

	/* Bredesen Seven (portal style guide) */
	--b7-other: #13374b;        --b7-other-tint: #b9dbe7;
	--b7-nutrition: #00a04f;    --b7-nutrition-tint: #cde3d0;
	--b7-exercise: #a84260;     --b7-exercise-tint: #e0cad4;
	--b7-sleep: #19416b;        --b7-sleep-tint: #d1e0f1;
	--b7-stress: #37b8b4;       --b7-stress-tint: #c6dbda;
	--b7-stimulation: #d65d9c;  --b7-stimulation-tint: #fad9e6;
	--b7-detox: #f5aa41;        --b7-detox-tint: #fdebd2;
	--b7-supplements: #5f6063;  --b7-supplements-tint: #e1e1e1;

	color: var(--rl-text);
	font-family: var(--rl-font);
	max-width: 72rem;
	margin: 0 auto;
	padding: 0 clamp(1rem, 4vw, 2rem) 4rem;
}

@media (prefers-color-scheme: dark) {
	.rl {
		--b7-other: #3188b8;
		--b7-nutrition: #00ba5d;
		--b7-exercise: #b84b6c;
		--b7-sleep: #307ed1;
		--b7-stress: #42c7c2;
		--b7-stimulation: #db71a8;
		--b7-detox: #f6b559;
		--b7-supplements: #a5a6ad;
		--b7-other-tint: #213840;
		--b7-nutrition-tint: #17301f;
		--b7-exercise-tint: #351c25;
		--b7-sleep-tint: #182a40;
		--b7-stress-tint: #143230;
		--b7-stimulation-tint: #3a1d2c;
		--b7-detox-tint: #3a2a12;
		--b7-supplements-tint: #2c2c2c;
	}
}

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

.rl [hidden] {
	display: none !important;
}

.rl-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.rl :focus-visible {
	outline: 3px solid var(--rl-focus);
	outline-offset: 2px;
	border-radius: 6px;
}

/* Module color: one shared color for every module.
   (Per-pillar B7 colors were removed: modules 1–7 shared the same two colors,
   which was more distracting than helpful. The --b7-* tokens above are kept for reference.) */
.rl {
	--rl-num-bg: var(--rl-action);
	--rl-num-fg: #ffffff;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .rl { --rl-num-fg: #0d0d0d; }
}
:root[data-theme="dark"] .rl { --rl-num-fg: #0d0d0d; }

/* ---------- Toolbar (card) ---------- */

.rl-toolbar {
	background: var(--rl-surface);
	border-radius: var(--rl-radius);
	box-shadow: var(--rl-shadow);
	padding: 1.25rem clamp(1rem, 3vw, 1.5rem) 1rem;
	margin: 0 0 1.5rem;
	/* Stays pinned to the top of the screen while scrolling the library */
	position: sticky;
	top: env(safe-area-inset-top, 0px);
	z-index: 15;
}

.rl-toolbar.is-stuck {
	border-top-left-radius: 0;
	border-top-right-radius: 0;
	box-shadow: 0 8px 24px -10px rgba(19, 55, 75, 0.45);
}

.rl-sticky-sentinel {
	height: 1px;
	margin-bottom: -1px;
}

/* On phones, keep the pinned bar small: just the search box while scrolled */
@media (max-width: 40rem) {
	.rl-toolbar.is-stuck {
		padding-top: 0.75rem;
		padding-bottom: 0.75rem;
	}
	.rl-toolbar.is-stuck .rl-label[for="rl-q"],
	.rl-toolbar.is-stuck .rl-controls,
	.rl-toolbar.is-stuck .rl-status {
		display: none;
	}
}

@media print {
	.rl-toolbar { position: static; }
}

.rl-label {
	display: block;
	font-weight: 600;
	font-size: 1rem;
	color: var(--rl-heading);
	margin: 0 0 0.4rem;
	padding: 0;
}

.rl-search-field {
	position: relative;
	display: flex;
	align-items: center;
}

.rl-search-icon {
	position: absolute;
	left: 0.85rem;
	color: var(--rl-muted);
	pointer-events: none;
}

.rl-search-field input[type="search"] {
	width: 100%;
	min-height: 3.25rem;
	padding: 0.5rem 5.5rem 0.5rem 2.9rem;
	font: inherit;
	font-size: 1.125rem;
	color: var(--rl-text);
	background: var(--rl-surface);
	border: 1px solid var(--rl-field-line);
	border-radius: 6px;
	-webkit-appearance: none;
	appearance: none;
}

.rl-search-field input[type="search"]::placeholder {
	color: var(--rl-muted);
	opacity: 1;
}

.rl-search-field input[type="search"]:focus {
	border-color: var(--rl-action);
	box-shadow: 0 0 0 1px var(--rl-action);
	outline: none;
}

.rl-search-field input[type="search"]:focus-visible {
	outline: none;
}

.rl-search-field input[type="search"]::-webkit-search-cancel-button {
	display: none;
}

.rl-clear {
	position: absolute;
	right: 0.4rem;
	min-height: 2.5rem;
	padding: 0 0.9rem;
	font: inherit;
	font-size: 1rem;
	font-weight: 600;
	color: var(--rl-action);
	background: transparent;
	border: 0;
	border-radius: 6px;
	cursor: pointer;
}

.rl-clear:hover {
	background: var(--rl-surface-2);
}

.rl-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem 1.25rem;
	margin-top: 1rem;
	align-items: flex-end;
}

.rl-view {
	border: 0;
	margin: 0;
	padding: 0;
	min-width: 0;
}

/* Segmented picker, as in the style guide: gray track, blue selected pill */
.rl-segments {
	display: inline-flex;
	gap: 2px;
	padding: 3px;
	background: var(--rl-track);
	border-radius: 999px; /* pill, to match the portal and site */
}

.rl-segments label {
	position: relative;
	margin: 0;
}

.rl-segments input {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
	cursor: pointer;
}

.rl-segments span {
	display: flex;
	align-items: center;
	min-height: 2.6rem;
	padding: 0 1.15rem;
	font-size: 1.05rem;
	font-weight: 600; /* same weight in both states, so the toggle never changes width */
	color: var(--rl-text);
	border-radius: 7px;
	white-space: nowrap;
	cursor: pointer;
}

.rl-segments span {
	border-radius: 999px;
}

.rl-segments input:checked + span {
	background: var(--rl-action);
	color: var(--rl-on-action);
}

.rl-segments input:focus-visible + span {
	outline: 3px solid var(--rl-focus);
	outline-offset: 1px;
	border-radius: 999px;
}

.rl-select {
	flex: 1 1 14rem;
	max-width: 22rem;
}

.rl-select select {
	width: 100%;
	min-height: 3rem;
	padding: 0.4rem 2.4rem 0.4rem 0.8rem;
	font: inherit;
	font-size: 1.05rem;
	color: var(--rl-text);
	background-color: var(--rl-surface);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='%23828282' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75rem center;
	background-size: 1rem;
	border: 1px solid var(--rl-field-line);
	border-radius: 6px;
	-webkit-appearance: none;
	appearance: none;
}

.rl-select select:focus {
	border-color: var(--rl-action);
	box-shadow: 0 0 0 1px var(--rl-action);
}

.rl-status {
	margin: 0.9rem 0 0;
	font-size: 1rem;
	color: var(--rl-muted);
	min-height: 1.5em;
}

/* Desktop: search and the Arrange / Module tools share one row to save vertical space */
@media (min-width: 60rem) {
	.rl-toolbar {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-end;
		gap: 0 1.5rem;
		padding-top: 1rem;
		padding-bottom: 0.75rem;
	}
	.rl-search {
		flex: 1 1 18rem;
		min-width: 0;
	}
	.rl-controls {
		flex: 0 0 auto;
		flex-wrap: nowrap;
		margin-top: 0;
	}
	.rl-select {
		flex: 0 0 16rem;
	}
	.rl-search-field input[type="search"] {
		min-height: 3rem;
	}
	.rl-status {
		flex: 1 0 100%;
		margin-top: 0.5rem;
	}
}

/* ---------- Module index ---------- */

.rl-toc {
	background: var(--rl-surface);
	border-radius: var(--rl-radius);
	box-shadow: var(--rl-shadow);
	padding: 1.25rem clamp(1rem, 3vw, 1.5rem);
	margin: 0 0 1.5rem;
}

.rl-toc-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem 1rem;
	margin: 0 0 0.75rem;
}

.rl-toc-title {
	font-size: 1.25rem;
	font-weight: 700;
	color: var(--rl-heading);
	margin: 0;
}

/* The By module / A to Z switch only works with JavaScript on */
.rl:not(.is-enhanced) .rl-toc .rl-view {
	display: none;
}

/* With nothing to jump to (e.g. while searching), keep just the title row */
.rl-toc.is-compact .rl-toc-head {
	margin-bottom: 0;
}

/* Wide screens: fit every letter on a single row */
@media (min-width: 64rem) {
	.rl-toc .rl-letters ul {
		flex-wrap: nowrap;
		justify-content: space-between;
		gap: 0.2rem;
	}
	.rl-toc .rl-letters li {
		flex: 1 1 0;
		min-width: 0;
		max-width: 2.75rem;
	}
	.rl-toc .rl-letters a {
		min-width: 0;
		width: 100%;
		min-height: 2.5rem;
		font-size: 1.05rem;
	}
}

/* A to Z letters sit inside this card, so drop their own card styling */
.rl-toc .rl-letters {
	background: none;
	box-shadow: none;
	padding: 0;
	margin: 0;
}

.rl-toc ol {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
	gap: 0.5rem 1rem;
}

@media (max-width: 40rem) {
	.rl-toc ol {
		grid-template-columns: 1fr 1fr;
		gap: 0.25rem 0.5rem;
	}

	.rl-toc a {
		gap: 0.5rem;
		padding: 0.35rem 0.25rem;
		font-size: 1rem;
		line-height: 1.25;
	}
}

.rl-toc a {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-height: 3rem;
	padding: 0.4rem 0.6rem;
	color: var(--rl-text);
	text-decoration: none;
	font-size: 1.05rem;
	border-radius: 8px;
}

.rl-toc a:hover {
	background: var(--rl-surface-2);
}

.rl-toc-num {
	flex: none;
	display: grid;
	place-items: center;
	width: 2.1rem;
	height: 2.1rem;
	font-weight: 700;
	font-size: 1rem;
	color: var(--rl-num-fg);
	background: var(--rl-num-bg);
	border-radius: 50%;
	font-variant-numeric: tabular-nums;
}

/* ---------- Module cards ---------- */

.rl-module,
.rl-letter {
	background: var(--rl-surface);
	border-radius: var(--rl-radius);
	box-shadow: var(--rl-shadow);
	margin: 0 0 1.25rem;
	overflow: hidden;
	scroll-margin-top: calc(var(--rl-sticky-h, 0px) + 1rem);
}

.rl-module-head {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 1rem clamp(1rem, 3vw, 1.5rem);
	background: var(--rl-surface);
	border-bottom: 1px solid var(--rl-line);
}

.rl-module-num {
	flex: none;
	display: grid;
	place-items: center;
	width: 3.1rem;
	height: 3.1rem;
	font-size: 1.35rem;
	font-weight: 700;
	color: var(--rl-num-fg);
	background: var(--rl-num-bg);
	border-radius: 50%;
	font-variant-numeric: tabular-nums;
}

.rl-module-title {
	margin: 0;
	font-size: clamp(1.4rem, 2.6vw, 1.75rem);
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: 0.01em;
	color: var(--rl-heading);
}

.rl-module-kicker {
	display: block;
	font-size: 0.95rem;
	font-weight: 600;
	letter-spacing: 0;
	color: var(--rl-muted);
	margin-bottom: 0.1rem;
}

/* ---------- Resource rows ---------- */

.rl-list {
	list-style: none;
	margin: 0;
	padding: 0 clamp(1rem, 3vw, 1.5rem);
}

.rl-item {
	padding: 0.9rem 0;
	border-bottom: 1px solid var(--rl-line);
}

.rl-item:last-child {
	border-bottom: 0;
}

.rl-link {
	font-size: 1.125rem;
	line-height: 1.4;
	font-weight: 600;
	color: var(--rl-action);
	text-decoration: none;
}

a.rl-link:hover {
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.rl-ext {
	display: inline-block;
	margin-left: 0.4rem;
	vertical-align: -0.05em;
}

.rl-link.is-pending {
	color: var(--rl-text);
	font-weight: 400;
}

.rl-pending {
	display: inline-block;
	margin-left: 0.5rem;
	padding: 0.05rem 0.55rem;
	font-size: 0.85rem;
	color: var(--rl-muted);
	background: var(--rl-surface-2);
	border-radius: 999px;
	white-space: nowrap;
}

.rl-desc,
.rl-meta {
	margin: 0.3rem 0 0;
	font-size: 1rem;
	line-height: 1.5;
	color: var(--rl-muted);
	max-width: 44rem;
}

.rl mark {
	background: var(--rl-mark);
	color: inherit;
	padding: 0 0.08em;
	border-radius: 2px;
}

/* ---------- A to Z ---------- */

.rl-letters {
	background: var(--rl-surface);
	border-radius: var(--rl-radius);
	box-shadow: var(--rl-shadow);
	padding: 0.75rem;
	margin: 0 0 1.25rem;
}

.rl-letters ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
}

.rl-letters a {
	display: grid;
	place-items: center;
	min-width: 2.75rem;
	min-height: 2.75rem;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--rl-action);
	text-decoration: none;
	border-radius: 999px;
	background: var(--rl-surface-2);
}

.rl-letters a:hover {
	background: var(--rl-action);
	color: var(--rl-on-action);
}

.rl-letter-title {
	margin: 0;
	padding: 0.6rem clamp(1rem, 3vw, 1.5rem);
	font-size: 1.5rem;
	font-weight: 700;
	color: var(--rl-heading);
	background: var(--rl-surface-2);
}

/* ---------- Back to search ---------- */

.rl-back {
	position: fixed;
	right: max(1rem, env(safe-area-inset-right, 0px));
	bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
	z-index: 20;
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 3rem;
	padding: 0 1.2rem;
	font: inherit;
	font-size: 1.05rem;
	font-weight: 600;
	color: var(--rl-on-primary);
	background: var(--rl-primary);
	border: 0;
	border-radius: 6px;
	box-shadow: 0 6px 20px -8px rgba(19, 55, 75, 0.6);
	cursor: pointer;
}

.rl-back:hover {
	filter: brightness(1.15);
}

/* ---------- Empty state ---------- */

.rl-empty {
	padding: 2rem clamp(1rem, 4vw, 2rem);
	background: var(--rl-surface);
	border-radius: var(--rl-radius);
	box-shadow: var(--rl-shadow);
	font-size: 1.1rem;
}

.rl-empty p {
	margin: 0 0 0.75rem;
}

.rl-button {
	min-height: 3rem;
	padding: 0 1.4rem;
	font: inherit;
	font-weight: 600;
	color: var(--rl-on-primary);
	background: var(--rl-primary);
	border: 0;
	border-radius: 6px;
	cursor: pointer;
}

.rl-button:hover {
	filter: brightness(1.15);
}

@media (prefers-reduced-motion: no-preference) {
	html:has(.rl) {
		scroll-behavior: smooth;
	}
}

@media print {
	.rl-toolbar,
	.rl-toc,
	.rl-letters,
	.rl-back {
		display: none !important;
	}

	.rl-module,
	.rl-letter {
		box-shadow: none;
		border: 1px solid #ccc;
		break-inside: avoid-page;
	}

	a.rl-link::after {
		content: " (" attr(href) ")";
		font-size: 0.8em;
		color: #555;
		font-weight: 400;
	}
}
