/**
 * Joyful Care AI Receptionist — front end widget.
 *
 * Every rule is scoped to .jcar-* and sets its own typography, colour, and box
 * properties so an opinionated theme cannot bleed into the widget.
 */

.jcar-launcher,
.jcar-panel {
	--jcar-green: #176553;
	--jcar-green-dark: #0e493e;
	--jcar-ink: #18322d;
	--jcar-muted: #6c817a;
	--jcar-line: #e4ebe8;
	--jcar-soft: #f3f7f5;
	--jcar-error: #a03a2c;
	--jcar-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--jcar-shadow: 0 2px 6px rgba(16, 40, 34, 0.06), 0 16px 44px rgba(16, 40, 34, 0.16);

	box-sizing: border-box;
	font-family: var(--jcar-font);
}

.jcar-launcher *,
.jcar-panel *,
.jcar-launcher *::before,
.jcar-panel *::before,
.jcar-launcher *::after,
.jcar-panel *::after {
	box-sizing: border-box;
}

.jcar-icon {
	width: 22px;
	height: 22px;
	flex: none;
	fill: currentColor;
}

.jcar-audio {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

/* ---------- Launcher ---------- */

.jcar-launcher {
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 99998;
	display: grid;
	place-items: center;
	width: 60px !important;
	height: 60px !important;
	min-width: 0 !important;
	min-height: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 50% !important;
	background: var(--jcar-green) !important;
	background-image: none !important;
	color: #fff !important;
	cursor: pointer;
	box-shadow: var(--jcar-shadow);
	-webkit-appearance: none;
	appearance: none;
	transition: transform 0.18s ease, background 0.18s ease;
}

.jcar-launcher:hover {
	background: var(--jcar-green-dark) !important;
	transform: scale(1.04);
}

.jcar-launcher:focus-visible {
	outline: 3px solid rgba(23, 101, 83, 0.35);
	outline-offset: 3px;
}

/* Both icons share the grid cell so the swap does not shift the button. */
.jcar-launcher__open,
.jcar-launcher__close {
	grid-area: 1 / 1;
	width: 26px;
	height: 26px;
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.jcar-launcher__close {
	opacity: 0;
	transform: rotate(-90deg);
}

.jcar-launcher--active .jcar-launcher__open {
	opacity: 0;
	transform: rotate(90deg);
}

.jcar-launcher--active .jcar-launcher__close {
	opacity: 1;
	transform: rotate(0);
}

/* ---------- Panel ---------- */

.jcar-panel {
	position: fixed;
	right: 24px;
	bottom: 100px;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	width: 396px;
	max-width: calc(100vw - 32px);
	height: 620px;
	max-height: calc(100vh - 130px);
	border: 1px solid var(--jcar-line);
	border-radius: 20px;
	background: #fff;
	color: var(--jcar-ink);
	font-size: 15px;
	line-height: 1.55;
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px) scale(0.985);
	transform-origin: 100% 100%;
	box-shadow: var(--jcar-shadow);
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.jcar-panel--open {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

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

.jcar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 14px 16px 18px;
	border-bottom: 1px solid var(--jcar-line);
}

.jcar-identity {
	display: flex;
	align-items: center;
	gap: 11px;
	min-width: 0;
}

.jcar-identity__mark {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	flex: none;
	border-radius: 50%;
	background: var(--jcar-green);
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.03em;
}

.jcar-identity__name {
	font-size: 16px;
	font-weight: 600;
	line-height: 1.25;
	color: var(--jcar-ink);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.jcar-panel .jcar-close {
	display: grid;
	place-items: center;
	width: 34px !important;
	height: 34px !important;
	min-width: 0 !important;
	min-height: 0 !important;
	flex: none;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 50% !important;
	background: transparent !important;
	background-image: none !important;
	color: var(--jcar-muted) !important;
	box-shadow: none !important;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background 0.15s ease, color 0.15s ease;
}

.jcar-panel .jcar-close .jcar-icon {
	width: 18px;
	height: 18px;
}

.jcar-panel .jcar-close:hover {
	background: var(--jcar-soft) !important;
	color: var(--jcar-ink) !important;
}

.jcar-close:focus-visible {
	outline: 2px solid var(--jcar-green);
	outline-offset: 1px;
}

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

.jcar-messages {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 14px;
	padding: 20px 18px 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
}

.jcar-turn {
	display: flex;
	flex-direction: column;
	gap: 6px;
	max-width: 88%;
}

.jcar-turn--user {
	align-self: flex-end;
	align-items: flex-end;
}

.jcar-message {
	padding: 13px 16px;
	border-radius: 18px;
	font-size: 15px;
	line-height: 1.55;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.jcar-turn--assistant .jcar-message {
	background: var(--jcar-soft);
	color: var(--jcar-ink);
	border-bottom-left-radius: 6px;
}

.jcar-turn--user .jcar-message {
	background: var(--jcar-green);
	color: #fff;
	border-bottom-right-radius: 6px;
}

.jcar-meta {
	padding-left: 4px;
	color: var(--jcar-muted);
	font-size: 12.5px;
	line-height: 1.3;
}

.jcar-note {
	align-self: center;
	max-width: 90%;
	padding: 2px 4px;
	color: var(--jcar-muted);
	font-size: 12.5px;
	text-align: center;
}

.jcar-note--error {
	color: var(--jcar-error);
}

.jcar-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 15px 17px;
	border-radius: 18px;
	border-bottom-left-radius: 6px;
	background: var(--jcar-soft);
}

.jcar-typing__dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #9fb5ad;
	animation: jcar-bounce 1.2s ease-in-out infinite;
}

.jcar-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.jcar-typing__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes jcar-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Shortcut questions ---------- */

.jcar-shortcuts {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 8px;
	padding: 10px 18px 6px;
}

.jcar-shortcuts--done {
	display: none;
}

.jcar-panel .jcar-shortcut {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	width: 100% !important;
	margin: 0 !important;
	padding: 8px 12px !important;
	border: 1px solid var(--jcar-line) !important;
	border-radius: 12px !important;
	background: #fff !important;
	color: var(--jcar-ink) !important;
	font-family: inherit !important;
	font-size: 13px !important;
	font-weight: 500 !important;
	line-height: 1.3 !important;
	letter-spacing: normal !important;
	text-align: center;
	text-transform: none !important;
	box-shadow: none !important;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.jcar-panel .jcar-shortcut:hover {
	border-color: var(--jcar-green) !important;
	background: var(--jcar-soft) !important;
	color: var(--jcar-green-dark) !important;
}

.jcar-panel .jcar-shortcut:focus-visible {
	outline: 2px solid var(--jcar-green);
	outline-offset: 1px;
}

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

.jcar-composer {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 0;
	padding: 12px 16px 16px;
}

.jcar-field {
	display: flex;
	align-items: center;
	gap: 6px;
	height: 52px;
	padding: 0 6px 0 18px;
	border: 1px solid #cfdad6;
	border-radius: 26px;
	background: #fff;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.jcar-field:focus-within {
	border-color: var(--jcar-green);
	box-shadow: 0 0 0 3px rgba(23, 101, 83, 0.12);
}

/*
 * Themes routinely restyle every input and button on the page, and they win on
 * specificity against a single class. These declarations are deliberately loud so
 * the field reads as one clean pill rather than a box inside a box.
 */
.jcar-panel .jcar-input {
	flex: 1;
	min-width: 0;
	width: auto !important;
	height: 100% !important;
	min-height: 0 !important;
	max-height: none !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 0 !important;
	background: transparent !important;
	background-image: none !important;
	box-shadow: none !important;
	outline: none !important;
	color: var(--jcar-ink) !important;
	font-family: inherit !important;
	font-size: 15px !important;
	font-weight: 400 !important;
	line-height: 1.4 !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	-webkit-appearance: none !important;
	appearance: none !important;
}

.jcar-panel .jcar-input::placeholder {
	color: #93a7a1;
	opacity: 1;
}

.jcar-panel .jcar-send {
	display: grid;
	place-items: center;
	width: 40px !important;
	height: 40px !important;
	min-width: 0 !important;
	min-height: 0 !important;
	flex: none;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 50% !important;
	background: var(--jcar-green) !important;
	background-image: none !important;
	color: #fff !important;
	box-shadow: none !important;
	text-transform: none !important;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.jcar-panel .jcar-send .jcar-icon {
	width: 20px;
	height: 20px;
}

.jcar-panel .jcar-send:hover {
	background: var(--jcar-green-dark) !important;
}

.jcar-panel .jcar-send:disabled {
	opacity: 0.4;
	cursor: default;
}

.jcar-panel .jcar-send:focus-visible {
	outline: 2px solid var(--jcar-green);
	outline-offset: 2px;
}

/* ---------- Call button ---------- */

.jcar-panel .jcar-call {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100% !important;
	height: 48px !important;
	min-height: 0 !important;
	margin: 0 !important;
	padding: 0 16px !important;
	border: 1px solid var(--jcar-line) !important;
	border-radius: 26px !important;
	background: var(--jcar-soft) !important;
	background-image: none !important;
	color: var(--jcar-ink) !important;
	font-family: inherit !important;
	font-size: 14.5px !important;
	font-weight: 500 !important;
	line-height: 1 !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	box-shadow: none !important;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.jcar-panel .jcar-call .jcar-icon {
	width: 19px;
	height: 19px;
}

.jcar-panel .jcar-call:hover {
	border-color: var(--jcar-green) !important;
	background: #eaf2ef !important;
	color: var(--jcar-green-dark) !important;
}

.jcar-panel .jcar-call:focus-visible {
	outline: 2px solid var(--jcar-green);
	outline-offset: 2px;
}

.jcar-panel .jcar-call:disabled {
	opacity: 0.6;
	cursor: default;
}

.jcar-panel .jcar-call--active,
.jcar-panel .jcar-call--active:hover {
	border-color: var(--jcar-green) !important;
	background: var(--jcar-green) !important;
	color: #fff !important;
}

/* ---------- Footer ---------- */

.jcar-footer {
	padding: 0 18px 14px;
	color: var(--jcar-muted);
	font-size: 12px;
	line-height: 1.4;
	text-align: center;
}

.jcar-footer a {
	color: var(--jcar-muted);
	text-decoration: underline;
}

.jcar-footer a:hover {
	color: var(--jcar-green-dark);
}

/* ---------- Phones ---------- */

@media screen and (max-width: 600px) {
	.jcar-launcher {
		right: 16px;
		bottom: 16px;
		width: 56px;
		height: 56px;
	}

	.jcar-panel {
		right: 0;
		bottom: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		border: 0;
		border-radius: 0;
		transform: translateY(16px);
	}

	.jcar-panel--open {
		transform: translateY(0);
	}

	.jcar-turn {
		max-width: 92%;
	}

	.jcar-footer {
		padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
	}
}

@media (prefers-reduced-motion: reduce) {
	.jcar-launcher,
	.jcar-launcher__open,
	.jcar-launcher__close,
	.jcar-panel,
	.jcar-close,
	.jcar-shortcut,
	.jcar-field,
	.jcar-send,
	.jcar-call {
		transition: none;
	}

	.jcar-typing__dot {
		animation: none;
	}
}
