/* =============================================================
   Chat Hybride Orchidée — Widget de chat public
   La couleur principale est injectée dynamiquement via :
   :root { --cho-color: #6c5ce7; }
   ============================================================= */

/* ---------------------------------------------------------------
   Variables locales (fallback si --cho-color n'est pas défini)
--------------------------------------------------------------- */
:root {
	--cho-color: #6c5ce7;
	--cho-color-light: rgba(108, 92, 231, 0.12);
	--cho-radius: 16px;
	--cho-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
	--cho-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	--cho-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------------------------------------------------------------
   Conteneur principal (fixé en bas à droite)
--------------------------------------------------------------- */
#cho-wrapper {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 999999;
	font-family: var(--cho-font);
	font-size: 14px;
	line-height: 1.5;
	box-sizing: border-box;
	/* Flex row : bulle à gauche, bouton à droite */
	display: flex;
	flex-direction: row;
	align-items: flex-end;
}

/* ---------------------------------------------------------------
   Bouton flottant (rond, coloré)
--------------------------------------------------------------- */
#cho-toggle-btn {
	all: unset;
	cursor: pointer;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--cho-color);
	color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--cho-shadow);
	transition: transform var(--cho-transition), box-shadow var(--cho-transition);
	position: relative;
	z-index: 1;
}
#cho-toggle-btn:hover {
	transform: scale(1.08);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
}
#cho-toggle-btn:active {
	transform: scale(0.96);
}
#cho-toggle-btn svg {
	pointer-events: none;
	display: block;
}

/* ---------------------------------------------------------------
   Fenêtre de chat
--------------------------------------------------------------- */
#cho-window {
	position: absolute;
	bottom: 70px;
	right: 0;
	width: 360px;
	max-height: 580px;
	background: #fff;
	border-radius: var(--cho-radius);
	box-shadow: var(--cho-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	/* Animation d'ouverture */
	transform: scale(0.95) translateY(10px);
	opacity: 0;
	pointer-events: none;
	transition: transform var(--cho-transition), opacity var(--cho-transition);
	transform-origin: bottom right;
}

/* État ouvert */
#cho-window.cho-open {
	transform: scale(1) translateY(0);
	opacity: 1;
	pointer-events: all;
}

/* ---------------------------------------------------------------
   En-tête du chat
--------------------------------------------------------------- */
#cho-header {
	background: var(--cho-color);
	color: white;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}
#cho-header-info {
	display: flex;
	flex-direction: column;
}
#cho-header-title {
	font-weight: 600;
	font-size: 15px;
}
#cho-header-subtitle {
	font-size: 11px;
	opacity: 0.8;
	margin-top: 2px;
}
#cho-close-btn {
	all: unset;
	cursor: pointer;
	color: white;
	opacity: 0.8;
	font-size: 18px;
	line-height: 1;
	padding: 4px;
	border-radius: 50%;
	transition: opacity 0.2s, background 0.2s;
}
#cho-close-btn:hover {
	opacity: 1;
	background: rgba(255,255,255,0.15);
}

/* ---------------------------------------------------------------
   Zone des messages (scrollable)
--------------------------------------------------------------- */
#cho-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 12px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}
#cho-messages::-webkit-scrollbar {
	width: 4px;
}
#cho-messages::-webkit-scrollbar-track {
	background: #f1f1f1;
}
#cho-messages::-webkit-scrollbar-thumb {
	background: #ccc;
	border-radius: 4px;
}

/* ---------------------------------------------------------------
   Bulles de messages
--------------------------------------------------------------- */
.cho-message {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 14px;
	line-height: 1.5;
	word-wrap: break-word;
	white-space: pre-line;
	animation: cho-fade-in 0.2s ease;
}

/* Message du visiteur (droite, couleur principale) */
.cho-message--user {
	align-self: flex-end;
	background: var(--cho-color);
	color: white;
	border-bottom-right-radius: 6px;
}

