/**
 * Nova Lab Chat — widget flottante.
 * Tutte le regole sono agganciate a #novalab-chat-root: l'id vince sui CSS
 * del tema e di Elementor, che altrimenti gonfiano font e spaziature.
 * Le variabili sono iniettate da PHP (wp_add_inline_style).
 */

#novalab-chat-root {
	--nlc-dark: #0A0A0A;
	--nlc-accent: #E8540C;
	--nlc-bot-bg: #161616;
	--nlc-bot-text: #F5F2EB;
	--nlc-panel-bg: #0F0F0F;
	--nlc-radius: 14px;
	--nlc-font: 'DM Sans', sans-serif;
	--nlc-bottom: 96px;
	--nlc-side: 20px;
	--nlc-z: 2147483000;

	position: fixed;
	bottom: var(--nlc-bottom);
	z-index: var(--nlc-z);
	font-family: var(--nlc-font);
	font-size: 15px;
	line-height: 1.45;
}

/* Reset difensivo: il tema non deve poter cambiare tipografia dentro al widget. */
#novalab-chat-root,
#novalab-chat-root * {
	box-sizing: border-box;
	font-family: var(--nlc-font);
	font-style: normal;
	letter-spacing: normal;
	text-transform: none;
	margin: 0;
	padding: 0;
	max-width: none;
	min-width: 0;
	float: none;
	text-shadow: none;
}

#novalab-chat-root.nlc-pos-left { left: var(--nlc-side); }
#novalab-chat-root.nlc-pos-right { right: var(--nlc-side); }

/* ---------------------------------------------------------------- Pulsante */

#novalab-chat-root .nlc-toggle {
	width: 58px;
	height: 58px;
	border-radius: 50%;
	background: var(--nlc-dark);
	border: 2px solid var(--nlc-accent);
	color: var(--nlc-bot-text);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
	transition: transform .18s ease, box-shadow .18s ease;
}

#novalab-chat-root .nlc-toggle:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0, 0, 0, .34); }
#novalab-chat-root .nlc-toggle:focus-visible { outline: 2px solid var(--nlc-accent); outline-offset: 3px; }
#novalab-chat-root .nlc-toggle svg { width: 28px; height: 28px; display: block; }
#novalab-chat-root.is-open .nlc-toggle { border-color: rgba(232, 84, 12, .55); }

/* ----------------------------------------------------------------- Pannello */

#novalab-chat-root .nlc-panel {
	position: absolute;
	bottom: 72px;
	width: 360px;
	max-height: min(560px, calc(100vh - var(--nlc-bottom) - 110px));
	display: none;
	flex-direction: column;
	overflow: hidden;
	background: var(--nlc-panel-bg);
	border: 1px solid rgba(245, 242, 235, .12);
	border-radius: var(--nlc-radius);
	box-shadow: 0 18px 48px rgba(0, 0, 0, .38);
}

#novalab-chat-root.nlc-pos-left .nlc-panel { left: 0; }
#novalab-chat-root.nlc-pos-right .nlc-panel { right: 0; }
#novalab-chat-root.is-open .nlc-panel { display: flex; animation: nlc-in .18s ease both; }

@keyframes nlc-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ Header */

#novalab-chat-root .nlc-header {
	background: var(--nlc-dark);
	color: var(--nlc-bot-text);
	padding: 12px 10px 12px 16px;
	display: flex;
	align-items: center;
	gap: 8px;
	border-bottom: 1px solid rgba(245, 242, 235, .08);
	flex: 0 0 auto;
}

#novalab-chat-root .nlc-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--nlc-accent);
	flex: 0 0 auto;
}

#novalab-chat-root .nlc-title {
	font-size: 13px;
	font-weight: 600;
	line-height: 1.2;
	color: rgba(245, 242, 235, .72);
}

#novalab-chat-root .nlc-close {
	margin-left: auto;
	width: 28px;
	height: 28px;
	border: none;
	background: transparent;
	color: rgba(245, 242, 235, .5);
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
}

