/*
 * Movellino chatbot: in basso a destra sul computer, col fumetto alla sua
 * sinistra; sul telefono un pannello in basso, Movellino sopra il fumetto.
 * Ripreso da Bruno di 3AR (assets/css/bruno.css), coi ruoli del tema.
 * Spec: docs/superpowers/specs/2026-10-21-movellino-chatbot-design.md.
 *
 * Livelli: velo 55, Movellino aperto 57 (sopra la testata, 50); ridotto 45.
 * Il banner dei cookie (60) resta sopra: Movellino entra dopo che si è chiuso.
 */

.mv-chat {
	--c-attore: clamp(11rem, 16vw, 15rem);
	--c-rimbalzo: cubic-bezier(0.11, 1.21, 0, 1.06);
	position: fixed;
	right: 0;
	bottom: 0;
	z-index: 45;
	pointer-events: none;
	color: var(--mv-ink);
	font-family: var(--mv-testo);
}

.mv-chat[hidden],
.mv-chat__pannello[hidden],
.mv-chat__pulsante[hidden],
.mv-chat__storia[hidden],
.mv-chat__testo[hidden] {
	display: none;
}

.mv-chat__pannello {
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	padding-right: 1rem;
}

/* --- Lo sfocato -------------------------------------------------------------- */

.mv-chat-velo {
	position: fixed;
	inset: 0;
	z-index: 55;
	background: color-mix(in srgb, var(--mv-notte) 28%, transparent);
	-webkit-backdrop-filter: blur(6px) saturate(0.85);
	backdrop-filter: blur(6px) saturate(0.85);
	opacity: 0;
	visibility: hidden;
	cursor: pointer;
	transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

html.mv-chat-sfocato .mv-chat-velo {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.35s ease, visibility 0s;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
	.mv-chat-velo {
		background: color-mix(in srgb, var(--mv-notte) 60%, transparent);
	}
}

html.mv-chat-sfocato .mv-chat {
	z-index: 57;
}

/* --- Il fumetto ------------------------------------------------------------- */

.mv-chat__fumetto {
	position: relative;
	z-index: 1;
	width: min(23rem, calc(100vw - var(--c-attore) - 1rem));
	margin: 0 -1.5rem calc(var(--c-attore) * 0.4) 0;
	padding: 1rem 1.15rem 1.1rem;
	border: 1px solid var(--mv-bordo);
	border-radius: 18px;
	background: var(--mv-superficie);
	color: var(--mv-ink);
	box-shadow: 0 18px 48px color-mix(in srgb, var(--mv-notte) 28%, transparent), 0 2px 6px color-mix(in srgb, var(--mv-notte) 10%, transparent);
	pointer-events: auto;
	transform-origin: 100% 100%;
}

.mv-chat__fumetto:focus {
	outline: none;
}

.mv-chat__fumetto:focus-visible {
	box-shadow: 0 18px 48px color-mix(in srgb, var(--mv-notte) 28%, transparent), 0 0 0 3px var(--mv-accento);
}

/* La coda, verso Movellino. */
.mv-chat__fumetto::after {
	content: "";
	position: absolute;
	right: -10px;
	bottom: 1.6rem;
	border: 10px solid transparent;
	border-right: 0;
	border-left-color: var(--mv-superficie);
}

.mv-chat__testa {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0 0.5rem;
	margin: 0 2rem 0.5rem 0;
	color: var(--mv-minore);
	font-size: 0.8125rem;
	line-height: 1.3;
}

.mv-chat__testa strong {
	color: var(--mv-ink);
	font-family: var(--mv-titoli);
	font-size: 0.9375rem;
	font-weight: 600;
}

.mv-chat__testo {
	min-height: 3em;
	margin: 0;
	font-size: 0.9875rem;
	line-height: 1.5;
}

.mv-chat__chiudi {
	position: absolute;
	top: 0.45rem;
	right: 0.45rem;
	display: grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--mv-minore);
	cursor: pointer;
}

.mv-chat__chiudi:hover {
	background: var(--mv-fascia);
	color: var(--mv-ink);
}

.mv-chat__chiudi .mv-icona {
	width: 18px;
	height: 18px;
}

/* Le scelte: pillole; arancio quelle che fanno andare avanti e quelle scelte. Scorrono
 * da sole quando sono tante (pesi, accessori): il fumetto resta dentro la finestra. */