/* Message du bot (gauche, gris clair) */
.cho-message--assistant {
	align-self: flex-start;
	background: #f1f0f5;
	color: #333;
	border-bottom-left-radius: 6px;
}

/* Message système / notification */
.cho-message--system {
	align-self: center;
	background: #fff9e6;
	color: #856404;
	border: 1px solid #ffd466;
	font-size: 12px;
	text-align: center;
	border-radius: 8px;
	padding: 8px 14px;
	max-width: 90%;
}

/* Animation d'apparition des messages */
@keyframes cho-fade-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------
   Indicateur "le bot écrit..." (trois points animés)
--------------------------------------------------------------- */
#cho-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 6px 16px;
	flex-shrink: 0;
}
#cho-typing span {
	width: 7px;
	height: 7px;
	background: var(--cho-color);
	border-radius: 50%;
	opacity: 0.5;
	animation: cho-bounce 1.2s infinite ease-in-out;
}
#cho-typing span:nth-child(1) { animation-delay: 0s; }
#cho-typing span:nth-child(2) { animation-delay: 0.15s; }
#cho-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cho-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------------------------------------------------------------
   Barre "Parler à un humain"
--------------------------------------------------------------- */
#cho-human-bar {
	padding: 8px 12px;
	background: #fafafa;
	border-top: 1px solid #f0f0f0;
	flex-shrink: 0;
}
#cho-human-btn {
	all: unset;
	cursor: pointer;
	font-size: 12px;
	color: var(--cho-color);
	font-weight: 500;
	padding: 5px 10px;
	border: 1px solid var(--cho-color);
	border-radius: 20px;
	transition: background 0.2s, color 0.2s;
	display: inline-block;
}
#cho-human-btn:hover {
	background: var(--cho-color);
	color: white;
}
#cho-human-btn:disabled {
	opacity: 0.5;
	cursor: default;
	pointer-events: none;
}

/* ---------------------------------------------------------------
   Formulaire de contact humain
--------------------------------------------------------------- */
#cho-human-form {
	padding: 14px 12px;
	background: #fafafa;
	border-top: 1px solid #f0f0f0;
	flex-shrink: 0;
}
#cho-human-form-title {
	font-size: 12px;
	color: #555;
	margin: 0 0 10px;
}
#cho-human-email,
#cho-human-message {
	all: unset;
	width: 100%;
	box-sizing: border-box;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 13px;
	font-family: var(--cho-font);
	color: #333;
	background: white;
	margin-bottom: 8px;
	display: block;
	transition: border-color 0.2s;
}
#cho-human-email:focus,
#cho-human-message:focus {
	border-color: var(--cho-color);
	outline: 2px solid var(--cho-color-light);
}
#cho-human-message {
	resize: vertical;
	min-height: 60px;
}
#cho-human-form-buttons {
	display: flex;
	gap: 8px;
}
#cho-human-submit-btn {
	all: unset;
	cursor: pointer;
	background: var(--cho-color);
	color: white;
	padding: 7px 14px;
	border-radius: 8px;
	font-size: 12px;
	font-weight: 500;
	transition: opacity 0.2s;
	flex: 1;
	text-align: center;
}
#cho-human-submit-btn:hover { opacity: 0.88; }
#cho-human-cancel-btn {
	all: unset;
	cursor: pointer;
	color: #888;
	padding: 7px 12px;
	font-size: 12px;
	transition: color 0.2s;
}
#cho-human-cancel-btn:hover { color: #333; }

/* ---------------------------------------------------------------
   Zone de saisie
--------------------------------------------------------------- */
#cho-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #f0f0f0;
	background: white;
	flex-shrink: 0;
}
#cho-input {
	all: unset;
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 20px;
	padding: 9px 14px;
	font-size: 14px;
	font-family: var(--cho-font);
	color: #333;
	background: white;
	resize: none;
	max-height: 100px;
	overflow-y: auto;
	line-height: 1.4;
	transition: border-color 0.2s;
	display: block;
	box-sizing: border-box;
}
#cho-input:focus {
	border-color: var(--cho-color);
	outline: 2px solid var(--cho-color-light);
}
#cho-input:disabled {
	background: #f5f5f5;
	color: #aaa;
}
#cho-send-btn {
	all: unset;
	cursor: pointer;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--cho-color);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: opacity 0.2s, transform 0.1s;
}
#cho-send-btn:hover { opacity: 0.88; }
#cho-send-btn:active { transform: scale(0.94); }
#cho-send-btn:disabled {
	opacity: 0.4;
	cursor: default;
	pointer-events: none;
}

