/*
 * AI LABS Vetrina 0.3: Tutor LMS with the look of the showcase site.
 * Loaded only where Tutor loads its own styles (inc/tutor.php). Maps Tutor's CSS
 * variables to the section roles of theme.css (--ai-labs-*) and to the design
 * system; no Tutor template is overridden.
 * Course, lesson, quiz and student area are light sections under the dark header
 * (body.ai-labs-pagina-chiara, like the legal and FAQ pages of the site); the course
 * cards of the catalogue look like the master cards (MasterCard.astro).
 * Only design-system variables and CSS keywords: checked by tests/check-tokens.mjs.
 */

/* Light reading pages: the light roles on the body; header and footer stay dark. */
body.ai-labs-pagina-chiara {
	--ai-labs-fondo: var(--wp--custom--schema--chiaro--fondo);
	--ai-labs-pannello: var(--wp--custom--schema--chiaro--pannello);
	--ai-labs-bordo: var(--wp--custom--schema--chiaro--bordo);
	--ai-labs-testo: var(--wp--custom--schema--chiaro--testo);
	--ai-labs-grigio: var(--wp--custom--schema--chiaro--grigio);
	--ai-labs-accento: var(--wp--custom--schema--chiaro--accento);
	--ai-labs-link: var(--wp--custom--schema--chiaro--link);
	--ai-labs-sottolineatura: var(--wp--custom--schema--chiaro--sottolineatura);
	--ai-labs-sottolineatura-attiva: var(--wp--custom--schema--chiaro--sottolineatura-attiva);
	--ai-labs-campo: var(--wp--custom--schema--chiaro--campo);
	--ai-labs-focus: var(--wp--custom--schema--chiaro--focus);
	--ai-labs-errore: var(--wp--custom--schema--chiaro--errore);
	--ai-labs-segnaposto: var(--wp--custom--schema--chiaro--segnaposto);
	background-color: var(--ai-labs-fondo);
	color: var(--ai-labs-testo);
	color-scheme: light;
}

body.ai-labs-pagina-chiara a:where(:not(.wp-element-button, .tutor-btn, .tutor-iconic-btn, .ai-labs-logo)) {
	text-decoration-color: var(--ai-labs-sottolineatura);
}

/*
 * Tutor's variables. html:root beats Tutor's own :root declarations and its inline
 * palette, whatever the loading order. The values follow the section roles, so
 * Tutor components work on light pages and on the dark catalogue alike.
 */
html:root {
	--tutor-font-family-body: var(--wp--preset--font-family--body);
	--tutor-font-family-heading: var(--wp--preset--font-family--heading);
	--tutor-input-radius: var(--wp--custom--radius--base);
}

body {
	--tutor-color-primary: var(--ai-labs-accento);
	--tutor-color-primary-hover: var(--ai-labs-grigio);
	/* Tutor's blue scale: light tints = the section background, dark steps = the text. */
	--tutor-brand-50: var(--ai-labs-fondo);
	--tutor-brand-100: var(--ai-labs-fondo);
	--tutor-brand-200: var(--ai-labs-fondo);
	--tutor-brand-300: var(--ai-labs-fondo);
	--tutor-brand-400: var(--ai-labs-bordo);
	--tutor-brand-500: var(--ai-labs-accento);
	--tutor-brand-600: var(--ai-labs-accento);
	--tutor-brand-700: var(--ai-labs-testo);
	--tutor-brand-800: var(--ai-labs-testo);
	--tutor-brand-900: var(--ai-labs-testo);
	--tutor-brand-950: var(--ai-labs-testo);
	--tutor-text-brand: var(--ai-labs-testo);
	--tutor-border-brand: var(--ai-labs-campo);
	--tutor-body-color: var(--ai-labs-testo);
	--tutor-text-primary: var(--ai-labs-testo);
	--tutor-text-secondary: var(--ai-labs-grigio);
	--tutor-text-subdued: var(--ai-labs-grigio);
	--tutor-color-black: var(--ai-labs-testo);
	--tutor-color-secondary: var(--ai-labs-grigio);
	--tutor-color-subdued: var(--ai-labs-grigio);
	--tutor-color-hints: var(--ai-labs-grigio);
	--tutor-color-muted: var(--ai-labs-grigio);
	--tutor-border-color: var(--ai-labs-bordo);
	--tutor-border-idle: var(--ai-labs-bordo);
	--tutor-surface-base: var(--ai-labs-fondo);
	--tutor-surface-l1: var(--ai-labs-pannello);
	--tutor-surface-l1-hover: var(--ai-labs-fondo);
	--tutor-brand-450: var(--ai-labs-focus);
	--tutor-actions-brand-primary: var(--wp--preset--color--verde);
	--tutor-button-primary: var(--wp--preset--color--verde);
}

