/* ARIA: all rules are scoped under .aria so the theme (BeTheme) cannot leak in and vice versa. */

.aria {
	--aria-accent: #1d3557;
	--aria-ink: #1b1f24;
	--aria-muted: #5c6670;
	--aria-line: #e2e6eb;
	--aria-soft: #f2f4f7;
	--aria-surface: #ffffff;
	--aria-error: #a4262c;
	--aria-gap: 20px;
	--aria-bot-shell: #ffffff;
	--aria-bot-light: #ffc93c;

	position: fixed;
	bottom: var(--aria-gap);
	z-index: 99999;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.5;
	color: var(--aria-ink);
}
.aria--right { right: var(--aria-gap); }
.aria--left { left: var(--aria-gap); }

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

/* Neutralise theme button styles */
.aria button {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	color: inherit;
	font: inherit;
	text-transform: none;
	letter-spacing: normal;
	line-height: inherit;
	height: auto;
	min-width: 0;
	width: auto;
	cursor: pointer;
	border-radius: 0;
}
.aria button:disabled { cursor: default; opacity: .5; }
.aria :focus-visible { outline: 2px solid var(--aria-accent); outline-offset: 2px; }

.aria svg { width: 20px; height: 20px; flex: none; display: block; }

/* Launcher */
.aria .aria__launcher {
	display: inline-flex;
	align-items: center;
	gap: 12px;
	padding: 5px 20px 5px 8px;
	border-radius: 999px;
	background: var(--aria-accent);
	color: #fff;
	font-weight: 600;
	box-shadow: 0 6px 20px rgba(20, 30, 45, .22);
}
.aria .aria__launcher:hover { filter: brightness(1.1); }
.aria.is-open .aria__launcher .aria__launcher-text { display: none; }
.aria.is-open .aria__launcher { padding: 5px 8px; }

/* Robot */
.aria svg.aria-bot { width: 100%; height: 100%; overflow: visible; }
.aria__bot { display: block; flex: none; }
.aria__bot--launcher { width: 46px; height: 46px; }
.aria__bot--head { width: 38px; height: 38px; }
.aria-bot__shell { fill: var(--aria-bot-shell); }
.aria-bot__screen { fill: var(--aria-accent); }
.aria-bot__eye { fill: var(--aria-bot-shell); }
.aria-bot__light { fill: var(--aria-bot-light); }
.aria-bot__line { stroke: var(--aria-bot-shell); stroke-width: 1.8; stroke-linecap: round; }
.aria-bot__smile { fill: none; stroke: var(--aria-bot-shell); stroke-width: 1.6; stroke-linecap: round; }
.aria-bot__limb { fill: none; stroke: var(--aria-bot-shell); stroke-width: 3.2; stroke-linecap: round; }
.aria-bot__arm { transform-box: view-box; transform-origin: 31.5px 33.5px; }
.aria-bot__head { transform-box: view-box; transform-origin: 24px 30px; }

@media (prefers-reduced-motion: no-preference) {
	.aria__bot.is-waving .aria-bot__arm { animation: aria-wave 1.5s ease-in-out; }
	.aria__bot.is-waving .aria-bot__head { animation: aria-nod 1.5s ease-in-out; }
	.aria__bot.is-waving .aria-bot__eye { animation: aria-blink 1.5s steps(1, end); transform-box: fill-box; transform-origin: center; }
	@keyframes aria-wave {
		0%, 100% { transform: rotate(0deg); }
		12% { transform: rotate(-28deg); }
		26% { transform: rotate(12deg); }
		40% { transform: rotate(-28deg); }
		54% { transform: rotate(12deg); }
		68% { transform: rotate(-18deg); }
		82% { transform: rotate(4deg); }
	}
	@keyframes aria-nod {
		0%, 100% { transform: rotate(0deg); }
		20%, 70% { transform: rotate(-5deg); }
	}
	@keyframes aria-blink {
		0%, 100% { transform: scaleY(1); }
		76% { transform: scaleY(.15); }
		82% { transform: scaleY(1); }
	}
}

/* Reply avatar */
.aria__row { display: flex; align-items: flex-end; gap: 8px; align-self: flex-start; max-width: 94%; }
.aria__row .aria__msg { max-width: none; min-width: 0; }
.aria__avatar {
	flex: none;
	width: 30px;
	height: 30px;
	padding: 4px 3px 3px;
	border-radius: 50%;
	background: var(--aria-accent);
	display: flex;
	align-items: center;
	justify-content: center;
}
.aria svg.aria-bot--face { width: 100%; height: 100%; }

/* Panel */
.aria__panel {
	position: absolute;
	bottom: calc(100% + 12px);
	width: 400px;
	height: min(640px, calc(100vh - 110px));
	display: flex;
	flex-direction: column;
	background: var(--aria-surface);
	border: 1px solid var(--aria-line);
	border-radius: 16px;
	box-shadow: 0 18px 48px rgba(20, 30, 45, .2);
	overflow: hidden;
}
.aria--right .aria__panel { right: 0; }
.aria--left .aria__panel { left: 0; }
.aria__panel[hidden] { display: none; }
.aria__panel.aria__panel--gate { height: auto; }

