/* ==========================================================================
   Assistente Chat AI — stile del terminale di chat
   --------------------------------------------------------------------------
   I colori e le misure principali sono esposti come CSS custom properties
   (--acai-*): il plugin le sovrascrive con i valori delle impostazioni
   tramite wp_add_inline_style(), e lo shortcode può cambiarle per istanza.
   ========================================================================== */

.acai-chat {
	/* Valori predefiniti, sovrascritti dalle impostazioni. */
	--acai-colore: #1a7f64;
	--acai-bolla-utente: #1a7f64;
	--acai-bolla-assistente: #f0f2f5;
	--acai-raggio: 12px;
	--acai-font: 15px;

	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 100%;
	height: 500px;
	background: #ffffff;
	border: 1px solid #e2e4e8;
	border-radius: var(--acai-raggio);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
	overflow: hidden;
	font-size: var(--acai-font);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
	line-height: 1.45;
	box-sizing: border-box;
}

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

/* --------------------------------------------------------------------------
   Header: titolo, pallino "online", pulsante di chiusura (solo widget)
   -------------------------------------------------------------------------- */

.acai-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	background: var(--acai-colore);
	color: #ffffff;
	flex-shrink: 0;
}

.acai-stato {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.35);
	flex-shrink: 0;
}

.acai-titolo {
	flex: 1;
	font-weight: 600;
	font-size: 1.02em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.acai-chiudi {
	background: none;
	border: 0;
	color: #ffffff;
	font-size: 26px;
	line-height: 1;
	padding: 0 4px;
	cursor: pointer;
	opacity: 0.85;
	transition: opacity 0.15s;
}

.acai-chiudi:hover,
.acai-chiudi:focus {
	opacity: 1;
}

/* --------------------------------------------------------------------------
   Area messaggi
   -------------------------------------------------------------------------- */

.acai-messaggi {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #fafbfc;
	scroll-behavior: smooth;
}

/* Ogni messaggio entra con una piccola animazione fade/slide-in. */
.acai-riga {
	display: flex;
	animation: acai-entra 0.25s ease-out;
}

.acai-riga-utente {
	justify-content: flex-end;
}

.acai-riga-assistente {
	justify-content: flex-start;
}

.acai-bolla {
	max-width: 80%;
	padding: 10px 14px;
	border-radius: var(--acai-raggio);
}

.acai-bolla-utente {
	background: var(--acai-bolla-utente);
	color: #ffffff;
	border-bottom-right-radius: 4px;
}

.acai-bolla-assistente {
	background: var(--acai-bolla-assistente);
	color: #1f2328;
	border-bottom-left-radius: 4px;
}

/* Bolla di errore (timeout, rete, server). */
.acai-bolla-errore {
	background: #fdecea;
	color: #8a1f11;
}

.acai-testo {
	white-space: pre-wrap;
	overflow-wrap: break-word;
	word-break: break-word;
}

.acai-testo strong {
	font-weight: 700;
}

/* Timestamp discreto sotto ogni bolla. */
.acai-ora {
	display: block;
	font-size: 0.72em;
	opacity: 0.6;
	margin-top: 4px;
	text-align: right;
}

/* --------------------------------------------------------------------------
   Domande suggerite: pulsanti cliccabili sotto il benvenuto
   -------------------------------------------------------------------------- */

.acai-suggerimenti {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 2px 2px 4px;
	animation: acai-entra 0.25s ease-out;
}

.acai-chat button.acai-suggerimento {
	background: #ffffff !important;
	border: 1px solid var(--acai-colore) !important;
	color: var(--acai-colore) !important;
	border-radius: 999px !important;
	padding: 7px 14px !important;
	margin: 0 !important;
	font-size: 0.9em !important;
	font-family: inherit !important;
	line-height: 1.3 !important;
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
	transition: background 0.15s, color 0.15s, transform 0.12s, box-shadow 0.15s;
}

.acai-chat button.acai-suggerimento:hover,
.acai-chat button.acai-suggerimento:focus {
	background: var(--acai-colore) !important;
	color: #ffffff !important;
	transform: translateY(-1px);
	box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

/* --------------------------------------------------------------------------
   Pulsante WhatsApp (fallback NON_TROVATO ed errori di timeout)
   -------------------------------------------------------------------------- */

.acai-whatsapp {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 10px;
	padding: 9px 16px;
	background: #25d366;
	color: #ffffff !important;
	border-radius: 999px;
	text-decoration: none !important;
	font-weight: 600;
	font-size: 0.92em;
	transition: filter 0.15s, transform 0.1s;
}

.acai-whatsapp:hover,
.acai-whatsapp:focus {
	filter: brightness(1.08);
	transform: translateY(-1px);
	color: #ffffff;
}

.acai-whatsapp svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
	flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Pulsante "Prenota una visita" (fallback FUORI_AMBITO)
   -------------------------------------------------------------------------- */

.acai-prenota {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 10px;
	padding: 9px 16px;
	background: var(--acai-colore);
	color: #ffffff !important;
	border-radius: 999px;
	text-decoration: none !important;
	font-weight: 600;
	font-size: 0.92em;
	transition: filter 0.15s, transform 0.1s;
}

.acai-prenota:hover,
.acai-prenota:focus {
	filter: brightness(1.08);
	transform: translateY(-1px);
	color: #ffffff;
}

.acai-prenota svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
	flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Indicatore "sto pensando": tre puntini animati + testo
   -------------------------------------------------------------------------- */

.acai-pensando .acai-bolla {
	display: flex;
	align-items: center;
	gap: 10px;
	/* Comparsa/scomparsa morbida gestita insieme all'animazione di entrata. */
	transition: opacity 0.25s ease;
}

.acai-punti {
	display: inline-flex;
	gap: 4px;
}

.acai-punto {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #8b949e;
	animation: acai-rimbalzo 1.2s infinite ease-in-out;
}

.acai-punto:nth-child(2) { animation-delay: 0.15s; }
.acai-punto:nth-child(3) { animation-delay: 0.3s; }

.acai-pensando-testo {
	font-size: 0.9em;
	opacity: 0.7;
}

/* --------------------------------------------------------------------------
   Form di invio
   -------------------------------------------------------------------------- */

/* Nota: qui la specificità è volutamente alta (.acai-chat + elemento) e le
   proprietà visive chiave usano !important, perché i temi WordPress spesso
   stilizzano gli input con selettori forti che scavalcherebbero il plugin. */

.acai-chat .acai-form {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px;
	border-top: 1px solid #eceef1;
	background: #ffffff;
	box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
	flex-shrink: 0;
	margin: 0;
}

.acai-chat input.acai-input {
	flex: 1;
	min-width: 0;
	height: auto !important;
	border: 1.5px solid #e4e7eb !important;
	border-radius: 999px !important;
	padding: 12px 18px !important;
	margin: 0 !important;
	font-size: 1em !important;
	font-family: inherit !important;
	line-height: 1.4 !important;
	outline: none !important;
	transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
	background: #f1f3f5 !important;
	color: #1f2328 !important;
	box-shadow: none !important;
}

.acai-chat input.acai-input::placeholder {
	color: #9aa2aa !important;
	opacity: 1;
}

.acai-chat input.acai-input:focus {
	background: #ffffff !important;
	border-color: var(--acai-colore) !important;
	box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06) !important;
}

.acai-chat input.acai-input:disabled {
	opacity: 0.7;
	cursor: wait;
}

.acai-chat button.acai-invia {
	width: 46px;
	height: 46px;
	min-width: 46px;
	border: 0 !important;
	border-radius: 50% !important;
	background: var(--acai-colore) !important;
	color: #ffffff !important;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
	transition: filter 0.15s, transform 0.12s, box-shadow 0.15s, opacity 0.15s;
	padding: 0 !important;
}

.acai-chat button.acai-invia:hover:not(:disabled) {
	filter: brightness(1.08);
	transform: translateY(-1px) scale(1.04);
	box-shadow: 0 5px 16px rgba(0, 0, 0, 0.24);
}

.acai-chat button.acai-invia:active:not(:disabled) {
	transform: translateY(0) scale(0.97);
}

.acai-chat button.acai-invia:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	box-shadow: none;
}

