/**
 * TalkActive — panneau de discussion et bouton flottant, côté public.
 *
 * Deux animations vivent ici : l'anneau d'écoute et les ondes de parole. Les
 * deux sont neutralisées sous `prefers-reduced-motion` — un halo qui pulse en
 * permanence dans un coin de l'écran est, pour certaines personnes, un
 * déclencheur, pas une décoration.
 *
 * @package TalkActive
 */

.talkactive-chat {
	--talkactive-bg: #ffffff;
	--talkactive-fg: #1f2a44;
	--talkactive-accent: #2c5cc5;
	--talkactive-muted: #5b6472;
	--talkactive-line: #dfe3ea;

	box-sizing: border-box;
	max-width: 42rem;
	margin: 1.5rem 0;
	padding: 1rem;
	border: 1px solid var(--talkactive-line);
	border-radius: 10px;
	background: var(--talkactive-bg);
	color: var(--talkactive-fg);
	font-size: 1rem;
	line-height: 1.5;
}

.talkactive-chat *,
.talkactive-chat *::before,
.talkactive-chat *::after {
	box-sizing: inherit;
}

.talkactive-chat__title {
	margin: 0 0 0.75rem;
	font-size: 1.125rem;
}

.talkactive-chat__thread {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	max-height: 26rem;
	overflow-y: auto;
	padding: 0.25rem;
}

.talkactive-chat__bubble {
	max-width: 85%;
	padding: 0.6rem 0.85rem;
	border-radius: 12px;
	white-space: pre-wrap;

	/*
	 * Une réponse peut contenir une URL sans espace, plus large que le
	 * panneau : sans coupure, elle élargit la bulle et fait défiler toute la
	 * page horizontalement.
	 */
	overflow-wrap: anywhere;
}

.talkactive-chat__bubble--assistant {
	align-self: flex-start;
	background: #f2f5fa;
}

.talkactive-chat__bubble--user {
	align-self: flex-end;
	background: var(--talkactive-accent);
	color: #ffffff;

	/* Repère du bouton de correction, posé sur le bord droit. */
	position: relative;
	padding-right: 2.1rem;
}

/*
 * Corriger une réponse.
 *
 * Le bouton reste discret tant qu'on ne s'approche pas de la bulle : il ne doit
 * pas concurrencer la lecture. Mais il **existe** au clavier — `:focus-within`
 * le révèle —, sans quoi il serait réservé à la souris.
 */
.talkactive-chat__edit {
	position: absolute;
	top: 0.35rem;
	right: 0.35rem;
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: inherit;
	opacity: 0;
	cursor: pointer;
	transition: opacity .12s, background .12s;
}

.talkactive-chat__bubble--user:hover .talkactive-chat__edit,
.talkactive-chat__bubble--user:focus-within .talkactive-chat__edit,
.talkactive-chat__edit:focus {
	opacity: .85;
}

.talkactive-chat__edit:hover,
.talkactive-chat__edit:focus {
	background: rgba(255, 255, 255, .22);
	opacity: 1;
}

.talkactive-chat__bubble.is-editing {
	padding-right: 0.85rem;
}

.talkactive-chat__bubble.is-editing .talkactive-chat__edit {
	display: none;
}

.talkactive-chat__editor-field {
	width: 100%;
	min-width: 14rem;
	padding: 0.4rem 0.5rem;
	border: 0;
	border-radius: 8px;
	font: inherit;
	color: #17212b;
	background: #ffffff;
	resize: vertical;
}

.talkactive-chat__editor-actions {
	display: flex;
	gap: 0.4rem;
	margin-top: 0.4rem;
}

.talkactive-chat__editor-ok,
.talkactive-chat__editor-cancel {
	padding: 0.25rem 0.7rem;
	border: 1px solid rgba(255, 255, 255, .55);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 0.85rem;
	cursor: pointer;
}

.talkactive-chat__editor-ok {
	background: #ffffff;
	color: var(--talkactive-accent);
	font-weight: 600;
}

.talkactive-chat__bubble--error {
	align-self: flex-start;
	border: 1px solid #d33;
	background: #fdf2f2;
	color: #8a1f1f;
}

.talkactive-chat__form {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.75rem;
}

.talkactive-chat__input {
	flex: 1 1 auto;
	min-height: 2.75rem;
	padding: 0.5rem;
	border: 1px solid var(--talkactive-line);
	border-radius: 8px;
	font: inherit;
	resize: vertical;
}

.talkactive-chat__send {
	padding: 0 1.1rem;
	border: 0;
	border-radius: 8px;
	background: var(--talkactive-accent);
	color: #ffffff;
	font: inherit;
	cursor: pointer;
}

.talkactive-chat__status,
.talkactive-chat__privacy,
.talkactive-voice__status {
	margin: 0.5rem 0 0;
	color: var(--talkactive-muted);
	font-size: 0.85rem;
}

.talkactive-voice-bar {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin-top: 0.75rem;
	flex-wrap: wrap;
}

/*
 * Le bouton de dictée se **maintient** enfoncé pendant qu'on parle : il lui
 * faut une cible confortable, pas la taille d'un bouton qu'on effleure. 44 px
 * de haut est le minimum recommandé pour une cible tactile, et cela vaut
 * d'autant plus ici que le doigt y reste plusieurs secondes.
 */
.talkactive-voice__mic {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
	padding: 0.55rem 1.1rem;
	border: 1px solid var(--talkactive-line);
	border-radius: 999px;
	background: #ffffff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	/*
	 * Un appui long ne doit ni sélectionner l'intitulé, ni ouvrir le menu
	 * contextuel du tactile : les deux interrompraient la prise de son au
	 * moment précis où l'on parle.
	 */
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	touch-action: manipulation;
	transition: background .12s, border-color .12s, transform .08s;
}

