#rag-assistant-root {
	--rag-accent: #4f46e5;
	--rag-bg: #ffffff;
	--rag-fg: #1f2328;
	--rag-muted: #6b7280;
	--rag-border: #e5e7eb;
	--rag-user-bg: var(--rag-accent);
	--rag-user-fg: #ffffff;
	--rag-assist-bg: #f3f4f6;
	--rag-assist-fg: #1f2328;
	--rag-shadow: 0 12px 32px rgba(0, 0, 0, .18);
	font-size: 14px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}
#rag-assistant-root[data-theme="dark"] {
	--rag-bg: #1b1e24;
	--rag-fg: #e6e8eb;
	--rag-muted: #9ba1a9;
	--rag-border: #2c313a;
	--rag-assist-bg: #262b33;
	--rag-assist-fg: #e6e8eb;
	--rag-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}

.rag-launcher {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99999;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--rag-accent);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--rag-shadow);
	transition: transform .15s ease;
}
.rag-launcher:hover { transform: scale(1.05); }
.rag-launcher[hidden] { display: none; }

.rag-panel {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99999;
	width: 370px;
	max-width: calc(100vw - 24px);
	height: 560px;
	max-height: calc(100vh - 40px);
	background: var(--rag-bg);
	color: var(--rag-fg);
	border: 1px solid var(--rag-border);
	border-radius: 16px;
	box-shadow: var(--rag-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.rag-panel[hidden] { display: none; }

.rag-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 14px;
	background: var(--rag-accent);
	color: #fff;
}
.rag-title { font-weight: 600; font-size: 15px; }
.rag-close {
	background: transparent;
	border: none;
	color: #fff;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
}

.rag-log {
	flex: 1;
	overflow-y: auto;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.rag-msg { display: flex; }
.rag-msg-user { justify-content: flex-end; }
.rag-msg-assistant { justify-content: flex-start; }
.rag-bubble {
	max-width: 82%;
	padding: 8px 12px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.rag-msg-user .rag-bubble {
	background: var(--rag-user-bg);
	color: var(--rag-user-fg);
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}
.rag-msg-assistant .rag-bubble {
	background: var(--rag-assist-bg);
	color: var(--rag-assist-fg);
	border-bottom-left-radius: 4px;
}
.rag-streaming .rag-bubble::after {
	content: '▋';
	animation: rag-blink 1s steps(2) infinite;
	color: var(--rag-muted);
}
.rag-streaming .rag-bubble:has(.rag-loading-dots)::after { display: none; }
@keyframes rag-blink { 50% { opacity: 0; } }

.rag-loading-dots {
	display: inline-flex;
	gap: 5px;
	align-items: center;
	padding: 2px 0;
}
.rag-loading-dots span {
	display: block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--rag-muted);
	animation: rag-dot-pulse 1.2s ease-in-out infinite;
}
.rag-loading-dots span:nth-child(2) { animation-delay: .2s; }
.rag-loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes rag-dot-pulse {
	0%, 80%, 100% { transform: scale(.75); opacity: .4; }
	40% { transform: scale(1); opacity: 1; }
}

.rag-think {
	margin-bottom: 8px;
	font-size: 12.5px;
	color: var(--rag-muted);
	border-left: 2px solid var(--rag-border);
	padding-left: 8px;
}
.rag-think summary { cursor: pointer; user-select: none; }
.rag-think-body { margin-top: 4px; }

.rag-markdown > *:first-child { margin-top: 0; }
.rag-markdown > *:last-child { margin-bottom: 0; }
.rag-markdown p { margin: 0 0 8px; }
.rag-markdown h1,
.rag-markdown h2,
.rag-markdown h3 { font-size: 1.02em; margin: 10px 0 6px; font-weight: 600; }
.rag-markdown ul,
.rag-markdown ol { margin: 0 0 8px; padding-left: 20px; }
.rag-markdown li { margin: 2px 0; }
.rag-markdown a { color: var(--rag-accent); text-decoration: underline; }
.rag-markdown code {
	background: rgba(127, 127, 127, .16);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: .9em;
}
.rag-markdown pre {
	background: rgba(127, 127, 127, .14);
	padding: 10px;
	border-radius: 8px;
	overflow-x: auto;
	margin: 0 0 8px;
}
.rag-markdown pre code { background: none; padding: 0; }
.rag-markdown table { border-collapse: collapse; font-size: .92em; }
.rag-markdown th,
.rag-markdown td { border: 1px solid var(--rag-border); padding: 4px 8px; }
.rag-markdown blockquote {
	margin: 0 0 8px;
	padding-left: 10px;
	border-left: 3px solid var(--rag-border);
	color: var(--rag-muted);
}

.rag-input {
	display: flex;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid var(--rag-border);
	align-items: flex-end;
}
.rag-textarea {
	flex: 1;
	resize: none;
	border: 1px solid var(--rag-border);
	border-radius: 10px;
	padding: 8px 10px;
	font: inherit;
	font-size: 14px;
	background: var(--rag-bg);
	color: var(--rag-fg);
	max-height: 120px;
	outline: none;
}
.rag-textarea:focus { border-color: var(--rag-accent); }
.rag-send {
	flex: 0 0 auto;
	width: 38px;
	height: 38px;
	border-radius: 10px;
	border: none;
	background: var(--rag-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}
.rag-send:disabled { opacity: .5; cursor: default; }

@media (max-width: 480px) {
	.rag-launcher {
		right: max(16px, env(safe-area-inset-right));
		bottom: max(16px, env(safe-area-inset-bottom));
	}
	.rag-panel {
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		right: auto;
		bottom: auto;
	}
	.rag-header {
		padding-top: max(12px, env(safe-area-inset-top));
		padding-left: max(14px, env(safe-area-inset-left));
		padding-right: max(14px, env(safe-area-inset-right));
	}
	.rag-input {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
		padding-left: max(10px, env(safe-area-inset-left));
		padding-right: max(10px, env(safe-area-inset-right));
	}
	.rag-textarea {
		font-size: 16px;
	}
	.rag-send {
		width: 44px;
		height: 44px;
	}
	.rag-close {
		font-size: 28px;
		padding: 4px 8px;
	}
}