.acai-chat button.acai-invia svg {
	width: 20px;
	height: 20px;
	fill: currentColor;
}

/* --------------------------------------------------------------------------
   Widget flottante
   -------------------------------------------------------------------------- */

.acai-widget {
	position: fixed;
	bottom: 20px;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
}

.acai-pos-destra {
	right: 20px;
}

.acai-pos-sinistra {
	left: 20px;
	align-items: flex-start;
}

/* Bolla circolare di apertura. */
.acai-apri {
	width: 60px;
	height: 60px;
	border: 0;
	border-radius: 50%;
	background: #1a7f64; /* Sovrascritto inline dal colore delle impostazioni. */
	color: #ffffff;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: transform 0.15s;
}

.acai-apri:hover {
	transform: scale(1.07);
}

.acai-apri svg {
	width: 28px;
	height: 28px;
	fill: currentColor;
}

/* Pannello della chat: nascosto di default, mostrato con .acai-aperto. */
.acai-pannello {
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 520px;
	max-height: calc(100vh - 120px);
	opacity: 0;
	transform: translateY(12px) scale(0.97);
	pointer-events: none;
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.acai-widget.acai-aperto .acai-pannello {
	opacity: 1;
	transform: none;
	pointer-events: auto;
}

.acai-pannello .acai-chat {
	height: 100%;
}

/* --------------------------------------------------------------------------
   Responsive: su mobile il widget aperto occupa quasi tutto lo schermo
   -------------------------------------------------------------------------- */

@media (max-width: 480px) {
	.acai-widget.acai-aperto .acai-pannello {
		position: fixed;
		top: 8px;
		right: 8px;
		bottom: 88px; /* Lascia spazio alla bolla di chiusura in basso. */
		left: 8px;
		width: auto;
		height: auto;
		max-width: none;
		max-height: none;
	}

	.acai-bolla {
		max-width: 88%;
	}

	/* Su mobile le domande suggerite diventano una lista verticale di schede
	   a tutta larghezza: testo a sinistra, freccia a destra, comparsa a
	   cascata. Molto più chiaro di uno scroll orizzontale. */
	.acai-suggerimenti {
		flex-direction: column;
		flex-wrap: nowrap;
		align-items: stretch;
		gap: 7px;
	}

	.acai-chat button.acai-suggerimento {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
		text-align: left;
		background: #ffffff !important;
		border: 1px solid #e4e7eb !important;
		border-left: 3px solid var(--acai-colore) !important;
		border-radius: 12px !important;
		color: #1f2328 !important;
		padding: 12px 14px !important;
		font-size: 0.92em !important;
		box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
		animation: acai-entra 0.3s ease-out both;
	}

	/* Freccia a destra, nel colore principale. */
	.acai-chat button.acai-suggerimento::after {
		content: "\203A"; /* › */
		color: var(--acai-colore);
		font-size: 1.3em;
		font-weight: 700;
		line-height: 1;
		flex-shrink: 0;
	}

	.acai-chat button.acai-suggerimento:active {
		transform: scale(0.98);
		background: #f5f7f9 !important;
	}

	/* Su touch niente hover "invertito": il tap deve restare leggibile. */
	.acai-chat button.acai-suggerimento:hover,
	.acai-chat button.acai-suggerimento:focus {
		background: #ffffff !important;
		color: #1f2328 !important;
		transform: none;
	}

	/* Comparsa a cascata: ogni scheda entra poco dopo la precedente. */
	.acai-suggerimento:nth-child(1) { animation-delay: 0.05s; }
	.acai-suggerimento:nth-child(2) { animation-delay: 0.12s; }
	.acai-suggerimento:nth-child(3) { animation-delay: 0.19s; }
	.acai-suggerimento:nth-child(4) { animation-delay: 0.26s; }
	.acai-suggerimento:nth-child(5) { animation-delay: 0.33s; }
	.acai-suggerimento:nth-child(6) { animation-delay: 0.4s; }
	.acai-suggerimento:nth-child(7) { animation-delay: 0.47s; }
	.acai-suggerimento:nth-child(n+8) { animation-delay: 0.54s; }
}

/* --------------------------------------------------------------------------
   Animazioni
   -------------------------------------------------------------------------- */

@keyframes acai-entra {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes acai-rimbalzo {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	30% {
		transform: translateY(-5px);
		opacity: 1;
	}
}

/* Rispetta la preferenza di sistema per il movimento ridotto. */
@media (prefers-reduced-motion: reduce) {
	.acai-riga,
	.acai-punto {
		animation: none;
	}
	.acai-pannello,
	.acai-messaggi {
		transition: none;
		scroll-behavior: auto;
	}
}
