/* ==========================================================================
   SB ACADEMY / SB INSTITUT — Assistante IA, widget de chat flottant
   Marque : noir profond (#120f0c), bronze (#a07d57), or (#c59d5f), crème
   --------------------------------------------------------------------------
   Deux précautions, indispensables sur ce site :

   1. Toutes les classes sont préfixées « sbc- ».
   2. TOUS les sélecteurs commencent par #sb-chat.

   Le thème et Elementor imposent des styles très larges (« button » reçoit
   par exemple padding: 20px 40px). Sans le préfixe #sb-chat, ces règles
   l'emportent et la bulle devient un rectangle transparent : c'est arrivé
   au premier essai. Ne pas retirer les #sb-chat en croyant simplifier.
   ========================================================================== */

#sb-chat {
	--sbc-black: #120f0c;
	--sbc-bronze: #a07d57;
	--sbc-gold: #c59d5f;
	--sbc-gold-bright: #d2ad3a;
	--sbc-cream: #f7f3ee;
	--sbc-text: #272626;
	--sbc-muted: #6f6a64;
	--sbc-line: rgba(160, 125, 87, 0.28);
	--sbc-radius: 6px;
	--sbc-shadow: 0 18px 48px rgba(18, 15, 12, 0.28);
	/* Au-dessus de tout : le thème monte jusqu'à z-index 9999999999. */
	--sbc-z: 2147483000;

	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: var(--sbc-z);
	font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: var(--sbc-text);
}

#sb-chat *,
#sb-chat *::before,
#sb-chat *::after { box-sizing: border-box; }

#sb-chat button {
	font-family: inherit;
	font-size: inherit;
	margin: 0;
	padding: 0;
	cursor: pointer;
	border: 0;
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: inherit;
	text-transform: none;
	letter-spacing: normal;
	min-width: 0;
	min-height: 0;
	width: auto;
}

#sb-chat p { margin: 0; }

/* WordPress remplace chaque emoji par une <img class="emoji"> et le thème
   étire les images à 100 % de leur conteneur : sans cette règle, le ✨ du
   message d'accueil s'affiche en pleine largeur du panneau. */
#sb-chat img.emoji,
#sb-chat img.wp-smiley {
	display: inline-block !important;
	width: 1em !important;
	height: 1em !important;
	max-width: 1em !important;
	margin: 0 .07em !important;
	padding: 0 !important;
	border: 0 !important;
	background: none !important;
	box-shadow: none !important;
	vertical-align: -.1em !important;
}

/* --- Bulle d'appel -------------------------------------------------------- */

#sb-chat .sbc-launcher-wrap { position: relative; }

#sb-chat .sbc-launcher {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	margin-left: auto;
	border-radius: 50%;
	background: var(--sbc-bronze);
	color: #fff;
	box-shadow: var(--sbc-shadow);
	transition: background .2s ease, transform .2s ease;
}
#sb-chat .sbc-launcher:hover { background: var(--sbc-gold); transform: translateY(-2px); }
#sb-chat .sbc-launcher:focus-visible { outline: 3px solid var(--sbc-gold-bright); outline-offset: 3px; }
#sb-chat .sbc-launcher svg { width: 27px; height: 27px; display: block; fill: currentColor; }
#sb-chat .sbc-launcher .sbc-icon-close { display: none; }

#sb-chat[data-open="true"] .sbc-launcher .sbc-icon-open { display: none; }
#sb-chat[data-open="true"] .sbc-launcher .sbc-icon-close { display: block; }

/* --- Appel de l'attention ---------------------------------------------------
   Une onde qui s'échappe de la bulle, en boucle, dès l'affichage de la page et
   pour toutes les visiteuses : la bulle doit se remarquer tout de suite.

   Le temps mort à la fin du cycle est volontaire — l'onde part, puis la bulle
   se tait une seconde et demie. Une pulsation continue et sans répit fatigue
   l'œil et finit par se faire ignorer ; un appel espacé se remarque à chaque
   fois. C'est aussi pour cela que ce n'est pas un vrai clignotement
   (apparition/disparition), qui se lirait comme un bug d'affichage.

   Le halo est dessiné par ::before, donc à l'intérieur du bouton : l'ombre et
   le survol de la bulle restent intacts. Comme il est peint sous le <svg>,
   l'icône n'est jamais recouverte, et la partie du halo qui reste sur la bulle
   est bronze sur bronze — seul le débord est visible. */
@keyframes sbc-halo {
	0%   { transform: scale(1);   opacity: .5; }
	45%  { transform: scale(1.9); opacity: 0; }
	100% { transform: scale(1.9); opacity: 0; }
}
@keyframes sbc-nudge {
	0%             { transform: scale(1); }
	22%            { transform: scale(1.07); }
	45%, 100%      { transform: scale(1); }
}

/* Sur mobile la bulle est plus près des bords et du contenu : une onde à 1,9×
   déborde de l'écran et passe devant le texte. Même geste, amplitude réduite.
   Jeu de keyframes séparé plutôt qu'une variable dans @keyframes : la prise en
   charge de var() y est irrégulière selon les navigateurs. */
