/* Medisource Assistant - chat popup. Adapted from the BrewedOps Motion Library "Chat-style FAQ"
   (spring/bounce easing, bubble entrance, typing dots) and the Medisource v2 brand tokens. */
#msa {
	--msa-bg: #FFFFFF;
	--msa-surface: #F3F6FA;
	--msa-line: #E3E9F2;
	--msa-ink: #0E1E2E;
	--msa-muted: #4B5D73;
	--msa-accent: #0F6FC7;
	--msa-accent-ink: #0B5CA8;
	--msa-accent-soft: #E6F0FB;
	--msa-navy: #0A3D6E;
	--msa-grad: linear-gradient(135deg, #0F6FC7 0%, #4FA3FF 100%);
	--msa-shadow: 0 2px 4px rgba(16, 24, 40, .06), 0 24px 56px rgba(10, 30, 52, .22);
	--msa-spring: cubic-bezier(.22, 1, .36, 1);
	--msa-bounce: cubic-bezier(.34, 1.56, .64, 1);
	--msa-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 99990;
	font: 400 14px/1.5 var(--msa-font);
	color: var(--msa-ink);
	-webkit-font-smoothing: antialiased;
}
@supports (transition-timing-function: linear(0, 1)) {
	#msa {
		--msa-spring: linear(0, 0.0941 5.6%, 0.2736 11.1%, 0.4548 16.7%, 0.6076 22.2%, 0.7255 27.8%, 0.8119 33.3%, 0.8732 38.9%, 0.9156 44.4%, 0.9444 50%, 0.9636 55.6%, 0.9764 61.1%, 0.9848 66.7%, 0.9902 72.2%, 0.9938 77.8%, 0.996 83.3%, 0.9975 88.9%, 0.9984 94.4%, 1 100%);
		--msa-bounce: linear(0, 0.0833 5.6%, 0.2603 11.1%, 0.4566 16.7%, 0.6331 22.2%, 0.7737 27.8%, 0.8759 33.3%, 0.9442 38.9%, 0.9858 44.4%, 1.0081 50%, 1.0178 55.6%, 1.0199 61.1%, 1.018 66.7%, 1.0143 72.2%, 1.0104 77.8%, 1.007 83.3%, 1.0043 88.9%, 1.0023 94.4%, 1 100%);
	}
}
#msa *, #msa *::before, #msa *::after { box-sizing: border-box; }
#msa :where(button, input) {
	appearance: none; -webkit-appearance: none; margin: 0; min-height: 0; width: auto; border: 0; border-radius: 0; background: none; box-shadow: none;
	padding: 0; font: inherit; color: inherit; text-transform: none; letter-spacing: normal; text-decoration: none; line-height: inherit; }
#msa :where(button):where(:hover, :focus) { background-color: transparent; color: inherit; }
#msa svg { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#msa .msa-vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Launcher */
#msa .msa-launch {
	position: relative; display: grid; place-items: center; width: 60px; height: 60px; margin: 0 0 0 auto; padding: 0;
	border: 0; border-radius: 50%; cursor: pointer; color: #fff; background: var(--msa-grad);
	box-shadow: 0 10px 28px rgba(15, 111, 199, .38), 0 2px 6px rgba(10, 30, 52, .18), inset 0 1px 0 rgba(255, 255, 255, .25);
	transition: transform 600ms var(--msa-spring), box-shadow 300ms ease;
}
#msa[data-hover="1"] .msa-launch:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 34px rgba(15, 111, 199, .45), 0 2px 6px rgba(10, 30, 52, .18); }
#msa .msa-launch:active { transform: scale(.94); transition-duration: 90ms; }
#msa .msa-launch:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 6px var(--msa-accent); }
#msa .msa-launch__ic { grid-area: 1 / 1; display: grid; place-items: center; transition: transform 500ms var(--msa-spring), opacity 200ms ease; }
#msa .msa-launch__ic svg { width: 30px; height: 30px; }
#msa .msa-launch__ic--close svg { width: 24px; height: 24px; }
#msa .msa-launch__ic--close { opacity: 0; transform: rotate(-90deg) scale(.6); }
#msa[data-state="open"] .msa-launch__ic--open { opacity: 0; transform: rotate(90deg) scale(.6); }
#msa[data-state="open"] .msa-launch__ic--close { opacity: 1; transform: none; }
#msa .msa-i-bubble { fill: #fff; stroke: none; }
#msa .msa-i-eye { fill: var(--msa-accent); stroke: none; }
#msa .msa-i-smile { stroke: var(--msa-accent); stroke-width: 1.8; }

