/* 智能体群聊协同系统 - 公共端样式（移动优先，PC 自适应，微信风群聊） */
:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --border: #e4e6eb;
  --text: #1a1a1a;
  --muted: #8a8f99;
  --accent: #07c160;
  --accent-dark: #06ad56;
  --link: #576b95;
  --danger: #fa5151;
  --warn: #f0a35e;
  --shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.6;
}
a { color: var(--link); text-decoration: none; }
button { font-family: inherit; }
.view { display: none; }
.view.active { display: block; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
}
.topbar .brand { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; }
.topbar .brand small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.topbar button {
  background: #f5f6f7; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.topbar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 容器 ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 16px 0 8px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit; outline: none; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.btn {
  display: inline-block; width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #f5f6f7; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; padding: 7px 14px; font-size: 13px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 8px; }
.form-ok { color: var(--accent-dark); font-size: 13px; min-height: 20px; margin-top: 8px; }

/* ---------- 规则列表 ---------- */
.rule-list { padding-left: 20px; margin: 8px 0; }
.rule-list li { margin-bottom: 8px; }
.group-chip {
  display: block; width: 100%; text-align: left; background: #f7f8fa;
  border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.group-chip:hover { border-color: var(--accent); }
.group-chip .gn { font-weight: 700; font-size: 16px; }
.group-chip .gd { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- 群聊布局 ---------- */
.chat-shell { display: flex; flex-direction: column; height: calc(100dvh - 57px); }
.chat-head {
  flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
}
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title b { font-size: 16px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title small { color: var(--muted); font-size: 12px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 4px; }
.status-dot.off { background: var(--danger); }
.tabs-mini { display: flex; gap: 6px; }
.tabs-mini button {
  border: 1px solid var(--border); background: #f5f6f7; border-radius: 8px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; color: #555;
}
.tabs-mini button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 成员横栏 */
.members-bar {
  flex: 0 0 auto; display: flex; gap: 14px; overflow-x: auto; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border); scrollbar-width: none;
}
.members-bar::-webkit-scrollbar { display: none; }
.member { flex: 0 0 auto; width: 56px; text-align: center; position: relative; font-size: 11px; color: #555; }
.member .av {
  width: 44px; height: 44px; border-radius: 8px; margin: 0 auto 4px;
  background: #e2e5ea; display: flex; align-items: center; justify-content: center; font-size: 22px;
  overflow: hidden;
}
.member .av img { width: 100%; height: 100%; object-fit: cover; }
.member .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .online-flag {
  position: absolute; right: 6px; top: 0; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
}
.member .online-flag.off { background: #b5b8bf; }

/* 消息区 */
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px 20px; display: flex; flex-direction: column; gap: 16px; background: var(--bg); }
.sys-msg {
  align-self: center; max-width: 92%; text-align: center; color: #999; font-size: 12px;
  background: rgba(0, 0, 0, .06); border-radius: 6px; padding: 3px 12px;
}
.msg { display: flex; gap: 9px; align-items: flex-start; }
.msg .av {
  width: 40px; height: 40px; border-radius: 8px; flex: 0 0 40px;
  background: #e2e5ea; display: flex; align-items: center; justify-content: center; font-size: 20px; overflow: hidden;
}
.msg .av img { width: 100%; height: 100%; object-fit: cover; }
.msg .body { min-width: 0; flex: 1 1 auto; max-width: calc(100% - 60px); }
.msg .meta { font-size: 12px; color: #999; margin-bottom: 4px; padding-left: 4px; }
.msg .meta .model { background: #eceff3; border-radius: 4px; padding: 0 5px; font-size: 10px; margin-left: 5px; }
.msg .meta .role-tag { background: #e8f7ef; color: var(--accent-dark); border-radius: 4px; padding: 0 5px; font-size: 10px; margin-left: 5px; }
.msg .meta time { float: right; margin-right: 4px; }
.bubble {
  position: relative; background: #fff; border-radius: 8px; padding: 10px 13px;
  font-size: 15px; line-height: 1.65; word-break: break-word; overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05); display: inline-block; max-width: 100%;
}
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #2d2d2d; color: #e6e6e6; border-radius: 6px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; }
.bubble code { font-family: Consolas, "Cascadia Code", monospace; font-size: 13px; }
.bubble :not(pre) > code { background: #f1f1f3; border-radius: 4px; padding: 1px 5px; color: #c0392b; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--accent); color: #666; background: #f7faf8; }
.bubble table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid #ddd; padding: 5px 10px; font-size: 13px; }
.bubble th { background: #f3f4f6; }
.bubble img { max-width: 100%; border-radius: 6px; }
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; font-size: 16px; }

/* 人类自己的消息镜像（微信绿） */
.msg.mine { flex-direction: row-reverse; }
.msg.mine .meta { text-align: right; padding-right: 4px; }
.msg.mine .bubble { background: #95ec69; }
.msg.mine .bubble :not(pre) > code { background: rgba(255, 255, 255, .45); }

/* 超长消息默认折叠（人类端默认折叠，点击展开） */
.bubble.collapsed { max-height: 9em; overflow: hidden; }
.bubble.collapsed::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 34px; pointer-events: none;
  background: linear-gradient(transparent, #fff 80%);
}
.msg.mine .bubble.collapsed::after { background: linear-gradient(transparent, #95ec69 80%); }
.toggle-btn {
  display: inline-block; margin-top: 6px; padding: 2px 10px; font-size: 12px; color: var(--link);
  background: transparent; border: none; cursor: pointer;
}
.toggle-btn:hover { text-decoration: underline; }

/* 输入区 */
.composer { flex: 0 0 auto; background: #f7f8fa; border-top: 1px solid var(--border); padding: 10px 12px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-size: 15px; font-family: inherit; resize: none; min-height: 42px; max-height: 140px; outline: none; line-height: 1.5;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .send-btn {
  flex: 0 0 auto; background: var(--accent); border: none; color: #fff; border-radius: 8px;
  padding: 11px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.composer .send-btn:disabled { opacity: .5; }
.composer .hint { font-size: 11px; color: var(--muted); margin-top: 6px; text-align: center; }
.composer .hint.err { color: var(--danger); }

/* ---------- 文件面板 ---------- */
.panel-page { flex: 1 1 auto; overflow-y: auto; background: var(--bg); padding: 14px; }
.quota-bar { background: #eef1f5; border-radius: 8px; height: 10px; overflow: hidden; margin: 8px 0; }
.quota-bar i { display: block; height: 100%; background: var(--accent); }
.quota-bar i.warn { background: var(--warn); }
.quota-bar i.full { background: var(--danger); }
.file-row {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 13px; margin-bottom: 9px;
}
.file-row .ficon { font-size: 24px; flex: 0 0 auto; }
.file-row .finfo { flex: 1; min-width: 0; }
.file-row .fname { font-weight: 600; font-size: 14px; word-break: break-all; }
.file-row .fmeta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.file-row .facts { display: flex; gap: 6px; flex: 0 0 auto; }
.file-row .facts button {
  border: 1px solid var(--border); background: #f5f6f7; border-radius: 7px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.upload-zone {
  border: 2px dashed #c4c9d2; border-radius: 12px; padding: 22px; text-align: center;
  color: var(--muted); background: #fafbfc; margin-bottom: 14px; cursor: pointer;
}
.upload-zone.drag { border-color: var(--accent); background: #f0fbf5; color: var(--accent-dark); }
.upload-zone input { display: none; }

/* 登录页 */
.login-wrap { max-width: 420px; margin: 6vh auto 0; padding: 0 16px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo .logo-icn { font-size: 44px; }
.login-logo h1 { font-size: 21px; margin: 8px 0 4px; }

/* 提示 toast */
#toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .82); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 9999; max-width: 84vw; opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }

/* PC 自适应 */
@media (min-width: 768px) {
  .chat-shell { max-width: 1080px; margin: 0 auto; width: 100%; height: calc(100dvh - 57px); }
  .container { padding: 24px 16px; }
  .bubble { max-width: 78%; }
}
