/* AI 助手 - 前台聊天窗口样式
 * 主题色：#66ccff（AI 输出文字）
 * 深色模式：自动跟随系统 prefers-color-scheme
 */

/* ===== CSS 变量：浅色主题 ===== */
.ai-chat-root {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
	z-index: 99999;
	--chat-bg: #fff;
	--chat-bg2: #f7f8fa;
	--chat-border: #e3e6ea;
	--chat-border2: #d5d9de;
	--chat-text: #1d2327;
	--chat-text2: #444;
	--chat-text3: #666;
	--chat-header-bg: #1e88e5;
	--chat-header-text: #fff;
	--chat-accent: #66ccff;
	--chat-user-bg: #1e88e5;
	--chat-user-text: #fff;
	--chat-input-bg: #fff;
	--chat-input-border: #d5d9de;
	--chat-input-focus: #1e88e5;
	--chat-toggle-bg: #1e88e5;
	--chat-toggle-shadow: rgba(30, 136, 229, 0.45);
	--chat-send-bg: #1e88e5;
	--chat-send-hover: #1976d2;
}

/* ===== 深色主题（跟随系统） ===== */
@media (prefers-color-scheme: dark) {
	.ai-chat-root {
		--chat-bg: #1e1e2e;
		--chat-bg2: #181825;
		--chat-border: #313244;
		--chat-border2: #45475a;
		--chat-text: #cdd6f4;
		--chat-text2: #bac2de;
		--chat-text3: #9399b2;
		--chat-header-bg: #66ccff;
		--chat-header-text: #1e1e2e;
		--chat-accent: #66ccff;
		--chat-user-bg: #3b82f6;
		--chat-user-text: #fff;
		--chat-input-bg: #181825;
		--chat-input-border: #45475a;
		--chat-input-focus: #66ccff;
		--chat-toggle-bg: #66ccff;
		--chat-toggle-shadow: rgba(102, 204, 255, 0.4);
		--chat-send-bg: #66ccff;
		--chat-send-hover: #4db8e6;
	}
}

/* ===== 浮动按钮 ===== */
.ai-chat-toggle {
	position: fixed;
	right: 20px;
	bottom: 20px;
	width: 56px;
	height: 56px;
	border: 0;
	border-radius: 50%;
	background: var(--chat-toggle-bg);
	color: var(--chat-header-text);
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 4px 14px var(--chat-toggle-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease;
}

.ai-chat-toggle:hover {
	transform: scale(1.08);
}

/* ===== 面板 ===== */
.ai-chat-panel {
	position: fixed;
	right: 20px;
	bottom: 88px;
	width: 360px;
	max-width: calc(100vw - 40px);
	height: 520px;
	max-height: calc(100vh - 120px);
	background: var(--chat-bg);
	border-radius: 12px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
	display: none;
	flex-direction: column;
	overflow: hidden;
	z-index: 100000;
}

.ai-chat-panel.open {
	display: flex;
}

/* ===== 头部 ===== */
.ai-chat-header {
	background: var(--chat-header-bg);
	color: var(--chat-header-text);
	padding: 12px 16px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	flex-shrink: 0;
}

.ai-chat-title {
	font-size: 15px;
	font-weight: 600;
	flex: 1;
	min-width: 0;
}

/* ===== 头部右侧操作按钮组 ===== */
.ai-chat-header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}

.ai-chat-clear,
.ai-chat-close {
	background: none;
	border: 0;
	color: var(--chat-header-text);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	padding: 4px;
	opacity: 0.8;
	transition: opacity 0.15s;
}

.ai-chat-clear:hover,
.ai-chat-close:hover {
	opacity: 1;
}

/* ===== 消息区域 ===== */
.ai-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	background: var(--chat-bg2);
	scroll-behavior: smooth;
}

/* ===== 消息气泡通用 ===== */
.ai-chat-msg-wrap {
	margin-bottom: 8px;
}

.ai-chat-msg-wrap.user {
	text-align: right;
}

.ai-chat-msg-name {
	font-size: 12px;
	color: var(--chat-text3);
	margin-bottom: 2px;
	padding: 0 4px;
}

.ai-chat-msg-wrap.user .ai-chat-msg-name {
	text-align: right;
}

