/**
 * Assistant Juridique — widget flottant.
 *
 * Les valeurs reprennent la charte de la maquette (turquoise #17A2A0, rayons
 * de 8 à 12 px, ombres douces bleu nuit). Elles sont exposées en variables
 * pour que le thème puisse les redéfinir sans toucher à ce fichier, et
 * portées par .aj-fab / .aj-panel pour ne rien imposer au reste de la page.
 */

.aj-fab,
.aj-fab-label,
.aj-panel {
	--aj-teal: #17a2a0;
	--aj-teal-dark: #138f8d;
	--aj-navy: #0b2d4d;
	--aj-text: #243240;
	--aj-muted: #6b7785;
	--aj-muted-light: #93a1ae;
	--aj-line: #e2e8ee;
	--aj-bg: #f4f6f8;
	--aj-bg-soft: #eef2f5;
	--aj-white: #fff;
	--aj-green: #2faa6a;
	--aj-red: #c0392b;
	--aj-radius: 12px;
	--aj-radius-sm: 8px;
	--aj-shadow: 0 8px 28px rgba(11, 45, 77, 0.1);
	--aj-shadow-lg: 0 18px 48px rgba(11, 45, 77, 0.22);
	--aj-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
	--aj-font-display: "Poppins", "Segoe UI", system-ui, sans-serif;
	--aj-z: 999000;

	/* Écart au coin. Tout ce qui flotte s'y accroche : décaler le widget
	   pour cohabiter avec un autre bouton flottant ne demande donc qu'à
	   redéfinir ces deux valeurs. */
	--aj-gap-right: 24px;
	--aj-gap-bottom: 24px;

	box-sizing: border-box;
	font-family: var(--aj-font);
}

.aj-fab *,
.aj-fab *::before,
.aj-fab *::after,
.aj-fab-label *,
.aj-fab-label *::before,
.aj-fab-label *::after,
.aj-panel *,
.aj-panel *::before,
.aj-panel *::after {
	box-sizing: border-box;
}

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

.aj-fab {
	position: fixed;
	right: var(--aj-gap-right);
	bottom: var(--aj-gap-bottom);
	z-index: var(--aj-z);
	display: grid;
	place-items: center;
	width: 58px;
	height: 58px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--aj-teal);
	color: var(--aj-white);
	box-shadow: var(--aj-shadow-lg);
	cursor: pointer;
	transition: transform 0.2s ease, background-color 0.2s ease;
}

.aj-fab:hover {
	background: var(--aj-teal-dark);
	transform: translateY(-2px);
}

.aj-fab:focus-visible {
	outline: 3px solid var(--aj-teal);
	outline-offset: 3px;
}

.aj-fab__icon {
	display: grid;
	place-items: center;
	grid-area: 1 / 1;
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.aj-fab__icon svg {
	width: 26px;
	height: 26px;
	display: block;
}

.aj-fab__icon--close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.8);
}

.aj-fab.is-open .aj-fab__icon--open {
	opacity: 0;
	transform: rotate(90deg) scale(0.8);
}

.aj-fab.is-open .aj-fab__icon--close {
	opacity: 1;
	transform: none;
}

/* Halo d'appel, coupé dès l'ouverture et pour qui refuse les animations. */
.aj-fab__pulse {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--aj-teal);
	animation: aj-pulse 2.6s ease-out infinite;
	pointer-events: none;
}

.aj-fab.is-open .aj-fab__pulse {
	display: none;
}

@keyframes aj-pulse {
	0% { opacity: 0.5; transform: scale(1); }
	70% { opacity: 0; transform: scale(1.55); }
	100% { opacity: 0; transform: scale(1.55); }
}

/* Un autre bouton flottant occupe déjà le coin (retour en haut d'Astra,
   par exemple). Plutôt que de se superposer, on s'empile au-dessus de lui :
   la classe est posée par le script, qui sait ce qu'il a trouvé dans la page. */
body.aj-corner-busy .aj-fab,
body.aj-corner-busy .aj-fab-label,
body.aj-corner-busy .aj-panel {
	--aj-gap-bottom: 88px;
}