/* Same typefaces as the site: Inter for text, Space Grotesk for titles. */
:where([class^="tutor-"], [class*=" tutor-"]) {
	font-family: var(--wp--preset--font-family--body);
}

:where(.tutor-course-details-title, .tutor-course-content-title, .tutor-quiz-intro-title, .tutor-course-name, .tutor-dashboard-title, .tutor-fs-3, .tutor-fs-4, .tutor-fs-5, h1, h2, h3, h4)[class*="tutor-"],
.tutor-wrap :where(h1, h2, h3, h4) {
	font-family: var(--wp--preset--font-family--heading);
	letter-spacing: var(--wp--custom--letter-spacing--heading);
}

/* Text colours: Tutor writes some greys by hand (below WCAG AA on the light grey):
 * use the section roles instead. */
.tutor-color-black,
.tutor-course-details-title,
.tutor-course-content-title,
.tutor-quiz-intro-title,
.tutor-course-name,
.tutor-course-name a {
	color: var(--ai-labs-testo);
}

.tutor-color-muted,
.tutor-color-hints,
.tutor-color-subdued,
.tutor-color-secondary,
.tutor-btn-ghost,
.tutor-meta,
.tutor-meta > div,
.tutor-course-content-list-item-duration,
.tutor-course-content-list-item-status {
	color: var(--ai-labs-grigio);
}

/* Tutor's green «success» text (enrolment date) is 3:1 on the light panels: the text colour
 * instead; the meaning stays in the words. */
body.ai-labs-pagina-chiara .tutor-color-success {
	color: var(--ai-labs-testo);
}

/* List of the course tabs added by assets/js/tutor-a11y.js: no box of its own. */
.ai-labs-tutor-nav-list {
	display: contents;
}

/* Course and lesson titles: the page title size of the site (.titolo-doc). */
.tutor-course-details-title {
	font-size: var(--wp--preset--font-size--title);
	font-weight: var(--wp--custom--font-weight--bold);
	line-height: var(--wp--custom--line-height--heading);
}

/* No grey placeholder picture on the course page: the course has no image yet. */
.tutor-course-details-page .tutor-course-thumbnail:has(img[src*="placeholder"]) {
	display: none;
}

/* Room around the Tutor pages, as in a light section of the site. */
body.ai-labs-pagina-chiara .tutor-wrap.tutor-page-wrap {
	padding-block: var(--wp--preset--spacing--70);
}

/* ---------------------------------------------------------------------------
 * Buttons: primary = lime pill with dark text (.btn-verde), secondary = pill
 * with a border in the text colour (.btn-bordo).
 * ------------------------------------------------------------------------- */
.tutor-btn {
	border-radius: var(--wp--custom--radius--pill);
	font-family: var(--wp--preset--font-family--body);
	font-weight: var(--wp--custom--font-weight--bold);
	transition: box-shadow var(--wp--custom--motion--fast), background-color var(--wp--custom--motion--fast);
}

.tutor-btn.tutor-btn-primary,
.tutor-btn-primary {
	background-color: var(--wp--preset--color--verde);
	border-color: var(--wp--preset--color--verde);
	color: var(--wp--preset--color--fondo);
}