@keyframes sbc-halo-sm {
	0%   { transform: scale(1);    opacity: .42; }
	45%  { transform: scale(1.45); opacity: 0; }
	100% { transform: scale(1.45); opacity: 0; }
}

#sb-chat .sbc-launcher::before {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: var(--sbc-bronze);
	opacity: 0;
	pointer-events: none;
}
#sb-chat .sbc-launcher::before { animation: sbc-halo 3.4s ease-out infinite; }
#sb-chat .sbc-launcher { animation: sbc-nudge 3.4s ease-in-out infinite; }

/* Panneau ouvert : la bulle devient le bouton « fermer », elle n'a plus à
   appeler. Le survol s'arrête aussi, pour rendre la main au translateY. */
#sb-chat .sbc-launcher:hover,
#sb-chat .sbc-launcher:hover::before,
#sb-chat[data-open="true"] .sbc-launcher,
#sb-chat[data-open="true"] .sbc-launcher::before { animation: none; }

/* Pastille « nouvelle réponse » quand le panneau est fermé. */
#sb-chat .sbc-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	width: 14px;
	height: 14px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: var(--sbc-gold-bright);
	display: none;
}
#sb-chat[data-unread="true"] .sbc-badge { display: block; }

/* --- Panneau -------------------------------------------------------------- */

#sb-chat .sbc-panel {
	position: absolute;
	right: 0;
	bottom: 74px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 620px;
	max-height: calc(100vh - 130px);
	display: none;
	flex-direction: column;
	overflow: hidden;
	background: #fff;
	border: 1px solid var(--sbc-line);
	border-radius: var(--sbc-radius);
	box-shadow: var(--sbc-shadow);
	text-align: left;
}
#sb-chat[data-open="true"] .sbc-panel {
	display: flex;
	animation: sbc-rise .22s ease-out;
}

@keyframes sbc-rise {
	from { opacity: 0; transform: translateY(12px); }
	to   { opacity: 1; transform: none; }
}

/* --- En-tête -------------------------------------------------------------- */

#sb-chat .sbc-head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 16px 15px;
	background: var(--sbc-black);
	border-bottom: 1px solid rgba(197, 157, 95, .4);
	color: #fff;
}
#sb-chat .sbc-head-mark {
	flex: none;
	width: 38px;
	height: 38px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid var(--sbc-gold);
	border-radius: 50%;
	font-family: 'Abril Fatface', Georgia, serif;
	font-size: 1rem;
	color: var(--sbc-gold-bright);
}
#sb-chat .sbc-head-txt { flex: 1; min-width: 0; }
#sb-chat .sbc-head-title {
	font-family: 'Abril Fatface', Georgia, serif;
	font-size: 1.05rem;
	font-weight: 400;
	letter-spacing: .02em;
	line-height: 1.2;
	margin: 0;
	color: #fff;
}
#sb-chat .sbc-head-sub {
	margin: 2px 0 0;
	font-size: .78rem;
	letter-spacing: .02em;
	color: rgba(255, 255, 255, .68);
}
#sb-chat .sbc-head-sub::before {
	content: '';
	display: inline-block;
	width: 7px;
	height: 7px;
	margin-right: 6px;
	border-radius: 50%;
	background: #5cb85c;
	vertical-align: middle;
}
#sb-chat .sbc-head-btn {
	flex: none;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	color: rgba(255, 255, 255, .72);
	transition: background .2s ease, color .2s ease;
}
#sb-chat .sbc-head-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
#sb-chat .sbc-head-btn:focus-visible { outline: 2px solid var(--sbc-gold-bright); outline-offset: 1px; }
#sb-chat .sbc-head-btn svg { width: 17px; height: 17px; fill: currentColor; display: block; }

/* --- Fil de discussion ---------------------------------------------------- */

#sb-chat .sbc-log {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 18px 16px 8px;
	background: #fff;
	display: flex;
	flex-direction: column;
	gap: 12px;
}
#sb-chat .sbc-log::-webkit-scrollbar { width: 8px; }
#sb-chat .sbc-log::-webkit-scrollbar-thumb { background: rgba(160, 125, 87, .3); border-radius: 4px; }

#sb-chat .sbc-msg {
	max-width: 84%;
	padding: 11px 14px;
	border-radius: var(--sbc-radius);
	font-size: .92rem;
	line-height: 1.5;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
#sb-chat .sbc-msg--bot {
	align-self: flex-start;
	background: var(--sbc-cream);
	border: 1px solid var(--sbc-line);
	border-bottom-left-radius: 2px;
	color: var(--sbc-text);
}
#sb-chat .sbc-msg--user {
	align-self: flex-end;
	background: var(--sbc-bronze);
	border-bottom-right-radius: 2px;
	color: #fff;
	white-space: pre-wrap;
}
#sb-chat .sbc-msg--error {
	align-self: flex-start;
	background: #fdf3f2;
	border: 1px solid #e9c9c4;
	color: #8a3223;
}
#sb-chat .sbc-msg p { margin: 0 0 .6em; }
#sb-chat .sbc-msg p:last-child { margin-bottom: 0; }
#sb-chat .sbc-msg ul { margin: .2em 0 .6em; padding-left: 1.15em; list-style: disc; }
#sb-chat .sbc-msg li { margin: 0 0 .25em; }
#sb-chat .sbc-msg strong { font-weight: 700; }
#sb-chat .sbc-msg a { color: var(--sbc-bronze); text-decoration: underline; }
#sb-chat .sbc-msg--user a { color: #fff; }

