:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --primary: #18181b;
  --primary-text: #ffffff;
  --user-bg: #18181b;
  --user-text: #ffffff;
  --bot-bg: #ffffff;
  --code-bg: #f4f4f5;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 820px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title h1 {
  font-size: 16px;
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a1a1aa;
}

.dot.online { background: #16a34a; }
.dot.error { background: #dc2626; }

.quota-badge {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 24px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }

.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

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

.bubble.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: #fecaca;
}

/* 轻量 Markdown 排版 */
.bubble h2, .bubble h3, .bubble h4 {
  font-size: 15px;
  font-weight: 600;
  margin: 10px 0 4px;
}

.bubble h2:first-child, .bubble h3:first-child, .bubble p:first-child {
  margin-top: 0;
}

.bubble p {
  margin: 6px 0;
}

.bubble ul, .bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.bubble li {
  margin: 2px 0;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

.bubble pre {
  background: #18181b;
  color: #f4f4f5;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.bubble pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

.status-pill {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2563eb;
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.msg-actions {
  margin-top: 4px;
  display: flex;
  gap: 8px;
}

.copy-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.copy-btn:hover {
  background: var(--border);
  color: var(--text);
}

.composer-wrap {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.45;
  max-height: 160px;
  outline: none;
  background: var(--bg);
}

.composer textarea:focus {
  border-color: #71717a;
  background: var(--surface);
}

.composer button {
  border: none;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  height: 42px;
}

.composer button.stop-btn {
  background: #dc2626;
}

.composer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 600px) {
  .msg { max-width: 94%; }
  .chat-list { padding: 12px; }
}
