:root {
  --bg: #0f1117;
  --bg-2: #171a24;
  --bg-3: #1e2330;
  --border: #2a3040;
  --text: #e8ecf4;
  --text-dim: #9aa4b8;
  --accent: #6c8cff;
  --accent-2: #8a63ff;
  --code-bg: #12141d;
  --success: #34d399;
  --error: #f87171;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
}

/* ===== 白天模式 ===== */
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #ffffff;
  --bg-3: #eaeef6;
  --border: #d5dce8;
  --text: #161b26;
  --text-dim: #5c6779;
  --accent: #4361ee;
  --accent-2: #7048e8;
  --code-bg: #f8f9fc;
  --success: #059669;
  --error: #dc2626;
  --shadow: 0 4px 16px rgba(22, 27, 38, .10);
}

/* 主题切换过渡 */
body, .topbar, .input-area, .msg-body, .code-header, .code-block,
.tool-btn, .model-select, .input-row textarea, .btn, .welcome-tips span {
  transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 960px;
  margin: 0 auto;
}

/* ===== 顶部栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand h1 { font-size: 18px; font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.err { background: var(--error); }

/* ===== 按钮 ===== */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); background: #262d40; }
.btn.ghost { background: transparent; }

/* ===== 主区域 ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 消息区 ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-area::-webkit-scrollbar { width: 8px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* 欢迎界面 */
.welcome {
  text-align: center;
  margin: auto;
  padding: 40px 20px;
  color: var(--text-dim);
}
.welcome-icon { font-size: 56px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome h2 { color: var(--text); margin: 16px 0 8px; font-size: 24px; }
.welcome p { margin-bottom: 24px; }
.welcome-tips { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.welcome-tips span { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 16px; display: inline-block; }

/* 消息气泡 */
.msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.msg.assistant .msg-avatar { background: var(--bg-3); border: 1px solid var(--border); }

.msg-body {
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.65;
  font-size: 15px;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg.user .msg-body { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .msg-body { background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

/* 图片消息 */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; }
.msg-images img {
  width: 200px; height: 200px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border);
}

/* ===== Markdown / 代码块 ===== */
.md-body { white-space: normal; }
.md-body p { margin: 6px 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 12px 0 6px; }
.md-body ul, .md-body ol { padding-left: 20px; margin: 6px 0; }
.md-body code:not(pre code) {
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
}
.md-body blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim); margin: 8px 0; }
.md-body table { border-collapse: collapse; margin: 8px 0; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 10px; }

.code-block {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}
.code-lang { font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.code-actions { display: flex; gap: 8px; }
.code-actions button {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.code-actions button:hover { border-color: var(--accent); color: var(--accent); }
.code-block pre {
  padding: 14px;
  overflow-x: auto;
  font-family: "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}
.code-block pre::-webkit-scrollbar { height: 8px; }
.code-block pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== 输入区 ===== */
.input-area {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  background: var(--bg-2);
}

.image-preview {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 12px;
}
.image-preview .preview-item {
  position: relative;
  width: 72px; height: 72px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.image-preview .preview-item img { width: 100%; height: 100%; object-fit: cover; }
.image-preview .preview-item .remove-img {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  background: rgba(0,0,0,.7);
  border: none; color: #fff; border-radius: 50%;
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}

.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.tool-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer; font-size: 18px;
  transition: all .15s;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn input { display: none; }
.model-select {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; cursor: pointer;
  outline: none;
}

.input-row {
  display: flex; gap: 10px; align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 160px;
  outline: none;
  transition: border-color .15s;
}
.input-row textarea:focus { border-color: var(--accent); }
.input-row textarea::placeholder { color: var(--text-dim); }
.send-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  font-size: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff;
  flex-shrink: 0;
}
.send-btn:hover { opacity: .9; }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

.hint { margin-top: 8px; font-size: 12px; color: var(--text-dim); text-align: center; }

/* 打字指示 */
.typing .msg-body::after {
  content: '▊';
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 错误消息 */
.msg.error .msg-body { border-color: var(--error); color: var(--error); }

@media (max-width: 600px) {
  .brand h1 { font-size: 15px; }
  .msg { max-width: 92%; }
}