/* AI Chatbot KB - stili frontend */
:root {
	--aickb-primary: #2563eb;
	--aickb-btn: #2563eb;
	--aickb-linkbox: #2563eb;
	--aickb-panel-height: 75vh;
	--aickb-mobile-height: 80vh;
	--aickb-icon-size: 60px;
	--aickb-msg-radius: 14px;
	--aickb-msg-tail: 4px;
	--aickb-container-radius: 16px;
}

#aickb-widget {
	position: fixed;
	bottom: var(--aickb-bottom, 20px);
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}
#aickb-widget.aickb-pos-right { right: 20px; left: auto; }
#aickb-widget.aickb-pos-left { left: 20px; right: auto; }

/* Reset per neutralizzare gli stili dei bottoni imposti dal tema del sito */
#aickb-widget button {
	-webkit-appearance: none;
	appearance: none;
	box-shadow: none;
	border: none;
	outline: none;
	margin: 0;
	padding: 0;
	min-width: 0;
	min-height: 0;
	max-width: none;
	width: auto;
	height: auto;
	line-height: 1;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	font-family: inherit;
	box-sizing: border-box;
	background-image: none;
	cursor: pointer;
}
#aickb-widget button svg { display: block; }

/* Bolla di apertura */
#aickb-widget .aickb-toggle {
	width: var(--aickb-icon-size, 60px);
	height: var(--aickb-icon-size, 60px);
	border-radius: 50%;
	background: var(--aickb-btn);
	color: #fff;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform .15s ease;
	position: relative;
	margin-left: auto;
	padding: 0;
}
#aickb-widget .aickb-toggle:hover { transform: scale(1.06); }
#aickb-widget .aickb-toggle .aickb-icon-chat { display: inline-flex; align-items: center; justify-content: center; }
#aickb-widget .aickb-toggle .aickb-icon-close { display: none; }
#aickb-widget.aickb-open .aickb-toggle .aickb-icon-chat { display: none; }
#aickb-widget.aickb-open .aickb-toggle .aickb-icon-close { display: block; }
#aickb-widget .aickb-custom-icon {
	width: 100%;
	height: 100%;
	object-fit: contain;
	border-radius: 50%;
	padding: 8px;
	box-sizing: border-box;
	display: block;
}

/* Fumetto teaser accanto all'icona (quando chiuso) */
.aickb-teaser {
	position: absolute;
	bottom: 12px;
	display: none;
	align-items: center;
	gap: 8px;
	background: #fff;
	color: #1f2937;
	padding: 10px 14px;
	border-radius: 14px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
	font-size: 14px;
	font-weight: 500;
	white-space: nowrap;
	max-width: 240px;
	animation: aickb-fade .25s ease;
}
.aickb-teaser.aickb-teaser-visible { display: inline-flex; }
#aickb-widget.aickb-open .aickb-teaser { display: none !important; }
#aickb-widget.aickb-pos-right .aickb-teaser { right: 72px; }
#aickb-widget.aickb-pos-left .aickb-teaser { left: 72px; }
.aickb-teaser-text { cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.aickb-teaser::after {
	content: "";
	position: absolute;
	bottom: 18px;
	width: 0;
	height: 0;
	border: 7px solid transparent;
}
#aickb-widget.aickb-pos-right .aickb-teaser::after { right: -12px; border-left-color: #fff; }
#aickb-widget.aickb-pos-left .aickb-teaser::after { left: -12px; border-right-color: #fff; }
.aickb-teaser-close {
	background: transparent;
	border: none;
	color: #9ca3af;
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	padding: 0 2px;
	flex: 0 0 auto;
}
.aickb-teaser-close:hover { color: #4b5563; }

/* Pannello */
.aickb-panel {
	position: absolute;
	bottom: calc(var(--aickb-icon-size, 60px) + 14px);
	width: 360px;
	max-width: calc(100vw - 40px);
	height: var(--aickb-panel-height, 75vh);
	max-height: calc(100vh - var(--aickb-icon-size, 60px) - var(--aickb-bottom, 20px) - 24px);
	background: #fff;
	border-radius: var(--aickb-container-radius, 16px);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
	display: none;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px);
	transition: opacity .2s ease, transform .2s ease;
}
#aickb-widget.aickb-pos-right .aickb-panel { right: 0; }
#aickb-widget.aickb-pos-left .aickb-panel { left: 0; }
#aickb-widget.aickb-open .aickb-panel {
	display: flex;
	opacity: 1;
	transform: translateY(0);
}

/* Header */
.aickb-header {
	background: var(--aickb-primary);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
}
.aickb-title { font-weight: 600; font-size: 16px; }
#aickb-widget .aickb-min {
	background: transparent;
	color: #fff;
	font-size: 20px;
	width: 28px;
	height: 28px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: .85;
	flex: 0 0 auto;
}
#aickb-widget .aickb-min:hover { opacity: 1; background: rgba(255, 255, 255, 0.15); }

