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

:root {
  --bg: #ffffff;
  --text: #0d0d0d;
  --muted: #6e6e80;
  --user-bg: #f4f4f4;
  --border: #e5e5e5;
  --input-bg: #ffffff;
  --input-border: #d9d9e3;
  --send-bg: #0d0d0d;
  --send-text: #ffffff;
  --send-disabled: #c5c5d2;
  --code-bg: #171717;
  --code-text: #ececf1;
  --inline-code-bg: #f0f0f0;
  --radius-lg: 24px;
  --radius-md: 12px;
  --max-width: 768px;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ===== 头部 ===== */

header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  background: var(--bg);
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* ===== 消息区域 ===== */

#chat {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  padding: 24px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-behavior: smooth;
}

/* 每条消息占据统一宽度，居中显示 */
#chat > * {
  width: 100%;
  max-width: var(--max-width);
}

#chat > * + * {
  margin-top: 20px;
}

/* 用户消息：右对齐的气泡 */
#chat .user,
#chat .message.user,
#chat .message-row.user {
  display: flex;
  justify-content: flex-end;
}

#chat .user .bubble,
#chat .message.user .bubble,
#chat .message-row.user .bubble {
  max-width: 80%;
  background: var(--user-bg);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* AI 消息：左侧全宽，无气泡背景，类似 ChatGPT */
#chat .assistant,
#chat .message.assistant,
#chat .message-row.assistant {
  display: block;
  padding: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

#chat .assistant .bubble,
#chat .message.assistant .bubble,
#chat .message-row.assistant .bubble {
  background: none;
  padding: 0;
}

/* 加载中的提示 */
#chat .loading,
#chat .message-row.loading {
  color: var(--muted);
  font-style: italic;
}

/* ===== Markdown 渲染样式 ===== */

#chat p + p {
  margin-top: 0.8em;
}

#chat h1,
#chat h2,
#chat h3,
#chat h4 {
  margin: 1em 0 0.5em;
  line-height: 1.3;
  font-weight: 600;
}

#chat h1 { font-size: 1.5rem; }
#chat h2 { font-size: 1.3rem; }
#chat h3 { font-size: 1.1rem; }

#chat ul,
#chat ol {
  padding-left: 1.6em;
  margin: 0.6em 0;
}

#chat li + li {
  margin-top: 0.3em;
}

#chat blockquote {
  border-left: 3px solid var(--border);
  padding-left: 14px;
  color: var(--muted);
  margin: 0.6em 0;
}

#chat a {
  color: #10a37f;
  text-decoration: underline;
}

#chat table {
  border-collapse: collapse;
  margin: 0.8em 0;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

#chat th,
#chat td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

#chat th {
  background: var(--user-bg);
  font-weight: 600;
}

#chat :not(pre) > code {
  background: var(--inline-code-bg);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
}

#chat pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0.8em 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

#chat pre code {
  background: none;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ===== 输入区域 ===== */

#form {
  flex-shrink: 0;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 16px 20px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
}

#input {
  flex: 1;
  resize: none;
  min-height: 52px;
  max-height: 200px;
  padding: 14px 52px 14px 18px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#input::placeholder {
  color: var(--muted);
}

#input:focus {
  border-color: #b4b4c0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

#input:disabled {
  opacity: 0.6;
}

#send {
  flex-shrink: 0;
  height: 40px;
  padding: 0 18px;
  margin-bottom: 6px;
  border: none;
  border-radius: 20px;
  background: var(--send-bg);
  color: var(--send-text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

#send:hover:not(:disabled) {
  opacity: 0.85;
}

#send:disabled {
  background: var(--send-disabled);
  cursor: not-allowed;
}

/* ===== 响应式 ===== */

@media (max-width: 600px) {
  #chat {
    padding: 16px 12px 12px;
  }

  #chat .user .bubble,
  #chat .message.user .bubble,
  #chat .message-row.user .bubble {
    max-width: 90%;
  }

  #form {
    padding: 8px 12px 14px;
  }
}
