/* RFI Chatbot — floating chat widget (scoped, no dependencies) */

.rfi-chatbot,
.rfi-chatbot *,
.rfi-chatbot *::before,
.rfi-chatbot *::after {
	box-sizing: border-box;
}

.rfi-chatbot {
	--rfi-primary: #0d9488;
	--rfi-primary-dark: #0f766e;
	--rfi-primary-light: #ccfbf1;
	--rfi-surface: #ffffff;
	--rfi-bg: #f4f6f8;
	--rfi-bg-chat: #e8ecf0;
	--rfi-text: #0f172a;
	--rfi-muted: #64748b;
	--rfi-bubble-user: #0d9488;
	--rfi-bubble-user-text: #ffffff;
	--rfi-bubble-bot: #ffffff;
	--rfi-shadow: 0 12px 40px rgba(15, 23, 42, 0.15);
	--rfi-radius: 16px;
	--rfi-z: 999999;

	position: fixed;
	inset-block-end: 24px;
	inset-inline-end: 24px;
	z-index: var(--rfi-z);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	color: var(--rfi-text);
	-webkit-font-smoothing: antialiased;
}

/* Floating action button */
.rfi-chatbot-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin-inline-start: auto;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--rfi-primary) 0%, var(--rfi-primary-dark) 100%);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--rfi-shadow);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rfi-chatbot-toggle:hover {
	transform: translateY(-2px);
	box-shadow: 0 16px 48px rgba(13, 148, 136, 0.35);
}

.rfi-chatbot-toggle:active {
	transform: translateY(0);
}

.rfi-chatbot-toggle:focus-visible {
	outline: 2px solid var(--rfi-primary-dark);
	outline-offset: 3px;
}

.rfi-chatbot-toggle__icon--close {
	display: none;
}

.rfi-chatbot[data-open="true"] .rfi-chatbot-toggle {
	display: none;
}

/* Chat panel */
.rfi-chatbot-panel {
	display: flex;
	flex-direction: column;
	width: 400px;
	max-width: min(400px, calc(100vw - 32px));
	height: 560px;
	max-height: min(560px, calc(100vh - 112px));
	margin-block-end: 12px;
	border-radius: var(--rfi-radius);
	overflow: hidden;
	background: var(--rfi-surface);
	box-shadow: var(--rfi-shadow);
	border: 1px solid rgba(15, 23, 42, 0.08);
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	pointer-events: none;
	transition: opacity 0.22s ease, transform 0.22s ease;
}

.rfi-chatbot-panel[hidden] {
	display: none !important;
}

.rfi-chatbot[data-open="true"] .rfi-chatbot-panel {
	display: flex;
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Header */
.rfi-chatbot-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--rfi-primary-dark) 0%, var(--rfi-primary) 100%);
	color: #fff;
	flex-shrink: 0;
}

.rfi-chatbot-header__avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.03em;
	flex-shrink: 0;
}

.rfi-chatbot-header__meta {
	flex: 1;
	min-width: 0;
}

.rfi-chatbot-header__title {
	display: block;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.25;
}

.rfi-chatbot-header__status {
	display: block;
	margin-block-start: 2px;
	font-size: 12px;
	opacity: 0.9;
}

.rfi-chatbot-header__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
	transition: background 0.15s ease;
}

.rfi-chatbot-header__close:hover {
	background: rgba(255, 255, 255, 0.18);
}

.rfi-chatbot-header__close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

/* Message list */
.rfi-chatbot-messages {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: var(--rfi-bg-chat);
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
}

.rfi-chatbot-messages__loading,
.rfi-chatbot-messages__empty,
.rfi-chatbot-messages__error {
	align-self: center;
	margin: auto;
	padding: 12px 20px;
	font-size: 13px;
	color: var(--rfi-muted);
	text-align: center;
	background: var(--rfi-surface);
	border-radius: 20px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.rfi-chatbot-messages__error {
	color: #b91c1c;
	background: #fef2f2;
}

.rfi-chatbot-msg {
	display: flex;
	max-width: 82%;
	animation: rfi-chatbot-fade-in 0.2s ease;
}

@keyframes rfi-chatbot-fade-in {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.rfi-chatbot-msg--user {
	align-self: flex-end;
}

.rfi-chatbot-msg--assistant {
	align-self: flex-start;
}

.rfi-chatbot-msg__bubble {
	padding: 10px 14px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: break-word;
	white-space: pre-wrap;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.rfi-chatbot-msg--user .rfi-chatbot-msg__bubble {
	background: var(--rfi-bubble-user);
	color: var(--rfi-bubble-user-text);
	border-end-end-radius: 4px;
}

.rfi-chatbot-msg--assistant .rfi-chatbot-msg__bubble {
	background: var(--rfi-bubble-bot);
	color: var(--rfi-text);
	border-end-start-radius: 4px;
}

.rfi-chatbot-msg__text {
	display: block;
}

.rfi-chatbot-msg__time {
	display: block;
	margin-block-start: 4px;
	font-size: 11px;
	opacity: 0.75;
	text-align: end;
}

.rfi-chatbot-msg--assistant .rfi-chatbot-msg__time {
	color: var(--rfi-muted);
	opacity: 1;
}

/* Composer / input */
.rfi-chatbot-composer {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	padding: 12px 14px;
	background: var(--rfi-bg);
	border-block-start: 1px solid rgba(15, 23, 42, 0.06);
	flex-shrink: 0;
}

.rfi-chatbot-composer__input {
	flex: 1;
	min-height: 44px;
	max-height: 120px;
	padding: 11px 16px;
	border: 1px solid rgba(15, 23, 42, 0.1);
	border-radius: 22px;
	background: var(--rfi-surface);
	font: inherit;
	line-height: 1.4;
	color: var(--rfi-text);
	resize: none;
	outline: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.rfi-chatbot-composer__input::placeholder {
	color: var(--rfi-muted);
}

.rfi-chatbot-composer__input:focus {
	border-color: var(--rfi-primary);
	box-shadow: 0 0 0 3px var(--rfi-primary-light);
}

.rfi-chatbot-composer__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	flex-shrink: 0;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--rfi-primary);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease;
}

.rfi-chatbot-composer__send:hover:not(:disabled) {
	background: var(--rfi-primary-dark);
	transform: scale(1.05);
}

.rfi-chatbot-composer__send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.rfi-chatbot-composer__send:focus-visible {
	outline: 2px solid var(--rfi-primary-dark);
	outline-offset: 2px;
}

.rfi-chatbot.is-sending .rfi-chatbot-composer__send {
	pointer-events: none;
}

/* Mobile */
@media (max-width: 640px) {
	.rfi-chatbot {
		inset-block-end: 16px;
		inset-inline-end: 16px;
	}

	.rfi-chatbot[data-open="true"] {
		inset: 0;
		inset-block-end: 0;
		inset-inline: 0;
	}

	.rfi-chatbot-panel {
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		margin: 0;
		border-radius: 0;
		border: none;
	}

	.rfi-chatbot-composer {
		padding-block-end: max(12px, env(safe-area-inset-bottom));
	}
}

/* RTL / LTR — logical properties + per-bubble dir="auto" */
.rfi-chatbot[dir="rtl"] .rfi-chatbot-msg__time {
	text-align: start;
}

.rfi-chatbot[dir="rtl"] .rfi-chatbot-composer__input {
	text-align: start;
}

@media (prefers-reduced-motion: reduce) {
	.rfi-chatbot-panel,
	.rfi-chatbot-toggle,
	.rfi-chatbot-msg,
	.rfi-chatbot-composer__send {
		transition: none;
		animation: none;
	}
}