/* ------------------------------------------------------------------ *
 * Étiquette d'invitation, à gauche du bouton
 *
 * Positionnée en « fixed » et calée sur le bouton plutôt qu'imbriquée dans
 * lui : le bouton reste un bouton, sans contenu cliquable à l'intérieur.
 * ------------------------------------------------------------------ */

.aj-fab-label {
	position: fixed;
	right: calc( var(--aj-gap-right) + 70px );   /* bouton 58 + écart 12 */
	bottom: calc( var(--aj-gap-bottom) + 11px ); /* centre la pastille sur le bouton */
	z-index: var(--aj-z);
	display: flex;
	align-items: center;
	gap: 2px;
	max-width: min(260px, calc(100vw - 120px));
	padding: 0 4px 0 14px;
	border: 1px solid var(--aj-line);
	border-radius: 20px;
	background: var(--aj-white);
	box-shadow: var(--aj-shadow);
	font-family: var(--aj-font);
	opacity: 0;
	transform: translateX(8px);
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.aj-fab-label[hidden] {
	display: none !important;
}

.aj-fab-label.is-visible {
	opacity: 1;
	transform: none;
}

.aj-fab-label__text {
	padding: 9px 4px 9px 0;
	border: none;
	background: none;
	color: var(--aj-navy);
	font-family: inherit;
	font-size: 13.5px;
	font-weight: 500;
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	cursor: pointer;
}

.aj-fab-label__text:focus-visible,
.aj-fab-label__close:focus-visible {
	outline: 2px solid var(--aj-teal);
	outline-offset: 1px;
	border-radius: 4px;
}

.aj-fab-label__close {
	display: grid;
	place-items: center;
	flex: none;
	width: 22px;
	height: 22px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--aj-muted-light);
	cursor: pointer;
	transition: background-color 0.18s ease, color 0.18s ease;
}

.aj-fab-label__close:hover {
	background: var(--aj-bg-soft);
	color: var(--aj-navy);
}

.aj-fab-label__close svg {
	width: 12px;
	height: 12px;
}

/* Petite pointe vers le bouton, comme une bulle de dialogue. */
.aj-fab-label::after {
	content: "";
	position: absolute;
	right: -5px;
	top: 50%;
	width: 9px;
	height: 9px;
	margin-top: -5px;
	border: 1px solid var(--aj-line);
	border-left: none;
	border-bottom: none;
	background: var(--aj-white);
	transform: rotate(45deg);
}

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

.aj-panel {
	position: fixed;
	right: var(--aj-gap-right);
	bottom: calc( var(--aj-gap-bottom) + 72px );
	z-index: var(--aj-z);
	display: flex;
	flex-direction: column;
	width: 374px;
	max-width: calc(100vw - 32px);
	max-height: min( 620px, calc( 100vh - var(--aj-gap-bottom) - 106px ) );
	border: 1px solid var(--aj-line);
	border-radius: var(--aj-radius);
	background: var(--aj-white);
	box-shadow: var(--aj-shadow-lg);
	overflow: hidden;
	color: var(--aj-text);
	font-size: 13.5px;
	line-height: 1.55;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.aj-panel[hidden] {
	display: none !important;
}

.aj-panel.is-visible {
	opacity: 1;
	transform: none;
}

/* En-tête */

.aj-head {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: none;
	padding: 14px 16px;
	border-bottom: 1px solid var(--aj-line);
	background: var(--aj-white);
}

.aj-avatar {
	display: grid;
	place-items: center;
	flex: none;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--aj-teal);
	color: var(--aj-white);
}

.aj-avatar svg {
	width: 22px;
	height: 22px;
}

.aj-head__text {
	flex: 1;
	min-width: 0;
}

.aj-title {
	font-family: var(--aj-font-display);
	font-weight: 600;
	font-size: 13.5px;
	color: var(--aj-navy);
	line-height: 1.3;
}

.aj-status {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 11.5px;
	color: var(--aj-green);
}

.aj-status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aj-green);
	flex: none;
}

.aj-head__tools {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: none;
}

.aj-icon-btn {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--aj-muted-light);
	cursor: pointer;
	transition: background-color 0.18s ease, color 0.18s ease;
}

.aj-icon-btn:hover {
	background: var(--aj-bg-soft);
	color: var(--aj-navy);
}