/* Panel */
#msa .msa-panel {
	position: absolute; right: 0; bottom: 76px; width: 392px; height: min(640px, calc(100vh - 128px)); height: min(640px, calc(100dvh - 128px));
	display: grid; grid-template-rows: auto 1fr auto auto; overflow: hidden; border-radius: 20px; background: var(--msa-bg);
	box-shadow: var(--msa-shadow); border: 1px solid rgba(14, 30, 46, .06);
	transform-origin: 100% 100%; opacity: 0; transform: translateY(12px) scale(.92);
	transition: opacity 220ms ease, transform 520ms var(--msa-spring);
}
#msa .msa-panel[hidden] { display: none; }
#msa[data-state="open"] .msa-panel { opacity: 1; transform: none; }

#msa .msa-hd { display: flex; align-items: center; gap: 10px; padding: 14px 12px 14px 16px; color: #fff;
	background: radial-gradient(120% 140% at 100% 0%, rgba(79, 163, 255, .45), transparent 55%), linear-gradient(135deg, #0A3D6E 0%, #0F2A4A 100%); }
#msa .msa-av { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 12px; background: var(--msa-grad); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25); }
#msa .msa-av svg { width: 24px; height: 24px; }
#msa .msa-hd__txt { min-width: 0; flex: 1; }
#msa .msa-hd__title { margin: 0; font: 700 15px/1.2 var(--msa-font); color: #fff; letter-spacing: -.01em; }
#msa .msa-hd__sub { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font-size: 12px; line-height: 1.3; color: #B9CDE2; }
#msa .msa-dot { width: 7px; height: 7px; border-radius: 50%; background: #3DDC97; box-shadow: 0 0 0 3px rgba(61, 220, 151, .2); flex: none; }
#msa .msa-ib { display: grid; place-items: center; width: 36px; height: 36px; flex: none; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #DCEBFA; cursor: pointer; transition: background 150ms ease; }
#msa .msa-ib svg { width: 18px; height: 18px; }
#msa .msa-ib:hover { background: rgba(255, 255, 255, .12); color: #fff; }
#msa .msa-ib:focus-visible { outline: 2px solid #8CC4F5; outline-offset: 1px; }

/* Thread */
#msa .msa-th { position: relative; overflow-x: hidden; display: flex; flex-direction: column; gap: 10px; padding: 16px 14px 18px; overflow-y: auto; overscroll-behavior: contain; min-height: 0; background: var(--msa-surface); scroll-behavior: smooth; }
#msa .msa-th:focus { outline: none; }
#msa .msa-m { max-width: 88%; padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.5; animation: msa-in 460ms var(--msa-bounce) both; overflow-wrap: anywhere; }
#msa .msa-m.u { align-self: flex-end; background: var(--msa-accent); color: #fff; border-bottom-right-radius: 5px; transform-origin: right bottom; }
#msa .msa-m.r { align-self: flex-start; background: var(--msa-bg); color: var(--msa-ink); border-bottom-left-radius: 5px; transform-origin: left bottom; box-shadow: inset 0 0 0 1px var(--msa-line); }
#msa .msa-m.r p { margin: 0; }
#msa .msa-m.r p + p { margin-top: 6px; }
#msa .msa-m.w { max-width: 100%; }
#msa .msa-welcome { padding: 4px 2px 2px; animation: msa-in 460ms var(--msa-bounce) both; transform-origin: left top; }
#msa .msa-welcome h3 { margin: 0 0 2px; font: 700 18px/1.25 var(--msa-font); color: var(--msa-ink); letter-spacing: -.01em; }
#msa .msa-welcome p { margin: 0 0 12px; color: var(--msa-muted); }
#msa .msa-label { margin: 2px 0 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--msa-muted); }

#msa .msa-chips { display: flex; flex-wrap: wrap; gap: 6px; }
#msa .msa-chip {
	appearance: none; cursor: pointer; border: 0; padding: 8px 12px; border-radius: 99px; text-align: left;
	font: 600 13px/1.25 var(--msa-font); color: var(--msa-accent-ink); background: var(--msa-accent-soft);
	transition: transform 587ms var(--msa-spring), background 150ms ease;
}
#msa .msa-chip:hover { background: #D6E7F9; }
#msa .msa-chip:active { transform: scale(.95); transition-duration: 90ms; }
#msa .msa-chip:focus-visible, #msa .msa-card a:focus-visible, #msa .msa-rel button:focus-visible { outline: 2px solid var(--msa-accent); outline-offset: 2px; }
#msa .msa-chip small { font-weight: 500; color: var(--msa-muted); margin-left: 4px; }
#msa .msa-chip--ghost { background: #fff; box-shadow: inset 0 0 0 1px var(--msa-line); color: var(--msa-ink); }

