:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1d2129;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2a2f37;
    --accent: #4f8cff;
    --danger: #f97066;
    --danger-bg: #2a1614;
    --ok: #47cd89;
    --ok-bg: #102419;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
header .brand { font-weight: 600; }
header nav { display: flex; gap: 16px; align-items: center; }
header nav a { color: var(--text); text-decoration: none; }
header nav form { margin: 0; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], select {
  width: 100%; padding: 10px 12px; font-size: 16px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--text); }
button {
  margin-top: 16px; padding: 10px 18px; font-size: 16px; cursor: pointer;
  color: var(--accent-text); background: var(--accent); border: 0; border-radius: 8px;
}
button.link { margin: 0; padding: 0; background: none; color: var(--text); font-size: inherit; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; }
.msg.error { color: var(--danger); background: var(--danger-bg); }
.msg.ok { color: var(--ok); background: var(--ok-bg); }
.muted { color: var(--muted); font-size: 14px; }
table { width: 100%; border-collapse: collapse; }
td { padding: 8px 0; border-bottom: 1px solid var(--line); }
td:last-child { text-align: right; }
code { font-size: 14px; word-break: break-all; }
.login { max-width: 360px; margin: 10vh auto 0; }

/* ---------- P2：交易与对谈 ---------- */
a.button {
  display: inline-block; padding: 10px 18px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); text-decoration: none;
}
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: .55; cursor: wait; }
textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; resize: vertical;
}
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.warn { color: var(--danger); border-color: var(--danger); }
.row-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.disclaimer { font-size: 12px; color: var(--muted); margin-top: 16px; }

main:has(.dialogue-grid) { max-width: 1180px; }
.dialogue-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .dialogue-grid { grid-template-columns: 1fr; } }
#side-wrap { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
@media (max-width: 860px) { #side-wrap { position: static; max-height: none; } }

#messages { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.bubble { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.bubble.user { align-self: flex-end; max-width: 85%; background: var(--accent); color: var(--accent-text); border: 0; white-space: pre-wrap; }
.bubble.assistant p:first-child { margin-top: 0; }
.bubble.assistant p:last-child { margin-bottom: 0; }
.bubble.streaming { white-space: pre-wrap; }
.bubble.error { color: var(--danger); background: var(--danger-bg); }
.tool-note { font-size: 13px; color: var(--muted); padding-left: 4px; }
.tool-note::before { content: "⟳ "; }
a.cite { font-size: 12px; text-decoration: none; vertical-align: super; }
.cite.bad { color: var(--danger); font-size: 12px; vertical-align: super; }
.inferred { text-decoration: underline dotted var(--danger); text-underline-offset: 3px; cursor: help; }

.progress { list-style: none; padding: 0; margin: 0; }
.progress li { padding: 4px 0; }
.progress li.ok { color: var(--ok); }
.progress li.todo { color: var(--muted); }
ol.facts { padding-left: 0; list-style: none; margin: 0; font-size: 14px; }
ol.facts li { padding: 8px 0; border-bottom: 1px solid var(--line); }
ol.facts li:target { background: var(--ok-bg); }
.fact-kind { font-size: 12px; padding: 1px 6px; border-radius: 4px; margin-right: 4px; }
.fact-kind.data { background: var(--ok-bg); color: var(--ok); }
.fact-kind.news { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.verdict.pass { border-color: var(--ok); }
.verdict.reject { border-color: var(--danger); }
table.kv td:first-child { color: var(--muted); width: 8em; vertical-align: top; }
table.kv td:last-child { text-align: left; }
