:root {
  --bg: #f7f7f8;
  --sidebar-bg: #ffffff;
  --border: #e5e5e5;
  --text: #1a1a1a;
  --text-secondary: #6b6b6b;
  --primary: #10a37f;
  --primary-hover: #0d8a6a;
  --msg-user-bg: #95ec69;
  --msg-assistant-bg: #ffffff;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --sidebar-bg: #171717;
    --border: #2e2e2e;
    --text: #ececec;
    --text-secondary: #9a9a9a;
    --primary: #10a37f;
    --msg-user-bg: #2a5e1e;
    --msg-assistant-bg: #1e1e1e;
    --input-bg: #2a2a2a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

[data-theme="dark"] {
  --bg: #212121;
  --sidebar-bg: #171717;
  --border: #2e2e2e;
  --text: #ececec;
  --text-secondary: #9a9a9a;
  --msg-user-bg: #2a5e1e;
  --msg-assistant-bg: #1e1e1e;
  --input-bg: #2a2a2a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ── 侧边栏 ── */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s;
  flex-shrink: 0;
}
.sidebar.collapsed { margin-left: -260px; }

.new-chat-btn {
  margin: 12px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--primary-hover); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.chat-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  transition: background 0.1s;
}
.chat-item:hover { background: rgba(0,0,0,0.05); }
.chat-item.active { background: rgba(16,163,127,0.1); color: var(--text); }
.chat-item .del {
  float: right;
  opacity: 0;
  color: #e74c3c;
  font-size: 16px;
}
.chat-item:hover .del { opacity: 0.6; }
.chat-item .del:hover { opacity: 1; }

/* ── 主区域 ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── 顶栏 ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 52px;
}

.sidebar-toggle {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
}

.select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  max-width: 200px;
}
.select:disabled { opacity: 0.5; cursor: not-allowed; }
.select-sm { padding: 4px 8px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text); }

.tabs {
  margin-left: auto;
  margin-right: 140px;
  display: flex;
  gap: 4px;
}
.tab {
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
}
.tab.active { background: var(--primary); color: #fff; }
.tab:not(.active):hover { background: rgba(0,0,0,0.05); }

/* ── 聊天区 ── */
.chat-area, .image-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  scroll-behavior: smooth;
}

.welcome {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.welcome-icon { font-size: 48px; margin-bottom: 12px; }
.welcome h2 { font-size: 22px; margin-bottom: 8px; color: var(--text); }
.welcome p { font-size: 14px; }

/* ── 左右气泡对话 ── */
.message {
  max-width: 800px;
  margin: 0 auto 12px;
  padding: 0 24px;
  display: flex;
  gap: 10px;
}
/* 用户消息靠右 */
.message.user {
  flex-direction: row-reverse;
}
/* AI 消息靠左 */
.message.assistant {
  flex-direction: row;
}

/* 头像 */
.message .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.message.user .avatar { background: var(--primary); color: #fff; }
.message.assistant .avatar { background: #4a9eff; color: #fff; }

/* 气泡 */
.message .bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
  position: relative;
}
.message.user .bubble {
  background: var(--msg-user-bg);
  color: #1a1a1a;
  border-top-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--msg-assistant-bg);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
}
[data-theme="dark"] .message.user .bubble { color: #fff; }

/* Markdown 内容 */
.bubble pre {
  background: rgba(0,0,0,0.06);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 13px;
}
[data-theme="dark"] .bubble pre { background: rgba(255,255,255,0.06); }
.bubble code {
  background: rgba(0,0,0,0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 13px;
}
[data-theme="dark"] .bubble code { background: rgba(255,255,255,0.08); }
.bubble pre code { background: none; padding: 0; }
.bubble img { max-width: 100%; border-radius: 8px; margin: 6px 0; }
.bubble p { margin-bottom: 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 18px; margin-bottom: 6px; }
.bubble table { border-collapse: collapse; margin: 6px 0; width: 100%; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }

/* 流式光标 */
.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--text-secondary);
  animation: blink 0.8s steps(2) infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
  border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* 打字指示器 */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-dots span {
  width: 7px; height: 7px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── 输入区 ── */
.input-area {
  padding: 12px 20px 16px;
  background: var(--bg);
  flex-shrink: 0;
}
.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.input-wrapper textarea {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 150px;
  min-height: 24px;
  line-height: 1.5;
  padding: 4px 0;
}
.input-wrapper textarea::placeholder { color: var(--text-secondary); }

.send-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── 生图 ── */
.image-results {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.image-grid {
  max-width: 800px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(256px, 1fr));
  gap: 16px;
}
.image-card {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--msg-assistant-bg);
}
.image-card img { width: 100%; display: block; cursor: pointer; }
.image-card .prompt {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

/* ── 图片放大 overlay ── */
.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
}
.img-overlay.show { display: flex; }
.img-overlay img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 4px 30px rgba(0,0,0,0.5);
}

/* ── 滚动条 ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── 响应式 ── */
@media (max-width: 768px) {
  .sidebar { position: absolute; z-index: 100; height: 100%; }
  .select { max-width: 120px; font-size: 12px; }
  .tabs .tab { padding: 4px 8px; font-size: 12px; }
  .tabs { margin-right: 100px; }
  .message { padding: 0 12px; }
  .message .bubble { max-width: 85%; }
}
