/* AgriMag AI Advisor - widget chat frontend */

#aaa-widget-root {
	--aaa-accent: #0c71c3;
	--aaa-accent-dark: #095a9c;
	position: fixed;
	bottom: 20px;
	right: 20px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Posizione a sinistra */
#aaa-widget-root.aaa-pos-left {
	right: auto;
	left: 20px;
}

#aaa-widget-root.aaa-pos-left .aaa-panel {
	right: auto;
	left: 0;
}

.aaa-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--aaa-accent);
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease, background 0.15s ease;
}

.aaa-launcher:hover {
	transform: scale(1.06);
	background: var(--aaa-accent-dark);
}

.aaa-launcher svg {
	width: 30px;
	height: 30px;
	fill: #fff;
}

/* Fumetto d'invito (teaser) */
.aaa-teaser {
	position: absolute;
	bottom: 78px;
	left: 0;
	width: max-content;
	max-width: 240px;
	background: #fff;
	color: #1d2b1a;
	border: 1px solid #e6e8e6;
	border-radius: 14px;
	border-bottom-left-radius: 4px;
	box-shadow: 0 6px 22px rgba(0, 0, 0, 0.18);
	padding: 12px 34px 12px 14px;
	font-size: 14px;
	line-height: 1.4;
	cursor: pointer;
	display: none;
	animation: aaa-teaser-in 0.3s ease;
}

.aaa-teaser.aaa-show {
	display: block;
}

/* Posizione a destra: il fumetto si allinea a destra */
#aaa-widget-root:not(.aaa-pos-left) .aaa-teaser {
	left: auto;
	right: 0;
	border-bottom-left-radius: 14px;
	border-bottom-right-radius: 4px;
}

.aaa-teaser-close {
	position: absolute;
	top: 3px;
	right: 6px;
	background: none;
	border: none;
	font-size: 18px;
	line-height: 1;
	color: #9aa199;
	cursor: pointer;
	padding: 2px 4px;
}

.aaa-teaser-close:hover {
	color: #5a625a;
}

@keyframes aaa-teaser-in {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: none; }
}

.aaa-panel {
	position: absolute;
	bottom: 76px;
	right: 0;
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 540px;
	max-height: calc(100vh - 120px);
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
	display: none;
	flex-direction: column;
	overflow: hidden;
}

.aaa-panel.aaa-open {
	display: flex;
}

.aaa-header {
	background: var(--aaa-accent);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.aaa-header-title {
	font-weight: 600;
	font-size: 15px;
	display: flex;
	align-items: center;
	gap: 8px;
}

.aaa-header-title .aaa-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #7CFC00;
	display: inline-block;
}

.aaa-close {
	background: none;
	border: none;
	color: #fff;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	opacity: 0.9;
}

.aaa-close:hover { opacity: 1; }

.aaa-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	background: #f7f8f7;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.aaa-msg {
	max-width: 85%;
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.45;
	word-wrap: break-word;
	white-space: pre-wrap;
}

.aaa-msg a {
	color: var(--aaa-accent-dark);
	text-decoration: underline;
	word-break: break-all;
}

.aaa-msg-bot {
	background: #fff;
	color: #1d2b1a;
	align-self: flex-start;
	border: 1px solid #e6e8e6;
	border-bottom-left-radius: 4px;
}

.aaa-msg-user {
	background: var(--aaa-accent);
	color: #fff;
	align-self: flex-end;
	border-bottom-right-radius: 4px;
}

.aaa-msg-user a { color: #fff; }

.aaa-typing {
	display: flex;
	gap: 4px;
	padding: 12px 14px;
}

.aaa-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #b7bdb5;
	animation: aaa-blink 1.2s infinite both;
}

.aaa-typing span:nth-child(2) { animation-delay: 0.2s; }
.aaa-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aaa-blink {
	0%, 80%, 100% { opacity: 0.3; }
	40% { opacity: 1; }
}

.aaa-input-bar {
	display: flex;
	padding: 10px;
	gap: 8px;
	border-top: 1px solid #e6e8e6;
	background: #fff;
}

.aaa-input-bar textarea {
	flex: 1;
	resize: none;
	border: 1px solid #d5d9d4;
	border-radius: 10px;
	padding: 9px 11px;
	font-size: 14px;
	font-family: inherit;
	max-height: 90px;
	line-height: 1.4;
	outline: none;
}

.aaa-input-bar textarea:focus {
	border-color: var(--aaa-accent);
}

.aaa-send {
	background: var(--aaa-accent);
	border: none;
	border-radius: 10px;
	color: #fff;
	width: 42px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.aaa-send:hover { background: var(--aaa-accent-dark); }
.aaa-send:disabled { opacity: 0.5; cursor: not-allowed; }
.aaa-send svg { width: 20px; height: 20px; fill: #fff; }

.aaa-footer-note {
	font-size: 11px;
	color: #9aa199;
	text-align: center;
	padding: 4px 10px 8px;
	background: #fff;
}

.aaa-msg strong {
	font-weight: 700;
}

/* --- Mobile: pannello a schermo intero --- */
@media (max-width: 600px) {
	#aaa-widget-root .aaa-panel,
	#aaa-widget-root.aaa-pos-left .aaa-panel {
		position: fixed !important;
		top: 0 !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		width: 100% !important;
		height: 100vh !important;
		height: 100dvh !important;
		height: 100svh !important; /* altezza reale visibile (barra browser inclusa) */
		max-width: 100% !important;
		max-height: 100vh !important;
		max-height: 100svh !important;
		border-radius: 0 !important;
		margin: 0 !important;
	}

	/* Header un filo più alto e comodo da chiudere col pollice */
	#aaa-widget-root .aaa-header {
		padding: 16px;
	}

	#aaa-widget-root .aaa-close {
		font-size: 28px;
		padding: 0 6px;
	}
}

/* Pulsante "Parla con un operatore" su WhatsApp (link wa.me nei messaggi) */
.aaa-wa-btn{display:inline-flex;align-items:center;gap:.5em;margin-top:.45em;padding:.55em .95em;background:#25d366;color:#fff !important;border-radius:999px;text-decoration:none !important;font-weight:600;font-size:.95em;line-height:1;box-shadow:0 2px 6px rgba(37,211,102,.35)}
.aaa-wa-btn:hover{background:#1ebe5d;color:#fff !important}
.aaa-wa-btn svg{flex:0 0 auto}