/* Typing / loading */
#msa .msa-dots { display: inline-flex; align-items: center; gap: 4px; padding: 4px 0; }
#msa .msa-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--msa-muted); animation: msa-bn 1s infinite ease-in-out both; }
#msa .msa-dots i:nth-child(2) { animation-delay: .15s; }
#msa .msa-dots i:nth-child(3) { animation-delay: .3s; }
#msa .msa-dots span { margin-left: 6px; font-size: 12px; color: var(--msa-muted); }

/* Answer cards */
#msa .msa-card { align-self: stretch; padding: 12px 14px 12px; border-radius: 14px; background: var(--msa-bg); box-shadow: inset 0 0 0 1px var(--msa-line), 0 1px 2px rgba(16, 24, 40, .04); animation: msa-in 460ms var(--msa-bounce) both; transform-origin: left bottom; }
#msa .msa-card + .msa-card { margin-top: -2px; }
#msa .msa-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
#msa .msa-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
#msa .msa-badge--RealtimeEHR { background: #E6F0FB; color: #0B5CA8; }
#msa .msa-badge--WoundTrack { background: #E3F6EF; color: #0D7A55; }
#msa .msa-badge--Medisource { background: #EEF0F6; color: #36435A; }
#msa .msa-badge--cat { background: transparent; color: var(--msa-muted); font-weight: 600; padding-left: 0; }
#msa .msa-card h4 { margin: 0 0 4px; font: 700 15px/1.3 var(--msa-font); color: var(--msa-ink); }
#msa .msa-card p { margin: 0 0 6px; color: #23344A; }
#msa .msa-card ul.msa-det { margin: 0 0 6px; padding-left: 18px; color: #23344A; }
#msa .msa-card ol { margin: 4px 0 6px; padding-left: 20px; color: #23344A; }
#msa .msa-card li { margin: 2px 0; }
#msa .msa-more { margin: 0 0 6px; font-size: 12.5px; color: var(--msa-muted); }
#msa .msa-src { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--msa-line); font-size: 12px; color: var(--msa-muted); }
#msa .msa-src a { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--msa-accent-ink); text-decoration: none; }
#msa .msa-src a:hover { text-decoration: underline; }
#msa .msa-src a svg { width: 13px; height: 13px; }
#msa .msa-rel { align-self: stretch; animation: msa-in 460ms var(--msa-bounce) both; }
#msa .msa-rel .msa-chip { font-weight: 600; }
#msa .msa-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#msa .msa-links a { display: inline-flex; align-items: center; gap: 4px; padding: 7px 11px; border-radius: 99px; background: var(--msa-accent-soft); color: var(--msa-accent-ink); font-size: 13px; font-weight: 600; text-decoration: none; }
#msa .msa-links a:hover { background: #D6E7F9; }
#msa .msa-links a svg { flex: none; width: 13px; height: 13px; }
/* Long topic and article titles wrap inside the panel instead of forcing a horizontal scroll. */
#msa .msa-chip, #msa .msa-links a { max-width: 100%; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; height: auto; }
#msa .msa-chips, #msa .msa-links, #msa .msa-m, #msa .msa-card, #msa .msa-rel { min-width: 0; max-width: 100%; }

