/**
 * MycoRova Assistant — launcher and chat window.
 * Uses the theme's design tokens (with fallbacks) so it reads as part of the site.
 */

.la-chat-launcher,
.la-chat {
	--lac-forest: var(--c-forest, #17331f);
	--lac-deep: var(--c-deep, #1f4a2a);
	--lac-gold: var(--c-gold, #4e8b3a);
	--lac-gold-ink: var(--c-gold-ink, #6e3b17);
	--lac-ivory: var(--c-ivory, #f7f5ef);
	--lac-parchment: var(--c-parchment, #eeeadf);
	--lac-ink: var(--c-ink, #1b231e);
	--lac-line: rgb(23 51 31 / 0.12);
	--lac-serif: var(--font-serif, Georgia, serif);
	--lac-sans: var(--font-sans, system-ui, sans-serif);
	--lac-edge: max(16px, env(safe-area-inset-right));
	--lac-bottom: max(16px, env(safe-area-inset-bottom));
	font-family: var(--lac-sans);
}

/* ---- Launcher ------------------------------------------------------------- */

/* A green orb with a chat bubble and AI sparkle; on desktop a light label
   tab sits to its left. */
.la-chat-launcher {
	position: fixed;
	inset-block-end: var(--lac-bottom);
	inset-inline-end: var(--lac-edge);
	z-index: 990; /* Below theme dialogs and marketing popups (1000+). */
	display: inline-flex;
	align-items: center;
	gap: 0;
	padding: 0;
	border: 0;
	background: none;
	color: var(--lac-forest);
	font-size: 0.875rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	cursor: pointer;
	transition: transform 0.2s ease, opacity 0.2s ease;
}
.la-chat-launcher[hidden] { display: none; }
.la-chat-launcher:focus-visible { outline: none; }
.la-chat-launcher:focus-visible .la-chat-launcher__orb { outline: 3px solid var(--lac-gold-ink); outline-offset: 3px; }
.la-chat-launcher[aria-busy="true"] { opacity: 0.75; cursor: progress; }

.la-chat-launcher__label {
	margin-inline-end: -14px; /* Tucks under the orb. */
	padding: 0.55rem 1.5rem 0.55rem 1rem;
	border: 1px solid rgb(78 139 58 / 0.3);
	border-radius: 999px 0 0 999px;
	background: var(--lac-ivory);
	box-shadow: 0 8px 22px -12px rgb(23 51 31 / 0.45);
	white-space: nowrap;
	transition: transform 0.2s ease, background-color 0.2s ease;
}

.la-chat-launcher__orb {
	position: relative;
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background:
		radial-gradient(circle at 30% 25%, rgb(255 255 255 / 0.28), transparent 55%),
		linear-gradient(145deg, var(--lac-gold) 0%, var(--lac-deep) 55%, var(--lac-forest) 100%);
	color: #fff;
	box-shadow: 0 12px 28px -10px rgb(23 51 31 / 0.65), inset 0 0 0 2px rgb(255 255 255 / 0.18);
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}
/* Soft ring that breathes around the orb. */
.la-chat-launcher__orb::before {
	content: "";
	position: absolute;
	inset: -6px;
	border-radius: 50%;
	border: 2px solid rgb(78 139 58 / 0.35);
	animation: la-orb-ring 2.8s ease-out infinite;
}
.la-chat-launcher__icon { flex: none; }
.la-chat-launcher__spark { transform-origin: 16px 14.5px; animation: la-orb-spark 3.2s ease-in-out infinite; }
.la-chat-launcher__spark--small { animation-delay: 0.4s; }

/* "Online" dot. */
.la-chat-launcher__status {
	position: absolute;
	inset-block-start: 3px;
	inset-inline-end: 3px;
	width: 13px;
	height: 13px;
	border-radius: 50%;
	background: #8fd16a;
	box-shadow: 0 0 0 2.5px var(--lac-forest);
}

.la-chat-launcher:hover .la-chat-launcher__orb { transform: rotate(-8deg) scale(1.06); box-shadow: 0 16px 32px -10px rgb(23 51 31 / 0.7), inset 0 0 0 2px rgb(255 255 255 / 0.25); }
.la-chat-launcher:hover .la-chat-launcher__label { background: var(--lac-parchment); transform: translateX(-3px); }

@keyframes la-orb-ring {
	0% { transform: scale(0.92); opacity: 0.9; }
	70%, 100% { transform: scale(1.18); opacity: 0; }
}
@keyframes la-orb-spark {
	0%, 100% { transform: scale(1); opacity: 1; }
	50% { transform: scale(0.75); opacity: 0.7; }
}

/* Out of the way while the theme's menu/dialogs or the chat itself are open. */
.has-dialog .la-chat-launcher,
.la-chat-is-open .la-chat-launcher { opacity: 0; pointer-events: none; visibility: hidden; }

@media (max-width: 639px) {
	/* Orb only on phones; the label stays for screen readers. */
	.la-chat-launcher__label { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
	.la-chat-launcher__orb { width: 56px; height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
	.la-chat-launcher__orb::before,
	.la-chat-launcher__spark { animation: none; }
	.la-chat-launcher__orb::before { opacity: 0.5; }
}

/* ---- Panel ------------------------------------------------------------------ */

.la-chat {
	position: fixed;
	z-index: 995;
	inset-block-end: calc(var(--lac-bottom) + 8px);
	inset-inline-end: var(--lac-edge);
	display: flex;
	flex-direction: column;
	width: min(400px, calc(100vw - 32px));
	height: min(640px, calc(100dvh - 120px));
	background: var(--lac-ivory);
	color: var(--lac-ink);
	border: 1px solid var(--lac-line);
	border-radius: 14px;
	box-shadow: 0 30px 70px -30px rgb(23 51 31 / 0.55), 0 2px 6px rgb(23 51 31 / 0.08);
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity 0.22s ease, transform 0.22s ease;
}
.la-chat[hidden] { display: none; }
.la-chat.is-open { opacity: 1; transform: none; }

@media (max-width: 639px) {
	.la-chat { inset: 0; width: 100%; height: 100dvh; border-radius: 0; border: 0; }
	html.la-chat-is-open, html.la-chat-is-open body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
	.la-chat, .la-chat-launcher { transition: none; }
	.la-chat { transform: none; }
	.la-dots i { animation: none !important; opacity: 0.6; }
}

.la-chat .screen-reader-text {
	position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Header: same green gradient and bubble mark as the launcher orb. */
.la-chat__head {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 1rem 0.85rem 1.1rem 1rem;
	padding-block-start: max(1rem, env(safe-area-inset-top));
	background:
		radial-gradient(120% 140% at 0% 0%, rgb(255 255 255 / 0.16), transparent 50%),
		linear-gradient(120deg, var(--lac-gold) 0%, var(--lac-deep) 60%, var(--lac-forest) 100%);
	color: #fff;
	overflow: hidden;
}
/* Faint spore dots in the corner. */
.la-chat__head::after {
	content: "";
	position: absolute;
	inset-block-start: -30px;
	inset-inline-end: 70px;
	width: 120px;
	height: 120px;
	background: radial-gradient(rgb(255 255 255 / 0.14) 1.5px, transparent 1.6px) 0 0 / 14px 14px;
	border-radius: 50%;
	pointer-events: none;
}
.la-chat__mark {
	position: relative;
	flex: none;
	width: 42px;
	height: 42px;
	border-radius: 14px;
	background: rgb(255 255 255 / 0.16) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 5.5c-6.4 0-11.5 4.3-11.5 9.7 0 2.7 1.3 5.2 3.4 6.9l-1 4.4 4.6-2.4c1.4.5 2.9.8 4.5.8 6.4 0 11.5-4.3 11.5-9.7S22.4 5.5 16 5.5z' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linejoin='round'/%3E%3Cpath d='M16 9.6l1.3 3.6 3.6 1.3-3.6 1.3-1.3 3.6-1.3-3.6-3.6-1.3 3.6-1.3z' fill='%23fff'/%3E%3Ccircle cx='21.6' cy='10' r='1.3' fill='%23fff'/%3E%3C/svg%3E") center / 64% no-repeat;
	box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.28);
	backdrop-filter: blur(4px);
}
.la-chat__heading { position: relative; z-index: 1; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
.la-chat__title { margin: 0; font-family: var(--lac-sans); font-size: 1.02rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; color: inherit; }
.la-chat__badge {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	padding: 0.15rem 0.55rem 0.15rem 0.45rem;
	border-radius: 999px;
	background: rgb(0 0 0 / 0.18);
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: rgb(255 255 255 / 0.92);
}
.la-chat__badge::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #8fd16a;
	box-shadow: 0 0 0 3px rgb(143 209 106 / 0.25);
}
.la-chat__icon-btn {
	position: relative;
	z-index: 1;
	display: inline-grid; place-items: center;
	width: 38px; height: 38px;
	border: 0; border-radius: 11px;
	background: rgb(255 255 255 / 0.12); color: inherit; cursor: pointer;
	transition: background-color 0.15s ease;
}
.la-chat__icon-btn:hover { background: rgb(255 255 255 / 0.24); }
.la-chat__icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.la-chat__disclosure {
	margin: 0;
	padding: 0.55rem 1rem;
	font-size: 0.75rem;
	line-height: 1.45;
	color: rgb(27 35 30 / 0.75);
	background: var(--lac-parchment);
	border-block-end: 1px solid var(--lac-line);
}
.la-chat__disclosure a { color: var(--lac-gold-ink); }

.la-chat__log {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.65rem;
	scroll-padding-block-end: 1rem;
}
.la-chat__log:focus-visible { outline: 2px solid var(--lac-gold); outline-offset: -2px; }

.la-msg { max-width: 86%; font-size: 0.93rem; line-height: 1.5; }
.la-msg__body { padding: 0.65rem 0.85rem; border-radius: 12px; overflow-wrap: anywhere; }
.la-msg__body > :first-child { margin-top: 0; }
.la-msg__body > :last-child { margin-bottom: 0; }
.la-msg__body p, .la-msg__body ul, .la-msg__body ol { margin: 0 0 0.5em; }
.la-msg__body ul, .la-msg__body ol { padding-inline-start: 1.2em; }
.la-msg__body a { color: var(--lac-gold-ink); text-underline-offset: 2px; }

.la-msg--assistant { align-self: flex-start; }
.la-msg--assistant .la-msg__body { background: #fff; border: 1px solid var(--lac-line); border-end-start-radius: 4px; }
.la-msg--staff { align-self: flex-start; }
.la-msg--staff .la-msg__body { background: #fff8e6; border: 1px solid rgb(78 139 58 / 0.45); border-end-start-radius: 4px; }
.la-msg--user { align-self: flex-end; }
.la-msg--user .la-msg__body { background: var(--lac-deep); color: var(--lac-ivory); border-end-end-radius: 4px; }
.la-msg--user .la-msg__body a { color: var(--lac-gold); }
.la-msg--notice .la-msg__body { background: #fbf4e4; border-color: rgb(78 139 58 / 0.5); }

.la-msg__actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.45rem; }
.la-msg__action, .la-chip {
	display: inline-flex; align-items: center;
	min-height: 36px;
	padding: 0.4rem 0.8rem;
	border: 1px solid rgb(23 51 31 / 0.25);
	border-radius: 999px;
	background: #fff;
	color: var(--lac-forest);
	font: inherit; font-size: 0.85rem; font-weight: 600;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}
.la-msg__action:hover, .la-chip:hover { background: var(--lac-parchment); border-color: var(--lac-gold); }
.la-msg__action:focus-visible, .la-chip:focus-visible { outline: 2px solid var(--lac-gold); outline-offset: 2px; }

.la-chat__chips { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0 1rem 0.75rem; }
.la-chat__chips[hidden] { display: none; }

.la-msg--typing .la-msg__body, .la-msg--typing { padding: 0; }
.la-dots { display: inline-flex; gap: 4px; padding: 0.8rem 0.9rem; background: #fff; border: 1px solid var(--lac-line); border-radius: 12px; }
.la-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--lac-gold-ink); animation: la-dot 1.2s infinite ease-in-out; }
.la-dots i:nth-child(2) { animation-delay: 0.15s; }
.la-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes la-dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.la-chat__counter { margin: 0; padding: 0 1rem; font-size: 0.75rem; color: var(--lac-gold-ink); min-height: 0; }
.la-chat__counter:empty { display: none; }

.la-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	padding: 0.75rem;
	padding-block-end: max(0.75rem, env(safe-area-inset-bottom));
	border-block-start: 1px solid var(--lac-line);
	background: #fff;
}
.la-chat__input {
	flex: 1;
	min-height: 44px;
	max-height: 140px;
	padding: 0.65rem 0.8rem;
	border: 1px solid rgb(23 51 31 / 0.22);
	border-radius: 10px;
	background: var(--lac-ivory);
	color: var(--lac-ink);
	font: inherit;
	font-size: 16px; /* Prevents iOS zoom on focus. */
	line-height: 1.4;
	resize: none;
}
.la-chat__input:focus { outline: 2px solid var(--lac-gold); outline-offset: 0; border-color: transparent; }
.la-chat__send {
	flex: none;
	display: inline-grid; place-items: center;
	width: 44px; height: 44px;
	border: 0; border-radius: 10px;
	background: var(--lac-gold); color: var(--lac-forest);
	cursor: pointer;
}
.la-chat__send:hover { background: #d6b25c; }
.la-chat__send:disabled { opacity: 0.55; cursor: not-allowed; }
.la-chat__send:focus-visible { outline: 2px solid var(--lac-forest); outline-offset: 2px; }

/* ---- Quote confirmation card ------------------------------------------------- */

.la-card {
	margin-top: 0.5rem;
	padding: 0.85rem;
	background: #fff;
	border: 1px solid var(--lac-gold);
	border-radius: 12px;
	box-shadow: 0 6px 18px -12px rgb(23 51 31 / 0.35);
}
.la-card__title { margin: 0 0 0.5rem; font-family: var(--lac-serif); font-size: 1rem; color: var(--lac-forest); }
.la-card__rows { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem; margin: 0 0 0.75rem; font-size: 0.85rem; }
.la-card__rows dt { color: rgb(27 35 30 / 0.65); }
.la-card__rows dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.la-card__consent { display: block; font-size: 0.8rem; line-height: 1.45; margin-bottom: 0.75rem; cursor: pointer; }
.la-card__consent input { width: 18px; height: 18px; vertical-align: -3px; accent-color: var(--lac-forest); }
.la-card__consent a { color: var(--lac-gold-ink); }
.la-card__buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.la-card__submit, .la-card__edit {
	min-height: 40px; padding: 0.5rem 1rem; border-radius: 999px; font: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.la-card__submit { border: 0; background: var(--lac-forest); color: var(--lac-ivory); }
.la-card__submit:disabled { opacity: 0.45; cursor: not-allowed; }
.la-card__edit { border: 1px solid rgb(23 51 31 / 0.25); background: #fff; color: var(--lac-forest); }
.la-card__submit:focus-visible, .la-card__edit:focus-visible { outline: 2px solid var(--lac-gold); outline-offset: 2px; }
.la-card.is-done { border-color: #2f7a46; }
.la-card.is-done .la-card__submit { background: #2f7a46; opacity: 1; }
.la-card.is-done .la-card__edit, .la-card.is-done .la-card__consent { display: none; }
@media (max-width: 639px) { .la-card__rows { grid-template-columns: 1fr; gap: 0 0; } .la-card__rows dd { margin-bottom: 0.35rem; } }
