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

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --user-bubble: #2563eb;
  --assistant-bubble: #ffffff;
  --border: #e5e7eb;
  --code-bg: #0f172a;
  --radius: 12px;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== 首页 ===== */

.home {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.home h1 {
  font-size: 2rem;
  font-weight: 700;
}

.home p {
  color: var(--muted);
}

.enter-btn {
  margin-top: 8px;
  display: inline-block;
  padding: 12px 28px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.2s ease;
}

.enter-btn:hover {
  background: var(--primary-hover);
}

/* ===== 聊天页整体布局 ===== */

.chat-app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
  background: var(--panel);
}

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

.chat-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.chat-header a {
  font-size: 0.9rem;
  color: var(--primary);
  text-decoration: none;
  margin-right: 12px;
}

#newChat {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s ease;
}

#newChat:hover {
  background: var(--bg);
}

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

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

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

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.message-row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

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

.message-row.loading .bubble {
  color: var(--muted);
  font-style: italic;
}

/* Markdown 渲染样式 */

.bubble p + p {
  margin-top: 0.6em;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4 {
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}

.bubble h1 { font-size: 1.3rem; }
.bubble h2 { font-size: 1.15rem; }
.bubble h3 { font-size: 1.05rem; }

.bubble ul,
.bubble ol {
  padding-left: 1.4em;
  margin: 0.5em 0;
}

.bubble li + li {
  margin-top: 0.2em;
}

.bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--muted);
  margin: 0.5em 0;
}

.bubble a {
  color: var(--primary);
}

.bubble table {
  border-collapse: collapse;
  margin: 0.6em 0;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

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

.bubble th {
  background: var(--bg);
}

.bubble :not(pre) > code {
  background: #eef0f3;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
}

.bubble pre {
  background: var(--code-bg);
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.6em 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.bubble pre code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  background: none;
  padding: 0;
}

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

.input-area {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

#input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#sendBtn {
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}

#sendBtn:hover:not(:disabled) {
  background: var(--primary-hover);
}

#sendBtn:disabled,
#input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

@media (max-width: 600px) {
  .chat-app {
    max-width: 100%;
  }

  .bubble {
    max-width: 92%;
  }

  #messages,
  .input-area,
  .chat-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  .home h1 {
    font-size: 1.6rem;
  }
}