/* Input */
#msa .msa-in { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-top: 1px solid var(--msa-line); background: var(--msa-bg); }
#msa .msa-in input { flex: 1; min-width: 0; height: 42px; padding: 0 12px; border: 1px solid var(--msa-line); border-radius: 12px; background: var(--msa-surface); font-size: 15px; outline: none; transition: border-color 150ms ease, box-shadow 150ms ease; }
#msa .msa-in input:focus { border-color: var(--msa-accent); box-shadow: 0 0 0 3px rgba(15, 111, 199, .15); background: #fff; }
#msa .msa-send { display: grid; place-items: center; width: 42px; height: 42px; flex: none; padding: 0; border: 0; border-radius: 12px; cursor: pointer; color: #fff; background: var(--msa-accent); transition: transform 587ms var(--msa-spring), background 150ms ease; }
#msa .msa-send:hover { background: var(--msa-accent-ink); }
#msa .msa-send:active { transform: scale(.92); transition-duration: 90ms; }
#msa .msa-send:disabled { opacity: .5; cursor: default; }
#msa .msa-send svg { width: 20px; height: 20px; }
#msa .msa-send:focus-visible { outline: 2px solid var(--msa-accent); outline-offset: 2px; }
#msa .msa-foot { margin: 0; padding: 0 14px 10px; background: var(--msa-bg); font-size: 11px; color: var(--msa-muted); text-align: center; }

/* Attention prompt (2026-11-17). Bubble beside the launcher; entrance adapted from the Motion Library
   "Chat-style FAQ" (bubble pop with the bounce curve, typing dots, typed text). Hidden = no pointer events. */
#msa .msa-tip { position: absolute; right: calc(100% + 12px); bottom: 50%; translate: 0 50%; display: flex; align-items: center; gap: 2px;
	max-width: min(300px, calc(100vw - 112px)); padding: 4px 4px 4px 4px; border-radius: 18px; background: var(--msa-ink); color: #fff;
	box-shadow: 0 10px 30px -8px rgba(10, 30, 52, .45), 0 2px 6px rgba(10, 30, 52, .18);
	transform-origin: 100% 50%; opacity: 0; transform: translateX(8px) scale(.94); pointer-events: none; visibility: hidden;
	transition: opacity 260ms ease, transform 520ms var(--msa-spring), visibility 0s linear 520ms; }
