/* Chat Ruotino — aspetto WhatsApp */

#cr-root, #cr-root * { box-sizing: border-box; }

#cr-root {
	--cr-verde-scuro: #075E54;
	--cr-verde: #128C7E;
	--cr-verde-chiaro: #25D366;
	--cr-bolla-mia: #DCF8C6;
	--cr-sfondo: #ECE5DD;
	--cr-testo: #111b21;
	--cr-grigio: #667781;
	font-family: "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ---------------------------------------------------------- richiamo */

#cr-root .cr-richiamo {
	position: fixed;
	right: 96px;
	bottom: 34px;
	z-index: 2147483000;
	background: #fff;
	color: var(--cr-testo);
	border-radius: 14px;
	padding: 12px 16px;
	max-width: 240px;
	font-size: 14px;
	line-height: 1.35;
	box-shadow: 0 6px 24px rgba(0,0,0,.22);
	cursor: pointer;
	animation: cr-entra .35s ease-out;
}
#cr-root .cr-richiamo::after {
	content: "";
	position: absolute;
	right: -8px;
	bottom: 18px;
	border: 8px solid transparent;
	border-left-color: #fff;
	border-right: 0;
}
#cr-root .cr-richiamo b { display: block; margin-bottom: 2px; }
#cr-root .cr-richiamo .cr-freccia {
	position: absolute;
	right: -34px;
	bottom: 6px;
	font-size: 26px;
	color: var(--cr-verde-chiaro);
	animation: cr-punta 1.1s ease-in-out infinite;
}
#cr-root .cr-richiamo-x {
	position: absolute;
	top: -9px;
	left: -9px;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #54656f;
	color: #fff;
	border: 0;
	font-size: 14px;
	line-height: 20px;
	cursor: pointer;
	padding: 0;
}

@keyframes cr-punta {
	0%,100% { transform: translateX(0); }
	50% { transform: translateX(7px); }
}
@keyframes cr-entra {
	from { opacity: 0; transform: translateY(12px) scale(.94); }
	to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------- pannello */

#cr-root .cr-velo {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,.45);
	z-index: 2147483400;
	animation: cr-sfuma .2s ease-out;
}
@keyframes cr-sfuma { from { opacity: 0; } to { opacity: 1; } }

#cr-root .cr-pannello {
	position: fixed;
	right: 24px;
	bottom: 24px;
	width: 380px;
	height: 640px;
	max-height: calc(100vh - 48px);
	z-index: 2147483500;
	display: flex;
	flex-direction: column;
	border-radius: 12px;
	overflow: hidden;
	box-shadow: 0 18px 60px rgba(0,0,0,.35);
	background: var(--cr-sfondo);
	animation: cr-apri .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes cr-apri {
	from { opacity: 0; transform: translateY(24px) scale(.97); }
	to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------- testata */

#cr-root .cr-testata {
	background: var(--cr-verde-scuro);
	color: #fff;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	flex: 0 0 auto;
}
#cr-root .cr-indietro {
	background: none;
	border: 0;
	color: #fff;
	cursor: pointer;
	padding: 2px;
	display: flex;
	align-items: center;
}
#cr-root .cr-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: #ccd0d5;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	overflow: hidden;
}
#cr-root .cr-avatar svg { width: 38px; height: 38px; }
#cr-root .cr-chi { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
#cr-root .cr-chi .cr-nome {
	font-size: 15px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
#cr-root .cr-chi .cr-stato { font-size: 12px; opacity: .85; }
#cr-root .cr-azioni { display: flex; align-items: center; gap: 16px; flex: 0 0 auto; }
#cr-root .cr-azioni svg { width: 20px; height: 20px; fill: #fff; opacity: .95; }

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

#cr-root .cr-corpo {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 14px 12px 8px;
	background-color: var(--cr-sfondo);
	background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='none' stroke='%23d9d2c8' stroke-width='1.4' stroke-linecap='round'%3E%3Ccircle cx='24' cy='26' r='8'/%3E%3Cpath d='M58 18h18v14H58z'/%3E%3Cpath d='M100 20l10 10-10 10-10-10z'/%3E%3Cpath d='M18 68c6-8 16-8 22 0'/%3E%3Ccircle cx='74' cy='72' r='6'/%3E%3Cpath d='M104 64v18M96 73h16'/%3E%3Cpath d='M20 112h20M30 102v20'/%3E%3Ccircle cx='70' cy='114' r='9'/%3E%3Cpath d='M104 106l12 12M116 106l-12 12'/%3E%3C/g%3E%3C/svg%3E");
	background-repeat: repeat;
}

#cr-root .cr-giorno {
	text-align: center;
	margin: 6px 0 12px;
}
#cr-root .cr-giorno span {
	background: #E1F2FA;
	color: #54656f;
	font-size: 12px;
	padding: 5px 12px;
	border-radius: 8px;
	box-shadow: 0 1px 1px rgba(0,0,0,.08);
}