.talkactive-voice__mic:hover {
	border-color: var(--talkactive-accent);
}

.talkactive-voice__mic[aria-pressed="true"] {
	border-color: var(--talkactive-accent);
	background: var(--talkactive-accent);
	color: #ffffff;
	/* Le bouton s'enfonce : le retour visuel dit que la prise est ouverte. */
	transform: scale(0.98);
}

.talkactive-voice__mic-icon {
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
}

/*
 * La lecture à voix haute est un **état durable**, pas une action : une case à
 * cocher, alignée sur la barre, et qui ne se déguise pas en bouton.
 */
.talkactive-voice__speak {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.4rem 0.6rem;
	font: inherit;
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
}

.talkactive-voice__speak-input {
	width: 1rem;
	height: 1rem;
	margin: 0;
	cursor: pointer;
}

/*
 * `screen-reader-text` est redéfini ici : le panneau s'affiche aussi sur des
 * thèmes qui ne chargent pas les styles d'administration, et sans cette règle
 * les intitulés destinés aux lecteurs d'écran s'afficheraient en clair au
 * milieu du panneau.
 */
.talkactive-chat .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ------------------------------------------------------------------ */
/* Bouton flottant                                                      */
/* ------------------------------------------------------------------ */

.talkactive-fab {
	--talkactive-fab-size: 64px;
	--talkactive-fab-x: 24px;
	--talkactive-fab-y: 24px;

	position: fixed;
	z-index: 99998;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--talkactive-fab-size);
	height: var(--talkactive-fab-size);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	cursor: pointer;
}

.talkactive-fab--bottom-right {
	right: var(--talkactive-fab-x);
	bottom: var(--talkactive-fab-y);
}

.talkactive-fab--bottom-left {
	left: var(--talkactive-fab-x);
	bottom: var(--talkactive-fab-y);
}

.talkactive-fab--top-right {
	top: var(--talkactive-fab-y);
	right: var(--talkactive-fab-x);
}

.talkactive-fab--top-left {
	top: var(--talkactive-fab-y);
	left: var(--talkactive-fab-x);
}

.talkactive-fab--draggable {
	touch-action: none;
}

.talkactive-fab__image {
	position: relative;
	z-index: 2;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	pointer-events: none;
}

.talkactive-fab__waves {
	position: absolute;
	inset: 0;
	z-index: 1;
	pointer-events: none;
}

.talkactive-fab__wave {
	position: absolute;
	inset: 0;
	border: 2px solid var(--talkactive-accent, #2c5cc5);
	border-radius: 50%;
	opacity: 0;
}

/* Écoute : anneaux concentriques qui pulsent, portés tels quels. */
.talkactive-fab.is-listening .talkactive-fab__wave {
	animation: talkactive-listening 1.8s ease-out infinite;
}

.talkactive-fab.is-listening .talkactive-fab__wave:nth-child(2) {
	animation-delay: 0.6s;
}

.talkactive-fab.is-listening .talkactive-fab__wave:nth-child(3) {
	animation-delay: 1.2s;
}

.talkactive-fab.is-listening::after {
	content: "";
	position: absolute;
	inset: -6px;
	border-radius: 50%;
	animation: talkactive-halo 2.4s ease-in-out infinite;
}

@keyframes talkactive-listening {
	0% {
		opacity: 0.55;
		transform: scale(1);
	}

	100% {
		opacity: 0;
		transform: scale(1.9);
	}
}

@keyframes talkactive-halo {
	0%,
	100% {
		box-shadow: 0 0 0 0 rgba(44, 92, 197, 0.35);
	}

	50% {
		box-shadow: 0 0 0 10px rgba(44, 92, 197, 0);
	}
}

/*
 * Parole : des arcs naissent au centre et se propagent vers la droite.
 *
 * `clip-path` ne garde que la moitié droite de chaque anneau, ce qui donne des
 * arcs sans avoir à dessiner de SVG ni à charger quoi que ce soit. Le décalage
 * de 200 ms entre les trois produit la propagation.
 */
.talkactive-fab.is-speaking .talkactive-fab__wave {
	border-color: var(--talkactive-accent, #2c5cc5);
	clip-path: inset(0 0 0 50%);
	animation: talkactive-speaking 1.2s ease-out infinite;
}

.talkactive-fab.is-speaking .talkactive-fab__wave:nth-child(2) {
	animation-delay: 0.2s;
}

.talkactive-fab.is-speaking .talkactive-fab__wave:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes talkactive-speaking {
	0% {
		opacity: 0.7;
		transform: translateX(0) scale(0.6);
	}

	100% {
		opacity: 0;
		transform: translateX(45%) scale(1.5);
	}
}

/*
 * Mouvement réduit : les états restent **visibles**, mais fixes. Supprimer
 * l'indication au lieu de l'animation priverait ces utilisateurs du seul
 * signal disant que le micro est ouvert.
 */
@media ( prefers-reduced-motion: reduce ) {
	.talkactive-fab.is-listening .talkactive-fab__wave,
	.talkactive-fab.is-speaking .talkactive-fab__wave {
		animation: none;
		opacity: 0.45;
		transform: none;
		clip-path: none;
	}

	.talkactive-fab.is-listening::after {
		animation: none;
		box-shadow: 0 0 0 4px rgba(44, 92, 197, 0.3);
	}
}

.talkactive-chat.is-open {
	display: block;
}