#msa .msa-tip[hidden] { display: none; }
#msa .msa-tip::after { content: ""; position: absolute; right: -5px; top: 50%; width: 10px; height: 10px; margin-top: -5px; background: inherit; border-radius: 2px; transform: rotate(45deg); }
#msa .msa-tip.is-on { opacity: 1; transform: none; pointer-events: auto; visibility: visible; transition: opacity 220ms ease, transform 520ms var(--msa-spring), visibility 0s; }
#msa[data-entrance="pop"] .msa-tip.is-on, #msa[data-entrance="typing"] .msa-tip.is-on { animation: msa-in 460ms var(--msa-bounce) both; }
#msa .msa-tip__body { display: grid; gap: 1px; min-height: 36px; padding: 7px 8px 7px 12px; border-radius: 14px; text-align: left; cursor: pointer; color: #fff; }
#msa .msa-tip__txt { font: 600 13.5px/1.3 var(--msa-font); white-space: nowrap; }
#msa .msa-tip__sub { font: 500 12px/1.3 var(--msa-font); color: #B9CDE2; }
#msa .msa-tip__txt .msa-dots { padding: 2px 0; }
#msa .msa-tip__txt .msa-dots i { width: 5px; height: 5px; background: #B9CDE2; }
#msa .msa-tip__x { display: grid; place-items: center; flex: none; width: 26px; height: 26px; margin-right: 2px; border-radius: 50%; color: #B9CDE2; cursor: pointer; transition: background 150ms ease, color 150ms ease; }
#msa .msa-tip__x svg { width: 14px; height: 14px; }
#msa .msa-tip__x:hover { background: rgba(255, 255, 255, .14); color: #fff; }
#msa[data-hover="1"] .msa-tip.is-on:hover { transform: translateY(-1px); }
#msa[data-hover="1"] .msa-launch:hover ~ .msa-tip { opacity: 1; transform: none; visibility: visible; transition: opacity 200ms ease, transform 400ms var(--msa-spring), visibility 0s; }
#msa[data-state="open"] .msa-tip { display: none; }
/* Launcher pulse: runs only while the prompt is appearing (class added by script), never continuously. */
#msa .msa-launch::after { content: ""; position: absolute; inset: 0; border-radius: 50%; pointer-events: none; opacity: 0; }
#msa { --msa-pulse-dur: 2.4s; --msa-pulse-scale: 1.45; --msa-pulse-alpha: .45; }
#msa[data-pulse-speed="slow"] { --msa-pulse-dur: 3.2s; }
#msa[data-pulse-speed="fast"] { --msa-pulse-dur: 1.6s; }
#msa[data-intensity="medium"] { --msa-pulse-scale: 1.7; --msa-pulse-alpha: .65; }
#msa[data-pulse-style="ring"] .msa-launch.is-pulse::after { border: 2px solid rgba(15, 111, 199, var(--msa-pulse-alpha)); animation: msa-ring var(--msa-pulse-dur) ease-out 2 both; }
#msa[data-pulse-style="glow"] .msa-launch.is-pulse::after { box-shadow: 0 0 0 0 rgba(15, 111, 199, var(--msa-pulse-alpha)); animation: msa-glow var(--msa-pulse-dur) ease-out 2 both; opacity: 1; }
#msa[data-pulse-style="breathe"] .msa-launch.is-pulse { animation: msa-breathe var(--msa-pulse-dur) ease-in-out 2 both; }
@keyframes msa-ring { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(var(--msa-pulse-scale)); opacity: 0; } }
@keyframes msa-glow { 0% { box-shadow: 0 0 0 0 rgba(15, 111, 199, var(--msa-pulse-alpha)); } 100% { box-shadow: 0 0 0 calc((var(--msa-pulse-scale) - 1) * 56px) rgba(15, 111, 199, 0); } }
@keyframes msa-breathe { 0%, 100% { transform: scale(1); } 40% { transform: scale(calc(1 + (var(--msa-pulse-scale) - 1) * .16)); } }
#msa[data-motion="0"] .msa-tip, #msa[data-motion="0"] .msa-tip.is-on { transition: none; animation: none; transform: none; }
#msa[data-motion="0"] .msa-launch.is-pulse, #msa[data-motion="0"] .msa-launch.is-pulse::after { animation: none; }

@keyframes msa-in { 0% { opacity: 0; transform: translateY(10px) scale(.9); } 100% { opacity: 1; transform: none; } }
@keyframes msa-bn { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-3px); opacity: 1; } }

/* Phones: a bottom sheet that leaves the launcher visible. */
@media (max-width: 560px) {
	#msa { right: 16px; bottom: 16px; }
	#msa .msa-launch { width: 56px; height: 56px; }
	#msa .msa-tip { right: calc(100% + 10px); }
	#msa .msa-tip__txt { font-size: 13px; }
	#msa .msa-panel { position: fixed; left: 8px; right: 8px; bottom: 84px; width: auto; height: calc(100vh - 100px); height: calc(100dvh - 100px); max-height: 680px; border-radius: 18px; }
	#msa .msa-in input { font-size: 16px; } /* no iOS zoom on focus */
}
@media (prefers-reduced-motion: reduce) {
	#msa *, #msa *::before, #msa *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print { #msa { display: none !important; } }