#cr-root .cr-msg {
	max-width: 82%;
	margin-bottom: 8px;
	padding: 6px 9px 8px;
	border-radius: 8px;
	position: relative;
	font-size: 14.4px;
	line-height: 1.42;
	color: var(--cr-testo);
	box-shadow: 0 1px .5px rgba(11,20,26,.13);
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: cr-bolla .18s ease-out;
}
@keyframes cr-bolla {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

#cr-root .cr-msg.cr-loro {
	background: #fff;
	margin-right: auto;
	border-top-left-radius: 0;
}
#cr-root .cr-msg.cr-loro::before {
	content: "";
	position: absolute;
	top: 0;
	left: -8px;
	width: 0;
	height: 0;
	border: 8px solid transparent;
	border-right-color: #fff;
	border-top-color: #fff;
	border-left: 0;
	border-bottom: 0;
}

#cr-root .cr-msg.cr-io {
	background: var(--cr-bolla-mia);
	margin-left: auto;
	border-top-right-radius: 0;
}
#cr-root .cr-msg.cr-io::before {
	content: "";
	position: absolute;
	top: 0;
	right: -8px;
	width: 0;
	height: 0;
	border: 8px solid transparent;
	border-left-color: var(--cr-bolla-mia);
	border-top-color: var(--cr-bolla-mia);
	border-right: 0;
	border-bottom: 0;
}

#cr-root .cr-ora {
	float: right;
	margin: 6px -2px -4px 8px;
	font-size: 11px;
	color: var(--cr-grigio);
	display: flex;
	align-items: center;
	gap: 3px;
	white-space: nowrap;
}
#cr-root .cr-ora svg { width: 15px; height: 15px; fill: #53bdeb; }

#cr-root .cr-privacy {
	font-size: 11.5px;
	color: #54656f;
	background: #FFF3C4;
	border-radius: 8px;
	padding: 7px 10px;
	margin: 0 auto 10px;
	max-width: 92%;
	text-align: center;
	line-height: 1.35;
}
#cr-root .cr-privacy a { color: #027eb5; }

/* sta scrivendo */
#cr-root .cr-scrive {
	background: #fff;
	border-radius: 8px;
	border-top-left-radius: 0;
	padding: 11px 14px;
	width: 56px;
	margin-bottom: 8px;
	box-shadow: 0 1px .5px rgba(11,20,26,.13);
	display: flex;
	gap: 4px;
}
#cr-root .cr-scrive i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9aa4ab;
	display: block;
	animation: cr-salta 1.2s infinite;
}
#cr-root .cr-scrive i:nth-child(2) { animation-delay: .18s; }
#cr-root .cr-scrive i:nth-child(3) { animation-delay: .36s; }
@keyframes cr-salta {
	0%,60%,100% { transform: translateY(0); opacity: .5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------------------------------------------------------- scelte */

#cr-root .cr-scelte {
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	justify-content: flex-end;
	padding: 4px 2px 10px;
}
#cr-root .cr-scelte button {
	background: #fff;
	color: var(--cr-verde);
	border: 1px solid rgba(18,140,126,.4);
	border-radius: 18px;
	padding: 8px 14px;
	font-size: 13.5px;
	cursor: pointer;
	font-family: inherit;
	box-shadow: 0 1px 2px rgba(0,0,0,.08);
	transition: background .15s, transform .1s;
}
#cr-root .cr-scelte button:hover { background: #f0fbf8; }
#cr-root .cr-scelte button:active { transform: scale(.97); }

/* ---------------------------------------------------------- barra input */

#cr-root .cr-barra {
	flex: 0 0 auto;
	background: #F0F0F0;
	padding: 8px 10px;
	display: flex;
	align-items: flex-end;
	gap: 8px;
}
#cr-root .cr-campo {
	flex: 1 1 auto;
	background: #fff;
	border-radius: 22px;
	display: flex;
	align-items: flex-end;
	padding: 6px 10px;
	gap: 8px;
	min-height: 42px;
}
#cr-root .cr-campo svg { width: 22px; height: 22px; fill: #54656f; flex: 0 0 auto; margin-bottom: 3px; }
#cr-root .cr-campo textarea {
	flex: 1 1 auto;
	border: 0;
	outline: 0;
	resize: none;
	font: inherit;
	font-size: 14.5px;
	line-height: 1.4;
	max-height: 96px;
	padding: 6px 0;
	background: transparent;
	color: var(--cr-testo);
	font-family: inherit;
}
#cr-root .cr-campo textarea::placeholder { color: #8696a0; }
#cr-root .cr-invia {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--cr-verde);
	border: 0;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	transition: transform .1s;
}
#cr-root .cr-invia:active { transform: scale(.94); }
#cr-root .cr-invia svg { width: 24px; height: 24px; display: block; }
#cr-root .cr-invia svg path {
	fill: #fff !important;
	stroke: #fff !important;
	stroke-width: 2.6px !important;
	stroke-linejoin: round !important;
	stroke-linecap: round !important;
}
#cr-root .cr-invia[disabled] { opacity: .45; cursor: default; }
#cr-root .cr-invia.cr-pronto { opacity: 1; }

