/**
 * Atomico AI Chat — chat widget.
 *
 * Mobile-first. Everything is scoped under .aic-root and uses explicit values so
 * an opinionated theme cannot bleed into the widget.
 */

.aic-root {
	/*
	 * The accent family. Every value here is the bundled teal, and every one is
	 * replaced wholesale by the colour the operator picks — PHP derives the four
	 * shades from it and inlines them after this file. They are the fallbacks,
	 * not the palette.
	 */
	--aic-accent: #00796b;
	--aic-accent-dark: #00695c;
	--aic-accent-soft: #e0f2f1;
	/* Readable *on* the accent; and the accent made readable on white. */
	--aic-accent-fg: #ffffff;
	--aic-accent-ink: #00695c;
	--aic-accent-veil: rgba(255, 255, 255, 0.18);
	--aic-navy: #1a237e;
	--aic-navy-soft: #3949ab;
	--aic-surface: #ffffff;
	--aic-clinical: #f5f7f8;
	--aic-border: #e1e6e9;
	--aic-muted: #5f6f77;
	--aic-radius: 20px;
	--aic-radius-bubble: 16px;
	--aic-font: "Inter", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

	position: fixed;
	z-index: 99999;
	inset: auto 0 0 auto;
	font-family: var(--aic-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--aic-navy);
	-webkit-font-smoothing: antialiased;
}

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

/* :where() keeps the reset at zero added specificity so the component rules
   below — .aic-chip, .aic-send and friends — still win. */
.aic-root :where(button) {
	font-family: inherit;
	cursor: pointer;
	border: 0;
	background: none;
	padding: 0;
	color: inherit;
}

.aic-root :where(svg) {
	display: block;
	width: 100%;
	height: 100%;
}

.aic-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

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

/*
 * Mobile is the base case: a round icon button, nothing else. A pill with the
 * assistant's name in it eats a strip of a phone screen for a label nobody
 * needs to read twice — the chat bubble says what it is.
 */
.aic-launcher {
	position: fixed;
	right: 16px;
	bottom: 16px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0;
	width: 56px;
	height: 56px;
	padding: 0;
	border-radius: 50%;
	/* Both fall back to the bundled palette, so the widget still paints itself
	   correctly if the inline custom properties never arrive. */
	background: var(--aic-accent);
	color: var(--aic-accent-fg);
	font-size: 15px;
	font-weight: 600;
	letter-spacing: 0.01em;
	box-shadow: 0 4px 16px rgba(26, 35, 126, 0.18);
	transition: background-color 0.18s ease, transform 0.18s ease;
}

.aic-launcher:hover {
	background: var(--aic-accent-dark);
}

.aic-launcher:active {
	transform: scale(0.97);
}

.aic-launcher:focus-visible {
	outline: 3px solid var(--aic-navy);
	outline-offset: 2px;
}

.aic-launcher-icon {
	width: 24px;
	height: 24px;
	flex: none;
}

/*
 * On a phone the button is the assistant's face, with the chat bubble reduced
 * to a badge on the rim — a bare portrait does not read as "tap me to talk",
 * and a bare bubble is plainer than it needs to be.
 */
.aic-launcher-avatar {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	overflow: hidden;
	background: var(--aic-accent-soft);
}

.aic-launcher-avatar .aic-avatar-img {
	width: 100%;
	height: 100%;
}

.aic-launcher-icon {
	position: absolute;
	right: -1px;
	bottom: -1px;
	box-sizing: border-box;
	width: 22px;
	height: 22px;
	padding: 4px;
	border-radius: 50%;
	background: var(--aic-accent);
	box-shadow: 0 0 0 2px #fff;
}

/*
 * An operator's own logo in place of the bubble. `contain` rather than `cover`
 * because a mark that is not square must not be cropped, and the badge keeps a
 * little more padding so a full-bleed PNG does not touch the rim.
 */
