/* @famedico chat widget — v2.4 "right dock".
 *
 * Layout change from v2.3 floating popup:
 *   · Matches demolab LabAI: the agent occupies the full right edge of the
 *     viewport as a fixed dock. Main content is padded left of it on desktop
 *     so nothing sits under the panel.
 *   · Minimise collapses to a thin bottom-right strip (header only) rather
 *     than a floating launcher pill.
 *   · On tablet/phone the dock becomes a bottom sheet (~55–60vh).
 *
 * Brand tokens and bubble/chip language are unchanged from the v2.3 brand pass
 * (navy #1B2951, red #EE3A46, presence dot, asymmetric bubbles).
 *
 * Everything remains scoped under .fma- to avoid theme collisions.
 */

:root {
	--fma-dock-w: 380px;
	--fma-dock-min-h: 56px;
}

/* Desktop: main content leaves room for the expanded dock. */
@media (min-width: 1100px) {
	body.has-fma-dock     { padding-right: var(--fma-dock-w) !important; }
	body.has-fma-dock-min { padding-right: 0 !important; }
}

.fma-root {
	/* Brand — from the Famedico brand guide. */
	--fma-brand: #1b2951;
	--fma-brand-dark: #111c3a;
	--fma-brand-mid: #2a3a6b;
	--fma-tint: #eef1f8;
	--fma-tint-2: #f6f8fc;

	--fma-red: #ee3a46;
	--fma-red-dark: #d93340;
	--fma-red-soft: #fee9eb;

	/* Neutrals. */
	--fma-ink: #1c2333;
	--fma-ink-soft: #3f4552;
	--fma-muted: #6b7280;
	--fma-line: #e4e8f1;
	--fma-card: #ffffff;
	--fma-bg: #f4f6fb;

	/* Safety reds stay muted — alarm copy, not brand accent. */
	--fma-alert: #b42318;
	--fma-alert-bg: #fef3f2;
	--fma-alert-line: #fecdc9;

	--fma-radius-lg: 18px;
	--fma-radius: 14px;
	--fma-radius-sm: 10px;

	--fma-sans: "Inter", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont,
		"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

	/* Dock chrome — full right edge. */
	position: fixed;
	right: 0;
	top: 0;
	width: var(--fma-dock-w);
	height: 100vh;
	height: 100dvh;
	z-index: 999999;
	font-family: var(--fma-sans);
	font-size: 15px;
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
	display: flex;
	flex-direction: column;
	background: var(--fma-card);
	border-left: 1px solid var(--fma-line);
	box-shadow: -6px 0 24px rgba(27, 41, 81, 0.08);
	transition: height 0.18s ease, top 0.18s ease, transform 0.18s ease;
}

/* Inherited-typography reset — the host theme carries text-transform on body,
   which would rewrite clinical and pricing copy. See v2.1 notes. */
.fma-root,
.fma-root * {
	text-transform: none;
	letter-spacing: normal;
	word-spacing: normal;
	font-variant: normal;
}

.fma-root *,
.fma-root *::before,
.fma-root *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------- launcher
   Kept in the DOM for site.js [data-action="chat"] wiring, but hidden —
   the dock header is the permanent control surface. */

.fma-launcher {
	display: none !important;
}

/* ------------------------------------------------------------------- panel
   The panel IS the dock body. Always flex-column when expanded. */

.fma-panel {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	padding: 0;
	margin: 0;
	width: 100%;
	height: 100%;
	max-height: none;
	background: var(--fma-card);
	border: 0;
	border-radius: 0;
	box-shadow: none;
	overflow: hidden;
}

.fma-panel[hidden] {
	/* Dock never fully removes the panel; minimise hides body sections. */
	display: flex !important;
}

/* Layout hardening: host themes carry generic rules for anything that looks
   like a header/form/footer ([class*="header"] width caps, margin:auto,
   centred max-widths). Every structural row of the panel pins its own box so
   none of that lands here. */
.fma-header,
.fma-notice,
.fma-log,
.fma-quick,
.fma-form,
.fma-foot,
.fma-ended {
	width: 100%;
	max-width: none;
	margin: 0;
}