.aj-icon-btn:focus-visible {
	outline: 2px solid var(--aj-teal);
	outline-offset: 1px;
}

.aj-icon-btn svg {
	width: 16px;
	height: 16px;
}

/* Corps */

.aj-body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	background: var(--aj-white);
	scrollbar-width: thin;
}

.aj-body::-webkit-scrollbar {
	width: 8px;
}

.aj-body::-webkit-scrollbar-thumb {
	border-radius: 4px;
	background: #d7dee6;
}

.aj-thread {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.aj-msg {
	display: flex;
	max-width: 100%;
}

.aj-msg--bot {
	justify-content: flex-start;
}

.aj-msg--user {
	justify-content: flex-end;
}

.aj-bubble {
	max-width: 88%;
	padding: 11px 14px;
	border-radius: 12px;
	font-size: 13.5px;
	overflow-wrap: break-word;
	word-break: break-word;
}

.aj-msg--bot .aj-bubble {
	background: var(--aj-bg);
	color: var(--aj-text);
	border-bottom-left-radius: 4px;
}

.aj-msg--user .aj-bubble {
	background: var(--aj-teal);
	color: var(--aj-white);
	border-bottom-right-radius: 4px;
}

.aj-msg--error .aj-bubble {
	background: #fdecea;
	color: #7f231b;
	border: 1px solid #f5c6c2;
	border-bottom-left-radius: 12px;
}

.aj-bubble p {
	margin: 0 0 0.6em;
}

.aj-bubble p:last-child {
	margin-bottom: 0;
}

.aj-bubble ul {
	margin: 0.4em 0;
	padding-left: 1.1em;
	list-style: disc;
}

.aj-bubble li {
	margin-bottom: 0.25em;
}

.aj-bubble a {
	color: inherit;
	text-decoration: underline;
}

.aj-msg--bot .aj-bubble a {
	color: var(--aj-teal-dark);
}

.aj-bubble strong {
	font-weight: 600;
}

/* Actions rapides — reprise exacte des .chat-opt de la maquette. */

.aj-options {
	display: flex;
	flex-direction: column;
	gap: 9px;
	margin-top: 14px;
}

.aj-options[hidden] {
	display: none;
}

.aj-opt {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 11px 13px;
	border: 1px solid var(--aj-line);
	border-radius: var(--aj-radius-sm);
	background: var(--aj-white);
	color: var(--aj-navy);
	font-family: inherit;
	font-size: 13px;
	line-height: 1.35;
	text-align: left;
	cursor: pointer;
	transition: border-color 0.2s ease, background-color 0.2s ease;
}

.aj-opt:hover {
	border-color: var(--aj-teal);
	background: var(--aj-bg-soft);
}

.aj-opt:focus-visible {
	outline: 2px solid var(--aj-teal);
	outline-offset: 1px;
}

.aj-opt svg {
	flex: none;
	width: 16px;
	height: 16px;
	color: var(--aj-teal);
}

/* Indicateur de frappe */

.aj-typing {
	display: flex;
	align-items: center;
	gap: 9px;
	margin-top: 12px;
	color: var(--aj-muted);
	font-size: 12px;
}

.aj-typing[hidden] {
	display: none;
}

.aj-typing__dots {
	display: inline-flex;
	gap: 4px;
	padding: 8px 11px;
	border-radius: 12px;
	background: var(--aj-bg);
}

.aj-typing__dots i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--aj-muted-light);
	animation: aj-bounce 1.2s infinite ease-in-out;
}

.aj-typing__dots i:nth-child(2) { animation-delay: 0.15s; }
.aj-typing__dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes aj-bounce {
	0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-3px); }
}

/* Pied : notice, consentement, saisie, mention légale */

.aj-foot {
	flex: none;
	padding: 12px 16px 14px;
	border-top: 1px solid var(--aj-line);
	background: var(--aj-white);
}

.aj-notice {
	margin-bottom: 10px;
	padding: 8px 11px;
	border-radius: var(--aj-radius-sm);
	background: var(--aj-bg-soft);
	color: var(--aj-muted);
	font-size: 12px;
}

.aj-notice[hidden] {
	display: none;
}

.aj-notice.is-error {
	background: #fdecea;
	color: #7f231b;
}

