/* ========== 全局样式 ========== */
:root {
	--primary: #4f46e5;
	--primary-light: #6366f1;
	--primary-dark: #3730a3;
	--primary-bg: #eef2ff;
	--success: #10b981;
	--warning: #f59e0b;
	--danger: #ef4444;
	--bg: #f8fafc;
	--bg-card: #ffffff;
	--bg-sidebar: #1e1b4b;
	--text: #1e293b;
	--text-secondary: #64748b;
	--text-light: #94a3b8;
	--border: #e2e8f0;
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
	--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
	--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
	--radius: 12px;
	--radius-sm: 8px;
	--transition: 0.2s ease;
}

/* 深色模式 */
[data-theme="dark"] {
	--bg: #0f172a;
	--bg-card: #1e293b;
	--bg-sidebar: #0b1120;
	--text: #e2e8f0;
	--text-secondary: #94a3b8;
	--text-light: #64748b;
	--border: #334155;
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
	--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
	--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
	--primary-bg: #1e1b4b;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html {
	-webkit-tap-highlight-color: transparent;
	-webkit-text-size-adjust: 100%;
	touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ========== 应用容器 ========== */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100%;
}

/* ========== 侧边栏 ========== */
.sidebar {
	width: 280px;
	min-width: 280px;
	background: #111b2a;
	color: #ffffff;
	display: flex;
	flex-direction: column;
	transition: width var(--transition), min-width var(--transition), transform var(--transition);
	z-index: 100;
	overflow: hidden;
}

.sidebar.collapsed {
	width: 0;
	min-width: 0;
	margin-left: 0;
}

.sidebar-header {
	padding: 20px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
	display: flex;
	align-items: center;
	gap: 12px;
	font-size: 18px;
	font-weight: 700;
}

.logo svg {
	width: 32px;
	height: 32px;
	color: #a5b4fc;
}

.sidebar-content {
	flex: 1;
	padding: 16px;
	overflow-y: auto;
}

.new-chat-btn {
	width: 100%;
	padding: 12px 16px;
	background: rgba(255, 255, 255, 0.1);
	color: #e2e8f0;
	border: 1px solid rgba(255, 255, 255, 0.15);
	border-radius: var(--radius-sm);
	cursor: pointer;
	font-size: 14px;
	display: flex;
	align-items: center;
	gap: 8px;
	transition: all var(--transition);
}

.new-chat-btn:hover {
	background: rgba(255, 255, 255, 0.2);
	border-color: rgba(255, 255, 255, 0.3);
}

.chat-history {
	margin-top: 16px;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.history-item {
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	cursor: pointer;
	font-size: 13px;
	transition: all var(--transition);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	display: flex;
	align-items: center;
	gap: 8px;
}

.history-item:hover {
	background: rgba(255, 255, 255, 0.1);
}

.history-item.active {
	background: rgba(99, 102, 241, 0.3);
}

.history-item svg {
	min-width: 16px;
	color: #a5b4fc;
}



/* ========== 主区域 ========== */
.main-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	background: var(--bg);
}

.chat-header {
	display: flex;
	align-items: center;
	padding: 16px 24px;
	background: var(--bg-card);
	border-bottom: 1px solid var(--border);
	gap: 16px;
}

.menu-toggle {
	background: none;
	border: none;
	cursor: pointer;
	color: var(--text-secondary);
	padding: 8px;
	border-radius: var(--radius-sm);
	transition: all var(--transition);
	display: flex;
	align-items: center;
}

.menu-toggle:hover {
	background: var(--primary-bg);
	color: var(--primary);
}

.header-title h1 {
	font-size: 18px;
	font-weight: 600;
	color: var(--text);
}

.header-subtitle {
	font-size: 12px;
	color: var(--text-light);
}

.header-actions {
	margin-left: auto;
	display: flex;
	align-items: center;
	gap: 8px;
}

.theme-toggle {
	background: none;
	border: 1px solid var(--border);
	cursor: pointer;
	font-size: 18px;
	padding: 4px 8px;
	border-radius: var(--radius-sm);
	transition: all var(--transition);
}

.theme-toggle:hover {
	background: var(--primary-bg);
}

.online-badge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 12px;
	background: #ecfdf5;
	color: var(--success);
	font-size: 12px;
	border-radius: 20px;
	font-weight: 500;
}

.online-badge::before {
	content: '';
	width: 6px;
	height: 6px;
	background: var(--success);
	border-radius: 50%;
}

/* ========== 聊天消息区域 ========== */
.chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 24px;
	display: flex;
	flex-direction: column;
	gap: 20px;
}

.chat-messages::-webkit-scrollbar {
	width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
	background: #cbd5e1;
	border-radius: 3px;
}

