/* Model Council — 唯一聊天页面的样式。无外部字体、无 CDN。 */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --user: #e8f0fe;
  --moderator: #fdf3e0;
  --member: #ffffff;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e6e8ec; --muted: #9aa3b2;
  --border: #2a2f3a; --accent: #3b82f6; --user: #1e2a44; --moderator: #332a1a; --member: #171a21;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e6e8ec; --muted: #9aa3b2;
    --border: #2a2f3a; --accent: #3b82f6; --user: #1e2a44; --moderator: #332a1a; --member: #171a21;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg);
  display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
.icon-btn { padding: 6px 10px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
.error:empty { display: none; }
.mono { font-family: var(--mono); font-size: 12px; }
[hidden] { display: none !important; }

.topbar {
  grid-row: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: calc(8px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
body[data-view="login"] [data-requires-auth], body[data-view="loading"] [data-requires-auth] { display: none; }

.banner { grid-row: 2; padding: 6px 12px; background: var(--moderator); border-bottom: 1px solid var(--border); font-size: 13px; }
.banner.offline { background: #fde2e2; color: var(--danger); }

.chat { grid-row: 3; overflow-y: auto; padding: 12px; scroll-behavior: smooth; }
.messages { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.empty { max-width: 640px; margin: 15vh auto; text-align: center; color: var(--muted); }

.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--member); }
.msg.user { background: var(--user); margin-left: 10%; }
.msg.moderator { background: var(--moderator); }
.msg.pending { opacity: .6; }
.msg .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .meta .name { font-weight: 600; color: var(--text); }
.msg .meta .model { font-family: var(--mono); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }

.composer { grid-row: 4; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.composer form { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 40vh; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.status { max-width: 860px; margin: 0 auto 4px; min-height: 1em; }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 16px 18px; width: min(92vw, 440px); max-height: 90dvh; overflow: auto; }
.dialog.wide { width: min(96vw, 720px); }
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog h3 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dialog section { border-top: 1px solid var(--border); padding-top: 4px; }
.dialog label { display: block; margin: 8px 0; }
.dialog label input, .dialog label select { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.dialog label.inline { display: inline-flex; align-items: center; gap: 6px; }
.dialog label.inline input { display: inline; width: auto; margin: 0; }
.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list li button { padding: 4px 8px; font-size: 13px; }
.profile-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; margin-top: 8px; }
.profile-form input, .profile-form select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); min-width: 0; }
.profile-form input[name="model_id"] { grid-column: 1 / -1; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

@media (max-width: 600px) {
  .brand span { display: none; }
  .composer form { gap: 6px; }
  .composer .icon-btn, .composer .primary, .composer .danger { padding: 6px 8px; }
  .msg.user { margin-left: 0; }
  .profile-form { grid-template-columns: 1fr; }
  .dialog { width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; max-width: none; }
}

/* M2：模型发言、流式占位、决策行、运行状态 */
.msg.moderator { border-left: 3px solid #f59e0b; }
.msg.member { border-left: 3px solid var(--accent); }
.msg.system { background: var(--surface-2); color: var(--muted); font-size: 14px; }
.msg.cancelled { opacity: .5; }
.msg.cancelled .body::before { content: "（已作废的迟到回复）"; display: block; font-size: 12px; color: var(--muted); }
.msg .badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #f59e0b; color: #1a1d23; font-weight: 600; }
.msg .reply { font-size: 12px; color: var(--muted); }
.msg.final { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b inset; }
.decision { max-width: 860px; margin: 0 auto; font-size: 13px; color: var(--muted); padding: 2px 12px; }
.decision b { color: var(--text); font-weight: 600; }
.pending-area { margin-top: 10px; }
.pending-area .msg { border-style: dashed; }
.pending-area .meta .name::after { content: " · 正在发言…"; color: var(--muted); font-weight: 400; }
.status .chip { display: inline-block; margin-right: 8px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.menu { position: relative; max-width: 860px; margin: 6px auto 0; display: flex; gap: 6px; flex-wrap: wrap; }
.menu button { font-size: 13px; }
.msg .body code { font-family: var(--mono); font-size: 13px; }

/* ---------- 资料：待发送托盘、附件卡片、原文查看 ---------- */
.attach-tray { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 12px 0; }
.tray-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.tray-chip button { padding: 0 4px; line-height: 1; }
.tray-chip.state-error { color: var(--danger); }
.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.attachment-card { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface); font-size: 13px; max-width: 100%; }
.attachment-card .ac-head { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.attachment-card .ac-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attachment-card .ac-status { color: var(--muted); }
.attachment-card .ac-warn { font-size: 12px; }
.attachment-card .ac-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.attachment-card .ac-actions button { padding: 2px 8px; font-size: 12px; }
.attachment-card progress { width: 100%; height: 6px; }
.attachment-card.state-ready .ac-status { color: #15803d; }
.attachment-card.state-partial .ac-status { color: #b45309; }
.attachment-card.state-needs_input .ac-status, .attachment-card.state-failed .ac-status { color: var(--danger); }
.attachment-card.state-deleted { color: var(--muted); font-style: italic; }
body.dragging::after { content: "松开以添加资料"; position: fixed; inset: 0; display: grid; place-items: center; background: rgba(37, 99, 235, .12); border: 3px dashed var(--accent); font-size: 20px; pointer-events: none; z-index: 50; }
.source-view { max-height: 60vh; overflow: auto; }
.source-seg { border-top: 1px solid var(--border); padding: 8px 0; }
.source-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.source-text { white-space: pre-wrap; word-break: break-word; margin: 0; font-family: inherit; font-size: 14px; max-height: 40vh; overflow: auto; }
.page-image { display: block; max-width: 100%; margin-top: 6px; border: 1px solid var(--border); }
.source-text .overlap { color: var(--muted); opacity: .75; }
.cite { display: inline-block; padding: 0 6px; margin: 0 2px; font-size: 12px; line-height: 1.5; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); background: transparent; vertical-align: baseline; }
.cite.invalid { border-color: var(--muted); color: var(--muted); text-decoration: line-through; cursor: help; }
.source-seg.cited { background: var(--user); border-radius: 6px; padding-left: 6px; padding-right: 6px; }
