:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #667080;
  --line: #e3e1dc;
  --accent: #2f6f5e;
  --accent-soft: #e5f0ec;
  --client: #2f6f5e;
  --client-text: #ffffff;
  --error: #b42318;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --card: #1f2226;
    --text: #e8e6e3;
    --muted: #9aa3ad;
    --line: #33373d;
    --accent: #6fc2a8;
    --accent-soft: #23352f;
    --client: #2c5d50;
    --client-text: #f1f5f3;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}

.lead { margin-top: 0; }
.muted { color: var(--muted); font-size: .9rem; }

label { display: block; font-weight: 600; margin: 0 0 14px; }
input, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button { font: inherit; cursor: pointer; border-radius: 10px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--card); border: 0; padding: 10px 20px; font-weight: 600; }
.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); padding: 9px 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

.error { color: var(--error); margin: 0 0 12px; }

.status { padding: 12px 18px; position: sticky; top: 8px; z-index: 1; }
.status-row { display: flex; justify-content: space-between; gap: 12px; }
.title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 8px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }

.log { list-style: none; padding: 0; margin: 18px 0; display: flex; flex-direction: column; gap: 12px; }

.bubble { max-width: 88%; padding: 12px 16px; border-radius: 14px; overflow-wrap: anywhere; }
.bubble.client { align-self: flex-end; background: var(--client); color: var(--client-text); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.bubble.agent { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .question { margin: 0; white-space: pre-wrap; }
.bubble .reason { margin: 6px 0 0; color: var(--muted); font-size: .9rem; }

.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.option {
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid transparent;
  padding: 6px 12px;
  text-align: left;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .tag { font-size: .75rem; font-weight: 700; color: var(--accent); margin-right: 6px; }

.thinking { margin: -6px 0 18px; color: var(--muted); }
.dots { display: inline-flex; gap: 3px; margin-right: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer textarea { margin: 0 0 10px; }
.actions { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.spec { align-self: stretch; }
.spec-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 8px; }
.spec-tools { display: flex; gap: 14px; }
.markdown h1 { font-size: 1.35rem; margin: 12px 0 8px; }
.markdown h2 { font-size: 1.1rem; margin: 18px 0 6px; }
.markdown h3 { font-size: 1rem; margin: 14px 0 4px; }
.markdown ul, .markdown ol { padding-left: 1.4em; margin: 6px 0; }
.markdown p { margin: 6px 0; }
.markdown code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.markdown pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.markdown li.task { list-style: none; margin-left: -1.2em; }

@media (max-width: 520px) {
  .bubble { max-width: 100%; }
  .actions { flex-direction: column-reverse; }
  .actions button { width: 100%; }
}