.aic-launcher-icon-img {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.aic-launcher-icon.has-custom-icon {
	padding: 3px;
}

/*
 * Hidden rather than removed: the icon is aria-hidden, so this span is the
 * button's accessible name.
 */
.aic-launcher-label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

.aic-root.is-open .aic-launcher {
	opacity: 0;
	pointer-events: none;
	transform: scale(0.8);
}

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

.aic-panel {
	position: fixed;
	right: 12px;
	bottom: 12px;
	left: 12px;
	display: flex;
	flex-direction: column;
	max-height: calc(100dvh - 24px);
	height: 82dvh;
	overflow: hidden;
	background: var(--aic-surface);
	border: 1px solid var(--aic-border);
	border-radius: var(--aic-radius);
	box-shadow: 0 8px 32px rgba(26, 35, 126, 0.14);
}

.aic-panel[hidden] {
	display: none;
}

.aic-root.is-open .aic-panel {
	animation: aic-rise 0.22s ease-out;
}

@keyframes aic-rise {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
}

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

/*
 * The header carries the accent, so opening the panel shows the practice's
 * colour rather than the same white chrome every install has. Everything in it
 * is drawn in --aic-accent-fg, which PHP flips between white and dark navy
 * depending on how light the picked colour is.
 *
 * No bottom border: against a painted header the grey rule reads as a seam, and
 * the colour change already separates the header from the log below it.
 */
.aic-header {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: none;
	padding: 14px 14px 14px 16px;
	background: var(--aic-accent);
	color: var(--aic-accent-fg);
}

.aic-avatar {
	width: 44px;
	height: 44px;
	flex: none;
	border-radius: 50%;
	overflow: hidden;
	background: var(--aic-accent-soft);
}

.aic-avatar-img {
	width: 44px;
	height: 44px;
	object-fit: cover;
	border-radius: 50%;
}

.aic-identity {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1;
}

.aic-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--aic-accent-fg);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aic-status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	color: var(--aic-accent-fg);
}

/*
 * The dot follows the header ink rather than staying green: a mid green on a
 * dark teal header is barely visible, and the word beside it already says
 * "Online". The busy pulse below is what it is really carrying.
 */
.aic-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--aic-accent-fg);
	flex: none;
}

.aic-root.is-busy .aic-dot {
	animation: aic-pulse 1.2s ease-in-out infinite;
}

@keyframes aic-pulse {
	50% {
		opacity: 0.35;
	}
}