/* ---------------------------------------------------------------
   Responsive : mobile (écrans < 420px)
--------------------------------------------------------------- */
@media (max-width: 420px) {
	#cho-wrapper {
		bottom: 16px;
		right: 16px;
	}
	#cho-window {
		width: calc(100vw - 32px);
		max-height: 70vh;
		right: 0;
		bottom: 66px;
	}
}

/* ---------------------------------------------------------------
   Bulle d'accroche (Teaser)
   Positionnée à gauche du bouton sur desktop,
   au-dessus du bouton sur mobile.
--------------------------------------------------------------- */

/* État initial masqué — géré par JS qui met display:flex puis ajoute la classe visible */
#cho-teaser {
	display: none;
	align-items: flex-start;
	gap: 0;
	position: relative;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 4px 18px rgba(0, 0, 0, 0.13);
	padding: 12px 36px 12px 14px; /* padding-right laisse la place au bouton X */
	max-width: 280px;
	margin-right: 12px;
	cursor: pointer;
	/* État initial de l'animation : invisible et légèrement décalé à droite */
	opacity: 0;
	transform: translateX(12px);
	transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.2s;
}

/* État visible : déclenché par JS via classList.add('cho-teaser-visible') */
#cho-teaser.cho-teaser-visible {
	opacity: 1;
	transform: translateX(0);
}

#cho-teaser:hover {
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

/* Queue de bulle pointant vers le bouton (triangle à droite) */
#cho-teaser::after {
	content: '';
	position: absolute;
	right: -8px;
	bottom: 18px;
	width: 0;
	height: 0;
	border-top: 8px solid transparent;
	border-bottom: 8px solid transparent;
	border-left: 8px solid #fff;
	/* Petite ombre sur le triangle pour cohérence visuelle */
	filter: drop-shadow(2px 0 2px rgba(0,0,0,0.06));
}

/* Texte du message */
#cho-teaser-text {
	margin: 0;
	font-size: 14px;
	color: #333;
	line-height: 1.45;
	pointer-events: none; /* Le clic remonte au parent #cho-teaser */
}

/* Bouton fermer (X) */
#cho-teaser-close {
	all: unset;
	position: absolute;
	top: 7px;
	right: 8px;
	width: 20px;
	height: 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	color: #bbb;
	border-radius: 50%;
	cursor: pointer;
	transition: color 0.2s, background 0.2s;
	line-height: 1;
}
#cho-teaser-close:hover {
	color: #555;
	background: #f0f0f0;
}

/* ---------------------------------------------------------------
   Animation de pulsation sur le bouton flottant
   (3 secondes après l'apparition de la bulle)
--------------------------------------------------------------- */
@keyframes cho-pulse {
	0%   { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.45), var(--cho-shadow); }
	60%  { box-shadow: 0 0 0 12px rgba(108, 92, 231, 0), var(--cho-shadow); }
	100% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0), var(--cho-shadow); }
}

#cho-toggle-btn.cho-pulse {
	/* 3 itérations × 1s = 3 secondes exactement */
	animation: cho-pulse 1s ease-out 3;
}

