/**
 * LoadX Chatbot — Phase 1 widget styles
 * Aligns with theme navy / deep blue / charcoal system.
 */

.lx-chat {
	--lx-chat-navy: #0a1a32;
	--lx-chat-navy-soft: #13294b;
	--lx-chat-blue: #1b4fe0;
	--lx-chat-blue-dark: #123cb3;
	--lx-chat-base: #ffffff;
	--lx-chat-surface: #f4f7fb;
	--lx-chat-line: #e1e7f0;
	--lx-chat-text: #111826;
	--lx-chat-muted: #5b6b80;
	--lx-chat-shadow: 0 18px 50px rgba(10, 26, 50, 0.22);
	--lx-chat-radius: 18px;
	--lx-chat-font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--lx-chat-z: 99990;

	position: fixed;
	bottom: 1.25rem;
	z-index: var(--lx-chat-z);
	font-family: var(--lx-chat-font);
	color: var(--lx-chat-text);
	line-height: 1.45;
}

.lx-chat--right { right: 1.25rem; }
.lx-chat--left { left: 1.25rem; }

.lx-chat .screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

/* Launcher */
.lx-chat__launcher {
	appearance: none;
	border: 0;
	width: 3.75rem;
	height: 3.75rem;
	border-radius: 999px;
	background: linear-gradient(160deg, var(--lx-chat-navy) 0%, var(--lx-chat-navy-soft) 100%);
	color: #fff;
	display: grid;
	place-items: center;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(10, 26, 50, 0.35);
	transition: transform 180ms ease, box-shadow 180ms ease;
}

.lx-chat__launcher:hover,
.lx-chat__launcher:focus-visible {
	transform: translateY(-2px) scale(1.03);
	box-shadow: 0 14px 32px rgba(10, 26, 50, 0.42);
	outline: none;
}

.lx-chat__launcher:focus-visible {
	box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--lx-chat-blue);
}

.lx-chat.is-open .lx-chat__launcher {
	display: none;
}

/* Panel */
.lx-chat__panel {
	position: absolute;
	bottom: 0;
	width: min(100vw - 1.5rem, 390px);
	height: min(640px, calc(100vh - 2rem));
	display: flex;
	flex-direction: column;
	background: var(--lx-chat-base);
	border: 1px solid var(--lx-chat-line);
	border-radius: var(--lx-chat-radius);
	box-shadow: var(--lx-chat-shadow);
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	pointer-events: none;
	transition: opacity 200ms ease, transform 220ms cubic-bezier(0.2, 0, 0.2, 1);
}

.lx-chat--right .lx-chat__panel { right: 0; }
.lx-chat--left .lx-chat__panel { left: 0; }

.lx-chat.is-open .lx-chat__panel {
	opacity: 1;
	transform: none;
	pointer-events: auto;
}

.lx-chat__panel[hidden] {
	display: none !important;
}

.lx-chat.is-open .lx-chat__panel[hidden] {
	display: flex !important;
}

/* Header */
.lx-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.9rem 1rem;
	background: linear-gradient(160deg, var(--lx-chat-navy) 0%, var(--lx-chat-navy-soft) 100%);
	color: #fff;
}

.lx-chat__brand {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-width: 0;
}

.lx-chat__avatar {
	width: 2.4rem;
	height: 2.4rem;
	border-radius: 999px;
	display: grid;
	place-items: center;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.2);
	flex-shrink: 0;
}

.lx-chat__title {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 650;
	letter-spacing: -0.01em;
	color: #fff;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.lx-chat__status {
	margin: 0.1rem 0 0;
	font-size: 0.75rem;
	color: rgba(233, 239, 250, 0.78);
}

.lx-chat__header-actions {
	display: flex;
	gap: 0.25rem;
}

.lx-chat__icon-btn {
	appearance: none;
	border: 0;
	background: transparent;
	color: rgba(255, 255, 255, 0.88);
	width: 2rem;
	height: 2rem;
	border-radius: 8px;
	display: grid;
	place-items: center;
	cursor: pointer;
}

.lx-chat__icon-btn:hover,
.lx-chat__icon-btn:focus-visible {
	background: rgba(255, 255, 255, 0.1);
	outline: none;
}

/* Messages */
.lx-chat__messages {
	flex: 1;
	overflow-y: auto;
	padding: 1rem;
	background:
		radial-gradient(1200px 400px at 100% -10%, rgba(27, 79, 224, 0.06), transparent 55%),
		var(--lx-chat-surface);
	scroll-behavior: smooth;
}

.lx-chat__row {
	display: flex;
	margin: 0 0 0.75rem;
	animation: lx-chat-in 220ms ease both;
}

.lx-chat__row--user {
	justify-content: flex-end;
}

.lx-chat__bubble {
	max-width: 88%;
	padding: 0.7rem 0.85rem;
	border-radius: 14px;
	font-size: 0.9rem;
	white-space: pre-wrap;
	word-break: break-word;
}

