/* AI 聊天助手 — 前台浮窗样式 */

.ai-chat-root {
	--ai-bubble-color: #2563eb;
	--ai-bubble-icon: #ffffff;
	--ai-window-bg: #ffffff;
	--ai-header-bg: #2563eb;
	--ai-header-text: #ffffff;
	--ai-user-bubble: #2563eb;
	--ai-user-text: #ffffff;
	--ai-ai-bubble: #f1f5f9;
	--ai-ai-text: #111827;
	--ai-text: #111827;
	--ai-desktop-height: 80vh;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.ai-chat-bubble {
	position: fixed;
	z-index: 99990;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--ai-bubble-color);
	color: var(--ai-bubble-icon);
	border: none;
	cursor: pointer;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ai-chat-pos-right .ai-chat-bubble { right: 20px; bottom: 20px; }
.ai-chat-pos-left .ai-chat-bubble { left: 20px; bottom: 20px; }
.ai-chat-bubble:hover { transform: scale(1.05); }
.ai-chat-bubble svg { width: 28px; height: 28px; fill: currentColor; }

.ai-chat-window {
	position: fixed;
	z-index: 99991;
	display: none;
	flex-direction: column;
	width: 400px;
	max-width: calc(100vw - 24px);
	height: var(--ai-desktop-height);
	min-height: 500px;
	background: var(--ai-window-bg);
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
	color: var(--ai-text);
}
.ai-chat-pos-right .ai-chat-window { right: 20px; bottom: 92px; }
.ai-chat-pos-left .ai-chat-window { left: 20px; bottom: 92px; }
.ai-chat-window.ai-chat-open { display: flex; }
.ai-chat-root.ai-chat-open .ai-chat-bubble { display: none; }
@media (min-width: 641px) {
	.ai-chat-root.ai-chat-open .ai-chat-window { bottom: 20px; }
}

.ai-chat-header {
	background: var(--ai-header-bg);
	color: var(--ai-header-text);
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
}
.ai-chat-header-title { font-size: 16px; font-weight: 600; }
.ai-chat-header-actions { display: flex; gap: 4px; }
.ai-chat-header-btn {
	background: transparent;
	border: none;
	color: inherit;
	cursor: pointer;
	width: 30px;
	height: 30px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0.85;
}
.ai-chat-header-btn:hover { background: rgba(255, 255, 255, 0.15); opacity: 1; }
.ai-chat-header-btn svg { width: 18px; height: 18px; fill: currentColor; }

.ai-chat-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	-webkit-overflow-scrolling: touch;
}

.ai-chat-msg { max-width: 82%; display: flex; }
.ai-chat-msg-user { align-self: flex-end; justify-content: flex-end; }
.ai-chat-msg-assistant { align-self: flex-start; justify-content: flex-start; }

.ai-chat-bubble-msg {
	padding: 10px 14px;
	border-radius: 14px;
	line-height: 1.55;
	font-size: 14px;
	word-break: break-word;
	white-space: normal;
}
.ai-chat-msg-user .ai-chat-bubble-msg {
	background: var(--ai-user-bubble);
	color: var(--ai-user-text);
	border-bottom-right-radius: 4px;
}
.ai-chat-msg-assistant .ai-chat-bubble-msg {
	background: var(--ai-ai-bubble);
	color: var(--ai-ai-text);
	border-bottom-left-radius: 4px;
}

/* Markdown 内容 */
.ai-chat-bubble-msg p { margin: 0 0 8px; }
.ai-chat-bubble-msg p:last-child { margin-bottom: 0; }
.ai-chat-bubble-msg code {
	background: rgba(0, 0, 0, 0.08);
	padding: 2px 5px;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 13px;
}
.ai-chat-bubble-msg pre {
	background: rgba(0, 0, 0, 0.06);
	padding: 10px;
	border-radius: 8px;
	overflow-x: auto;
	margin: 8px 0;
}
.ai-chat-bubble-msg pre code { background: transparent; padding: 0; }
.ai-chat-bubble-msg ul, .ai-chat-bubble-msg ol { margin: 4px 0 8px; padding-left: 20px; }
.ai-chat-bubble-msg a { color: inherit; text-decoration: underline; }
.ai-chat-bubble-msg blockquote { border-left: 3px solid rgba(0,0,0,0.2); margin: 6px 0; padding-left: 10px; }

.ai-chat-typing { color: var(--ai-text); opacity: 0.6; font-size: 13px; align-self: flex-start; }

/* 线索表单 */
.ai-chat-lead {
	flex: 0 0 auto;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	padding: 12px 16px;
}
.ai-chat-lead-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.ai-chat-lead input {
	width: 100%;
	box-sizing: border-box;
	margin-bottom: 8px;
	padding: 8px 10px;
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: 8px;
	font-size: 14px;
	background: var(--ai-window-bg);
	color: var(--ai-text);
}
.ai-chat-lead-actions { display: flex; gap: 8px; align-items: center; }
.ai-chat-lead-submit {
	background: var(--ai-header-bg);
	color: var(--ai-header-text);
	border: none;
	padding: 8px 16px;
	border-radius: 8px;
	cursor: pointer;
	font-size: 14px;
}
.ai-chat-lead-skip { background: none; border: none; color: var(--ai-text); opacity: 0.6; cursor: pointer; font-size: 13px; }

/* 输入区 */
.ai-chat-input-area {
	flex: 0 0 auto;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	padding: 10px 12px;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	background: var(--ai-window-bg);
}
.ai-chat-input {
	flex: 1 1 auto;
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: 10px;
	padding: 10px 12px;
	resize: none;
	max-height: 120px;
	font-size: 14px;
	font-family: inherit;
	background: var(--ai-window-bg);
	color: var(--ai-text);
}
.ai-chat-input:focus { outline: none; border-color: var(--ai-header-bg); }
.ai-chat-upload-btn {
	background: transparent;
	border: none;
	cursor: pointer;
	color: var(--ai-text);
	opacity: 0.6;
	width: 34px;
	height: 34px;
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
}
.ai-chat-upload-btn:hover { opacity: 1; }
.ai-chat-upload-btn svg { width: 22px; height: 22px; fill: currentColor; }
.ai-chat-send-btn {
	background: var(--ai-header-bg);
	color: var(--ai-header-text);
	border: none;
	width: 38px;
	height: 38px;
	border-radius: 10px;
	cursor: pointer;
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
}
.ai-chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-chat-send-btn svg { width: 20px; height: 20px; fill: currentColor; }

/* 手机端 */
@media (max-width: 640px) {
	.ai-chat-window {
		width: 100%;
		max-width: 100%;
		height: 100vh;
		height: 100dvh;
		min-height: 0;
		border-radius: 0;
	}
	.ai-chat-pos-right .ai-chat-window,
	.ai-chat-pos-left .ai-chat-window {
		right: 0;
		left: 0;
		bottom: 0;
	}
	.ai-chat-window.ai-chat-mode-sheet {
		height: 85vh;
		height: 85dvh;
		border-radius: 16px 16px 0 0;
	}
	.ai-chat-window {
		padding-bottom: env(safe-area-inset-bottom, 0);
	}
	.ai-chat-header { padding-top: calc(14px + env(safe-area-inset-top, 0)); }
}