/* Indicateur de saisie. */
#sb-chat .sbc-typing { display: flex; gap: 5px; align-items: center; }
#sb-chat .sbc-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--sbc-bronze);
	opacity: .45;
	animation: sbc-blink 1.3s infinite ease-in-out;
}
#sb-chat .sbc-typing span:nth-child(2) { animation-delay: .18s; }
#sb-chat .sbc-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes sbc-blink {
	0%, 80%, 100% { opacity: .3; transform: translateY(0); }
	40%           { opacity: 1;  transform: translateY(-3px); }
}

#sb-chat .sbc-note {
	align-self: center;
	max-width: 90%;
	text-align: center;
	font-size: .78rem;
	color: var(--sbc-muted);
}

/* --- Suggestions ---------------------------------------------------------- */

#sb-chat .sbc-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 4px 16px 12px;
	background: #fff;
}
#sb-chat .sbc-chip {
	padding: 8px 13px;
	border: 1px solid var(--sbc-line);
	border-radius: 999px;
	background: #fff;
	font-size: .82rem;
	color: var(--sbc-bronze);
	transition: background .2s ease, color .2s ease, border-color .2s ease;
}
#sb-chat .sbc-chip:hover { background: var(--sbc-bronze); border-color: var(--sbc-bronze); color: #fff; }
#sb-chat .sbc-chip:focus-visible { outline: 2px solid var(--sbc-gold-bright); outline-offset: 2px; }

/* --- Zone de saisie ------------------------------------------------------- */

#sb-chat .sbc-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0;
	padding: 12px 14px;
	border-top: 1px solid var(--sbc-line);
	background: #fff;
}
#sb-chat .sbc-input {
	flex: 1;
	max-height: 96px;
	min-height: 42px;
	padding: 11px 13px;
	border: 1px solid var(--sbc-line);
	border-radius: var(--sbc-radius);
	background: #fff;
	font-family: inherit;
	font-size: .92rem;
	line-height: 1.4;
	color: var(--sbc-text);
	resize: none;
	overflow-y: auto;
	box-shadow: none;
}
#sb-chat .sbc-input::placeholder { color: var(--sbc-muted); }
#sb-chat .sbc-input:focus { outline: none; border-color: var(--sbc-bronze); box-shadow: none; }

#sb-chat .sbc-send {
	flex: none;
	width: 42px;
	height: 42px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--sbc-radius);
	background: var(--sbc-bronze);
	color: #fff;
	transition: background .2s ease;
}
#sb-chat .sbc-send:hover:not(:disabled) { background: var(--sbc-gold); }
#sb-chat .sbc-send:disabled { opacity: .45; cursor: not-allowed; }
#sb-chat .sbc-send:focus-visible { outline: 2px solid var(--sbc-gold-bright); outline-offset: 2px; }
#sb-chat .sbc-send svg { width: 18px; height: 18px; fill: currentColor; display: block; }

#sb-chat .sbc-foot {
	padding: 0 14px 12px;
	font-size: .72rem;
	line-height: 1.4;
	text-align: center;
	color: var(--sbc-muted);
	background: #fff;
}
#sb-chat .sbc-foot a { color: var(--sbc-bronze); text-decoration: underline; }

/* --- Adaptatif ------------------------------------------------------------ */

@media (max-width: 560px) {
	#sb-chat { right: 16px; bottom: 16px; }
	#sb-chat .sbc-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: none;
		height: 100%;
		max-height: none;
		border: 0;
		border-radius: 0;
		padding-bottom: env(safe-area-inset-bottom);
	}
	#sb-chat .sbc-launcher { width: 56px; height: 56px; }
	#sb-chat .sbc-launcher::before { animation-name: sbc-halo-sm; }
	/* Panneau ouvert : la bulle gênerait le clavier, on la masque. */
	#sb-chat[data-open="true"] .sbc-launcher-wrap { display: none; }
}

/* Les pages du tunnel affichent une barre de prix collée en bas sur mobile
   (.sb-sticky). Sans ce décalage la bulle atterrit dessus.
   La hauteur est mesurée par academy.js (--sb-sticky-h) plutôt que supposée :
   la barre grandit dès que le texte passe à la ligne, par exemple quand le
   navigateur traduit la page. Le repli 64px vaut pour une barre sur une ligne. */
@media (max-width: 720px) {
	#sb-chat.sbc--above-sticky { bottom: calc(var(--sb-sticky-h, 64px) + 20px); }
}

@media (prefers-reduced-motion: reduce) {
	#sb-chat *,
	#sb-chat *::before,
	#sb-chat *::after {
		animation-duration: .001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: .001ms !important;
	}
}

@media print {
	#sb-chat { display: none !important; }
}