.mv-chat__scelte {
	display: flex;
	flex-wrap: wrap;
	gap: 0.45rem;
	max-height: min(44vh, 21rem);
	max-height: min(44dvh, 21rem);
	margin: 0.85rem -0.35rem 0 0;
	padding: 2px 0.35rem 2px 2px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.mv-chat__scelte:empty,
.mv-chat__comandi:empty {
	display: none;
}

.mv-chat__scelta {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.5rem 0.85rem;
	border: 1.5px solid var(--mv-bordo);
	border-radius: 999px;
	background: var(--mv-superficie);
	color: var(--mv-ink);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.25;
	text-align: left;
	text-decoration: none;
	cursor: pointer;
}

.mv-chat__scelta:hover {
	border-color: var(--mv-arancio);
}

.mv-chat__scelta[aria-pressed="true"],
.mv-chat__scelta.is-avanti {
	border-color: var(--mv-arancio);
	background: var(--mv-arancio);
	color: var(--mv-notte);
}

.mv-chat__scelta:disabled {
	opacity: 0.5;
	cursor: default;
}

.mv-chat__scelta.is-secondaria {
	border-color: transparent;
	background: transparent;
	color: var(--mv-minore);
}

.mv-chat__scelta.is-peso {
	min-width: 3.6rem;
	justify-content: center;
	font-family: var(--mv-dati);
	font-weight: 500;
}

.mv-chat__scelte--model .mv-chat__scelta,
.mv-chat__scelte--accessories .mv-chat__scelta.is-accessorio {
	width: 100%;
	border-radius: 12px;
}

.mv-chat__scelta.is-modello {
	display: grid;
	gap: 0.1rem;
}

.mv-chat__scelta.is-modello small {
	font-size: 0.75rem;
	font-weight: 400;
	opacity: 0.85;
}

/* Gli accessori: la casella davanti, piena quando è scelto. */
.mv-chat__scelta.is-accessorio::before {
	content: "";
	flex: none;
	width: 12px;
	height: 12px;
	border: 2px solid currentColor;
	border-radius: 4px;
	opacity: 0.7;
}

.mv-chat__scelta.is-accessorio[aria-pressed="true"]::before {
	background: currentColor;
	opacity: 1;
}

.mv-chat__avviso {
	width: 100%;
	margin: 0.15rem 0 0;
	padding: 0.5rem 0.7rem;
	border-radius: 10px;
	background: color-mix(in srgb, var(--mv-arancio) 14%, var(--mv-superficie));
	color: var(--mv-ink);
	font-size: 0.8125rem;
	line-height: 1.4;
}

.mv-chat__comandi {
	display: flex;
	margin-top: 0.4rem;
}

.mv-chat__scelta.is-indietro {
	padding: 0.3rem 0.2rem;
	border: 0;
	background: transparent;
	color: var(--mv-link);
	font-size: 0.8125rem;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.mv-chat__scelta:focus-visible,
.mv-chat__chiudi:focus-visible,
.mv-chat__pulsante:focus-visible,
.mv-chat__manda:focus-visible,
.mv-chat__spunta a:focus-visible {
	outline: 3px solid var(--mv-accento);
	outline-offset: 2px;
}

/* --- La conversazione scritta ------------------------------------------------- */

.mv-chat__storia {
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	max-height: min(34vh, 16rem);
	max-height: min(34dvh, 16rem);
	margin: 0 -0.4rem 0 0;
	padding: 2px 0.4rem 2px 2px;
	overflow-y: auto;
	overscroll-behavior: contain;
	list-style: none;
}

.mv-chat__msg {
	max-width: 92%;
	font-size: 0.9375rem;
	line-height: 1.5;
}

.mv-chat__msg p {
	margin: 0;
	white-space: pre-line;
}

.mv-chat__msg--tu {
	align-self: flex-end;
	padding: 0.45rem 0.8rem;
	border-radius: 14px 14px 4px 14px;
	background: var(--mv-arancio);
	color: var(--mv-notte);
}

.mv-chat__msg--movellino {
	align-self: flex-start;
}

.mv-chat__scrivi {
	display: flex;
	gap: 0.4rem;
	margin-top: 0.85rem;
}

.mv-chat__scrivi input {
	flex: 1;
	min-width: 0;
	min-height: 2.75rem;
	padding: 0.5rem 0.85rem;
	border: 1.5px solid var(--mv-bordo-campo);
	border-radius: 999px;
	background: var(--mv-campo);
	color: var(--mv-ink);
	font: inherit;
	font-size: 1rem; /* Sotto i 16px l'iPhone ingrandisce la pagina. */
}

.mv-chat__scrivi input::placeholder {
	color: var(--mv-minore);
	opacity: 1;
}

.mv-chat__scrivi input:focus-visible {
	outline: 3px solid var(--mv-accento);
	outline-offset: 1px;
}

.mv-chat__scrivi input:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.mv-chat__manda {
	flex: none;
	display: grid;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--mv-arancio);
	color: var(--mv-notte);
	cursor: pointer;
}

.mv-chat__manda:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.mv-chat__manda .mv-icona {
	width: 18px;
	height: 18px;
}

.mv-chat__spunta {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	margin-top: 0.55rem;
	color: var(--mv-minore);
	font-size: 0.75rem;
	line-height: 1.4;
	cursor: pointer;
}

.mv-chat__spunta input {
	flex: none;
	width: 1rem;
	height: 1rem;
	margin: 0.1rem 0 0;
	accent-color: var(--mv-arancio);
}

.mv-chat__spunta a {
	color: var(--mv-link);
}

.mv-chat__nota {
	margin: 0.45rem 0 0;
	color: var(--mv-minore);
	font-size: 0.75rem;
	line-height: 1.35;
}

.mv-chat__nota.is-errore {
	color: var(--mv-errore-testo);
}

/* --- Movellino ---------------------------------------------------------------- */

.mv-chat__attore {
	position: relative;
	flex: none;
	width: var(--c-attore);
	aspect-ratio: 1;
	pointer-events: none;
}

.mv-chat__ferma,
.mv-chat__video {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
}

/* Due video sovrapposti: quello nuovo compare quando parte, l'altro sparisce. */
.mv-chat__video {
	opacity: 0;
	transition: opacity 0.12s linear;
}

.mv-chat__video.is-attivo {
	opacity: 1;
}

.mv-chat.is-video .mv-chat__ferma {
	visibility: hidden;
}

/* --- Il pulsante «Chiedi a Movellino» ------------------------------------------- */

.mv-chat__pulsante {
	position: fixed;
	right: max(1rem, env(safe-area-inset-right, 0px));
	bottom: max(1rem, env(safe-area-inset-bottom, 0px));
	display: inline-flex;
	align-items: center;
	gap: 0.55rem;
	padding: 0.2rem 1.1rem 0.2rem 0.2rem;
	border: 1px solid var(--mv-bordo);
	border-radius: 999px;
	background: var(--mv-superficie);
	color: var(--mv-ink);
	box-shadow: 0 8px 24px color-mix(in srgb, var(--mv-notte) 22%, transparent);
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 700;
	pointer-events: auto;
	cursor: pointer;
}

.mv-chat__pulsante:hover {
	border-color: var(--mv-arancio);
}

/* La cabina con la faccia (mv-movellino-viso.webp) su un tondo. */
.mv-chat__pulsante img {
	width: 3.5rem;
	height: 3.5rem;
	border-radius: 50%;
	background: var(--mv-fascia);
}

/* --- Telefono: Movellino sopra il fumetto, a destra ------------------------------ */

@media (max-width: 639px) {
	.mv-chat {
		--c-attore: 8.5rem;
		left: 0;
	}

	.mv-chat__pannello {
		flex-direction: column;
		align-items: stretch;
		padding: 0 0.75rem 0.75rem;
	}

	.mv-chat__attore {
		order: -1;
		align-self: flex-end;
		margin: 0 0.75rem -1.1rem 0;
	}

	.mv-chat__fumetto {
		width: auto;
		margin: 0;
		transform-origin: 85% 0;
	}

	.mv-chat__fumetto::after {
		top: -10px;
		right: 3.6rem;
		bottom: auto;
		border: 10px solid transparent;
		border-top: 0;
		border-bottom-color: var(--mv-superficie);
	}

	.mv-chat__scelte {
		max-height: 38vh;
		max-height: 38dvh;
	}

	.mv-chat__pulsante {
		right: 0.75rem;
		bottom: 0.75rem;
	}
}

/* --- Entrata e uscita ---------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
	.mv-chat.is-aperto .mv-chat__attore {
		animation: mv-chat-sale 0.9s var(--c-rimbalzo) both;
	}

	.mv-chat.is-aperto .mv-chat__fumetto {
		animation: mv-chat-apre 0.45s 0.6s var(--c-rimbalzo) both;
	}

	.mv-chat.is-uscita .mv-chat__attore {
		animation: mv-chat-scende 0.4s ease-in both;
	}

	.mv-chat.is-uscita .mv-chat__fumetto {
		animation: mv-chat-chiude 0.25s ease-in both;
	}

	.mv-chat__pulsante:not([hidden]) {
		animation: mv-chat-pulsante 0.45s var(--c-rimbalzo) both;
	}
}

@keyframes mv-chat-sale {
	from { transform: translateY(105%); }
	to { transform: none; }
}

@keyframes mv-chat-scende {
	to { transform: translateY(105%); }
}

@keyframes mv-chat-apre {
	from { opacity: 0; transform: scale(0.7) translateY(10px); }
	to { opacity: 1; transform: none; }
}

@keyframes mv-chat-chiude {
	to { opacity: 0; transform: scale(0.85); }
}

@keyframes mv-chat-pulsante {
	from { transform: translateY(150%); }
	to { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
	.mv-chat__video {
		display: none;
	}

	.mv-chat-velo,
	html.mv-chat-sfocato .mv-chat-velo {
		transition: none;
	}
}

@media print {
	.mv-chat,
	.mv-chat-velo {
		display: none;
	}
}