/* Identity block: navy, so the dock owns its edge over any page beneath. */
.fma-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 12px 14px 16px;
	background: linear-gradient(135deg, var(--fma-brand) 0%, var(--fma-brand-dark) 100%);
	color: #fff;
	flex: none;
	cursor: default;
}

.fma-avatar {
	width: 40px;
	height: 40px;
	flex: none;
	border-radius: 50%;
	background: #fff;
	color: var(--fma-brand);
	display: grid;
	place-items: center;
	font-weight: 800;
	font-size: 15px;
	box-shadow: inset 0 0 0 2px rgba(27, 41, 81, 0.08);
	position: relative;
}

/* Presence dot — clipped to the avatar so it reads as part of the identity. */
.fma-avatar::after {
	content: "";
	position: absolute;
	right: -1px;
	bottom: -1px;
	width: 11px;
	height: 11px;
	border-radius: 50%;
	background: #2fbf71;
	border: 2px solid var(--fma-brand);
}

.fma-titles {
	flex: 1;
	min-width: 0;
}

.fma-name {
	font-weight: 700;
	font-size: 15.5px;
	color: #fff;
	line-height: 1.3;
}

.fma-role {
	font-size: 12.5px;
	color: rgba(255, 255, 255, 0.72);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.35;
}

.fma-close {
	flex: none;
	width: 34px;
	height: 34px;
	border: 0;
	border-radius: var(--fma-radius-sm);
	background: transparent;
	color: rgba(255, 255, 255, 0.75);
	line-height: 1;
	cursor: pointer;
	display: grid;
	place-items: center;
	transition: background 0.12s ease, color 0.12s ease;
}

.fma-close svg {
	width: 19px;
	height: 19px;
	transition: transform 0.18s ease;
}

.fma-close:hover {
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
}

.fma-close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 1px;
}

/* --------------------------------------------------------------- disclosure */

.fma-notice {
	padding: 8px 16px;
	background: var(--fma-tint-2);
	border-bottom: 1px solid var(--fma-line);
	color: var(--fma-muted);
	font-size: 11.5px;
	line-height: 1.5;
	flex: none;
}

.fma-notice strong {
	color: var(--fma-alert);
	font-weight: 700;
}

/* -------------------------------------------------------------------- log */

.fma-log {
	flex: 1;
	overflow-y: auto;
	padding: 18px 16px 14px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	background: var(--fma-bg);
	scrollbar-width: thin;
	scrollbar-color: #c4ccdd transparent;
	min-height: 0;
}

.fma-msg {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	max-width: 100%;
}

.fma-ava {
	width: 28px;
	height: 28px;
	flex: none;
	border-radius: 50%;
	background: var(--fma-brand);
	color: #fff;
	display: grid;
	place-items: center;
	font-weight: 800;
	font-size: 11px;
	margin-top: 2px;
}

/* Assistant: white card on the tinted log, tight corner toward the avatar. */
.fma-bubble {
	background: var(--fma-card);
	border: 1px solid var(--fma-line);
	color: var(--fma-ink);
	padding: 11px 14px;
	border-radius: var(--fma-radius);
	border-top-left-radius: 6px;
	box-shadow: 0 1px 2px rgba(27, 41, 81, 0.05);
	overflow-wrap: anywhere;
	min-width: 0;
}

/* Visitor: navy, mirrored tight corner, no avatar (see v2 notes). */
.fma-msg-user {
	justify-content: flex-end;
}

.fma-msg-user .fma-bubble {
	background: var(--fma-brand);
	border-color: var(--fma-brand);
	color: #fff;
	max-width: 86%;
	border-radius: var(--fma-radius);
	border-top-right-radius: 6px;
	border-top-left-radius: var(--fma-radius);
	box-shadow: none;
}

/* Structured reply lines. */
.fma-p + .fma-p,
.fma-p + .fma-li,
.fma-li + .fma-p {
	margin-top: 7px;
}

.fma-li {
	padding-left: 14px;
	position: relative;
}

.fma-li::before {
	content: "•";
	position: absolute;
	left: 2px;
	opacity: 0.55;
}

