/* ============ 主题变量 ============ */
:root {
  --bg: #1e1f24;
  --panel: #26282f;
  --border: #363943;
  --text: #e6e7eb;
  --muted: #9aa0ab;
  --accent: #4f8cff;
  --user-bubble: #2f6bff;
  --code-bg: #17181d;
  --danger: #ff5d5d;
}

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

html, body { height: 100%; }

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

/* ============ 侧边栏 ============ */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow-y: auto;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.config-group { display: flex; flex-direction: column; gap: 6px; }
.config-group label { font-size: 12px; color: var(--muted); }

input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

textarea { resize: vertical; min-height: 80px; font-family: inherit; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
}
button:hover { opacity: .85; }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.sidebar-footer { margin-top: auto; font-size: 12px; color: var(--muted); }

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

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

#chatBox {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ============ 消息气泡 ============ */
.msg { display: flex; }
.msg.user { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.65;
  font-size: 14px;
  word-break: break-word;
  white-space: normal;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown 元素样式 */
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; }
.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }
.bubble ul { padding-left: 20px; margin: 6px 0; }
.bubble li { margin: 2px 0; }
.bubble code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.bubble pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; }
.bubble .error { color: var(--danger); }

.cursor {
  display: inline-block;
  width: 8px;
  height: 15px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ============ 输入区 ============ */
.input-area {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.input-area textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  line-height: 1.5;
}
#stopBtn { background: var(--danger); }
