:root {
  --bg: #faf9f7; --side: #f3f1ed; --panel: #ffffff; --text: #1f1e1c; --muted: #6f6b66; --border: #e5e2dc;
  --accent: #c2410c; --accent-soft: #fbe9df; --accent-text: #ffffff; --ok: #15803d; --fail: #dc2626; --run: #2563eb;
  --wait: #a8a29e; --warn-bg: #fef3c7; --warn-text: #854d0e; --err-bg: #fee2e2; --err-text: #991b1b;
  --code-bg: #f1efeb; --user-bg: #efece6; --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1c; --side: #181715; --panel: #262523; --text: #ecebe8; --muted: #a29e97; --border: #3a3834;
    --accent: #f08a5d; --accent-soft: #3a2a22; --accent-text: #1b1310; --ok: #4ade80; --fail: #f87171; --run: #60a5fa;
    --wait: #78716c; --warn-bg: #3b3210; --warn-text: #fde68a; --err-bg: #3b1515; --err-text: #fecaca;
    --code-bg: #2f2d2a; --user-bg: #33312d; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- 三栏布局 ---------- */
.app { display: grid; grid-template-columns: 260px minmax(0, 1fr) 460px; height: 100vh; height: 100dvh; }
.app.no-right { grid-template-columns: 260px minmax(0, 1fr) 0; }
.app.no-right .right { display: none; }
.left { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.mid { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.right { background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
@media (max-width: 1280px) { .app { grid-template-columns: 230px minmax(0, 1fr) 400px; } .app.no-right { grid-template-columns: 230px minmax(0, 1fr) 0; } }
@media (max-width: 880px) {
  .app, .app.no-right { grid-template-columns: minmax(0, 1fr); }
  .left, .right { position: fixed; top: 0; bottom: 0; z-index: 30; width: min(86vw, 360px); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  .left { left: 0; transform: translateX(-105%); }
  .right { right: 0; transform: translateX(105%); }
  .app.no-right .right { display: flex; }
  body.show-left .left, body.show-right .right { transform: none; }
  body.show-left .scrim, body.show-right .scrim { display: block; }
}
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
.only-narrow { display: none !important; }
@media (max-width: 880px) { .only-narrow { display: inline-flex !important; } .only-wide { display: none !important; } }

/* ---------- 左栏 ---------- */
.left-top { padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-weight: 700; font-size: 17px; padding: 0 6px; }
.new-btn { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); cursor: pointer; font-weight: 600; }
.new-btn:hover { border-color: var(--accent); }
.hist-title { font-size: 12px; color: var(--muted); padding: 8px 18px 4px; }
.hist { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.hist-item { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.hist-item:hover { background: var(--code-bg); }
.hist-item.active { background: var(--accent-soft); }
.hist-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.left-foot { border-top: 1px solid var(--border); padding: 8px; }
.nav-btn { width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav-btn:hover, .nav-btn.active { background: var(--code-bg); }

/* ---------- 中栏 ---------- */
.mid-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 52px; }
.mid-head .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mid-body { flex: 1; overflow-y: auto; padding: 20px 16px 28px; }
.col { max-width: 780px; margin: 0 auto; }
.composer-wrap { padding: 0 16px 14px; }
.composer { max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.composer textarea { width: 100%; border: 0; background: transparent; resize: none; outline: none; padding: 4px 2px; min-height: 48px; max-height: 40vh; }
.composer-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.composer-bar .spacer { flex: 1; }
.hero { text-align: center; padding: 8vh 0 18px; }
.hero h1 { font-size: 26px; font-weight: 600; margin: 0 0 8px; font-family: Georgia, "Songti SC", "SimSun", serif; }

/* 对话流 */
.bubble-user { margin: 14px 0 14px auto; max-width: 85%; width: fit-content; background: var(--user-bg); padding: 10px 14px;
  border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-user .lbl { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.round-sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 22px 0 10px; }
.round-sep::before, .round-sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.msg { display: flex; gap: 10px; margin: 12px 0; }
.msg-main { flex: 1; min-width: 0; }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-head .who { font-weight: 600; }
.msg-head .meta { color: var(--muted); font-size: 12px; }
.msg-body { overflow-wrap: anywhere; }
.msg-body.plain { white-space: pre-wrap; }
.msg-foot { color: var(--muted); font-size: 12px; }
.report-chip { display: flex; gap: 10px; align-items: center; margin: 16px 0; padding: 12px 14px; border: 1px solid var(--accent);
  background: var(--accent-soft); border-radius: 12px; cursor: pointer; }
.report-chip .t { font-weight: 600; flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--wait); flex: none; display: inline-block; }
.dot.running { background: var(--run); animation: pulse 1s infinite; }
.dot.ok, .dot.done { background: var(--ok); } .dot.failed { background: var(--fail); }
.dot.partial, .dot.cancelled, .dot.interrupted { background: #d97706; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- 右栏 ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .x { margin-left: auto; }
.right-body { flex: 1; overflow-y: auto; padding: 14px; }
.sec { margin-bottom: 18px; }
.sec h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
/* 参会者：一人一行（勾选 · 名称 · 模型 · 角色 · 加减） */
.seats { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seat { display: grid; grid-template-columns: 18px 24px 104px minmax(0, 1fr) 46px; gap: 6px; align-items: center;
  padding: 5px 8px; border-top: 1px solid var(--border); background: var(--panel); }
.seat.people { grid-template-columns: 24px 104px minmax(0, 1fr) 26px; }
.seat .pname { font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 模型自带图标（内置 SVG，简化版） */
.picon { width: 24px; height: 24px; flex: none; display: inline-block; border-radius: 6px; overflow: hidden; }
.picon svg { width: 100%; height: 100%; display: block; }
.picon.big { width: 30px; height: 30px; border-radius: 8px; }
/* 角色名：按角色上色、换字体，本身就是下拉菜单 */
.rolename { border: 1px solid transparent; background: transparent; font-size: 15px; padding: 2px 2px; border-radius: 6px;
  cursor: pointer; min-width: 0; max-width: 100%; appearance: auto; }
.rolename:hover:not(:disabled) { border-color: var(--border); background: var(--code-bg); }
.rolename:disabled { cursor: default; opacity: 1; }
.rolename option { color: var(--text); font-style: normal; font-weight: 400; font-family: inherit; }
.rolechip { font-size: 14px; }
.addrow { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.addrow select { flex: 1; min-width: 0; }
.seat.added { background: var(--accent-soft); }
.seat:first-child { border-top: 0; }
.seat.off .sel { opacity: .5; }
.seat .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .sel { padding: 4px 6px; font-size: 13px; }
.seat .acts { display: flex; gap: 2px; }
.seat .acts button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 5px; border-radius: 6px; }
.seat .acts button:hover { background: var(--code-bg); color: var(--text); }
.seat .nokey { grid-column: 4 / 6; font-size: 13px; }

/* ---------- 通用控件 ---------- */
input[type=text], input[type=password], input[type=number], textarea.box, select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); min-width: 0; }
input:focus, textarea.box:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--fail); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.icon { padding: 4px 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.hint { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.fail { color: var(--fail); border-color: var(--fail); }
.badge.free { color: var(--accent); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 4px 2px 8px; border-radius: 8px;
  background: var(--code-bg); border: 1px solid var(--border); max-width: 100%; }
.chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; }
.composer.drop { outline: 2px dashed var(--accent); }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 7px 10px; border-radius: 8px; font-size: 13px; }
.err { background: var(--err-bg); color: var(--err-text); padding: 7px 10px; border-radius: 8px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.num { width: 64px !important; text-align: center; }
label.lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.35; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16px; } .md h3, .md h4 { font-size: 15px; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; font-size: 90%; }
.md pre { background: var(--code-bg); padding: 10px; border-radius: 6px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.srow { padding: 14px 0; border-top: 1px solid var(--border); }
.srow:first-child { border-top: 0; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
.toast.show { opacity: .95; }
.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 60; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; display: grid; gap: 10px; }
.login h2 { margin: 0 0 4px; }
.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); }
.me-row { display: flex; align-items: center; gap: 6px; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.me-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col > .warn { margin: 0 0 12px; }