/* ---------------------------------------------------------------
   Responsive teaser : mobile (< 768px)
   La bulle passe au-dessus du bouton (flex-column sur le wrapper)
--------------------------------------------------------------- */
@media (max-width: 768px) {
	#cho-wrapper {
		flex-direction: column;
		align-items: flex-end;
	}

	#cho-teaser {
		margin-right: 0;
		margin-bottom: 10px;
		max-width: 240px;
		/* Réinitialiser l'animation : slide du bas vers le haut sur mobile */
		transform: translateY(8px);
	}
	#cho-teaser.cho-teaser-visible {
		transform: translateY(0);
	}

	/* Queue de bulle pointant vers le bas (vers le bouton) sur mobile */
	#cho-teaser::after {
		right: 18px;
		bottom: -8px;
		border-left: 8px solid transparent;
		border-right: 8px solid transparent;
		border-top: 8px solid #fff;
		border-bottom: none;
		filter: drop-shadow(0 2px 2px rgba(0,0,0,0.06));
	}
}

/* Ajustement mobile existant (fusionné pour éviter les doublons) */
@media (max-width: 420px) {
	#cho-teaser {
		max-width: calc(100vw - 80px);
	}
}

/* ---------------------------------------------------------------
   Formulaire WhatsApp
--------------------------------------------------------------- */
#cho-whatsapp-form {
	padding: 14px 12px;
	background: #fafafa;
	border-top: 1px solid #f0f0f0;
	flex-shrink: 0;
}
#cho-wa-form-title {
	font-size: 13px;
	font-weight: 600;
	color: #333;
	margin: 0 0 2px;
}
#cho-wa-form-subtitle {
	font-size: 12px;
	color: #777;
	margin: 0 0 10px;
}
#cho-wa-name-row {
	display: flex;
	gap: 8px;
	margin-bottom: 8px;
}
#cho-wa-name-row input {
	flex: 1;
}
#cho-wa-prenom,
#cho-wa-nom,
#cho-wa-phone,
#cho-wa-email,
#cho-wa-message {
	all: unset;
	width: 100%;
	box-sizing: border-box;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 13px;
	font-family: var(--cho-font);
	color: #333;
	background: white;
	display: block;
	transition: border-color 0.2s;
}
#cho-wa-phone-wrapper {
	margin-bottom: 8px;
}
#cho-wa-phone-error {
	display: none;
	font-size: 11px;
	color: #c0392b;
	margin-top: 3px;
}
#cho-wa-email,
#cho-wa-message {
	margin-bottom: 8px;
}
#cho-wa-prenom:focus,
#cho-wa-nom:focus,
#cho-wa-phone:focus,
#cho-wa-email:focus,
#cho-wa-message:focus {
	border-color: var(--cho-color);
	outline: 2px solid var(--cho-color-light);
}
#cho-wa-message {
	resize: vertical;
	min-height: 50px;
}
#cho-wa-privacy {
	font-size: 11px;
	color: #aaa;
	margin: 0 0 8px;
	text-align: center;
}
#cho-wa-form-buttons {
	display: flex;
	gap: 8px;
	margin-top: 4px;
}
#cho-wa-submit-btn {
	all: unset;
	cursor: pointer;
	background: #25d366;
	color: white;
	padding: 7px 14px;
	border-radius: 8px;
	font-size: 12px;
	font-weight: 500;
	transition: opacity 0.2s;
	flex: 1;
	text-align: center;
}
#cho-wa-submit-btn:hover { opacity: 0.88; }
#cho-wa-submit-btn:disabled {
	opacity: 0.5;
	cursor: default;
}
#cho-wa-cancel-btn {
	all: unset;
	cursor: pointer;
	color: #888;
	padding: 7px 12px;
	font-size: 12px;
	transition: color 0.2s;
}
#cho-wa-cancel-btn:hover { color: #333; }

/* ---------------------------------------------------------------
   Couleurs dynamiques de la bulle (variables injectées via PHP)
--------------------------------------------------------------- */
#cho-teaser {
	background: var(--cho-teaser-bg, #fff);
}
#cho-teaser::after {
	border-left-color: var(--cho-teaser-bg, #fff);
}
#cho-teaser-text {
	color: var(--cho-teaser-text, #333);
}

