/**
 * Emotta Chat IA — widget flottant
 */

#emotta-chat-widget {
	--emotta-chat-bg: #12121a;
	--emotta-chat-panel: #0f0f14;
	--emotta-chat-border: rgba(255, 255, 255, 0.1);
	--emotta-chat-violet: #7c3aed;
	--emotta-chat-violet-light: #a78bfa;
	--emotta-chat-text: #e5e7eb;
	--emotta-chat-muted: #9ca3af;
	--emotta-chat-invite-bg1: #1c1830;
	--emotta-chat-invite-bg2: #12121c;
	--emotta-chat-invite-tail: #181326;
	/* Marge depuis le bord : évite dépassement + halo violet hors viewport */
	--emotta-chat-inset: max(1rem, env(safe-area-inset-right));
	font-family: 'Inter', system-ui, -apple-system, sans-serif;
	position: fixed;
	z-index: 99990;
	right: var(--emotta-chat-inset);
	bottom: max(1rem, env(safe-area-inset-bottom));
	left: auto;
	/* Pas de 100vw seul (barre de scroll → dépassement / bande). vi = largeur utile ; repli 92vw. */
	max-width: min(24rem, 92vw);
	max-width: min(24rem, calc(100vi - var(--emotta-chat-inset) - max(1rem, env(safe-area-inset-left))));
	width: max-content;
	overflow-x: clip;
	overflow-y: visible;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.75rem;
	pointer-events: none;
}

#emotta-chat-widget .emotta-chat__panel,
#emotta-chat-widget .emotta-chat__launcher {
	pointer-events: auto;
}

#emotta-chat-widget * {
	box-sizing: border-box;
}

/* Rangée : bulle d’invitation à gauche, bouton rond à droite */
.emotta-chat__launcher {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 0.65rem;
	max-width: min(20rem, 100%);
}

.emotta-chat__invite {
	position: relative;
	flex: 1;
	min-width: 0;
	margin: 0;
	padding: 0.7rem 1rem 0.7rem 0.95rem;
	border-radius: 1.05rem;
	border: 1px solid rgba(124, 58, 237, 0.42);
	background: linear-gradient(
		155deg,
		var(--emotta-chat-invite-bg1) 0%,
		var(--emotta-chat-invite-bg2) 48%,
		#0f0e18 100%
	);
	color: #f4f4f8;
	font-family: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: 0.01em;
	text-align: left;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
	cursor: pointer;
	box-shadow:
		0 4px 6px rgba(0, 0, 0, 0.15) inset,
		0 14px 40px rgba(0, 0, 0, 0.55),
		0 0 0 1px rgba(255, 255, 255, 0.06) inset,
		0 0 24px -10px rgba(124, 58, 237, 0.45);
	transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease, color 0.22s ease;
}

/* Accent violet discret en haut de la bulle */
.emotta-chat__invite::before {
	content: '';
	position: absolute;
	left: 0.85rem;
	right: 0.85rem;
	top: 0;
	height: 2px;
	border-radius: 2px;
	background: linear-gradient(
		90deg,
		transparent,
		rgba(167, 139, 250, 0.85) 30%,
		rgba(124, 58, 237, 0.65) 70%,
		transparent
	);
	opacity: 0.95;
	pointer-events: none;
}

.emotta-chat__invite::after {
	content: '';
	position: absolute;
	right: -6px;
	top: 50%;
	width: 11px;
	height: 11px;
	background: var(--emotta-chat-invite-tail);
	border-right: 1px solid rgba(124, 58, 237, 0.38);
	border-top: 1px solid rgba(124, 58, 237, 0.38);
	transform: translateY(-50%) rotate(45deg);
	box-shadow: 2px -2px 8px rgba(124, 58, 237, 0.2);
	pointer-events: none;
}

.emotta-chat__invite:hover {
	transform: translateY(-2px);
	border-color: rgba(167, 139, 250, 0.65);
	color: #fff;
	box-shadow:
		0 4px 8px rgba(0, 0, 0, 0.18) inset,
		0 18px 48px rgba(0, 0, 0, 0.6),
		0 0 0 1px rgba(255, 255, 255, 0.09) inset,
		0 0 28px -8px rgba(124, 58, 237, 0.55);
}

.emotta-chat__invite:active {
	transform: translateY(0);
}

.emotta-chat__invite:focus-visible {
	outline: 2px solid var(--emotta-chat-violet-light);
	outline-offset: 3px;
}

.emotta-chat__toggle-wrap {
	position: relative;
	flex-shrink: 0;
}

.emotta-chat__badge {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 0.65rem;
	height: 0.65rem;
	border-radius: 50%;
	background: linear-gradient(145deg, #fb7185, #e11d48);
	border: 2px solid #1a1528;
	box-shadow:
		0 0 0 1px rgba(255, 255, 255, 0.2),
		0 2px 8px rgba(244, 63, 94, 0.55);
	animation: emotta-chat-badge-pulse 2.2s ease-in-out infinite;
	z-index: 1;
}

#emotta-chat-widget.emotta-chat--teaser-off .emotta-chat__badge,
#emotta-chat-widget.emotta-chat--teaser-off .emotta-chat__invite {
	display: none;
}