.lx-chat__row--assistant .lx-chat__bubble {
	background: #fff;
	border: 1px solid var(--lx-chat-line);
	color: var(--lx-chat-text);
	border-bottom-left-radius: 5px;
	box-shadow: 0 1px 2px rgba(10, 26, 50, 0.04);
}

.lx-chat__row--user .lx-chat__bubble {
	background: var(--lx-chat-blue);
	color: #fff;
	border-bottom-right-radius: 5px;
}

.lx-chat__typing {
	display: inline-flex;
	gap: 0.3rem;
	align-items: center;
	padding: 0.85rem 1rem;
	background: #fff;
	border: 1px solid var(--lx-chat-line);
	border-radius: 14px;
	border-bottom-left-radius: 5px;
}

.lx-chat__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--lx-chat-muted);
	animation: lx-chat-dot 1.1s infinite ease-in-out;
}

.lx-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.lx-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

/* Quick replies */
.lx-chat__replies {
	display: flex;
	flex-wrap: wrap;
	gap: 0.45rem;
	padding: 0.55rem 0.85rem 0.75rem;
	border-top: 1px solid var(--lx-chat-line);
	background: var(--lx-chat-base);
}

.lx-chat__replies[hidden] {
	display: none !important;
}

.lx-chat__chip {
	appearance: none;
	border: 1px solid rgba(27, 79, 224, 0.28);
	background: rgba(27, 79, 224, 0.06);
	color: var(--lx-chat-blue-dark);
	border-radius: 999px;
	padding: 0.4rem 0.75rem;
	font-size: 0.78rem;
	font-weight: 600;
	cursor: pointer;
	transition: background 160ms ease, border-color 160ms ease;
}

.lx-chat__chip:hover,
.lx-chat__chip:focus-visible {
	background: rgba(27, 79, 224, 0.12);
	border-color: var(--lx-chat-blue);
	outline: none;
}

/* Composer */
.lx-chat__composer {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	padding: 0.75rem;
	border-top: 1px solid var(--lx-chat-line);
	background: var(--lx-chat-base);
}

.lx-chat__input {
	flex: 1;
	resize: none;
	max-height: 110px;
	min-height: 42px;
	border: 1px solid var(--lx-chat-line);
	border-radius: 12px;
	padding: 0.65rem 0.8rem;
	font: inherit;
	font-size: 0.9rem;
	background: var(--lx-chat-surface);
	color: var(--lx-chat-text);
}

.lx-chat__input:focus {
	outline: none;
	border-color: rgba(27, 79, 224, 0.55);
	box-shadow: 0 0 0 3px rgba(27, 79, 224, 0.12);
}

.lx-chat__send {
	appearance: none;
	border: 0;
	width: 2.6rem;
	height: 2.6rem;
	border-radius: 12px;
	background: var(--lx-chat-blue);
	color: #fff;
	display: grid;
	place-items: center;
	cursor: pointer;
	flex-shrink: 0;
}

.lx-chat__send:hover,
.lx-chat__send:focus-visible {
	background: var(--lx-chat-blue-dark);
	outline: none;
}

.lx-chat__send:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.lx-chat__toast {
	position: absolute;
	left: 50%;
	bottom: 5.5rem;
	transform: translateX(-50%);
	background: var(--lx-chat-navy);
	color: #fff;
	font-size: 0.78rem;
	font-weight: 600;
	padding: 0.55rem 0.85rem;
	border-radius: 999px;
	box-shadow: 0 8px 24px rgba(10, 26, 50, 0.28);
	z-index: 2;
	animation: lx-chat-in 180ms ease both;
	white-space: nowrap;
}

@keyframes lx-chat-in {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

@keyframes lx-chat-dot {
	0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

/* Dark preference */
@media (prefers-color-scheme: dark) {
	.lx-chat {
		--lx-chat-base: #0f1b2e;
		--lx-chat-surface: #132038;
		--lx-chat-line: rgba(255, 255, 255, 0.1);
		--lx-chat-text: #e9effa;
		--lx-chat-muted: #9aabc2;
	}

	.lx-chat__row--assistant .lx-chat__bubble,
	.lx-chat__typing {
		background: #182742;
		border-color: var(--lx-chat-line);
		color: var(--lx-chat-text);
	}

	.lx-chat__chip {
		background: rgba(27, 79, 224, 0.18);
		color: #c9d8ff;
		border-color: rgba(169, 196, 255, 0.35);
	}

	.lx-chat__input {
		background: #0f1b2e;
		color: var(--lx-chat-text);
	}
}

@media (max-width: 480px) {
	.lx-chat {
		bottom: 0.75rem;
	}

	.lx-chat--right { right: 0.75rem; }
	.lx-chat--left { left: 0.75rem; }

	.lx-chat__panel {
		width: calc(100vw - 1.5rem);
		height: min(72vh, 620px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.lx-chat__panel,
	.lx-chat__launcher,
	.lx-chat__row,
	.lx-chat__typing span {
		animation: none !important;
		transition: none !important;
	}
}
