/*
 * Thin, standalone stylesheet for the optional real MaditSpirit AI
 * conversation embedded directly under the Dedicated Diagnostic result.
 *
 * Deliberately duplicates (does not import) the relevant subset of
 * assets/css/frontend-app.css's composer/message/markdown/toast rules so
 * this page never has to load the full My AI Coach app stylesheet. Values
 * below are copied verbatim from frontend-app.css to look and behave
 * identically to the existing chat composer.
 */

.msai-fq-conversation {
	margin-top: 28px;
	font-family: "Inter", "Segoe UI", sans-serif;
}

.msai-fq-conversation .msai-screen-reader-heading {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.msai-fq-conversation__feed {
	display: none;
	grid-template-columns: 1fr;
	gap: 16px;
	margin-bottom: 16px;
}

.msai-fq-conversation__feed.is-visible {
	display: grid;
}

.msai-fq-conversation__message {
	width: fit-content;
	max-width: min(840px, 92%);
	padding: 16px 18px;
	border-radius: 24px;
	box-shadow: 0 10px 24px rgba(0, 51, 102, 0.07);
}

.msai-fq-conversation__message--assistant {
	width: min(1280px, calc(100% - 12px));
	max-width: min(1280px, calc(100% - 12px));
	background: rgba(255, 255, 255, 0.98);
}

.msai-fq-conversation__message--user {
	margin-left: auto;
	max-width: min(720px, 68%);
	background: linear-gradient(135deg, #003366 0%, #4A90E2 100%);
	color: #fff;
}

.msai-fq-conversation__message--pending {
	opacity: 0.7;
}

.msai-fq-conversation__meta {
	margin-bottom: 8px;
	font-size: 0.78rem;
	font-weight: 700;
	opacity: 0.7;
}

.msai-fq-conversation__body {
	line-height: 1.66;
	white-space: pre-wrap;
}

.msai-fq-conversation__message--user .msai-fq-conversation__body {
	white-space: pre-wrap;
}

.msai-fq-conversation__proposal {
	margin-top: 14px;
	padding: 14px 16px;
	border-radius: 16px;
	background: rgba(74, 144, 226, 0.06);
	border: 1px solid rgba(0, 51, 102, 0.12);
}

.msai-fq-conversation__proposal-eyebrow {
	font-size: 0.72rem;
	font-weight: 800;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: #4A90E2;
	margin-bottom: 8px;
}

.msai-fq-conversation__proposal-list {
	margin: 0 0 8px;
	padding-left: 20px;
	display: grid;
	gap: 4px;
	font-size: 0.92rem;
	line-height: 1.4;
	color: #102A43;
}

.msai-fq-conversation__proposal-note {
	margin: 0 0 8px;
	font-size: 0.82rem;
	opacity: 0.7;
}

.msai-fq-conversation__proposal-error {
	margin: 0 0 8px;
	font-size: 0.88rem;
	color: #b3261e;
}

.msai-fq-conversation__proposal-success {
	margin: 0;
	font-size: 0.9rem;
	font-weight: 700;
	color: #1e7a3c;
}

.msai-fq-conversation__proposal-actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.msai-fq-conversation__proposal-approve,
.msai-fq-conversation__proposal-cancel {
	border: 0;
	border-radius: 999px;
	padding: 8px 16px;
	font-size: 0.85rem;
	font-weight: 700;
	cursor: pointer;
}

.msai-fq-conversation__proposal-approve {
	background: linear-gradient(135deg, #003366 0%, #4A90E2 100%);
	color: #fff;
}

.msai-fq-conversation__proposal-approve[disabled],
.msai-fq-conversation__proposal-cancel[disabled] {
	opacity: 0.6;
	cursor: default;
}

.msai-fq-conversation__proposal-cancel {
	background: rgba(0, 51, 102, 0.06);
	color: #003366;
}

/* Markdown body (assistant messages only) */
.msai-fq-conversation__markdown {
	display: grid;
	gap: 14px;
	font-size: 0.97rem;
	line-height: 1.72;
	color: inherit;
	width: 100%;
	white-space: normal;
}

.msai-fq-conversation__markdown > :first-child { margin-top: 0; }
.msai-fq-conversation__markdown > :last-child { margin-bottom: 0; }

.msai-fq-conversation__markdown h1,
.msai-fq-conversation__markdown h2,
.msai-fq-conversation__markdown h3,
.msai-fq-conversation__markdown h4 {
	margin: 0;
	color: #102A43;
	line-height: 1.24;
	letter-spacing: -0.015em;
}

.msai-fq-conversation__markdown h1 { font-size: 1.28rem; font-weight: 820; }
.msai-fq-conversation__markdown h2 { font-size: 1.18rem; font-weight: 800; }
.msai-fq-conversation__markdown h3 { font-size: 1.05rem; font-weight: 780; }
.msai-fq-conversation__markdown h4 { font-size: 0.96rem; font-weight: 760; }

.msai-fq-conversation__markdown p,
.msai-fq-conversation__markdown ul,
.msai-fq-conversation__markdown ol,
.msai-fq-conversation__markdown blockquote,
.msai-fq-conversation__markdown pre {
	margin: 0;
}

.msai-fq-conversation__markdown ul,
.msai-fq-conversation__markdown ol {
	padding-left: 1.2rem;
	display: grid;
	gap: 0.4rem;
}

.msai-fq-conversation__markdown ol { list-style: decimal outside; }
.msai-fq-conversation__markdown ul { list-style: disc outside; }
.msai-fq-conversation__markdown ol ol { list-style-type: lower-alpha; }
.msai-fq-conversation__markdown ul ul { list-style-type: circle; }

.msai-fq-conversation__markdown li {
	display: list-item;
	padding-left: 0.12rem;
}

.msai-fq-conversation__markdown strong { font-weight: 760; color: #102A43; }
.msai-fq-conversation__markdown em { font-style: italic; }

.msai-fq-conversation__markdown a {
	color: #003366;
	font-weight: 600;
	text-decoration: underline;
	text-decoration-thickness: 0.08em;
	text-underline-offset: 0.14em;
	word-break: break-word;
}

.msai-fq-conversation__markdown a:hover,
.msai-fq-conversation__markdown a:focus-visible {
	color: #00264d;
}

/*
 * The five semantic colors an assistant message may request via the
 * allowlisted [color=NAME]...[/color] extension - mirrors the canonical
 * colors used by frontend-app.css so responses look identical regardless
 * of which surface rendered them.
 */
.msai-fq-conversation__markdown .msai-color-blue { color: #003366; font-weight: 650; }
.msai-fq-conversation__markdown .msai-color-green { color: #17895d; font-weight: 650; }
.msai-fq-conversation__markdown .msai-color-yellow { color: #8b6619; font-weight: 650; }
.msai-fq-conversation__markdown .msai-color-orange { color: #b5530a; font-weight: 650; }
.msai-fq-conversation__markdown .msai-color-red { color: #D92D20; font-weight: 700; }

.msai-fq-conversation__markdown blockquote {
	padding: 0.85rem 1rem;
	border-left: 3px solid rgba(74, 144, 226, 0.52);
	border-radius: 0 16px 16px 0;
	background: linear-gradient(180deg, rgba(234, 243, 255, 0.92) 0%, rgba(247, 251, 255, 0.98) 100%);
	color: #60758F;
}

.msai-fq-conversation__markdown hr {
	border: 0;
	border-top: 1px solid rgba(116, 153, 208, 0.24);
	margin: 0;
}

.msai-fq-conversation__markdown code {
	padding: 0.16rem 0.42rem;
	border-radius: 8px;
	background: rgba(7, 35, 74, 0.08);
	color: #003366;
	font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
	font-size: 0.9em;
	word-break: break-word;
}

.msai-fq-conversation__markdown pre {
	max-width: 100%;
	padding: 1rem 1.05rem;
	border: 1px solid rgba(7, 35, 74, 0.08);
	border-radius: 18px;
	background: linear-gradient(180deg, rgba(11, 29, 54, 0.97) 0%, rgba(16, 42, 67, 0.98) 100%);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.msai-fq-conversation__markdown pre code {
	display: block;
	padding: 0;
	border-radius: 0;
	background: transparent;
	color: #eaf3ff;
	font-size: 0.9rem;
	line-height: 1.65;
	white-space: pre;
	word-break: normal;
}

.msai-fq-conversation__markdown .msai-markdown-table-wrap {
	max-width: 100%;
	overflow-x: auto;
	overflow-y: hidden;
	padding-bottom: 2px;
	-webkit-overflow-scrolling: touch;
}

.msai-fq-conversation__markdown .msai-markdown-table {
	width: 100%;
	min-width: max(100%, calc(var(--msai-table-columns, 1) * 13.75rem));
	border-collapse: separate;
	border-spacing: 0;
	border: 1px solid rgba(116, 153, 208, 0.22);
	border-radius: 16px;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.96);
	table-layout: auto;
}

.msai-fq-conversation__markdown .msai-markdown-table th,
.msai-fq-conversation__markdown .msai-markdown-table td {
	padding: 0.82rem 0.9rem;
	border-bottom: 1px solid rgba(116, 153, 208, 0.16);
	border-right: 1px solid rgba(116, 153, 208, 0.16);
	text-align: left;
	vertical-align: top;
	white-space: normal;
	word-break: normal;
	overflow-wrap: break-word;
	line-height: 1.55;
}

.msai-fq-conversation__markdown .msai-markdown-table th {
	background: linear-gradient(180deg, rgba(234, 243, 255, 0.98) 0%, rgba(245, 250, 255, 0.98) 100%);
	color: #102A43;
	font-size: 0.84rem;
	font-weight: 760;
}

.msai-fq-conversation__markdown .msai-markdown-table td { color: #60758F; }
.msai-fq-conversation__markdown .msai-markdown-table tr:last-child td { border-bottom: 0; }
.msai-fq-conversation__markdown .msai-markdown-table th:last-child,
.msai-fq-conversation__markdown .msai-markdown-table td:last-child { border-right: 0; }

/* Blinking caret shown only while a response is actively streaming in -
   disappears the instant the final message replaces it. */
.msai-fq-conversation__caret {
	display: inline-block;
	width: 2px;
	height: 1.1em;
	margin-left: 2px;
	vertical-align: text-bottom;
	background: currentColor;
	opacity: 0.75;
	animation: msai-fq-conv-caret-blink 0.9s steps(1) infinite;
}

@keyframes msai-fq-conv-caret-blink {
	0%, 49% { opacity: 0.75; }
	50%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.msai-fq-conversation__caret {
		animation: none;
		opacity: 0.5;
	}
}

/* Thinking indicator while waiting for the first token */
.msai-fq-conversation__thinking {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.msai-fq-conversation__thinking-dots span {
	display: inline-block;
	width: 5px;
	height: 5px;
	margin-left: 3px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.35;
	animation: msai-fq-conv-blink 1.2s infinite ease-in-out;
}

.msai-fq-conversation__thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.msai-fq-conversation__thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes msai-fq-conv-blink {
	0%, 80%, 100% { opacity: 0.25; }
	40% { opacity: 0.9; }
}

/*
 * Composer - dimensions/typography/radius copied from .msai-chat-composer.
 *
 * Fixed to the bottom of the VIEWPORT (not the document) so it stays
 * reachable while the visitor scrolls through the Diagnostic/offer content
 * above it - matching the persistent composer behavior in My AI Coach.
 * Only the input bar is fixed; the message feed itself stays in normal
 * document flow at the position where it was mounted (end of the
 * Diagnostic content), so scrolling down still reveals the conversation
 * naturally. body.msai-fq-conv-active supplies the matching bottom
 * padding (see mount-time class below) so the last Diagnostic/offer
 * content is never hidden behind the fixed bar.
 */
.msai-fq-conversation__composer-wrap {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 9999;
	display: flex;
	justify-content: center;
	padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
	background: linear-gradient(180deg, rgba(247, 250, 255, 0) 0%, rgba(247, 250, 255, 0.94) 28%, rgba(247, 250, 255, 0.99) 100%);
	pointer-events: none;
}

.msai-fq-conversation__composer-wrap > * {
	pointer-events: auto;
}

.msai-fq-conversation__composer {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 8px;
	align-items: end;
	width: 100%;
	max-width: 840px;
	padding: 8px;
	border-radius: 24px;
	background: rgba(255, 255, 255, 0.98);
	border: 1px solid rgba(114, 154, 209, 0.16);
	box-shadow: 0 16px 30px rgba(48, 86, 141, 0.14);
	overflow: hidden;
	position: relative;
}

/* Reserves scroll space so the fixed composer never covers the last
   Diagnostic/offer content - width/height applied only via the mount-time
   body class, never affecting any other page. */
body.msai-fq-conv-active {
	padding-bottom: var(--msai-fq-composer-space, 88px);
}

@media (max-width: 600px) {
	body.msai-fq-conv-active {
		padding-bottom: var(--msai-fq-composer-space, 96px);
	}
}

.msai-fq-conversation__composer textarea {
	width: 100%;
	min-height: 48px;
	max-height: 168px;
	padding: 12px 8px 10px;
	resize: none;
	box-shadow: none;
	background: transparent;
	color: #102A43;
	border: 0;
	outline: none;
	appearance: none;
	-webkit-appearance: none;
	font: inherit;
	line-height: 1.45;
	overflow-y: auto;
}

.msai-fq-conversation__composer textarea::placeholder {
	color: #7B93AD;
}

.msai-fq-conversation__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 42px;
	min-width: 42px;
	width: 42px;
	padding: 0;
	border: 0;
	border-radius: 14px;
	background: linear-gradient(135deg, #003366 0%, #4A90E2 100%);
	color: #fff;
	box-shadow: 0 14px 26px rgba(47, 124, 255, 0.18);
	flex: 0 0 auto;
	align-self: end;
	cursor: pointer;
	font: inherit;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.msai-fq-conversation__send:hover,
.msai-fq-conversation__send:focus-visible {
	transform: translateY(-1px);
}

.msai-fq-conversation__send:disabled {
	opacity: 0.6;
	cursor: default;
	transform: none;
}

.msai-fq-conversation__send svg {
	display: block;
	pointer-events: none;
}

.msai-fq-conversation__status {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* Local toast - mirrors #msai-toast-stack / .msai-toast from frontend-app.css */
.msai-fq-conversation__toast-stack {
	position: fixed;
	z-index: 100050;
	top: max(20px, env(safe-area-inset-top));
	right: 20px;
	display: grid;
	gap: 10px;
	width: min(390px, calc(100vw - 40px));
	pointer-events: none;
}

.msai-fq-conversation__toast {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 10px;
	padding: 13px 14px;
	border: 1px solid #cfdad4;
	border-left: 4px solid #b44848;
	border-radius: 14px;
	background: #fff;
	color: #17251e;
	box-shadow: 0 14px 38px rgba(18, 40, 29, 0.16);
	pointer-events: auto;
	overflow-wrap: anywhere;
	font-family: "Inter", "Segoe UI", sans-serif;
	animation: msai-fq-conv-toast-in 0.22s ease-out;
}

.msai-fq-conversation__toast.is-leaving {
	animation: msai-fq-conv-toast-out 0.18s ease-in forwards;
}

.msai-fq-conversation__toast-message {
	font-size: 0.9rem;
	line-height: 1.45;
	font-weight: 600;
}

.msai-fq-conversation__toast-close {
	min-width: 40px;
	min-height: 40px;
	border: 0;
	border-radius: 10px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1.25rem;
	cursor: pointer;
}

.msai-fq-conversation__toast-close:focus-visible {
	outline: 3px solid rgba(58, 112, 83, 0.3);
	outline-offset: 2px;
}

@keyframes msai-fq-conv-toast-in {
	from { opacity: 0; transform: translateY(-8px) scale(0.98); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes msai-fq-conv-toast-out {
	from { opacity: 1; transform: translateY(0) scale(1); }
	to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

@media (prefers-reduced-motion: reduce) {
	.msai-fq-conversation__toast,
	.msai-fq-conversation__toast.is-leaving {
		animation: none;
	}
	.msai-fq-conversation__thinking-dots span {
		animation: none;
		opacity: 0.6;
	}
}

@media (max-width: 600px) {
	.msai-fq-conversation__toast-stack {
		top: calc(max(8px, env(safe-area-inset-top)) + 12px);
		right: 12px;
		left: 12px;
		width: auto;
		max-width: none;
	}
}

@media (max-width: 768px) {
	.msai-fq-conversation {
		margin-top: 20px;
	}
	.msai-fq-conversation__message {
		max-width: 94%;
	}
	.msai-fq-conversation__message--user {
		max-width: 88%;
	}
	.msai-fq-conversation__composer {
		padding: 6px;
		border-radius: 20px;
	}
	.msai-fq-conversation__composer textarea {
		min-height: 44px;
		padding: 10px 6px 8px;
	}
	.msai-fq-conversation__send {
		height: 38px;
		min-width: 38px;
		width: 38px;
		border-radius: 12px;
	}
}

@media (max-width: 420px) {
	.msai-fq-conversation__message {
		max-width: 100%;
	}
	.msai-fq-conversation__message--user {
		max-width: 96%;
	}
}