/* Spunta verde accanto al numero riconosciuto valido. */
#cr-root .cr-oktel {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	margin: 0 2px;
	animation: cr-spunta .25s ease-out 1;
}
#cr-root .cr-oktel svg,
#cr-root .cr-oktel svg path { fill: #25D366 !important; }

@keyframes cr-spunta {
	from { transform: scale(.4); opacity: 0; }
	to   { transform: scale(1); opacity: 1; }
}

#cr-root .cr-nota-prova {
	background: #8b1f1f;
	color: #fff;
	font-size: 11px;
	text-align: center;
	padding: 4px 8px;
}

/* ---------------------------------------------------------- telefono */

/* ------------------------------------------------------ telefoni e tablet */

@media (max-width: 820px) {

	/* A schermo pieno. dvh segue la barra del browser che appare e scompare
	   su iPhone e Android; vh resta come riserva per i telefoni vecchi. */
	#cr-root .cr-pannello {
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: 100vh;
		max-height: 100dvh;
		border-radius: 0;
		box-shadow: none;
	}

	/* Notch e barra di stato: la testata scende sotto, non ci finisce dentro. */
	#cr-root .cr-testata {
		padding-top: calc(10px + env(safe-area-inset-top));
		padding-left: calc(12px + env(safe-area-inset-left));
		padding-right: calc(12px + env(safe-area-inset-right));
	}

	/* Barra di scrittura sopra la lineetta home dell'iPhone. */
	#cr-root .cr-barra {
		padding-bottom: calc(8px + env(safe-area-inset-bottom));
		padding-left: calc(10px + env(safe-area-inset-left));
		padding-right: calc(10px + env(safe-area-inset-right));
	}

	#cr-root .cr-corpo {
		padding: 12px 10px 8px;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
	}

	/* 16px esatti: sotto questa misura iPhone ingrandisce la pagina da solo
	   appena si tocca il campo, e la chat esce dallo schermo. */
	#cr-root .cr-campo textarea {
		font-size: 16px;
		max-height: 120px;
	}

	#cr-root .cr-msg { max-width: 86%; font-size: 15px; }

	/* Bersagli abbastanza grandi da centrare col pollice. */
	#cr-root .cr-scelte { gap: 8px; padding: 4px 8px 10px; }
	#cr-root .cr-scelte button { padding: 11px 16px; font-size: 15px; min-height: 44px; }
	#cr-root .cr-invia { width: 46px; height: 46px; }
	#cr-root .cr-indietro { padding: 6px; }
	#cr-root .cr-azioni { gap: 18px; }

	#cr-root .cr-richiamo {
		right: 90px;
		bottom: calc(26px + env(safe-area-inset-bottom));
		max-width: 190px;
		font-size: 14px;
		padding: 12px 14px;
	}
	#cr-root .cr-richiamo .cr-freccia { display: none; }
}

/* Telefoni piccoli (iPhone SE e simili). */
@media (max-width: 380px) {
	#cr-root .cr-chi .cr-nome { font-size: 14px; }
	#cr-root .cr-azioni { gap: 14px; }
	#cr-root .cr-avatar, #cr-root .cr-avatar svg { width: 34px; height: 34px; }
	#cr-root .cr-scelte button { font-size: 14px; padding: 10px 13px; }
	#cr-root .cr-richiamo { right: 84px; max-width: 165px; font-size: 13px; }
}

/* Telefono coricato: poco spazio in altezza, si recupera dai margini. */
@media (max-height: 460px) and (orientation: landscape) {
	#cr-root .cr-testata { padding-top: 6px; padding-bottom: 6px; }
	#cr-root .cr-avatar, #cr-root .cr-avatar svg { width: 30px; height: 30px; }
	#cr-root .cr-corpo { padding-top: 8px; }
	#cr-root .cr-msg { margin-bottom: 6px; }
	#cr-root .cr-scelte { padding-bottom: 6px; }
	#cr-root .cr-campo textarea { max-height: 60px; }
}

/* Mentre la chat è aperta la pagina dietro non deve scorrere: su iPhone
   overflow:hidden da solo non basta. */
html.cr-chat-aperta,
body.cr-chat-aperta {
	overflow: hidden !important;
	overscroll-behavior: none;
}

@media (prefers-reduced-motion: reduce) {
	#cr-root * { animation: none !important; transition: none !important; }
}
