/**
 * The assistant widget.
 *
 * Brand v4, like the theme: ink and the blue flame, IBM Plex Sans Arabic, 3px control radii and a 10px panel, flat surfaces with one
 * shadow because the panel floats, the 2px amber focus ring. No red, no green, no italics. The colours come from the theme's --k-* tokens;
 * the fallbacks are the same v4 values, so the widget stays on brand under any theme. Fixed to the corner on a desktop; on a phone it opens
 * full screen, because a 380px panel on a 390px screen is unusable.
 */

.kalis-assistant {
	--a-graphite: var(--k-graphite, #0c1620); /* ink-900 */
	--a-steel: var(--k-steel, #253544); /* ink-700 */
	--a-chalk: var(--k-chalk, #f2f6f8); /* ink-50 */
	--a-paper: var(--k-paper, #ffffff);
	--a-fire: var(--k-fire, #0e4fa5); /* blue-600: the brand and the only interactive accent */
	--a-fire-deep: var(--k-fire-deep, #0e4590); /* blue-700: hover darkens, never lightens */
	--a-soft: #5a6b7a; /* ink-500 */
	--a-line: #cbd4db; /* ink-200 hairline */
	--a-control: #7b8b98; /* ink-400: a control's edge, 3:1 on white */
	--a-amber: #e8940a; /* signal amber: the focus ring */
	--a-charcoal: #2b3440; /* non-conformance */
	--a-ember: #e4e7ea; /* the non-conformance tint */
	--a-accent-quiet: #e7effb; /* blue-100 */
	--a-accent-ink: #0a3673; /* blue-800 */
	--a-shadow: 0 12px 32px -8px rgba(12, 22, 32, 0.2); /* shadow-3: dialogs, toasts, this panel */
	--a-display: var(--k-display, 'IBM Plex Sans Arabic', 'Segoe UI', Arial, sans-serif);
	--a-body: var(--k-body, 'IBM Plex Sans Arabic', 'Segoe UI', Arial, sans-serif);

	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	z-index: 9999;
	font-family: var(--a-body);
	font-size: 16px;
	line-height: 1.5;
}

/* ---------------------------------------------------------------- launcher */

.kalis-assistant__launcher {
	display: inline-flex;
	align-items: center;
	gap: 0.65rem;
	padding: 0.95rem 1.25rem;
	border: 0;
	border-radius: 3px;
	background: var(--a-fire);
	color: #fff;
	font-family: var(--a-body);
	font-size: 0.875rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	cursor: pointer;
	box-shadow: var(--a-shadow);
	transition: background-color 120ms cubic-bezier(0.2, 0.6, 0.25, 1);
}

.kalis-assistant__launcher:hover {
	background: var(--a-fire-deep);
}

.kalis-assistant__launcher:focus-visible {
	outline: 2px solid var(--a-amber);
	outline-offset: 2px;
}

.kalis-assistant__launcher-icon {
	display: inline-flex;
}

.kalis-assistant[data-state="open"] .kalis-assistant__launcher {
	display: none;
}

/* ------------------------------------------------------------------- panel */

.kalis-assistant__panel {
	display: flex;
	flex-direction: column;
	width: min(25rem, calc(100vw - 2.5rem));
	height: min(36rem, calc(100vh - 4rem));
	background: var(--a-paper);
	border: 1px solid var(--a-line);
	border-radius: 10px;
	overflow: hidden;
	box-shadow: var(--a-shadow);
}

.kalis-assistant__panel[hidden] {
	display: none;
}

.kalis-assistant__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.9rem 1rem 0.9rem 1.15rem;
	background: var(--a-graphite);
	color: var(--a-chalk);
}

.kalis-assistant__title {
	font-family: var(--a-display);
	font-size: 1.125rem;
	font-weight: 600;
	letter-spacing: -0.01em;
	line-height: 1.2;
}

.kalis-assistant__close {
	display: inline-flex;
	padding: 0.35rem;
	border: 0;
	border-radius: 3px;
	background: transparent;
	color: var(--a-chalk);
	cursor: pointer;
}

.kalis-assistant__close:hover {
	background: rgba(255, 255, 255, 0.12);
}

.kalis-assistant__close:focus-visible {
	outline: 2px solid var(--a-amber);
	outline-offset: 2px;
}

/* --------------------------------------------------------------- transcript */

.kalis-assistant__log {
	flex: 1 1 auto;
	padding: 1.1rem;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--a-chalk);
}

.kalis-msg {
	display: flex;
	margin-bottom: 0.85rem;
}

.kalis-msg--user {
	justify-content: flex-end;
}

.kalis-msg__body {
	max-width: 86%;
	padding: 0.7rem 0.9rem;
	border-radius: 6px;
	font-size: 0.9375rem;
	/* Replies arrive as plain text set with textContent, so newlines are kept and long strings wrap. */
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

/* the assistant's reply is a flat card: white, an ink-200 hairline, no coloured edge */
.kalis-msg--assistant .kalis-msg__body {
	background: #fff;
	border: 1px solid var(--a-line);
	color: var(--a-graphite);
}

.kalis-msg--user .kalis-msg__body {
	background: var(--a-accent-quiet);
	color: var(--a-accent-ink);
}

/* waiting for a reply: muted, upright (no italics in the brand) */
.kalis-msg__body.is-waiting {
	color: var(--a-soft);
}

/* Notes are banners: a tint and a 3px leading rule bind them to the conversation. Sent is blue, a failure charcoal — never green or red. */
.kalis-note {
	margin: 0 0 0.85rem;
	padding: 0.65rem 0.8rem;
	border-radius: 3px;
	background: #fff;
	border-inline-start: 3px solid var(--a-line);
	font-size: 0.875rem;
	color: var(--a-graphite);
}

.kalis-note--ok {
	background: var(--a-accent-quiet);
	border-inline-start-color: var(--a-fire);
	font-weight: 600;
}

.kalis-note--error {
	background: var(--a-ember);
	border-inline-start-color: var(--a-charcoal);
}

/* ---------------------------------------------------------------- composer */

.kalis-assistant__composer {
	display: flex;
	gap: 0.5rem;
	align-items: flex-end;
	padding: 0.8rem;
	border-top: 1px solid var(--a-line);
	background: #fff;
}

.kalis-assistant__composer textarea {
	flex: 1 1 auto;
	padding: 0.65rem 0.75rem;
	border: 1px solid var(--a-control);
	border-radius: 3px;
	background: #fff;
	color: var(--a-graphite);
	font: inherit;
	font-size: 0.9375rem;
	line-height: 1.4;
	resize: none;
	max-height: 120px;
}

.kalis-assistant__composer textarea:focus-visible {
	outline: 2px solid var(--a-amber);
	outline-offset: 2px;
	border-color: var(--a-fire);
}

.kalis-assistant__composer button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 2.75rem;
	height: 2.75rem;
	border: 0;
	border-radius: 3px;
	background: var(--a-fire);
	color: #fff;
	cursor: pointer;
}

.kalis-assistant__composer button:hover:not([disabled]) {
	background: var(--a-fire-deep);
}

.kalis-assistant__composer button:focus-visible {
	outline: 2px solid var(--a-amber);
	outline-offset: 2px;
}

/* disabled: ink-100 fill, ink-400 icon, not-allowed */
.kalis-assistant__composer button[disabled] {
	background: #e4eaef;
	color: #7b8b98;
	cursor: not-allowed;
}

.kalis-assistant__notice {
	margin: 0;
	padding: 0.5rem 0.9rem 0.8rem;
	background: #fff;
	color: var(--a-soft);
	font-size: 0.75rem;
	line-height: 1.4;
}

/* ------------------------------------------------------------------- phone */

@media (max-width: 30rem) {
	.kalis-assistant {
		right: 0.9rem;
		bottom: 0.9rem;
	}

	.kalis-assistant[data-state="open"] {
		inset: 0;
	}

	.kalis-assistant[data-state="open"] .kalis-assistant__panel {
		width: 100vw;
		height: 100dvh;
		border: 0;
		border-radius: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.kalis-assistant * {
		transition: none !important;
	}
}
