* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

/* ========== 防止苹果手机自动放大 ========== */
html {
	-webkit-text-size-adjust: 100%;
	-webkit-tap-highlight-color: transparent;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	background: #f7f8fa;
	height: 100vh;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-size: 16px;
}

/* ========== 强制所有表单元素字体 >= 16px ========== */
input, select, textarea, button {
	font-size: 16px !important;
}

/* 顶部配置栏 */
.config-bar {
	background: #fff;
	padding: 10px 16px;
	border-bottom: 1px solid #e5e7eb;
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
	justify-content: flex-end;
	flex-shrink: 0;
}

.config-bar label {
	font-size: 13px;
	color: #666;
	white-space: nowrap;
}

.config-bar input,
.config-bar select {
	padding: 6px 10px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font-size: 13px;
	outline: none;
	transition: border-color .2s;
	max-width: max-content;
}

.config-bar input:focus,
.config-bar select:focus {
	border-color: #6366f1;
}

#apiKeyInput {
	width: 280px;
}

/* 聊天区域 */
#chat-container {
	flex: 1;
	overflow-y: auto;
	padding: 16px 12px;
	max-width: 800px;
	margin: 0 auto;
	width: 100%;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}

.message {
	display: flex;
	margin-bottom: 16px;
	animation: fadeIn .3s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.message.user {
	flex-direction: row-reverse;
	display: flex;
}

.message.assistant {
	justify-content: flex-start;
}

/* ========== 消息和头像样式 ========== */
.message {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	margin-bottom: 16px;
	animation: fadeIn 0.3s ease;
}

.message.assistant {
	flex-direction: row;
}

.avatar {
	width: 45px;
	height: 45px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	font-weight: bold;
	flex-shrink: 0;
	color: #fff;
	min-width: 40px;
}

.user-avatar {
	background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.ai-avatar {
	background: linear-gradient(135deg, #10b981, #059669);
}

.bubble {
	max-width: 80%;
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.7;
	word-break: break-word;
}

.user .bubble {
	background: #6366f1;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.assistant .bubble {
	background: #fff;
	color: #1f2937;
	border: 1px solid #e5e7eb;
	border-bottom-left-radius: 4px;
}

.message.user .bubble {
	background: #6366f1;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
	background: #fff;
	color: #1f2937;
	border: 1px solid #e5e7eb;
	border-bottom-left-radius: 4px;
}

.message.user .bubble code {
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
}

/* ========== 图片自适应 ========== */
.bubble img {
	max-width: 100%;
	max-height: 300px;
	height: auto;
	width: auto;
	border-radius: 8px;
	display: block;
	margin: 8px 0;
	object-fit: contain;
}

/* Markdown 样式 */
.bubble p {
	margin-bottom: 8px;
}

.bubble p:last-child {
	margin-bottom: 0;
}

.bubble pre {
	background: #1e1e1e;
	padding: 12px;
	border-radius: 8px;
	overflow-x: auto;
	margin: 8px 0;
	font-size: 13px;
}

.bubble code {
	font-family: "Fira Code", Consolas, monospace;
	font-size: 13px;
}

.bubble :not(pre)>code {
	background: #f3f4f6;
	padding: 2px 6px;
	border-radius: 4px;
	color: #e11d48;
}

.user .bubble :not(pre)>code {
	background: rgba(255, 255, 255, .2);
	color: #fff;
}

.bubble ul,
.bubble ol {
	padding-left: 20px;
	margin: 8px 0;
}

.bubble blockquote {
	border-left: 3px solid #6366f1;
	padding-left: 12px;
	color: #6b7280;
	margin: 8px 0;
}

.bubble table {
	border-collapse: collapse;
	margin: 8px 0;
	width: 100%;
	font-size: 13px;
}

.bubble th,
.bubble td {
	border: 1px solid #e5e7eb;
	padding: 6px 10px;
	text-align: left;
}

.bubble th {
	background: #f9fafb;
}

/* 加载动画 */
.typing-indicator span {
	display: inline-block;
	width: 6px;
	height: 6px;
	background: #9ca3af;
	border-radius: 50%;
	margin: 0 2px;
	animation: bounce .6s infinite alternate;
}

.typing-indicator span:nth-child(2) {
	animation-delay: .2s;
}

.typing-indicator span:nth-child(3) {
	animation-delay: .4s;
}

@keyframes bounce {
	to {
		transform: translateY(-6px);
		opacity: .4;
	}
}

/* 输入区域 */
.input-area {
	background: #fff;
	padding: 12px 16px;
	border-top: 1px solid #e5e7eb;
	display: flex;
	gap: 10px;
	max-width: 800px;
	margin: 0 auto;
	width: 100%;
	flex-shrink: 0;
}

#userInput {
	flex: 1;
	padding: 10px 14px;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	font-size: 16px !important;
	outline: none;
	resize: none;
	min-height: 44px;
	max-height: 120px;
	font-family: inherit;
	transition: border-color .2s;
	-webkit-appearance: none;
}

#userInput:focus {
	border-color: #6366f1;
}

#sendBtn {
	padding: 0 20px;
	background: #6366f1;
	color: #fff;
	border: none;
	border-radius: 10px;
	font-size: 16px !important;
	cursor: pointer;
	transition: background .2s;
	white-space: nowrap;
	min-height: 44px;
}

