/* 智元科研助手 — 深色工具风（zcode 风格） */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1b1922; --panel: #292136; --panel2: #332f42; --line: #3a3547;
  --ink: #d6d6d9; --sub: #83838c; --accent: #4d9dff; --accent-dim: rgba(77,157,255,.13);
  --ok: #4ac26b; --bad: #e5534b; --mono: "SF Mono", Menlo, Consolas, monospace;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px; background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
::selection { background: var(--accent-dim); }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #333338; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.brand { font-weight: 600; font-size: 13px; letter-spacing: .3px; }
.brand::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px;
  background: var(--accent); border-radius: 2px; vertical-align: 1px;
}
.badge {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  background: var(--panel2); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 4px;
}
.badge em { font-style: normal; color: var(--sub); margin-right: 4px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  border-radius: 5px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: background .12s, border-color .12s;
}
.btn:hover { background: #3b3749; border-color: #4a4560; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0c0c10; font-weight: 600; }
.btn.primary:hover { background: #6cabff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 登录 ---------- */
.login-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg);
}
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 32px 30px; text-align: left;
}
.login-card h1 { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.login-card h1::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 9px;
  background: var(--accent); border-radius: 2px;
}
.login-sub { font-size: 12px; color: var(--sub); line-height: 1.7; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 9px 11px; font-size: 13px; font-family: inherit;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 5px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.err {
  background: rgba(229,83,75,.1); border: 1px solid rgba(229,83,75,.35); color: var(--bad);
  font-size: 12px; padding: 8px 10px; border-radius: 5px; margin-bottom: 12px;
}

/* ---------- 聊天布局 ---------- */
.chat-wrap { flex: 1; display: flex; overflow: hidden; }
.agent-panel {
  width: 210px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 10px 8px; gap: 6px; flex-shrink: 0;
}
.agent-head {
  font-size: 11px; color: var(--sub); font-weight: 600; letter-spacing: 1px;
  padding: 4px 8px 2px; text-transform: uppercase;
}
.agent-list { flex: 1 1 40%; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; min-height: 120px; }
.conv-list { flex: 1 1 45%; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; min-height: 100px; }
.conv-empty { font-size: 11px; color: var(--sub); padding: 8px 10px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; font-size: 12.5px;
  cursor: pointer; border-radius: 4px; border-left: 2px solid transparent; color: var(--ink);
}
.conv-item:hover { background: var(--panel2); }
.conv-item.active { background: var(--accent-dim); border-left-color: var(--accent); }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .x {
  color: var(--sub); font-size: 14px; padding: 0 3px; border-radius: 3px; flex-shrink: 0;
}
.conv-item .x:hover { color: var(--bad); background: rgba(229,83,75,.15); }
.btn.slim { padding: 5px 10px; font-size: 12px; flex-shrink: 0; }
.agent-item {
  padding: 7px 10px; cursor: pointer; font-size: 13px; border-radius: 4px;
  border-left: 2px solid transparent; color: var(--ink); line-height: 1.4;
}
.agent-item:hover { background: var(--panel2); }
.agent-item.active {
  background: var(--accent-dim); border-left-color: var(--accent); color: #e8eef7;
}
.agent-item .d {
  font-size: 11px; color: var(--sub); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-stream { flex: 1; overflow-y: auto; padding: 8px 0 20px; }

.welcome { text-align: center; margin-top: 14vh; padding: 0 40px; }
.welcome h2 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.welcome h2::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 9px;
  background: var(--accent); border-radius: 2px; vertical-align: 0;
}
.welcome p { color: var(--sub); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; max-width: 560px; margin-left: auto; margin-right: auto; }
.chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--sub);
  border-radius: 4px; padding: 6px 12px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: color .12s, border-color .12s;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }

/* 消息：无气泡，日志式分块 */
.msg { padding: 14px 26px 16px; border-bottom: 1px solid var(--line); max-width: 860px; }
.msg .who {
  font-size: 11px; color: var(--sub); margin-bottom: 8px; letter-spacing: .5px;
}
.msg.user .who { color: var(--accent); }
.msg .body { font-size: 14px; line-height: 1.75; word-break: break-word; white-space: normal; }
.msg.user .body {
  color: #c5c9d2; border-left: 2px solid var(--line); padding-left: 12px;
}
.msg.ai .body { color: var(--ink); }
.msg.ai.thinking .body { color: var(--sub); }
.msg.ai.thinking .body::after {
  content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.meta-line {
  font-family: var(--mono); font-size: 11px; color: var(--sub);
  padding: 0 26px 12px; max-width: 860px;
}

/* markdown */
.md h1, .md h2, .md h3 { margin: 14px 0 6px; line-height: 1.4; color: #ececf0; }
.md h1 { font-size: 17px; } .md h2 { font-size: 15px; } .md h3 { font-size: 14px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0 6px 20px; }
.md li { margin: 3px 0; }
.md code {
  background: var(--panel2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 3px;
  font-family: var(--mono); font-size: 12.5px; color: #e3b341;
}
.md pre {
  background: #211e2b; border: 1px solid var(--line); padding: 12px 14px; border-radius: 6px;
  overflow-x: auto; margin: 8px 0;
}
.md pre code { background: transparent; border: none; color: #cdd6e4; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; }
.md th { background: var(--panel2); color: var(--sub); font-weight: 600; }
.md blockquote { border-left: 2px solid var(--accent); padding-left: 12px; color: var(--sub); margin: 8px 0; }
.md a { color: var(--accent); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }

/* 输入区 */
.chat-input {
  display: flex; gap: 10px; padding: 12px 20px 16px; max-width: 900px; width: 100%;
  margin: 0 auto; background: transparent;
}
.chat-input textarea {
  flex: 1; resize: none; font-size: 14px; font-family: inherit; line-height: 1.6;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px 13px; outline: none; max-height: 160px;
}
.chat-input textarea:focus { border-color: var(--accent); }

/* ---------- 管理面板 ---------- */
.admin-wrap { flex: 1; overflow-y: auto; padding: 20px; max-width: 980px; margin: 0 auto; width: 100%; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 0; }
.tab {
  border: none; background: transparent; color: var(--sub); padding: 8px 14px;
  font-size: 13px; cursor: pointer; font-family: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px; margin-bottom: 14px;
}
.card h3 { font-size: 13px; font-weight: 600; margin-bottom: 14px; color: var(--ink); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input, .row select {
  padding: 7px 10px; font-size: 13px; font-family: inherit;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 5px; outline: none; min-width: 130px;
}
.row input:focus { border-color: var(--accent); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--sub); font-weight: 600; font-size: 11.5px; letter-spacing: .5px; }
.tbl td b { font-family: var(--mono); font-weight: 500; }
.tbl .op { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.mini { padding: 3px 9px; font-size: 12px; border-radius: 4px; }
.btn.warn { color: var(--bad); border-color: rgba(229,83,75,.4); background: transparent; }
.btn.warn:hover { background: rgba(229,83,75,.12); }
.btn.ok { color: var(--ok); border-color: rgba(74,194,107,.4); background: transparent; }
.btn.ok:hover { background: rgba(74,194,107,.12); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 3px; font-size: 11px; font-weight: 500; }
.tag.admin { background: rgba(160,120,255,.15); color: #b394ff; }
.tag.user { background: var(--accent-dim); color: var(--accent); }
.tag.on { background: rgba(74,194,107,.13); color: var(--ok); }
.tag.off { background: rgba(229,83,75,.13); color: var(--bad); }
.hint { font-size: 12px; color: var(--sub); line-height: 1.7; margin: 10px 0; }
.hint code { font-family: var(--mono); color: #c8c8cc; }

/* toast */
.toast {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  padding: 8px 18px; border-radius: 6px; font-size: 13px; z-index: 99;
}
.toast.err { color: var(--bad); border-color: rgba(229,83,75,.4); }

/* 输入区下方信息行 */
.input-foot {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 900px; width: 100%; margin: 0 auto; padding: 0 20px 10px;
}
.hint-inline { font-size: 11px; color: var(--sub); }

/* 消息操作栏（导出） */
.msg-ops { margin-top: 8px; display: flex; gap: 8px; }
.msg-ops button {
  background: transparent; border: 1px solid var(--line); color: var(--sub);
  font-size: 11.5px; padding: 3px 10px; border-radius: 4px; cursor: pointer;
  font-family: inherit;
}
.msg-ops button:hover { color: var(--accent); border-color: var(--accent); }

/* 智能体欢迎卡 */
.agent-hero { text-align: center; padding: 0 30px; }
.agent-hero .tag-line { font-size: 11px; color: var(--accent); letter-spacing: 2px; margin-bottom: 8px; }
.agent-hero h2 { font-size: 17px; margin-bottom: 8px; }
.agent-hero h2::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 9px;
  background: var(--accent); border-radius: 2px; vertical-align: 0;
}
.agent-hero p { font-size: 12.5px; color: var(--sub); line-height: 1.8; max-width: 520px; margin: 0 auto 16px; }

/* 文档区与引用 */
.doc-list .conv-item { padding: 5px 8px; }
.doc-item .ops { display: none; gap: 2px; flex-shrink: 0; }
.doc-item:hover .ops { display: flex; }
.doc-item.attached { background: rgba(74,194,107,.12); border-left-color: var(--ok); }
.mini-op {
  color: var(--sub); font-size: 11px; padding: 0 4px; cursor: pointer;
  border-radius: 3px; user-select: none;
}
.mini-op:hover { color: var(--accent); background: var(--panel2); }
.mini-op.nsfc:hover { color: #b394ff; }
.mini-op.del:hover { color: var(--bad); background: rgba(229,83,75,.15); }
.link-btn {
  background: none; border: none; color: var(--accent); font-size: 11.5px;
  cursor: pointer; padding: 0; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }
.attach-chip {
  margin-left: 8px; background: rgba(74,194,107,.12); color: var(--ok);
  border: 1px solid rgba(74,194,107,.3); border-radius: 3px;
  font-size: 11px; padding: 2px 8px; cursor: pointer;
}

/* 导出标书按钮（醒目） */
.msg-ops .nsfc-btn { color: #b394ff; border-color: rgba(160,120,255,.45); }
.msg-ops .nsfc-btn:hover { color: #cdb2ff; border-color: #b394ff; background: rgba(160,120,255,.1); }

/* ---------- 标书工作流面板 ---------- */
.flow-panel {
  width: 375px; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden;
}
.flow-head {
  display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line);
  align-items: center;
}
.flow-head select {
  flex: 1; min-width: 0; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px;
  font-size: 12px; font-family: inherit;
}
.flow-steps {
  display: flex; padding: 10px 8px 6px; gap: 2px; border-bottom: 1px solid var(--line);
}
.flow-step {
  flex: 1; text-align: center; font-size: 10.5px; color: var(--sub);
  padding-top: 16px; position: relative;
}
.flow-step::before {
  content: ""; position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  width: 10px; height: 10px; border-radius: 50%; background: var(--line);
}
.flow-step.done::before { background: var(--ok); }
.flow-step.now { color: var(--accent); font-weight: 600; }
.flow-step.now::before { background: var(--accent); }
.flow-body { flex: 1; overflow-y: auto; padding: 12px; }
.flow-card {
  border: 1px solid var(--line); border-radius: 6px; padding: 10px;
  margin-bottom: 10px; background: var(--panel2);
}
.flow-card.locked { opacity: .45; pointer-events: none; }
.flow-card h4 { font-size: 12.5px; margin-bottom: 6px; color: var(--ink); }
.flow-card .desc { font-size: 11px; color: var(--sub); line-height: 1.6; margin-bottom: 8px; }
.flow-card .topic-box {
  font-size: 11.5px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: 8px;
  max-height: 110px; overflow-y: auto; line-height: 1.6; margin-bottom: 8px;
  white-space: pre-wrap;
}
.sec-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px;
  border-radius: 4px; font-size: 12px; margin-bottom: 2px;
}
.sec-item:hover { background: var(--panel); }
.sec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.sec-item.drafted .sec-dot { background: #e3b341; }
.sec-item.approved .sec-dot { background: var(--ok); }
.sec-item .name { flex: 1; }
.sec-item .ops { display: flex; gap: 4px; }
.sec-op {
  font-size: 10.5px; color: var(--sub); cursor: pointer; padding: 1px 5px;
  border: 1px solid var(--line); border-radius: 3px; user-select: none;
}
.sec-op:hover { color: var(--accent); border-color: var(--accent); }
.sec-op.ok:hover { color: var(--ok); border-color: var(--ok); }
.flow-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.flow-actions .btn { font-size: 12px; padding: 6px; }
.flow-note { font-size: 10.5px; color: var(--sub); margin-top: 6px; line-height: 1.5; }
@media (max-width: 1360px) { .flow-panel { display: none; } }

.msg-ops .topic-btn { color: var(--ok); border-color: rgba(74,194,107,.45); }
.msg-ops .topic-btn:hover { color: var(--ok); border-color: var(--ok); background: rgba(74,194,107,.1); }

.ws-toggle { font-size: 11.5px; color: var(--sub); cursor: pointer; user-select: none; margin-right: 10px; }
.ws-toggle input { vertical-align: -1px; accent-color: var(--accent); }

.flow-head.sub { gap: 8px; padding: 8px 10px; }
.flow-head.sub label { font-size: 11px; color: var(--sub); display: flex; align-items: center; gap: 4px; }
.flow-head.sub select, .flow-head.sub input {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 4px; font-size: 11px; font-family: inherit; width: 62px;
}
.flow-head.sub input { width: 54px; }
.flow-head .mini-op { font-size: 13px; }

.sec-quota {
  width: 46px; background: var(--bg); color: var(--accent); border: 1px solid var(--line);
  border-radius: 3px; padding: 1px 3px; font-size: 10.5px; font-family: var(--mono);
  text-align: right;
}
.sec-quota::-webkit-outer-spin-button, .sec-quota::-webkit-inner-spin-button { -webkit-appearance: none; }
.sec-quota:focus { border-color: var(--accent); outline: none; }

.tool-btn {
  margin-left: 10px; font-size: 11.5px; padding: 2px 10px; cursor: pointer;
  border-radius: 3px; border: 1px solid var(--line); background: transparent;
  color: var(--sub); font-family: inherit;
}
.tool-btn.topic { color: var(--ok); border-color: rgba(74,194,107,.45); }
.tool-btn.topic:hover { border-color: var(--ok); background: rgba(74,194,107,.1); }

/* ---------- 移动端 / 平板适配 ---------- */
.btn.icon { padding: 4px 10px; font-size: 15px; }
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40;
}

/* 平板（<=1024）：左栏保留，工作流面板变右侧抽屉 */
@media (max-width: 1024px) {
  .flow-panel {
    position: fixed; top: 42px; right: 0; bottom: 0; z-index: 50;
    width: min(375px, 88vw);
    transform: translateX(105%); transition: transform .22s ease;
    box-shadow: -8px 0 24px rgba(0,0,0,.35);
  }
  .flow-panel.open { transform: translateX(0); }
}

/* 手机（<=640）：左栏也变抽屉，聊天全屏 */
@media (max-width: 640px) {
  .agent-panel {
    position: fixed; top: 42px; left: 0; bottom: 0; z-index: 50;
    width: min(260px, 80vw);
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.35);
  }
  .agent-panel.open { transform: translateX(0); }
  #topbar { padding: 0 8px; gap: 6px; }
  #topbar .badge { font-size: 11px; padding: 3px 7px; }
  .brand { font-size: 14px; }
  .msg { padding: 12px 14px; max-width: 100%; }
  .meta-line { padding: 0 14px 8px; }
  .chat-input { padding: 8px 10px 10px; }
  .input-foot { padding: 0 10px 8px; flex-wrap: wrap; gap: 6px; }
  .chat-stream { padding: 4px 0 12px; }
  .welcome { margin-top: 6vh; padding: 0 14px; }
  .login-card { width: 92vw; padding: 24px 20px; }
  .admin-wrap { padding: 12px; }
  .card { padding: 12px; overflow-x: auto; }
  .tbl { font-size: 12px; }
  .row input, .row select { min-width: 110px; flex: 1; }
  .msg-ops { flex-wrap: wrap; }
  #btnAdmin, #btnDrawerFlow { padding: 5px 8px; font-size: 12px; }
}

.msg-ops .res-btn { color: #e3b341; border-color: rgba(227,179,65,.45); }
.msg-ops .res-btn:hover { color: #f0c664; border-color: #e3b341; background: rgba(227,179,65,.08); }
.msg-ops .sec-btn { color: #7ec8ff; border-color: rgba(126,200,255,.45); }
.msg-ops .sec-btn:hover { color: #a5d8ff; border-color: #7ec8ff; background: rgba(126,200,255,.08); }
.sec-len { font-style: normal; color: var(--sub); font-size: 10px; font-family: var(--mono); margin-left: 4px; }