/* 欢迎界面 */
.welcome-screen {
	text-align: center;
	padding: 60px 20px;
	animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.welcome-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 200px;
    background: transparent;
    border-radius: 50%;
    margin-bottom: 24px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.welcome-icon video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.welcome-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    padding: 5px;
    background: conic-gradient(from 0deg, #60a5fa, #3b82f6, #1d4ed8, #93c5fd, #60a5fa);
    -webkit-mask: radial-gradient(transparent 93%, black 93%);
    mask: radial-gradient(transparent 93%, black 93%);
    animation: rainbowSpin 4s linear infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes rainbowSpin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.welcome-screen h2 {
	font-size: 24px;
	font-weight: 700;
	margin-bottom: 12px;
	color: var(--text);
}

.welcome-screen p {
	color: var(--text-secondary);
	margin-bottom: 8px;
	font-size: 15px;
}

.welcome-note {
	font-size: 13px !important;
	color: var(--text-light) !important;
}



/* 消息气泡 */
.message {
	display: flex;
	gap: 12px;
	animation: messageIn 0.3s ease;
	max-width: 85%;
}

@keyframes messageIn {
	from {
		opacity: 0;
		transform: translateY(8px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.message.user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.message.assistant {
	align-self: flex-start;
}

.message-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	font-size: 16px;
}

.message.user .message-avatar {
	background: linear-gradient(135deg, #6366f1, #8b5cf6);
	color: white;
}

.message.assistant .message-avatar {
	background: linear-gradient(135deg, #10b981, #059669);
	color: white;
}

.message-content {
	padding: 12px 16px;
	border-radius: var(--radius);
	font-size: 15px;
	line-height: 1.7;
	word-wrap: break-word;
}

.message.user .message-content {
	background: var(--primary);
	color: white;
	border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
	background: var(--bg-card);
	color: var(--text);
	border: 1px solid var(--border);
	border-bottom-left-radius: 4px;
	box-shadow: var(--shadow-sm);
}

.message-content .message-image {
	max-width: 280px;
	max-height: 280px;
	border-radius: var(--radius-sm);
	margin-bottom: 8px;
	cursor: pointer;
	object-fit: cover;
}

.message-content p {
	margin-bottom: 8px;
}

.message-content p:last-child {
	margin-bottom: 0;
}

.message-content code {
	background: rgba(0, 0, 0, 0.06);
	padding: 2px 6px;
	border-radius: 4px;
	font-size: 13px;
	font-family: 'SF Mono', 'Consolas', monospace;
}

.message.user .message-content code {
	background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
	background: #1e293b;
	color: #e2e8f0;
	padding: 12px 16px;
	border-radius: var(--radius-sm);
	overflow-x: auto;
	margin: 8px 0;
	font-size: 13px;
}

.message-content pre code {
	background: none;
	padding: 0;
	color: inherit;
}

.message-content ul,
.message-content ol {
	padding-left: 20px;
	margin: 8px 0;
}

.message-content li {
	margin-bottom: 4px;
}

.message-time {
	font-size: 11px;
	color: var(--text-light);
	margin-top: 4px;
}

.message.user .message-time {
	text-align: right;
}

/* 语音播放按钮 */
.message-actions {
	display: flex;
	gap: 6px;
	margin-top: 6px;
}

.msg-action-btn {
	background: var(--primary-bg);
	border: 1px solid var(--primary-light);
	border-radius: 20px;
	cursor: pointer;
	padding: 5px 12px;
	font-size: 13px;
	color: var(--primary);
	display: inline-flex;
	align-items: center;
	gap: 5px;
	transition: all var(--transition);
}

.msg-action-btn:hover {
	background: var(--primary);
	color: white;
	border-color: var(--primary);
	box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.speak-icon {
	font-size: 15px;
}

.speak-text {
	font-size: 12px;
	font-weight: 500;
}

@media (max-width: 768px) {
	.msg-action-btn {
		padding: 4px 10px;
		font-size: 12px;
	}
	.speak-icon {
		font-size: 14px;
	}
	.speak-text {
		font-size: 11px;
	}
}
/* 加载动画 */
.typing-indicator {
	display: flex;
	gap: 4px;
	padding: 4px 0;
}

.typing-indicator span {
	width: 8px;
	height: 8px;
	background: var(--text-light);
	border-radius: 50%;
	animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
	animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes typing {

	0%,
	60%,
	100% {
		transform: translateY(0);
		opacity: 0.4;
	}

	30% {
		transform: translateY(-8px);
		opacity: 1;
	}
}

/* ========== 图片预览 ========== */
.image-preview-area {
	padding: 0 24px 12px;
}

.preview-container {
	position: relative;
	display: inline-block;
}

.preview-container img {
	max-width: 200px;
	max-height: 150px;
	border-radius: var(--radius-sm);
	border: 2px solid var(--border);
	object-fit: cover;
}

.remove-image-btn {
	position: absolute;
	top: -8px;
	right: -8px;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--danger);
	color: white;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--shadow);
	transition: all var(--transition);
}

.remove-image-btn:hover {
	background: #dc2626;
	transform: scale(1.1);
}

.image-preview-hint {
	font-size: 12px;
	color: var(--primary);
	margin-top: 6px;
	font-weight: 500;
}

/* ========== 输入区域 ========== */
.input-area {
	padding: 12px 24px 20px;
	background: var(--bg-card);
	border-top: 1px solid var(--border);
}

.input-container {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	background: var(--bg);
	border: 2px solid var(--border);
	border-radius: var(--radius);
	padding: 8px 12px;
	transition: border-color var(--transition);
}

.input-container:focus-within {
	border-color: var(--primary-light);
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.input-actions-left {
	display: flex;
	gap: 4px;
	align-items: center;
}

.action-btn {
	background: none;
	border: none;
	cursor: pointer;
	padding: 8px;
	border-radius: var(--radius-sm);
	color: var(--text-secondary);
	transition: all var(--transition);
	display: flex;
	align-items: center;
}

.action-btn:hover {
	background: var(--primary-bg);
	color: var(--primary);
}

#messageInput {
	flex: 1;
	border: none;
	background: none;
	resize: none;
	font-size: 14px;
	font-family: inherit;
	color: var(--text);
	outline: none;
	padding: 6px 0;
	max-height: 120px;
	line-height: 1.5;
}

#messageInput::placeholder {
	color: var(--text-light);
}

.send-btn {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: var(--primary);
	color: white;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all var(--transition);
	flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
	background: var(--primary-dark);
	transform: scale(1.05);
}

.send-btn:disabled {
	background: #cbd5e1;
	cursor: not-allowed;
}

.input-hint {
	text-align: center;
	font-size: 12px;
	color: var(--text-light);
	margin-top: 8px;
}

/* ========== Toast ========== */
.toast {
	position: fixed;
	top: 24px;
	left: 50%;
	transform: translateX(-50%);
	padding: 12px 24px;
	background: var(--bg-sidebar);
	color: white;
	border-radius: var(--radius-sm);
	font-size: 14px;
	z-index: 1000;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
	box-shadow: var(--shadow-lg);
}

.toast.show {
	opacity: 1;
}

.toast.warning {
	background: var(--warning);
	color: #1e293b;
}

.toast.error {
	background: var(--danger);
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
	.sidebar {
		position: fixed;
		left: 0;
		top: 0;
		height: 100vh;
		height: 100dvh;
		transform: translateX(-100%);
		z-index: 100;
		transition: transform 0.3s ease;
	}

	.sidebar.open {
		transform: translateX(0);
	}

	.sidebar.collapsed {
		transform: translateX(-100%);
		width: 280px;
		min-width: 280px;
	}

	.sidebar-overlay {
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, 0.5);
		z-index: 99;
		display: none;
	}

	.sidebar-overlay.show {
		display: block;
	}

	body,
	.app-container,
	.main-content,
	.chat-messages {
		max-width: 100vw;
		overflow-x: hidden;
	}

	.chat-header {
		padding: 12px 16px;
	}

	.header-title h1 {
		font-size: 16px;
	}

	.header-subtitle {
		font-size: 11px;
	}

	.chat-messages {
		padding: 12px;
		gap: 12px;
	}

	.message {
		max-width: 92%;
	}

	.message-content {
		font-size: 14px;
		padding: 10px 14px;
		max-width: 100%;
		word-break: break-word;
		overflow-wrap: break-word;
	}

	.message-content img,
	.message-content .katex-display,
	.message-content .katex {
		max-width: 100%;
		overflow-x: auto;
	}

	.message-content .katex-display .katex {
		white-space: normal;
	}

	.welcome-screen {
		padding: 30px 12px;
	}

	.welcome-icon {
		width: 120px;
		height: 120px;
		margin-bottom: 16px;
	}

	.welcome-screen h2 {
		font-size: 18px;
	}

	.welcome-screen p {
		font-size: 13px;
	}

	.input-area {
		padding: 8px 10px 12px;
	}

	.input-container {
		padding: 6px 10px;
	}

	#messageInput {
		font-size: 14px;
	}

	.send-btn {
		width: 36px;
		height: 36px;
	}

	.input-hint {
		font-size: 10px;
		margin-top: 4px;
	}

	.image-preview-area {
		padding: 0 12px 8px;
	}

	.preview-container img {
		max-width: 120px;
		max-height: 100px;
	}

	.message-avatar {
		width: 30px;
		height: 30px;
		font-size: 13px;
	}

	.toast {
		font-size: 13px;
		padding: 10px 18px;
		top: 16px;
	}

	.modal-content {
		max-width: 92vw;
		max-height: 85vh;
	}

	.modal-header,
	.modal-body,
	.modal-footer {
		padding: 12px 14px;
	}
}