.fma-li + .fma-li {
	margin-top: 3px;
}

/* Safety turns run full width, no avatar — the system speaking. */
.fma-msg-alert,
.fma-msg-crisis {
	display: block;
}

.fma-msg-alert .fma-bubble,
.fma-msg-crisis .fma-bubble {
	max-width: 100%;
	font-weight: 500;
	border-radius: var(--fma-radius);
}

.fma-msg-alert .fma-bubble {
	background: var(--fma-alert-bg);
	border-color: var(--fma-alert-line);
	color: var(--fma-alert);
}

.fma-msg-crisis .fma-bubble {
	background: #f4f7ff;
	border-color: #c9d8f5;
	color: #1e3a6b;
}

/* Call buttons attached to a turn. */
.fma-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-self: stretch;
}

.fma-action {
	flex: 1 1 auto;
	text-align: center;
	padding: 12px 14px;
	border-radius: var(--fma-radius-sm);
	background: var(--fma-red);
	border: 1px solid var(--fma-red);
	color: #fff !important;
	font-weight: 700;
	font-size: 14px;
	text-decoration: none;
	transition: background 0.12s ease;
}

.fma-action:hover {
	background: var(--fma-red-dark);
	border-color: var(--fma-red-dark);
	text-decoration: none;
}

.fma-action:focus-visible {
	outline: 2px solid var(--fma-red);
	outline-offset: 2px;
}

/* Conversation closed after a terminal turn. */
.fma-ended {
	padding: 11px 16px;
	border-top: 1px solid var(--fma-line);
	background: var(--fma-tint-2);
	color: var(--fma-muted);
	font-size: 12.5px;
	flex: none;
}

.fma-ended a {
	color: var(--fma-brand);
	font-weight: 700;
}

/* --------------------------------------------------------- quick replies */

.fma-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 12px;
	background: var(--fma-bg);
	flex: none;
	max-height: 140px;
	overflow-y: auto;
}

.fma-quick[hidden] {
	display: none;
}

.fma-quick.is-busy {
	opacity: 0.5;
	pointer-events: none;
}

/* Chips: white with a navy hairline — outlined choices on the tinted log.
   Hover fills navy so pressability is unmistakable. */
.fma-chip {
	padding: 8px 14px;
	border: 1px solid #cdd5e6;
	border-radius: 999px;
	background: var(--fma-card);
	color: var(--fma-brand);
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.fma-chip:hover {
	background: var(--fma-brand);
	border-color: var(--fma-brand);
	color: #fff;
}

.fma-chip:focus-visible {
	outline: 2px solid var(--fma-brand);
	outline-offset: 1px;
}

/* One chip is the action — the booking chip — and it wears the brand red. */
.fma-chip-primary {
	background: var(--fma-red);
	border-color: var(--fma-red);
	color: #fff;
}

.fma-chip-primary:hover {
	background: var(--fma-red-dark);
	border-color: var(--fma-red-dark);
	color: #fff;
}

/* Typing indicator. */
.fma-typing {
	display: flex;
	gap: 4px;
	align-items: center;
	padding: 14px;
}

.fma-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9aa4bd;
	animation: fma-bounce 1.3s infinite ease-in-out;
}

.fma-typing span:nth-child(2) { animation-delay: 0.16s; }
.fma-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes fma-bounce {
	0%, 70%, 100% { transform: translateY(0); opacity: 0.55; }
	35%           { transform: translateY(-5px); opacity: 1; }
}

/* ------------------------------------------------------------------ input */

.fma-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	border-top: 1px solid var(--fma-line);
	background: var(--fma-card);
	flex: none;
}

.fma-form[hidden] {
	display: none;
}