.ai-chat-msg {
	max-width: 85%;
	padding: 9px 12px;
	border-radius: 12px;
	white-space: pre-wrap;
	word-break: break-word;
	line-height: 1.55;
	font-size: 14px;
	display: inline-block;
	text-align: left;
}

/* ===== 用户消息 ===== */
.ai-chat-msg.user {
	background: var(--chat-user-bg);
	color: var(--chat-user-text);
	margin-left: auto;
	border-bottom-right-radius: 4px;
}

/* ===== AI 消息（仅文字颜色 #66ccff） ===== */
.ai-chat-msg.ai {
	background: var(--chat-bg);
	border: 1px solid var(--chat-border);
	border-bottom-left-radius: 4px;
	color: var(--chat-accent);
}

.ai-chat-msg.typing::after {
	content: "";
	display: inline-block;
	width: 10px;
	animation: ai-chat-blink 1s steps(2, start) infinite;
}

@keyframes ai-chat-blink {
	from { content: "…"; }
	to { content: ""; }
}

/* ===== 引用来源 ===== */
.ai-chat-sources {
	margin-top: 4px;
	padding: 6px 8px;
	font-size: 12px;
	color: var(--chat-text3);
	background: var(--chat-bg2);
	border-radius: 6px;
	border-top: 1px solid var(--chat-border);
}

.ai-chat-sources-label {
	font-weight: 600;
	margin-right: 4px;
}

.ai-chat-source-link {
	display: inline-block;
	margin-right: 8px;
	color: var(--chat-accent);
	text-decoration: none;
}

.ai-chat-source-link:hover {
	text-decoration: underline;
}

/* ===== 思考过程折叠面板 ===== */
.ai-chat-thinking {
	margin-bottom: 6px;
	border: 1px solid var(--chat-border);
	border-radius: 6px;
	overflow: hidden;
}

.ai-chat-thinking-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 6px 10px;
	background: var(--chat-bg2);
	cursor: pointer;
	user-select: none;
	font-size: 12px;
	color: var(--chat-text3);
	transition: background 0.15s;
}

.ai-chat-thinking-header:hover {
	background: var(--chat-border);
}

.ai-chat-thinking-label {
	font-weight: 600;
}

.ai-chat-thinking-arrow {
	font-size: 10px;
	transition: transform 0.2s;
}

.ai-chat-thinking-body {
	max-height: 0;
	overflow: hidden;
	transition: max-height 0.3s ease, padding 0.3s ease;
	padding: 0 10px;
	font-size: 13px;
	color: var(--chat-text2);
	background: var(--chat-bg);
	line-height: 1.6;
	white-space: pre-wrap;
	word-break: break-word;
}

.ai-chat-thinking-body.expanded {
	max-height: 50vh;
	padding: 8px 10px;
	overflow-y: auto;
}

/* ===== 输入表单 ===== */
.ai-chat-form {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--chat-border);
	flex-shrink: 0;
	background: var(--chat-bg);
}

.ai-chat-input {
	flex: 1;
	border: 1px solid var(--chat-input-border);
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 14px;
	font-family: inherit;
	outline: none;
	background: var(--chat-input-bg);
	color: var(--chat-text);
}

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

.ai-chat-send {
	background: var(--chat-send-bg);
	color: var(--chat-header-text);
	border: 0;
	border-radius: 8px;
	padding: 0 18px;
	font-size: 14px;
	cursor: pointer;
}

.ai-chat-send:hover {
	background: var(--chat-send-hover);
}

/* ===== 移动端适配 ===== */
@media (max-width: 480px) {
	.ai-chat-panel {
		right: 10px;
		left: 10px;
		bottom: 76px;
		width: auto;
		height: 70vh;
	}

	.ai-chat-toggle {
		right: 14px;
		bottom: 14px;
	}
}

/* ===== 短代码内嵌形态：随文档流排列，始终展开 ===== */
.ai-chat-root.ai-chat-inline {
	z-index: auto;
	margin: 12px 0;
}

.ai-chat-root.ai-chat-inline .ai-chat-panel {
	position: static;
	display: flex;
	width: 100%;
	height: 480px;
	max-height: none;
	border: 1px solid var(--chat-border);
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}