/**
 * Widget de conversation Netsystem.
 *
 * Les propriétés sont préfixées et la spécificité volontairement basse, le widget
 * s'insérant dans un thème dont on ne maîtrise pas les styles.
 */

.nschat {
	--nschat-accent: #1f3a5f;
	--nschat-surface: #ffffff;
	--nschat-text: #1a1a1a;
	--nschat-muted: #6b7280;
	--nschat-border: #e5e7eb;
	--nschat-radius: 12px;

	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}

.nschat-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin-left: auto;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--nschat-accent);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	transition: transform 0.15s ease;
}

.nschat-toggle:hover {
	transform: scale(1.05);
}

.nschat-toggle svg {
	width: 26px;
	height: 26px;
	fill: currentColor;
}

.nschat-panel {
	display: flex;
	flex-direction: column;
	width: 360px;
	max-width: calc(100vw - 40px);
	height: 480px;
	max-height: calc(100vh - 120px);
	margin-bottom: 12px;
	overflow: hidden;
	border: 1px solid var(--nschat-border);
	border-radius: var(--nschat-radius);
	background: var(--nschat-surface);
	color: var(--nschat-text);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.nschat-panel[hidden] {
	display: none;
}

.nschat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: var(--nschat-accent);
	color: #fff;
	font-weight: 600;
}

.nschat-close {
	border: 0;
	background: none;
	color: inherit;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
}

.nschat-thread {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	background: #fafafa;
}

.nschat-message {
	display: flex;
	margin-bottom: 10px;
}

.nschat-message--user {
	justify-content: flex-end;
}

.nschat-bubble {
	max-width: 85%;
	padding: 9px 13px;
	border-radius: var(--nschat-radius);
	overflow-wrap: anywhere;
}

/* Les messages du visiteur restent du texte brut : les sauts de ligne qu'il a
   saisis doivent être conservés. Les réponses, elles, sont structurées en blocs
   par le rendu Markdown — y préserver les retours ajouterait des trous. */
.nschat-message--user .nschat-bubble,
.nschat-bubble.is-pending,
.nschat-bubble.is-error {
	white-space: pre-wrap;
}

.nschat-message--assistant .nschat-bubble {
	border: 1px solid var(--nschat-border);
	background: var(--nschat-surface);
	border-bottom-left-radius: 4px;
}

.nschat-message--user .nschat-bubble {
	background: var(--nschat-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.nschat-bubble.is-pending {
	color: var(--nschat-muted);
	font-style: italic;
}

/* Mise en forme du Markdown rendu par le widget. Les marges sont resserrées :
   une bulle de conversation n'est pas un article. */
.nschat-paragraph {
	margin: 0 0 8px;
}

.nschat-bubble > .nschat-paragraph:last-child,
.nschat-bubble > .nschat-list:last-child {
	margin-bottom: 0;
}

.nschat-heading {
	display: block;
	margin: 10px 0 4px;
}

.nschat-bubble > .nschat-heading:first-child {
	margin-top: 0;
}

.nschat-list {
	margin: 0 0 8px;
	padding-left: 20px;
}

.nschat-list li {
	margin-bottom: 3px;
}

.nschat-bubble code {
	padding: 1px 4px;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.06);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.9em;
}

.nschat-message--assistant .nschat-bubble a {
	color: var(--nschat-accent);
	text-decoration: underline;
}

.nschat-bubble.is-error {
	border-color: #fca5a5;
	background: #fef2f2;
	color: #991b1b;
	font-style: normal;
}

.nschat-sources {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-items: baseline;
	margin: -2px 0 14px;
	font-size: 13px;
}

.nschat-sources__label {
	color: var(--nschat-muted);
}

.nschat-sources a {
	color: var(--nschat-accent);
	text-decoration: underline;
}

.nschat-form {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--nschat-border);
	background: var(--nschat-surface);
}

.nschat-input {
	flex: 1;
	min-width: 0;
	padding: 9px 12px;
	border: 1px solid var(--nschat-border);
	border-radius: 8px;
	font: inherit;
	color: inherit;
	background: #fff;
}

.nschat-input:focus {
	outline: 2px solid var(--nschat-accent);
	outline-offset: -1px;
}

.nschat-send {
	padding: 9px 16px;
	border: 0;
	border-radius: 8px;
	background: var(--nschat-accent);
	color: #fff;
	font: inherit;
	cursor: pointer;
}

.nschat-form.is-busy .nschat-send,
.nschat-form.is-busy .nschat-input {
	opacity: 0.6;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.nschat-toggle {
		transition: none;
	}
}

@media (max-width: 480px) {
	.nschat {
		right: 12px;
		bottom: 12px;
	}

	.nschat-panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 100px);
	}
}