.fma-input {
	flex: 1;
	min-width: 0;
	resize: none;
	border: 1px solid var(--fma-line);
	border-radius: var(--fma-radius-sm);
	padding: 10px 13px;
	font: inherit;
	font-size: 14.5px;
	line-height: 1.4;
	color: var(--fma-ink);
	max-height: 110px;
	background: var(--fma-tint-2);
	transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.fma-input::placeholder {
	color: var(--fma-muted);
}

.fma-input:focus {
	outline: none;
	border-color: var(--fma-brand);
	background: var(--fma-card);
	box-shadow: 0 0 0 3px rgba(27, 41, 81, 0.12);
}

/* Send is the second and last red element in the panel. */
.fma-send {
	flex: none;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 10px 16px;
	border: 1px solid var(--fma-red);
	border-radius: var(--fma-radius-sm);
	background: var(--fma-red);
	color: #fff;
	font: inherit;
	font-size: 14px;
	font-weight: 700;
	cursor: pointer;
	transition: background 0.12s ease;
}

.fma-send:hover:not(:disabled) {
	background: var(--fma-red-dark);
	border-color: var(--fma-red-dark);
}

.fma-send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

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

.fma-send-arrow {
	font-size: 15px;
	line-height: 1;
}

.fma-foot {
	padding: 0 16px 12px;
	background: var(--fma-card);
	color: var(--fma-muted);
	font-size: 11.5px;
	text-align: center;
	flex: none;
}

.fma-foot a {
	color: var(--fma-brand);
	font-weight: 700;
	text-decoration: none;
}

.fma-foot a:hover {
	text-decoration: underline;
}

/* -------------------------------------------------------- minimised dock */

.fma-root.is-minimised {
	height: var(--fma-dock-min-h);
	top: auto;
	bottom: 0;
	border-left: 1px solid var(--fma-line);
	border-top: 1px solid var(--fma-line);
	border-radius: 12px 0 0 0;
	box-shadow: -4px -4px 20px rgba(27, 41, 81, 0.1);
}

.fma-root.is-minimised .fma-panel {
	/* Only the header remains; hide the rest. */
}

.fma-root.is-minimised .fma-notice,
.fma-root.is-minimised .fma-log,
.fma-root.is-minimised .fma-quick,
.fma-root.is-minimised .fma-form,
.fma-root.is-minimised .fma-foot,
.fma-root.is-minimised .fma-ended {
	display: none !important;
}

.fma-root.is-minimised .fma-header {
	padding: 10px 12px 10px 14px;
	height: var(--fma-dock-min-h);
	border-radius: 12px 0 0 0;
	cursor: pointer;
}

.fma-root.is-minimised .fma-avatar {
	width: 32px;
	height: 32px;
	font-size: 13px;
}

.fma-root.is-minimised .fma-close svg {
	/* Chevron flips up when collapsed — "expand me". */
	transform: rotate(180deg);
}

/* ------------------------------------------------ mobile / tablet sheet */

@media (max-width: 1099px) {
	:root { --fma-dock-w: 100%; }

	.fma-root {
		top: auto;
		bottom: 0;
		right: 0;
		left: 0;
		width: 100%;
		height: 60vh;
		max-height: 520px;
		border-left: none;
		border-top: 1px solid var(--fma-line);
		border-radius: 16px 16px 0 0;
		box-shadow: 0 -6px 24px rgba(27, 41, 81, 0.12);
	}

	body.has-fma-dock {
		padding-right: 0 !important;
		padding-bottom: calc(60vh - 80px) !important;
	}

	body.has-fma-dock-min {
		padding-right: 0 !important;
		padding-bottom: var(--fma-dock-min-h) !important;
	}

	.fma-root.is-minimised {
		border-radius: 12px 12px 0 0;
		left: 0;
		right: 0;
		width: 100%;
	}

	.fma-root.is-minimised .fma-header {
		border-radius: 12px 12px 0 0;
	}
}

@media (max-width: 480px) {
	.fma-root {
		height: 55vh;
		max-height: 480px;
	}

	/* On small phones, don't push the whole page up under an open sheet —
	   visitors need to still read the marketing page. Bottom padding is light. */
	body.has-fma-dock {
		padding-bottom: 24px !important;
	}

	.fma-header {
		padding: 12px 12px 12px 14px;
	}

	.fma-name {
		font-size: 14.5px;
	}

	.fma-bubble {
		font-size: 14px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.fma-typing span { animation: none; }
	.fma-root { transition: none; }
	.fma-close svg { transition: none; }
}

/* Screen-reader-only helper */
.fma-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