.aj-consent {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	margin-bottom: 10px;
	color: var(--aj-muted);
	font-size: 11.5px;
	line-height: 1.4;
	cursor: pointer;
}

.aj-consent input {
	flex: none;
	margin: 2px 0 0;
	accent-color: var(--aj-teal);
}

.aj-form {
	margin: 0;
}

.aj-input {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 5px 5px 5px 15px;
	border: 1px solid var(--aj-line);
	border-radius: 24px;
	background: var(--aj-white);
	transition: border-color 0.2s ease;
}

.aj-input:focus-within {
	border-color: var(--aj-teal);
}

.aj-input textarea {
	flex: 1;
	min-width: 0;
	max-height: 96px;
	margin: 0;
	padding: 8px 0;
	border: none;
	background: none;
	color: var(--aj-text);
	font-family: inherit;
	font-size: 13px;
	line-height: 1.45;
	resize: none;
	overflow-y: auto;
	box-shadow: none;
}

.aj-input textarea:focus {
	outline: none;
	box-shadow: none;
}

.aj-input textarea::placeholder {
	color: var(--aj-muted-light);
}

.aj-send {
	display: grid;
	place-items: center;
	flex: none;
	width: 34px;
	height: 34px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--aj-teal);
	color: var(--aj-white);
	cursor: pointer;
	transition: background-color 0.2s ease, opacity 0.2s ease;
}

.aj-send:hover:not(:disabled) {
	background: var(--aj-teal-dark);
}

.aj-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.aj-send:focus-visible {
	outline: 2px solid var(--aj-teal);
	outline-offset: 2px;
}

.aj-send svg {
	width: 16px;
	height: 16px;
}

.aj-note {
	margin: 10px 0 0;
	color: var(--aj-muted-light);
	font-size: 11px;
	line-height: 1.4;
	text-align: center;
}

.aj-panel .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	border: 0;
	white-space: nowrap;
}

/* ------------------------------------------------------------------ *
 * Mobile : le panneau devient une feuille pleine largeur.
 * ------------------------------------------------------------------ */

@media (max-width: 600px) {
	.aj-fab {
		--aj-gap-right: 16px;
		--aj-gap-bottom: 16px;
		width: 52px;
		height: 52px;
	}

	.aj-fab__icon svg {
		width: 23px;
		height: 23px;
	}

	.aj-panel {
		right: 8px;
		left: 8px;
		bottom: 8px;
		width: auto;
		max-width: none;
		max-height: calc(100vh - 16px);
		max-height: calc(100dvh - 16px);
		border-radius: var(--aj-radius);
	}

	/* Le bouton flottant gênerait la saisie : on l'efface pendant l'échange. */
	.aj-fab.is-open {
		opacity: 0;
		pointer-events: none;
	}

	.aj-fab-label {
		--aj-gap-right: 16px;
		--aj-gap-bottom: 16px;
		right: calc( var(--aj-gap-right) + 62px ); /* bouton 52 + écart 10 */
		bottom: calc( var(--aj-gap-bottom) + 8px );
		max-width: calc(100vw - 100px);
	}

	.aj-fab-label__text {
		font-size: 13px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.aj-fab,
	.aj-fab__icon,
	.aj-fab-label,
	.aj-panel,
	.aj-typing__dots i {
		transition: none;
		animation: none;
	}

	.aj-fab__pulse {
		display: none;
	}
}

/* Le thème WiLDAF-AO embarque son propre bouton flottant (#fab-chat), qui ne
   fait que défiler jusqu'à la carte de la maquette. Deux pastilles empilées
   dans le même coin n'aideraient personne : on masque la sienne, et le script
   reprend sa carte en page pour la rendre réellement fonctionnelle. */
body.aj-has-widget #fab-chat {
	display: none !important;
}

/* Carte « Assistante juridique » de la page d'accueil, une fois branchée. */
body.aj-has-widget .chat-widget .chat-input input,
body.aj-has-widget .chat-widget .chat-opt,
body.aj-has-widget .chat-widget .chat-send {
	cursor: pointer;
}

@media print {
	.aj-fab,
	.aj-fab-label,
	.aj-panel {
		display: none !important;
	}
}