/* Messaggi */
.aickb-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #f7f8fa;
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.aickb-msg {
	max-width: 82%;
	padding: 10px 13px;
	border-radius: var(--aickb-msg-radius, 14px);
	word-wrap: break-word;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
	animation: aickb-fade .18s ease;
}
.aickb-msg a { color: inherit; text-decoration: underline; font-weight: 600; }
.aickb-msg-bot {
	background: #fff;
	color: #1f2937;
	align-self: flex-start;
	border: 1px solid #e5e7eb;
	border-bottom-left-radius: var(--aickb-msg-tail, 4px);
}
.aickb-msg-note {
	align-self: stretch;
	background: #f0f2f5;
	color: #6b7280;
	font-size: 11.5px;
	line-height: 1.5;
	border: none;
	border-radius: 8px;
	max-width: 100%;
	padding: 8px 11px;
}
.aickb-msg-user {
	background: var(--aickb-primary);
	color: #fff;
	align-self: flex-end;
	border-bottom-right-radius: var(--aickb-msg-tail, 4px);
}
.aickb-src {
	align-self: flex-start;
	font-size: 11px;
	color: #9ca3af;
	margin: -4px 0 2px 4px;
	font-style: italic;
	user-select: none;
}
.aickb-link-cta {
	display: inline-block;
	margin-top: 8px;
	padding: 8px 12px;
	background: var(--aickb-linkbox);
	color: #fff !important;
	border-radius: 8px;
	text-decoration: none !important;
	font-weight: 600;
	font-size: 14px;
}

/* Indicatore "sta scrivendo" */
.aickb-typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
	padding: 12px 14px;
}
.aickb-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9ca3af;
	animation: aickb-bounce 1.2s infinite ease-in-out;
}
.aickb-typing span:nth-child(2) { animation-delay: .2s; }
.aickb-typing span:nth-child(3) { animation-delay: .4s; }

/* Barra input */
.aickb-input-note {
	text-align: center;
	font-size: 11px;
	color: #9ca3af;
	padding: 6px 12px 0;
	background: #fff;
	line-height: 1.4;
}
.aickb-inputbar {
	display: flex;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid #e5e7eb;
	background: #fff;
	flex: 0 0 auto;
	align-items: center;
}
#aickb-input {
	flex: 1 1 auto;
	border: 1px solid #d1d5db;
	border-radius: 22px;
	padding: 10px 14px;
	font-size: 15px;
	outline: none;
	background: #fff;
	color: #1f2937;
	box-shadow: none;
	min-width: 0;
}
#aickb-input:focus { border-color: var(--aickb-primary); }
#aickb-widget .aickb-send {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--aickb-btn);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	padding: 0;
	overflow: visible;
}
#aickb-widget .aickb-send svg {
	width: 20px;
	height: 20px;
	display: block;
	margin: 0;
	position: relative;
	left: -1px;
}
#aickb-widget .aickb-send:disabled { opacity: .5; cursor: default; }

@keyframes aickb-fade {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}
@keyframes aickb-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: .5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

@media (max-width: 600px) {
	/* Usa i valori mobile senza toccare il desktop. */
	#aickb-widget {
		--aickb-icon-size: var(--aickb-icon-size-mobile, 60px);
		--aickb-bottom: var(--aickb-bottom-mobile, 20px);
		bottom: max(12px, var(--aickb-bottom-mobile, 20px));
	}

	/* Lato icona su mobile (indipendente dal desktop). */
	#aickb-widget.aickb-micon-right { right: 14px; left: auto; }
	#aickb-widget.aickb-micon-left { left: 14px; right: auto; }
	#aickb-widget.aickb-micon-right .aickb-teaser { right: calc(var(--aickb-icon-size, 60px) + 12px); left: auto; }
	#aickb-widget.aickb-micon-left .aickb-teaser { left: calc(var(--aickb-icon-size, 60px) + 12px); right: auto; }
	#aickb-widget.aickb-micon-right .aickb-teaser::after { right: -12px; left: auto; border-left-color: #fff; border-right-color: transparent; }
	#aickb-widget.aickb-micon-left .aickb-teaser::after { left: -12px; right: auto; border-right-color: #fff; border-left-color: transparent; }

	.aickb-panel {
		position: fixed;
		bottom: calc(var(--aickb-icon-size, 60px) + var(--aickb-bottom, 20px) + 16px);
		top: auto;
		height: var(--aickb-mobile-height, 80vh);
		/* Non superare mai lo schermo (considera icona, offset e barre di sistema). */
		max-height: calc(100vh - var(--aickb-icon-size, 60px) - var(--aickb-bottom, 20px) - 28px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
	}

	/* A tutta larghezza (default). */
	#aickb-widget.aickb-mpos-full .aickb-panel {
		left: 8px;
		right: 8px;
		width: auto;
		max-width: none;
	}
	/* Ancorato a destra / sinistra con larghezza limitata. */
	#aickb-widget.aickb-mpos-right .aickb-panel {
		right: 8px;
		left: auto;
		width: min(92vw, 380px);
		max-width: 92vw;
	}
	#aickb-widget.aickb-mpos-left .aickb-panel {
		left: 8px;
		right: auto;
		width: min(92vw, 380px);
		max-width: 92vw;
	}
}