#sendBtn:hover {
	background: #4f46e5;
}

#sendBtn:disabled {
	background: #a5b4fc;
	cursor: not-allowed;
}

#clearBtn {
	padding: 0 14px;
	background: #fff;
	color: #6b7280;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	font-size: 16px !important;
	cursor: pointer;
	transition: all .2s;
	min-height: 44px;
}

#clearBtn:hover {
	background: #f9fafb;
	color: #ef4444;
	border-color: #ef4444;
}

/* 错误提示 */
.error-toast {
	position: fixed;
	top: 20px;
	left: 50%;
	transform: translateX(-50%);
	background: #fef2f2;
	color: #dc2626;
	border: 1px solid #fecaca;
	padding: 10px 20px;
	border-radius: 8px;
	font-size: 13px;
	z-index: 999;
	display: none;
	animation: fadeIn .3s ease;
	max-width: 90%;
}

.typing-cursor::after {
	content: '|';
	animation: blink 0.8s step-end infinite;
	color: #6366f1;
	font-weight: 300;
}

@keyframes blink {
	0%,
	100% {
		opacity: 1;
	}
	50% {
		opacity: 0;
	}
}

/* ========== 移动端适配 ========== */
@media screen and (max-width: 600px) {
	.config-bar {
		padding: 8px 12px;
		gap: 6px;
	}
	
	.config-bar label {
		font-size: 16px;
	}
	
	.config-bar select {
		font-size: 13px;
		padding: 4px 8px;
	}
	
	#chat-container {
		padding: 12px 8px;
	}
	
	.bubble {
		font-size: 15px;
		padding: 10px 12px;
		max-width: 85%;
	}
	
	.avatar {
		width: 40px;
		height: 40px;
		min-width: 30px;
		font-size: 11px;
	}
	
	.message {
		gap: 6px;
		margin-bottom: 12px;
	}
	
	.input-area {
		padding: 8px 12px;
		gap: 8px;
	}
	
	#userInput {
		font-size: 16px !important;
		padding: 8px 12px;
		min-height: 70px;
	}
	
	#sendBtn {
		padding: 0 16px;
		font-size: 16px !important;
		min-height: 40px;
	}
	
	#clearBtn {
		padding: 0 12px;
		font-size: 16px !important;
		min-height: 40px;
	}
	
	.bubble img {
		max-height: 200px;
	}
}

/* 小屏手机 */
@media screen and (max-width: 400px) {
	.config-bar select {
		max-width: 190px;
		font-size: 12px;
	}
	
	.bubble {
		font-size: 16px;
		padding: 8px 10px;
		max-width: 88%;
	}
	
	.avatar {
		width: 24px;
		height: 24px;
		min-width: 24px;
		font-size: 10px;
	}
}