/**
 * Synterial AI Chatbot for Amelia - public chat widget.
 *
 * Palette is driven by the --saic-* custom properties below: a site can
 * retheme the widget by overriding them on .synterial-aic-chat. Keep the
 * accent / accent-strong split described in docs/adr-003: white text sits
 * only on --saic-accent-strong, which clears AA.
 */

.synterial-aic-chat {
	--saic-accent: #4caf50;
	--saic-accent-strong: #3d9142;
	--saic-accent-soft: #e8f5e9;
	--saic-accent-tint: #f1f8f2;
	--saic-online: #7ed957;
	--saic-text: #1d2327;
	--saic-muted: #5b6b60;
	--saic-surface: #fff;
	--saic-border: #d7e5d9;
	--saic-radius: 18px;
	--saic-error-bg: #fdf0ef;
	--saic-error-text: #8a2c25;

	display: flex;
	flex-direction: column;
	max-width: 720px;
	border: 1px solid var(--saic-border);
	border-radius: 14px;
	overflow: hidden;
	background: var(--saic-surface);
	color: var(--saic-text);
	box-shadow: 0 6px 24px rgba(29, 35, 39, 0.08);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}

/* Themes style button/textarea/p aggressively; reset inside our scope only. */
.synterial-aic-chat *,
.synterial-aic-chat *::before,
.synterial-aic-chat *::after { box-sizing: border-box; }
.synterial-aic-chat p { margin: 0; }
.synterial-aic-chat button {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	line-height: 1.2;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}
.synterial-aic-chat button:disabled { cursor: default; }

/* Header ------------------------------------------------------------------ */

.synterial-aic-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 14px;
	background: linear-gradient(135deg, var(--saic-accent) 0%, var(--saic-accent-strong) 65%);
	color: #fff;
}

.synterial-aic-chat__avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.22);
}

.synterial-aic-chat__avatar svg { width: 22px; height: 22px; }

.synterial-aic-chat__identity { flex: 1 1 auto; min-width: 0; }

.synterial-aic-chat__title {
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.01em;
}

.synterial-aic-chat__status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: rgba(255, 255, 255, 0.92);
}

.synterial-aic-chat__status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--saic-online);
	animation: synterial-aic-pulse 2.4s ease-in-out infinite;
}

@keyframes synterial-aic-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.45; }
}

.synterial-aic-chat__reset {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 32px;
	height: 32px;
	border-radius: 9px;
	background: rgba(255, 255, 255, 0.18);
	color: #fff;
	transition: background 0.15s ease;
}

.synterial-aic-chat__reset:hover { background: rgba(255, 255, 255, 0.32); }
.synterial-aic-chat__reset svg { width: 17px; height: 17px; }

.synterial-aic-chat__reset:focus-visible,
.synterial-aic-chat__btn:focus-visible,
.synterial-aic-chat__send:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.synterial-aic-chat__btn:focus-visible,
.synterial-aic-chat__send:focus-visible { outline-color: var(--saic-accent-strong); }

/* Transcript -------------------------------------------------------------- */

.synterial-aic-chat__messages {
	flex: 1 1 auto;
	min-height: 320px;
	max-height: 520px;
	overflow-y: auto;
	padding: 16px;
	background: var(--saic-accent-tint);
	scroll-behavior: smooth;
	scrollbar-width: thin;
	scrollbar-color: var(--saic-border) transparent;
}

.synterial-aic-chat__messages::-webkit-scrollbar { width: 8px; }
.synterial-aic-chat__messages::-webkit-scrollbar-track { background: transparent; }
.synterial-aic-chat__messages::-webkit-scrollbar-thumb {
	border: 2px solid var(--saic-accent-tint);
	border-radius: 8px;
	background: var(--saic-border);
}

/* Empty state ------------------------------------------------------------- */

.synterial-aic-chat__empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 280px;
	padding: 16px;
	text-align: center;
}

.synterial-aic-chat__empty-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin-bottom: 4px;
	border-radius: 50%;
	background: var(--saic-accent-soft);
	color: var(--saic-accent-strong);
}

.synterial-aic-chat__empty-icon svg { width: 28px; height: 28px; }

.synterial-aic-chat__empty-title {
	font-size: 16px;
	font-weight: 700;
}

.synterial-aic-chat__empty-text {
	max-width: 300px;
	color: var(--saic-muted);
}

/* Messages ---------------------------------------------------------------- */

