/**
 * R1 AI Assistant — chat widget (floating + full-page).
 * Self-contained; scoped under .r1-ai-widget-root so it never leaks into
 * (or inherits from) the host theme.
 */

.r1-ai-widget-root,
.r1-ai-widget-root * {
	box-sizing: border-box;
}

.r1-ai-widget-root {
	--r1-color: #2563eb;
	--r1-color-dark: #1d4ed8;
	--r1-bg: #ffffff;
	--r1-text: #1f2430;
	--r1-muted: #6b7280;
	--r1-bubble-bot: #f3f4f6;
	--r1-border: #e5e7eb;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "IRANSans", "Vazirmatn", Arial, sans-serif;
	direction: rtl;
	text-align: right;
	font-size: 14px;
	line-height: 1.6;
	z-index: 999999;
}

.r1-ai-hide-mobile {
	display: block;
}

@media (max-width: 640px) {
	.r1-ai-hide-mobile {
		display: none !important;
	}
}

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

.r1-ai-launcher {
	position: fixed;
	bottom: 24px;
	width: 62px;
	height: 62px;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--r1-color), var(--r1-color-dark));
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.15);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	z-index: 999999;
}

.r1-ai-launcher:hover {
	transform: scale(1.06);
	box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25), 0 3px 8px rgba(0, 0, 0, 0.18);
}

.r1-ai-pos-left .r1-ai-launcher { left: 24px; }
.r1-ai-pos-right .r1-ai-launcher { right: 24px; }

.r1-ai-launcher svg {
	width: 28px;
	height: 28px;
}

.r1-ai-launcher .r1-ai-dot {
	position: absolute;
	top: 4px;
	inset-inline-end: 4px;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: #22c55e;
	border: 2px solid #fff;
}

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

.r1-ai-panel {
	position: fixed;
	bottom: 100px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 140px);
	background: var(--r1-bg);
	border-radius: 18px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.12);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(0.98);
	pointer-events: none;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.r1-ai-pos-left .r1-ai-panel { left: 24px; }
.r1-ai-pos-right .r1-ai-panel { right: 24px; }

.r1-ai-widget-root.r1-ai-open .r1-ai-panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* ---------- Full-page mode ---------- */

.r1-ai-page-mode .r1-ai-panel,
.r1-ai-page-mode.r1-ai-chat-frame {
	position: relative;
	inset: auto;
	width: 100%;
	max-width: 720px;
	height: 78vh;
	min-height: 480px;
	max-height: none;
	margin: 0 auto;
	opacity: 1;
	transform: none;
	pointer-events: auto;
}

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

.r1-ai-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--r1-color), var(--r1-color-dark));
	color: #fff;
	flex: 0 0 auto;
}

.r1-ai-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	flex: 0 0 auto;
	font-weight: 700;
}

.r1-ai-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.r1-ai-header-text {
	flex: 1 1 auto;
	min-width: 0;
}

.r1-ai-header-name {
	font-weight: 700;
	font-size: 14.5px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.r1-ai-header-status {
	font-size: 12px;
	opacity: 0.9;
	display: flex;
	align-items: center;
	gap: 5px;
}

.r1-ai-header-status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #22c55e;
	display: inline-block;
}

.r1-ai-close {
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	transition: background 0.15s ease;
}

.r1-ai-close:hover {
	background: rgba(255, 255, 255, 0.28);
}

/* ---------- Messages ---------- */

.r1-ai-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #fafbfc;
}

.r1-ai-messages::-webkit-scrollbar {
	width: 6px;
}

.r1-ai-messages::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 3px;
}

.r1-ai-row {
	display: flex;
	max-width: 88%;
}

.r1-ai-row.r1-ai-row-user {
	margin-inline-start: auto;
	flex-direction: row-reverse;
}

.r1-ai-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 13.5px;
}

.r1-ai-row-bot .r1-ai-bubble {
	background: var(--r1-bubble-bot);
	color: var(--r1-text);
	border-bottom-left-radius: 4px;
}

.r1-ai-row-user .r1-ai-bubble {
	background: var(--r1-color);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.r1-ai-row-error .r1-ai-bubble {
	background: #fef2f2;
	color: #b91c1c;
	border: 1px solid #fecaca;
}

.r1-ai-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 12px 14px;
	background: var(--r1-bubble-bot);
	border-radius: 16px;
	border-bottom-left-radius: 4px;
}

.r1-ai-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--r1-muted);
	animation: r1-ai-bounce 1.2s infinite ease-in-out;
}

.r1-ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.r1-ai-typing span:nth-child(3) { animation-delay: 0.3s; }

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

/* ---------- Quick replies ---------- */

.r1-ai-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 12px;
	flex: 0 0 auto;
	background: #fafbfc;
}

.r1-ai-chip {
	border: 1px solid var(--r1-color);
	color: var(--r1-color);
	background: #fff;
	border-radius: 999px;
	padding: 7px 14px;
	font-size: 12.5px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.r1-ai-chip:hover {
	background: var(--r1-color);
	color: #fff;
}

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

.r1-ai-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--r1-border);
	background: #fff;
	flex: 0 0 auto;
}

.r1-ai-input {
	flex: 1 1 auto;
	resize: none;
	border: 1px solid var(--r1-border);
	border-radius: 14px;
	padding: 10px 14px;
	font-size: 13.5px;
	font-family: inherit;
	max-height: 100px;
	outline: none;
	transition: border-color 0.15s ease;
}

.r1-ai-input:focus {
	border-color: var(--r1-color);
}

.r1-ai-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: none;
	background: var(--r1-color);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease, transform 0.1s ease;
}

.r1-ai-send:hover {
	background: var(--r1-color-dark);
}

.r1-ai-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.r1-ai-send svg {
	width: 18px;
	height: 18px;
	transform: scaleX(-1); /* arrow points into RTL reading direction */
}

.r1-ai-footer {
	text-align: center;
	font-size: 11px;
	color: var(--r1-muted);
	padding: 6px 0 10px;
	background: #fff;
	flex: 0 0 auto;
}

.r1-ai-unavailable {
	color: var(--r1-muted);
	text-align: center;
}