@keyframes emotta-chat-badge-pulse {
	0%,
	100% {
		transform: scale(1);
		opacity: 1;
	}
	50% {
		transform: scale(1.15);
		opacity: 0.95;
	}
}

.emotta-chat__toggle {
	width: 3.5rem;
	height: 3.5rem;
	border-radius: 50%;
	border: 1px solid rgba(124, 58, 237, 0.45);
	background: linear-gradient(135deg, #7c3aed, #5b21b6);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 12px 32px -8px rgba(124, 58, 237, 0.55);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.emotta-chat__toggle:hover {
	transform: translateY(-2px);
	box-shadow: 0 16px 40px -8px rgba(124, 58, 237, 0.65);
}

.emotta-chat__toggle:focus-visible {
	outline: 2px solid var(--emotta-chat-violet-light);
	outline-offset: 3px;
}

.emotta-chat__toggle svg {
	width: 1.5rem;
	height: 1.5rem;
}

.emotta-chat__panel {
	width: min(22rem, 100%);
	max-height: min(32rem, 70vh);
	max-width: 100%;
	display: none;
	flex-direction: column;
	border-radius: 1rem;
	border: 1px solid var(--emotta-chat-border);
	background: var(--emotta-chat-panel);
	box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
	overflow: hidden;
}

#emotta-chat-widget.is-open .emotta-chat__panel {
	display: flex;
}

#emotta-chat-widget.is-open .emotta-chat__launcher {
	display: none;
}

.emotta-chat__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.85rem 1rem;
	background: rgba(124, 58, 237, 0.12);
	border-bottom: 1px solid var(--emotta-chat-border);
}

.emotta-chat__title {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 600;
	color: #fff;
}

.emotta-chat__close {
	border: none;
	background: rgba(255, 255, 255, 0.08);
	color: var(--emotta-chat-text);
	width: 2rem;
	height: 2rem;
	border-radius: 0.5rem;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

.emotta-chat__close:hover {
	background: rgba(255, 255, 255, 0.14);
	color: #fff;
}

.emotta-chat__messages {
	flex: 1;
	overflow-y: auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.65rem;
	min-height: 10rem;
	max-height: 18rem;
}

.emotta-chat__msg {
	max-width: 92%;
	padding: 0.55rem 0.75rem;
	border-radius: 0.65rem;
	font-size: 0.875rem;
	line-height: 1.5;
	white-space: pre-wrap;
	word-break: break-word;
}

.emotta-chat__msg--user {
	align-self: flex-end;
	background: rgba(124, 58, 237, 0.25);
	color: #f3f4f6;
	border: 1px solid rgba(124, 58, 237, 0.35);
}

.emotta-chat__msg--bot {
	align-self: flex-start;
	background: rgba(255, 255, 255, 0.05);
	color: var(--emotta-chat-text);
	border: 1px solid var(--emotta-chat-border);
}

.emotta-chat__msg--error {
	align-self: stretch;
	background: rgba(239, 68, 68, 0.12);
	color: #fecaca;
	border: 1px solid rgba(239, 68, 68, 0.25);
	font-size: 0.8125rem;
}

.emotta-chat__msg--loading {
	align-self: flex-start;
	color: var(--emotta-chat-muted);
	font-style: italic;
	font-size: 0.8125rem;
}

.emotta-chat__footer-note {
	padding: 0 1rem 0.5rem;
	font-size: 0.65rem;
	line-height: 1.45;
	color: var(--emotta-chat-muted);
	text-align: center;
}

.emotta-chat__footer-note a {
	color: var(--emotta-chat-violet-light);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.emotta-chat__footer-note a:hover {
	color: #fff;
}

.emotta-chat__form {
	display: flex;
	gap: 0.5rem;
	padding: 0.75rem;
	border-top: 1px solid var(--emotta-chat-border);
	background: var(--emotta-chat-bg);
}

.emotta-chat__input {
	flex: 1;
	border: 1px solid var(--emotta-chat-border);
	border-radius: 0.5rem;
	background: rgba(255, 255, 255, 0.04);
	color: #fff;
	padding: 0.5rem 0.65rem;
	font-size: 0.875rem;
	font-family: inherit;
	resize: none;
	min-height: 2.5rem;
	max-height: 6rem;
}

.emotta-chat__input::placeholder {
	color: #6b7280;
}

.emotta-chat__input:focus {
	outline: none;
	border-color: rgba(167, 139, 250, 0.45);
	box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.emotta-chat__send {
	flex-shrink: 0;
	border: none;
	border-radius: 0.5rem;
	background: var(--emotta-chat-violet);
	color: #fff;
	font-weight: 600;
	font-size: 0.8125rem;
	padding: 0 0.85rem;
	cursor: pointer;
	transition: background 0.2s;
}

.emotta-chat__send:hover:not(:disabled) {
	background: #6d28d9;
}

.emotta-chat__send:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
	.emotta-chat__toggle {
		transition: none;
	}
	.emotta-chat__badge {
		animation: none;
	}
}