.tutor-btn.tutor-btn-primary:hover,
.tutor-btn-primary:hover,
.tutor-btn.tutor-btn-primary:focus,
.tutor-btn-primary:focus {
	background-color: var(--wp--preset--color--verde);
	border-color: var(--wp--preset--color--verde);
	box-shadow: var(--wp--preset--shadow--glow);
	color: var(--wp--preset--color--fondo);
}

.tutor-btn.tutor-btn-outline-primary,
.tutor-btn.tutor-btn-secondary,
.tutor-btn.tutor-btn-tertiary {
	background-color: transparent;
	border: var(--wp--custom--border--width--thin) solid var(--ai-labs-testo);
	color: var(--ai-labs-testo);
}

.tutor-btn.tutor-btn-outline-primary:hover,
.tutor-btn.tutor-btn-secondary:hover,
.tutor-btn.tutor-btn-tertiary:hover {
	background-color: var(--ai-labs-testo);
	border-color: var(--ai-labs-testo);
	color: var(--ai-labs-fondo);
}

.tutor-btn.tutor-btn-ghost {
	background-color: transparent;
}

/* Panels: cards, sidebar boxes, curriculum, quiz box (.pannello). */
:where(.tutor-card, .tutor-quiz-wrapper, .tutor-single-course-sidebar .tutor-card, .tutor-accordion-item, .tutor-dashboard-content-inner .tutor-card) {
	background-color: var(--ai-labs-pannello);
	border-color: var(--ai-labs-bordo);
	border-radius: var(--wp--custom--radius--panel);
	color: var(--ai-labs-testo);
}

.tutor-card-footer {
	background-color: transparent;
	border-color: var(--ai-labs-bordo);
}

.tutor-accordion-item-header {
	background-color: var(--ai-labs-pannello);
	color: var(--ai-labs-testo);
}

/* Fields: 14 px radius, border with 3:1 contrast. */
.tutor-form-control {
	background-color: var(--ai-labs-pannello);
	border-color: var(--ai-labs-campo);
	border-radius: var(--wp--custom--radius--base);
	color: var(--ai-labs-testo);
}

.tutor-form-control:focus {
	border-color: var(--ai-labs-testo);
}

/* Links inside lessons and course descriptions: dark text with the lime underline. */
:where(.tutor-lesson-content, .tutor-course-details-content) a {
	color: var(--ai-labs-link);
	text-decoration-color: var(--ai-labs-sottolineatura);
	text-decoration-thickness: var(--wp--custom--border--width--strong);
}

:where(.tutor-lesson-content, .tutor-course-details-content) a:is(:hover, :focus-visible) {
	text-decoration-color: var(--ai-labs-sottolineatura-attiva);
}

/* Lessons on the phone (375 px): images and videos never wider than the screen, the buttons
 * of the lesson footer («Segna come completato», «Successivo») wrap instead of overflowing,
 * long lesson and course titles wrap instead of being cut with an ellipsis. */
:where(.tutor-lesson-content, .tutor-learning-area, .tutor-course-details-content) :where(img, video, iframe) {
	block-size: auto;
	max-inline-size: var(--wp--custom--size--media-max);
}

body .tutor-learning-area .tutor-learning-area-footer {
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--20);
}

body .tutor-learning-area .tutor-learning-area-footer > * {
	flex: 1 1 auto;
	inline-size: auto;
	white-space: normal;
}

body .tutor-learning-area .tutor-learning-header-title,
body .tutor-learning-sidebar .tutor-learning-sidebar-curriculum .tutor-learning-nav-topic .tutor-learning-nav-header-title {
	overflow: visible;
	text-overflow: clip;
	white-space: normal;
}

/* The «video realizzato con l'AI» label also works inside Tutor lessons. */
.tutor-course-single-content-wrapper .ai-labs-avviso-ai,
.tutor-lesson-content .ai-labs-avviso-ai {
	margin-block: var(--wp--preset--spacing--30);
}