.aic-close {
	width: 36px;
	height: 36px;
	flex: none;
	padding: 7px;
	border-radius: 50%;
	color: var(--aic-accent-fg);
	opacity: 0.8;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

/* A veil of the header's own ink, so the hover works on any picked colour. */
.aic-close:hover {
	background: var(--aic-accent-veil);
	opacity: 1;
}

.aic-close:focus-visible {
	outline: 2px solid var(--aic-accent-fg);
	outline-offset: 1px;
}

/* --------------------------------------------------------------- Chat flow */

.aic-log {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 18px 16px 8px;
	background: var(--aic-clinical);
	scrollbar-width: thin;
}

.aic-langs {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 18px;
}

.aic-chip {
	padding: 7px 14px;
	border: 1px solid var(--aic-border);
	border-radius: 999px;
	background: var(--aic-surface);
	font-size: 13px;
	font-weight: 500;
	color: var(--aic-muted);
	transition: all 0.15s ease;
}

.aic-chip:hover {
	border-color: var(--aic-accent-ink);
	color: var(--aic-accent-ink);
}

.aic-chip.is-active {
	background: var(--aic-accent);
	border-color: var(--aic-accent);
	color: var(--aic-accent-fg);
}

.aic-chip:focus-visible {
	outline: 2px solid var(--aic-navy);
	outline-offset: 2px;
}

.aic-messages {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.aic-msg {
	max-width: 84%;
	padding: 11px 15px;
	border-radius: var(--aic-radius-bubble);
	font-size: 15px;
	color: var(--aic-navy);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.aic-msg-assistant {
	align-self: flex-start;
	background: var(--aic-accent-soft);
	border-bottom-left-radius: 6px;
}

.aic-msg-user {
	align-self: flex-end;
	background: var(--aic-surface);
	border: 1px solid var(--aic-border);
	border-bottom-right-radius: 6px;
}

.aic-msg-error {
	align-self: flex-start;
	background: #fdecec;
	border: 1px solid #f5c6c6;
	color: #8c1d18;
	border-bottom-left-radius: 6px;
}

.aic-msg a {
	color: var(--aic-accent-ink);
	text-decoration: underline;
}

/* Typing indicator */

.aic-typing {
	align-self: flex-start;
	display: flex;
	gap: 5px;
	padding: 15px;
	border-radius: var(--aic-radius-bubble);
	border-bottom-left-radius: 6px;
	background: var(--aic-accent-soft);
}

.aic-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aic-accent-ink);
	animation: aic-bounce 1.1s ease-in-out infinite;
}

.aic-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.aic-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

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

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

.aic-composer {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	flex: none;
	padding: 12px 14px 6px;
	background: var(--aic-surface);
	border-top: 1px solid var(--aic-border);
}

.aic-field {
	position: relative;
	flex: 1;
	display: flex;
	align-items: flex-end;
	border: 1px solid var(--aic-border);
	border-radius: 24px;
	background: var(--aic-clinical);
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.aic-field:focus-within {
	border-color: var(--aic-accent-ink);
	background: var(--aic-surface);
}

.aic-input {
	flex: 1;
	max-height: 120px;
	padding: 12px 6px 12px 18px;
	border: 0;
	background: none;
	resize: none;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.4;
	color: var(--aic-navy);
	outline: none;
}

.aic-input::placeholder {
	color: var(--aic-muted);
	opacity: 1;
}

.aic-mic {
	width: 40px;
	height: 44px;
	flex: none;
	padding: 11px 12px 11px 4px;
	color: var(--aic-muted);
	transition: color 0.15s ease;
}

.aic-mic:hover {
	color: var(--aic-accent-ink);
}

.aic-mic.is-recording {
	color: #c62828;
	animation: aic-pulse 1s ease-in-out infinite;
}

.aic-mic:focus-visible,
.aic-send:focus-visible {
	outline: 2px solid var(--aic-navy);
	outline-offset: 2px;
}

.aic-send {
	width: 44px;
	height: 44px;
	flex: none;
	padding: 11px;
	border-radius: 50%;
	background: var(--aic-accent);
	color: var(--aic-accent-fg);
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

.aic-send:hover:not(:disabled) {
	background: var(--aic-accent-dark);
}

.aic-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.aic-disclaimer {
	flex: none;
	margin: 0;
	padding: 4px 18px 12px;
	background: var(--aic-surface);
	font-size: 11px;
	line-height: 1.4;
	color: var(--aic-muted);
	text-align: center;
}

/* ----------------------------------------------------------------- Desktop */

@media (min-width: 600px) {
	.aic-panel {
		right: 24px;
		bottom: 24px;
		left: auto;
		width: 396px;
		height: min(660px, calc(100dvh - 48px));
	}

	.aic-launcher {
		right: 24px;
		bottom: 24px;
		width: auto;
		gap: 10px;
		padding: 0 20px 0 16px;
		border-radius: 28px;
	}

	.aic-launcher-label {
		position: static;
		width: auto;
		height: auto;
		overflow: visible;
		clip: auto;
	}

	.aic-launcher-avatar {
		display: none;
	}

	.aic-launcher-icon,
	.aic-launcher-icon.has-custom-icon {
		position: static;
		width: 24px;
		height: 24px;
		padding: 0;
		border-radius: 0;
		background: none;
		box-shadow: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.aic-root * {
		animation: none !important;
		transition: none !important;
	}
}

/* --------------------------------------------------------------------- RTL */

/*
 * The language list is configurable, so Arabic, Hebrew and Persian can be added
 * to any install. The script mirrors `dir` on .aic-root as the visitor switches
 * language; these are the handful of places where the layout is anchored to a
 * physical side rather than a logical one.
 */
/* The panel is pinned to both edges on a phone; only the launcher moves there. */
.aic-root[dir="rtl"] .aic-launcher {
	right: auto;
	left: 16px;
}

.aic-root[dir="rtl"] .aic-launcher-icon {
	right: auto;
	left: -1px;
}

.aic-root[dir="rtl"] .aic-header {
	padding: 14px 16px 14px 14px;
}

.aic-root[dir="rtl"] .aic-msg-assistant,
.aic-root[dir="rtl"] .aic-msg-error,
.aic-root[dir="rtl"] .aic-typing {
	border-bottom-left-radius: var(--aic-radius-bubble);
	border-bottom-right-radius: 6px;
}

.aic-root[dir="rtl"] .aic-msg-user {
	border-bottom-right-radius: var(--aic-radius-bubble);
	border-bottom-left-radius: 6px;
}

.aic-root[dir="rtl"] .aic-input {
	padding: 12px 18px 12px 6px;
}

.aic-root[dir="rtl"] .aic-mic {
	padding: 11px 4px 11px 12px;
}

/* The send arrow points at the composer's trailing edge, whichever side it is. */
.aic-root[dir="rtl"] .aic-send svg {
	transform: scaleX(-1);
}

@media (min-width: 600px) {
	.aic-root[dir="rtl"] .aic-launcher,
	.aic-root[dir="rtl"] .aic-panel {
		right: auto;
		left: 24px;
	}

	.aic-root[dir="rtl"] .aic-launcher {
		padding: 0 16px 0 20px;
	}
}
