:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1c1a;
  --muted: #8a8a83;
  --line: #e5e5df;
  --accent: #2f6f4f;
  --accent-soft: #eaf3ee;
  --user: #1c1c1a;
  --danger: #b3402f;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --panel: #1c1c1a;
    --text: #ecece7;
    --muted: #8c8c84;
    --line: #2c2c29;
    --accent: #7fc8a0;
    --accent-soft: #1e2a24;
    --user: #ecece7;
    --danger: #e0776a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 2px 14px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand strong { font-size: 14px; letter-spacing: 0.2px; white-space: nowrap; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
  flex: none;
}
.dot.busy { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.dot.error { background: var(--danger); }

@keyframes pulse { 50% { opacity: 0.25; } }

.pill {
  font: 11px/1 var(--mono);
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 5px 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

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

select, button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

select:disabled { opacity: 0.45; cursor: not-allowed; }
button:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- 消息区 ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 2px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  text-align: center;
  max-width: 460px;
  padding-bottom: 8vh;
}
.empty h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.4px; margin: 0 0 10px; }
.empty p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.empty code { font-family: var(--mono); font-size: 12px; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

.hints { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.hint {
  font-size: 12.5px;
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 6px 12px;
}
.hint:hover { color: var(--text); border-color: var(--muted); }

.msg { display: flex; flex-direction: column; gap: 5px; animation: rise 0.18s ease-out; }
.msg.user { align-items: flex-end; }

.stack { display: flex; flex-direction: column; gap: 8px; width: 100%; align-items: flex-start; }
.msg.user .stack { align-items: flex-end; }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.msg .meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.msg.user { align-items: flex-end; }
.msg.user .meta { flex-direction: row-reverse; }
.bubble {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant .bubble { border-bottom-left-radius: 5px; }
.msg.user .bubble {
  background: var(--user);
  color: var(--bg);
  border-color: transparent;
  border-bottom-right-radius: 5px;
  max-width: 78%;
}
.msg.error .bubble { border-color: var(--danger); color: var(--danger); }

.bubble:empty { display: none; }

.cursor::after {
  content: "▍";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 思考块 */
.thinking {
  max-width: 88%;
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 12px;
  color: var(--muted);
  font-size: 13px;
}
.thinking summary { cursor: pointer; font-size: 12px; list-style: none; opacity: 0.8; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font: inherit;
  opacity: 0.85;
}

/* 工具调用 */
.tool {
  display: flex;
  align-items: baseline;
  gap: 8px;
  max-width: 88%;
  font: 12px/1.5 var(--mono);
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 7px 10px;
  overflow: hidden;
}
.tool .name { color: var(--accent); font-weight: 600; flex: none; }
.tool .args { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool.done .name::after { content: " ✓"; }

/* ---------- 输入区 ---------- */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 0 18px;
  border-top: 1px solid var(--line);
}

textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  min-height: 44px;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  outline: none;
}
textarea:focus { border-color: var(--accent); }

#send {
  height: 44px;
  padding: 0 18px;
  border-radius: 11px;
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 500;
}
@media (prefers-color-scheme: dark) { #send { color: #10251a; } }

@media (max-width: 560px) {
  .app { padding: 0 12px; }
  .brand strong { display: none; }
  .bubble, .thinking, .tool { max-width: 94%; }
}