/* ---------------------------------------------------------------------------
 * Catalogue: [tutor_course] in the light section of the page, wide like the site,
 * cards like MasterCard.astro (dark header with mono label and big name, panel
 * body, chips, button).
 * ------------------------------------------------------------------------- */
.ai-labs-sezione > .wp-block-post-content:has(> .tutor-courses-wrap),
.wp-block-post-content > .tutor-courses-wrap {
	max-inline-size: var(--wp--style--global--wide-size);
}

.tutor-courses-wrap.tutor-container,
.tutor-courses-wrap .tutor-container {
	padding-inline: 0;
}

.tutor-courses-wrap > .tutor-row {
	margin-inline: 0;
}

.tutor-courses-wrap > .tutor-row > [class*="tutor-col"] {
	padding-inline: 0;
}

.tutor-course-filter {
	margin-block-end: var(--wp--preset--spacing--50);
}

.tutor-course-list.tutor-grid {
	display: grid;
	gap: var(--wp--preset--spacing--40);
	grid-template-columns: var(--wp--custom--grid--cards);
	margin: 0;
}

.tutor-course-list.tutor-grid > * {
	margin: 0;
	max-inline-size: none;
	padding: 0;
}

.tutor-course-card.tutor-card {
	background-color: var(--ai-labs-pannello);
	border: var(--wp--custom--border--width--thin) solid var(--ai-labs-bordo);
	border-radius: var(--wp--custom--radius--card);
	box-shadow: none;
	color: var(--ai-labs-testo);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	position: relative;
	transition: transform var(--wp--custom--motion--fast), border-color var(--wp--custom--motion--fast);
}

.tutor-course-card.tutor-card:hover {
	border-color: var(--wp--preset--color--verde);
	transform: translateY(var(--wp--custom--size--lift));
}

/* Card header: dark, like every master card; Tutor's grey placeholder is hidden. */
.tutor-course-card .tutor-course-thumbnail {
	background-color: var(--wp--preset--color--fondo);
	border-block-end: var(--wp--custom--border--width--thin) solid var(--wp--preset--color--bordo);
	color: var(--wp--preset--color--testo);
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--20);
	justify-content: space-between;
	min-block-size: var(--wp--custom--size--card-header);
	overflow: hidden;
	padding: var(--wp--preset--spacing--40) var(--wp--preset--spacing--50);
	position: relative;
}

.tutor-course-card .tutor-course-thumbnail > a {
	inset: 0;
	position: absolute;
}

.tutor-course-card .tutor-course-thumbnail .tutor-ratio {
	inset: 0;
	padding: 0;
	position: absolute;
}

.tutor-course-card .tutor-course-thumbnail .tutor-ratio::before {
	content: none;
}

.tutor-course-card .tutor-course-thumbnail img {
	inset: 0;
	object-fit: cover;
	position: absolute;
}

.tutor-course-card .tutor-course-thumbnail img[src*="placeholder"] {
	visibility: hidden;
}

/* Veil over a real course image, so the name on top stays readable. */
.tutor-course-card .tutor-course-thumbnail > a::after {
	background-image: var(--wp--preset--gradient--velo-scheda);
	content: "";
	inset: 0;
	position: absolute;
}

.ai-labs-scheda-corso__etichetta,
.ai-labs-scheda-corso__nome {
	pointer-events: none;
	position: relative;
	z-index: 1;
}

.ai-labs-scheda-corso__etichetta {
	align-self: flex-start;
	background-color: var(--wp--custom--color--testata);
	border-radius: var(--wp--custom--radius--tag);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--mini);
	letter-spacing: var(--wp--custom--letter-spacing--label);
	padding: var(--wp--preset--spacing--10) var(--wp--preset--spacing--20);
	text-transform: uppercase;
}