#novalab-chat-root .nlc-close:hover { color: var(--nlc-bot-text); background: rgba(245, 242, 235, .08); }
#novalab-chat-root .nlc-close svg { width: 15px; height: 15px; display: block; }

/* ---------------------------------------------------------------- Messaggi */

#novalab-chat-root .nlc-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--nlc-panel-bg);
	overscroll-behavior: contain;
}

#novalab-chat-root .nlc-msg {
	max-width: 84%;
	padding: 10px 13px;
	border-radius: var(--nlc-radius);
	word-wrap: break-word;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
	font-size: 14.5px;
	line-height: 1.45;
	font-weight: 400;
}

#novalab-chat-root .nlc-msg-bot {
	align-self: flex-start;
	background: var(--nlc-bot-bg);
	color: var(--nlc-bot-text);
	border-bottom-left-radius: 4px;
}

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

#novalab-chat-root .nlc-msg-error {
	align-self: flex-start;
	background: rgba(232, 84, 12, .12);
	color: var(--nlc-bot-text);
	border: 1px solid rgba(232, 84, 12, .4);
	border-bottom-left-radius: 4px;
}

#novalab-chat-root .nlc-msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
#novalab-chat-root .nlc-msg-bot a { color: var(--nlc-accent); }

/* --------------------------------------------------------- Sta scrivendo */

#novalab-chat-root .nlc-typing { display: flex; gap: 4px; align-items: center; padding: 13px; }
#novalab-chat-root .nlc-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--nlc-bot-text);
	opacity: .35;
	animation: nlc-blink 1.2s infinite ease-in-out;
}
#novalab-chat-root .nlc-typing span:nth-child(2) { animation-delay: .18s; }
#novalab-chat-root .nlc-typing span:nth-child(3) { animation-delay: .36s; }

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

/* ------------------------------------------------------------------ Input */

#novalab-chat-root .nlc-form {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid rgba(245, 242, 235, .1);
	background: var(--nlc-dark);
	flex: 0 0 auto;
}

#novalab-chat-root .nlc-input {
	flex: 1 1 auto;
	resize: none;
	max-height: 96px;
	padding: 10px 12px;
	border-radius: 10px;
	border: 1px solid rgba(245, 242, 235, .16);
	background: var(--nlc-bot-bg);
	color: var(--nlc-bot-text);
	font-size: 14.5px;
	line-height: 1.4;
	box-shadow: none;
}

#novalab-chat-root .nlc-input::placeholder { color: rgba(245, 242, 235, .42); }
#novalab-chat-root .nlc-input:focus { outline: none; border-color: var(--nlc-accent); box-shadow: none; }

#novalab-chat-root .nlc-send {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	align-self: flex-end;
	border: none;
	border-radius: 10px;
	background: var(--nlc-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity .15s ease;
}

#novalab-chat-root .nlc-send:disabled { opacity: .45; cursor: default; }
#novalab-chat-root .nlc-send svg { width: 18px; height: 18px; display: block; }

/* ----------------------------------------------------------------- Footer */

#novalab-chat-root .nlc-footer {
	padding: 8px 14px 11px;
	background: var(--nlc-dark);
	color: rgba(245, 242, 235, .42);
	font-size: 11px;
	line-height: 1.35;
	text-align: center;
	flex: 0 0 auto;
}

#novalab-chat-root .nlc-footer a { color: rgba(245, 242, 235, .62); text-decoration: underline; }

/* ------------------------------------------------------------------ Mobile */

@media (max-width: 480px) {
	#novalab-chat-root { bottom: calc(var(--nlc-bottom) - 12px); }

	#novalab-chat-root .nlc-panel {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		max-height: 82vh;
		height: 82vh;
		border-radius: var(--nlc-radius) var(--nlc-radius) 0 0;
		border-left: none;
		border-right: none;
		border-bottom: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	#novalab-chat-root.is-open .nlc-panel { animation: none; }
	#novalab-chat-root .nlc-toggle { transition: none; }
	#novalab-chat-root .nlc-typing span { animation-duration: 2.4s; }
}