@media (prefers-reduced-motion: no-preference) {
	.aria.is-open .aria__panel { animation: aria-in .18s ease-out; }
	@keyframes aria-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

.aria__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 10px 10px 10px 10px;
	background: var(--aria-accent);
	color: #fff;
}
.aria__id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.aria__title { display: flex; flex-direction: column; min-width: 0; }
.aria__title strong { font-size: 16px; font-weight: 700; }
.aria__title span { font-size: 13px; opacity: .85; }
.aria__title strong { white-space: nowrap; }
.aria__head-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.aria .aria__reset {
	padding: 6px;
	border-radius: 8px;
	color: #fff;
}
.aria .aria__reset:hover,
.aria .aria__close:hover { background: rgba(255, 255, 255, .14); }
.aria .aria__close { padding: 6px; border-radius: 8px; color: #fff; }
.aria__head :focus-visible { outline-color: #fff; }

.aria__body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Messages */
.aria__log {
	flex: 1;
	overflow-y: auto;
	padding: 18px 16px 8px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	overscroll-behavior: contain;
}
.aria__msg {
	max-width: 88%;
	padding: 10px 14px;
	border-radius: 14px;
	overflow-wrap: anywhere;
}
.aria__msg--assistant { align-self: flex-start; background: var(--aria-soft); border-bottom-left-radius: 4px; }
.aria__msg--user {
	align-self: flex-end;
	background: var(--aria-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}
.aria__msg--error {
	align-self: stretch;
	max-width: none;
	background: #fdf2f2;
	color: var(--aria-error);
	border: 1px solid #f3d0d2;
	font-size: 14px;
}
.aria__msg p { margin: 0 0 8px; padding: 0; }
.aria__msg p:last-child { margin-bottom: 0; }
.aria__msg ul,
.aria__msg ol { margin: 4px 0 8px; padding-left: 20px; }
.aria__msg li { margin: 0 0 4px; padding: 0; list-style-position: outside; }
.aria__msg ul li { list-style-type: disc; }
.aria__msg ol li { list-style-type: decimal; }
.aria__msg a { color: var(--aria-accent); text-decoration: underline; text-underline-offset: 2px; }
.aria__msg--error a { color: inherit; }
.aria__msg code { font-size: 13px; background: rgba(0, 0, 0, .06); padding: 1px 4px; border-radius: 4px; }
.aria__h { font-weight: 700; }

.aria__sources {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid var(--aria-line);
	font-size: 13px;
}
.aria__sources span { width: 100%; color: var(--aria-muted); }
.aria .aria__sources a {
	display: inline-block;
	padding: 4px 10px;
	border: 1px solid var(--aria-line);
	border-radius: 999px;
	background: var(--aria-surface);
	text-decoration: none;
	color: var(--aria-ink);
}
.aria .aria__sources a:hover { border-color: var(--aria-accent); }

.aria__suggestions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.aria .aria__suggestion {
	text-align: left;
	padding: 8px 12px;
	border: 1px solid var(--aria-line);
	border-radius: 10px;
	background: var(--aria-surface);
	font-size: 14px;
	color: var(--aria-ink);
}
.aria .aria__suggestion:hover { border-color: var(--aria-accent); color: var(--aria-accent); }

.aria__typing { display: inline-flex; gap: 4px; padding: 14px; }
.aria__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--aria-muted); opacity: .4; }
@media (prefers-reduced-motion: no-preference) {
	.aria__typing span { animation: aria-dot 1.2s infinite ease-in-out; }
	.aria__typing span:nth-child(2) { animation-delay: .15s; }
	.aria__typing span:nth-child(3) { animation-delay: .3s; }
	@keyframes aria-dot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
}

/* Composer */
.aria__form { margin: 0; padding: 10px 14px 12px; border-top: 1px solid var(--aria-line); }
.aria__composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 6px 6px 6px 12px;
	border: 1px solid var(--aria-line);
	border-radius: 12px;
	background: var(--aria-surface);
}
.aria__composer:focus-within { border-color: var(--aria-accent); }
.aria .aria__input {
	flex: 1;
	min-width: 0;
	height: auto;
	min-height: 24px;
	max-height: 140px;
	margin: 0;
	padding: 6px 0;
	border: 0;
	background: transparent;
	box-shadow: none;
	color: var(--aria-ink);
	font: inherit;
	font-size: 15px;
	line-height: 1.45;
	resize: none;
	outline: none;
	white-space: pre-wrap;
}
.aria .aria__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 9px;
	background: var(--aria-accent);
	color: #fff;
}
.aria__note { margin: 8px 2px 0; padding: 0; font-size: 12px; line-height: 1.4; color: var(--aria-muted); }

/* Guest gate */
.aria__gate { margin: auto 0; padding: 28px 24px; }
.aria__gate p { margin: 0 0 12px; padding: 0; color: var(--aria-muted); }
.aria__gate .aria__gate-title { font-size: 17px; font-weight: 700; line-height: 1.35; color: var(--aria-ink); }
.aria__gate-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.aria .aria__btn {
	display: inline-block;
	padding: 10px 18px;
	border: 1px solid var(--aria-accent);
	border-radius: 10px;
	color: var(--aria-accent);
	font-weight: 600;
	text-decoration: none;
}
.aria .aria__btn--primary { background: var(--aria-accent); color: #fff; }
.aria .aria__btn:hover { filter: brightness(1.1); }

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

/* Mobile: full screen panel */
@media (max-width: 520px) {
	.aria { --aria-gap: 14px; }
	.aria__panel {
		position: fixed;
		inset: 0;
		width: auto;
		height: 100%;
		border: 0;
		border-radius: 0;
		padding-top: env(safe-area-inset-top, 0px);
		padding-bottom: env(safe-area-inset-bottom, 0px);
		background: var(--aria-accent);
	}
	.aria__body { background: var(--aria-surface); }
	.aria.is-open .aria__launcher { display: none; }
	.aria .aria__input { font-size: 16px; } /* prevents iOS zoom on focus */
}