.ai-labs-scheda-corso__nome {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--card);
	font-weight: var(--wp--custom--font-weight--bold);
	letter-spacing: var(--wp--custom--letter-spacing--logo);
	line-height: var(--wp--custom--line-height--heading);
	max-inline-size: var(--wp--custom--size--card-name);
}

.tutor-course-card .tutor-course-bookmark {
	z-index: 2;
}

.tutor-course-card .tutor-card-body {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: var(--wp--preset--spacing--10);
	padding: var(--wp--preset--spacing--50) var(--wp--preset--spacing--50) 0;
}

.tutor-course-card .tutor-course-name {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--medium);
	font-weight: var(--wp--custom--font-weight--bold);
	margin: 0;
}

body .tutor-course-card .tutor-course-name a {
	color: var(--ai-labs-testo);
	text-decoration: none;
}

/* The whole card is clickable through the course name, as on the site. */
.tutor-course-card .tutor-course-name a::after {
	content: "";
	inset: 0;
	position: absolute;
	z-index: 1;
}

.ai-labs-scheda-corso__riga {
	color: var(--ai-labs-grigio);
	font-size: var(--wp--preset--font-size--compact);
	margin: 0;
}

.ai-labs-scheda-corso__chip {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--10);
	margin: var(--wp--preset--spacing--20) 0 0;
}

/* The master cards show no author: the course card neither. */
.tutor-course-card .tutor-meta,
.tutor-course-card .tutor-course-ratings {
	display: none;
}

.tutor-course-card .tutor-card-footer {
	border: 0;
	margin-block-start: auto;
	padding: var(--wp--preset--spacing--50);
	position: relative;
	z-index: 2;
}

.tutor-course-card .tutor-card-footer .tutor-btn {
	display: flex;
	justify-content: center;
	min-block-size: var(--wp--custom--size--button-card);
}

/* Sort menu of the catalogue. */
.tutor-course-filter,
.tutor-courses-wrap .tutor-form-select {
	color: var(--ai-labs-testo);
}

/* Student area: sidebar on the panel colour, the current page on the section background. */
.tutor-dashboard-sidebar {
	background-color: var(--ai-labs-pannello);
	border-color: var(--ai-labs-bordo);
}

.tutor-dashboard-sidebar .tutor-dashboard-sidebar-nav ul li a {
	border-radius: var(--wp--custom--radius--base);
	color: var(--ai-labs-testo);
}

.tutor-dashboard-sidebar .tutor-dashboard-sidebar-nav ul li a.active,
.tutor-dashboard-sidebar .tutor-dashboard-sidebar-nav ul li a:hover {
	background-color: var(--ai-labs-fondo);
	font-weight: var(--wp--custom--font-weight--semibold);
}

.tutor-dashboard-header {
	border-color: var(--ai-labs-bordo);
}

/* ---------------------------------------------------------------------------
 * Keyboard focus in the learning area (focus.*): Tutor LMS removes the outline
 * on its navigation items, so the theme ring is restored here.
 * ------------------------------------------------------------------------- */
body.tutor-lms :is(a, button, summary, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus-visible,
body .tutor-learning-sidebar .tutor-learning-sidebar-curriculum .tutor-learning-nav .tutor-learning-nav-item:focus-visible {
	outline: var(--wp--custom--focus--width) solid var(--ai-labs-focus);
	outline-offset: var(--wp--custom--focus--offset);
}

/* Tutor removes the ring of the student area menu with !important: only !important restores it. */
.tutor-dashboard-sidebar .tutor-dashboard-sidebar-nav ul li a:focus-visible {
	outline: var(--wp--custom--focus--width) solid var(--ai-labs-focus) !important;
	outline-offset: calc(var(--wp--custom--focus--width) * -1) !important;
}

/* Card header link: lime ring on the dark header, inside the card (which clips its content). */
body.tutor-lms .tutor-course-card .tutor-course-thumbnail > a:focus-visible {
	outline-color: var(--wp--preset--color--verde);
	outline-offset: calc(var(--wp--custom--focus--offset) * -1);
}
