/**
 * AI Sales Assistant — widget frontend.
 * Nessuna dipendenza esterna, nessun webfont: il widget non deve costare
 * millisecondi alla pagina che lo ospita.
 */

#aisa-root {
	--aisa-accent: #1f6f5c;
	--aisa-accent-soft: #e8f2ee;
	--aisa-surface: #ffffff;
	--aisa-surface-2: #f6f7f8;
	--aisa-text: #1b1f23;
	--aisa-text-soft: #5c6670;
	--aisa-border: #e3e7ea;
	--aisa-shadow: 0 18px 48px -12px rgba(16, 24, 32, .28);
	--aisa-radius: 18px;

	position: fixed;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: var(--aisa-text);
}

#aisa-root[data-theme="dark"],
#aisa-root.aisa-dark {
	--aisa-surface: #16191d;
	--aisa-surface-2: #1e2228;
	--aisa-text: #eef1f4;
	--aisa-text-soft: #9aa5b1;
	--aisa-border: #2a2f36;
	--aisa-shadow: 0 18px 48px -12px rgba(0, 0, 0, .6);
}

#aisa-root[data-position="bottom-right"] { right: 20px; bottom: 20px; }
#aisa-root[data-position="bottom-left"] { left: 20px; bottom: 20px; }

/* --- Bolla di apertura --- */

.aisa-bubble {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 18px 12px 14px;
	border: 0;
	border-radius: 999px;
	background: var(--aisa-accent);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	box-shadow: var(--aisa-shadow);
	transition: transform .22s cubic-bezier(.2, .9, .3, 1), box-shadow .22s ease;
}

.aisa-bubble:hover { transform: translateY(-2px); }
.aisa-bubble:focus-visible { outline: 3px solid var(--aisa-accent); outline-offset: 3px; }
.aisa-bubble svg { width: 22px; height: 22px; flex: none; }
.aisa-bubble[hidden] { display: none; }

/* --- Pannello --- */

.aisa-panel {
	display: flex;
	flex-direction: column;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 100px);
	background: var(--aisa-surface);
	border: 1px solid var(--aisa-border);
	border-radius: var(--aisa-radius);
	box-shadow: var(--aisa-shadow);
	overflow: hidden;
	transform-origin: bottom right;
	animation: aisa-in .28s cubic-bezier(.2, .9, .3, 1);
}

#aisa-root[data-position="bottom-left"] .aisa-panel { transform-origin: bottom left; }
.aisa-panel[hidden] { display: none; }

@keyframes aisa-in {
	from { opacity: 0; transform: translateY(12px) scale(.97); }
	to { opacity: 1; transform: none; }
}

.aisa-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--aisa-border);
	background: var(--aisa-surface);
}

.aisa-avatar {
	width: 38px;
	height: 38px;
	flex: none;
	border-radius: 50%;
	background: var(--aisa-accent-soft);
	color: var(--aisa-accent);
	display: grid;
	place-items: center;
	font-weight: 700;
	overflow: hidden;
}

.aisa-avatar img { width: 100%; height: 100%; object-fit: cover; }

.aisa-identity { flex: 1; min-width: 0; }
.aisa-identity strong { display: block; font-size: 15px; }

.aisa-identity span {
	display: block;
	font-size: 12px;
	color: var(--aisa-text-soft);
}

.aisa-icon-btn {
	width: 32px;
	height: 32px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--aisa-text-soft);
	cursor: pointer;
}

.aisa-icon-btn:hover { background: var(--aisa-surface-2); color: var(--aisa-text); }
.aisa-icon-btn:focus-visible { outline: 2px solid var(--aisa-accent); outline-offset: 2px; }

.aisa-log {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
}

.aisa-msg { max-width: 86%; display: flex; flex-direction: column; gap: 4px; }
.aisa-msg[data-role="user"] { align-self: flex-end; align-items: flex-end; }

.aisa-msg .aisa-body {
	padding: 10px 14px;
	border-radius: 16px;
	background: var(--aisa-surface-2);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.aisa-msg[data-role="user"] .aisa-body {
	background: var(--aisa-accent);
	color: #fff;
	border-bottom-right-radius: 6px;
}

.aisa-msg[data-role="assistant"] .aisa-body { border-bottom-left-radius: 6px; }

.aisa-time { font-size: 11px; color: var(--aisa-text-soft); padding: 0 6px; }

.aisa-note {
	font-size: 12px;
	color: var(--aisa-text-soft);
	text-align: center;
	padding: 4px 12px;
}

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

.aisa-typing i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aisa-text-soft);
	animation: aisa-blink 1.2s infinite ease-in-out;
}

.aisa-typing i:nth-child(2) { animation-delay: .18s; }
.aisa-typing i:nth-child(3) { animation-delay: .36s; }

@keyframes aisa-blink {
	0%, 60%, 100% { opacity: .25; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-3px); }
}

.aisa-cta {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 6px;
	padding: 10px 16px;
	border-radius: 10px;
	background: var(--aisa-accent);
	color: #fff;
	font-weight: 600;
	font-size: 14px;
	text-decoration: none;
	align-self: flex-start;
}

.aisa-cta:hover { filter: brightness(1.06); color: #fff; }

.aisa-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }

.aisa-chip {
	padding: 8px 14px;
	border: 1px solid var(--aisa-border);
	border-radius: 999px;
	background: var(--aisa-surface);
	color: var(--aisa-text);
	font: inherit;
	font-size: 13px;
	cursor: pointer;
	transition: border-color .18s ease, background .18s ease;
}

.aisa-chip:hover { border-color: var(--aisa-accent); background: var(--aisa-accent-soft); }

.aisa-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 12px 10px;
	border-top: 1px solid var(--aisa-border);
}

.aisa-form textarea {
	flex: 1;
	resize: none;
	max-height: 110px;
	padding: 10px 12px;
	border: 1px solid var(--aisa-border);
	border-radius: 12px;
	background: var(--aisa-surface);
	color: var(--aisa-text);
	font: inherit;
	line-height: 1.45;
}

.aisa-form textarea:focus { outline: 2px solid var(--aisa-accent); outline-offset: -1px; }

.aisa-send {
	width: 40px;
	height: 40px;
	flex: none;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 12px;
	background: var(--aisa-accent);
	color: #fff;
	cursor: pointer;
}

.aisa-send[disabled] { opacity: .45; cursor: not-allowed; }

.aisa-disclosure {
	padding: 0 16px 12px;
	font-size: 11px;
	color: var(--aisa-text-soft);
	text-align: center;
}

.aisa-consent { padding: 24px 20px; display: flex; flex-direction: column; gap: 14px; }
.aisa-consent p { margin: 0; font-size: 14px; color: var(--aisa-text-soft); }

.aisa-consent button {
	padding: 11px 18px;
	border: 0;
	border-radius: 12px;
	background: var(--aisa-accent);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.aisa-feedback { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 4px 0 8px; font-size: 12px; color: var(--aisa-text-soft); }

.aisa-feedback button {
	padding: 4px 12px;
	border: 1px solid var(--aisa-border);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

@media (max-width: 480px) {
	#aisa-root[data-position] { left: 12px; right: 12px; bottom: 12px; }
	.aisa-panel { width: 100%; height: min(78vh, 620px); }
	.aisa-bubble { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
	.aisa-panel, .aisa-bubble { animation: none; transition: none; }
	.aisa-typing i { animation: none; opacity: .6; }
	.aisa-log { scroll-behavior: auto; }
}