.synterial-aic-chat__message {
	max-width: 80%;
	width: fit-content;
	margin: 0 0 10px;
	padding: 10px 14px;
	border-radius: 16px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.synterial-aic-chat__message--assistant {
	border-bottom-left-radius: 4px;
	background: var(--saic-accent-soft);
	color: var(--saic-text);
}

.synterial-aic-chat__message--visitor {
	margin-left: auto;
	border-bottom-right-radius: 4px;
	background: var(--saic-accent-strong);
	color: #fff;
}

/* Rendered Markdown inside assistant bubbles. The bubble keeps pre-wrap for
   plain text, but rendered blocks bring their own spacing, so it is turned off
   once real elements are present. */
.synterial-aic-chat__message--assistant { white-space: normal; }
.synterial-aic-chat__message--assistant p { margin: 0; }
.synterial-aic-chat__message--assistant p + p,
.synterial-aic-chat__message--assistant .synterial-aic-chat__md-list { margin-top: 8px; }
.synterial-aic-chat__message--assistant strong { font-weight: 700; }
.synterial-aic-chat__message--assistant em { font-style: italic; }
.synterial-aic-chat__message--assistant del { opacity: 0.75; }

.synterial-aic-chat__message--assistant code {
	padding: 1px 5px;
	border-radius: 5px;
	background: rgba(29, 35, 39, 0.07);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.92em;
	overflow-wrap: anywhere;
}

.synterial-aic-chat__md-list {
	margin: 0;
	padding-left: 20px;
	list-style-position: outside;
}

.synterial-aic-chat__md-list li { margin: 2px 0; }
.synterial-aic-chat__md-list li::marker { color: var(--saic-accent-strong); }

/* A failed turn must never look like the bot answered. */
.synterial-aic-chat__message--error {
	border-bottom-left-radius: 4px;
	background: var(--saic-error-bg);
	color: var(--saic-error-text);
}

/* Typing indicator -------------------------------------------------------- */

.synterial-aic-chat__typing {
	display: flex;
	align-items: center;
	gap: 5px;
	width: fit-content;
	margin: 0 0 10px;
	padding: 13px 14px;
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	background: var(--saic-accent-soft);
}

.synterial-aic-chat__typing-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--saic-accent-strong);
	opacity: 0.65;
	animation: synterial-aic-bounce 1.2s ease-in-out infinite;
}

.synterial-aic-chat__typing-dot:nth-child(3) { animation-delay: 0.16s; }
.synterial-aic-chat__typing-dot:nth-child(4) { animation-delay: 0.32s; }

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

/* Cards: consent and booking confirmation --------------------------------- */

.synterial-aic-chat__card {
	margin: 0 0 10px;
	padding: 14px 16px;
	border: 1px solid var(--saic-border);
	border-radius: var(--saic-radius);
	background: var(--saic-surface);
	text-align: center;
}

.synterial-aic-chat__card-text { color: var(--saic-text); }
.synterial-aic-chat__card-text a { color: var(--saic-accent-strong); }

.synterial-aic-chat__card-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-top: 12px;
}

.synterial-aic-chat__card-note {
	margin-top: 10px;
	color: var(--saic-muted);
	font-size: 13px;
}

.synterial-aic-chat__confirmation { text-align: left; }
.synterial-aic-chat__confirmation .synterial-aic-chat__card-actions { justify-content: flex-start; }

.synterial-aic-chat__btn {
	padding: 11px 28px;
	border: 1px solid transparent;
	border-radius: 999px;
	font-size: 14px;
	font-weight: 600;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.synterial-aic-chat__btn--primary {
	background: var(--saic-accent-strong);
	border-color: var(--saic-accent-strong);
	color: #fff;
}

.synterial-aic-chat__btn--primary:hover:not(:disabled) {
	background: #35803a;
	border-color: #35803a;
	color: #fff;
}

.synterial-aic-chat__btn--ghost {
	border-color: var(--saic-border);
	color: var(--saic-muted);
}

/* Fills on hover so the label stays readable once it turns white. */
.synterial-aic-chat__btn--ghost:hover:not(:disabled) {
	background: var(--saic-accent-strong);
	border-color: var(--saic-accent-strong);
	color: #fff;
}

.synterial-aic-chat__btn:disabled { opacity: 0.55; }

/* Composer ---------------------------------------------------------------- */

.synterial-aic-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--saic-border);
	background: var(--saic-surface);
}

.synterial-aic-chat__form textarea {
	flex: 1 1 auto;
	width: 100%;
	max-height: 120px;
	margin: 0;
	padding: 9px 10px;
	border: 0;
	border-radius: 10px;
	background: transparent;
	color: var(--saic-text);
	font: inherit;
	line-height: 1.4;
	resize: none;
	overflow-y: auto;
	-webkit-appearance: none;
	appearance: none;
}

.synterial-aic-chat__form textarea:focus { outline: none; }
.synterial-aic-chat__form textarea::placeholder { color: var(--saic-muted); opacity: 1; }

.synterial-aic-chat__form:focus-within {
	box-shadow: inset 0 0 0 2px var(--saic-accent-soft);
}

.synterial-aic-chat__form.is-disabled textarea { color: var(--saic-muted); }

.synterial-aic-chat__send {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--saic-accent);
	color: #fff;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.synterial-aic-chat__send:hover:not(:disabled) { background: var(--saic-accent-strong); }
.synterial-aic-chat__send:disabled { opacity: 0.45; }
.synterial-aic-chat__send svg { width: 18px; height: 18px; }

/* Screen-reader-only text. Themes usually ship .screen-reader-text, but the
   widget must not depend on the active theme for accessible labels. */
.synterial-aic-chat .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Responsive -------------------------------------------------------------- */

@media (max-width: 600px) {
	.synterial-aic-chat { font-size: 14px; }
	.synterial-aic-chat__header { padding: 10px 12px; }
	.synterial-aic-chat__messages { padding: 12px; min-height: 260px; }
	.synterial-aic-chat__message { max-width: 88%; }
	.synterial-aic-chat__card-actions { flex-direction: column; }
	.synterial-aic-chat__btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
	.synterial-aic-chat *,
	.synterial-aic-chat *::before,
	.synterial-aic-chat *::after {
		animation: none !important;
		transition: none !important;
	}
	.synterial-aic-chat__messages { scroll-behavior: auto; }
}