/* ---------------------------------------------------------------
   Position "top" : bulle au-dessus du bouton
--------------------------------------------------------------- */
#cho-wrapper.cho-teaser-top {
	flex-direction: column;
	align-items: flex-end;
}
#cho-wrapper.cho-teaser-top #cho-teaser {
	margin-right: 0;
	margin-bottom: 10px;
	transform: translateY(8px);
}
#cho-wrapper.cho-teaser-top #cho-teaser.cho-teaser-visible {
	transform: translateY(0);
}
#cho-wrapper.cho-teaser-top #cho-teaser::after {
	right: 18px;
	bottom: -8px;
	border-left: 8px solid transparent;
	border-right: 8px solid transparent;
	border-top: 8px solid var(--cho-teaser-bg, #fff);
	border-bottom: none;
	filter: drop-shadow(0 2px 2px rgba(0,0,0,0.06));
}

/* ---------------------------------------------------------------
   Animations d'apparition de la bulle
--------------------------------------------------------------- */

/* Slide : glissement depuis la droite */
#cho-teaser.cho-anim-slide {
	transform: translateX(28px);
	opacity: 0;
	transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
#cho-teaser.cho-anim-slide.cho-teaser-visible {
	transform: translateX(0);
	opacity: 1;
}

/* Bounce : rebond à l'entrée */
@keyframes cho-teaser-bounce-in {
	0%   { opacity: 0; transform: translateX(18px) scale(0.88); }
	55%  { transform: translateX(-4px) scale(1.04); }
	80%  { transform: translateX(2px) scale(0.98); }
	100% { opacity: 1; transform: translateX(0) scale(1); }
}
#cho-teaser.cho-anim-bounce {
	transition: none;
}
#cho-teaser.cho-anim-bounce.cho-teaser-visible {
	animation: cho-teaser-bounce-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
	opacity: 1;
}

/* None : apparition instantanée */
#cho-teaser.cho-anim-none {
	transition: none;
}
#cho-teaser.cho-anim-none.cho-teaser-visible {
	opacity: 1;
	transform: translateX(0);
}

/* ---------------------------------------------------------------
   Bouton flottant — position bottom-left
--------------------------------------------------------------- */
#cho-wrapper.cho-btn-bottom-left {
	right: auto;
	left: 24px;
	flex-direction: row-reverse;
}
#cho-wrapper.cho-btn-bottom-left #cho-window {
	right: auto;
	left: 0;
	transform-origin: bottom left;
}
#cho-wrapper.cho-btn-bottom-left #cho-teaser {
	margin-right: 0;
	margin-left: 12px;
}
#cho-wrapper.cho-btn-bottom-left #cho-teaser::after {
	right: auto;
	left: -8px;
	border-left: none;
	border-right: 8px solid var(--cho-teaser-bg, #fff);
}

/* ---------------------------------------------------------------
   Bouton flottant — forme "rounded" (rectangle arrondi)
--------------------------------------------------------------- */
#cho-toggle-btn.cho-btn-rounded {
	border-radius: 16px;
	width: 56px;
	height: 56px;
}

/* ---------------------------------------------------------------
   Responsive bottom-left
--------------------------------------------------------------- */
@media (max-width: 420px) {
	#cho-wrapper.cho-btn-bottom-left {
		left: 16px;
	}
}

/* ---------------------------------------------------------------
   Graphiques Chart.js (générés par Léa)
--------------------------------------------------------------- */
.cho-message--has-chart {
	max-width: 96%;
	padding: 10px 10px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.cho-msg-text {
	display: block;
	white-space: pre-line;
	font-size: 14px;
	line-height: 1.5;
}
.cho-chart-wrapper {
	width: 100%;
	background: #fff;
	border-radius: 10px;
	padding: 10px 10px 6px;
	box-shadow: 0 1px 6px rgba(0, 0, 0, 0.09);
	margin-top: 4px;
}
.cho-chart-title {
	font-size: 12px;
	font-weight: 600;
	color: #555;
	text-align: center;
	margin-bottom: 6px;
}
.cho-chart-canvas {
	max-height: 180px;
}
