:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e4e6eb; --text: #1f2329; --muted: #8a8f99;
  --accent: #1677ff; --wa: #25d366; --mail: #f59e0b; --in: #fff; --out: #d9fdd3; --danger: #e5484d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) { --bg: #0f1216; --panel: #181c22; --line: #2a2f38; --text: #e6e8eb; --muted: #8b919c; --in: #222730; --out: #144d37; color-scheme: dark; }
}
:root[data-theme=dark] { --bg: #0f1216; --panel: #181c22; --line: #2a2f38; --text: #e6e8eb; --muted: #8b919c; --in: #222730; --out: #144d37; color-scheme: dark; }
:root[data-theme=light] { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.5em; }
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; cursor: pointer; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--danger); }

.login { display: grid; place-items: center; height: 100%; }
.login-card { background: var(--panel); padding: 32px; border-radius: 12px; width: 320px; display: grid; gap: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }

.app { display: flex; height: 100%; }
.rail { width: 64px; background: #1f2937; display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 6px; flex: none; }
.rail button { background: transparent; width: 52px; height: 52px; padding: 0; border-radius: 8px; color: #e5e7eb;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; }
.rail button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail button.active, .rail button:hover { background: #374151; color: #fff; }
.rail button.active { box-shadow: inset 3px 0 0 var(--accent); }
.rail .spacer { flex: 1; }
.view { flex: 1; min-width: 0; }

.inbox { display: flex; }
.list { width: 320px; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.list-head { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--bg); }
.conv.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; position: relative; }
.avatar.whatsapp { background: var(--wa); } .avatar.email { background: var(--mail); }
.conv-main { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 6px; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { color: var(--muted); font-size: 12px; flex: none; }
.conv-bottom { display: flex; justify-content: space-between; gap: 6px; }
.conv-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; height: 18px; line-height: 18px; flex: none; }
.tag { font-size: 11px; color: var(--muted); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head b { font-size: 15px; }
.msg-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }
.msg { max-width: 70%; padding: 8px 12px; border-radius: 10px; background: var(--in); border: 1px solid var(--line);
  word-break: break-word; }
.msg .body { white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg .subj { font-weight: 600; margin-bottom: 4px; }
.msg .media { display: inline-block; font-size: 12px; background: var(--bg); border-radius: 4px; padding: 0 6px; margin-bottom: 4px; }
.msg.email { max-width: 85%; }
.msg.email .body { max-height: 320px; overflow: auto; }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; display: grid; gap: 6px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: vertical; min-height: 44px; max-height: 240px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; }
.composer .err:empty { display: none; }
.composer button:disabled { opacity: .6; cursor: wait; }
.panel { padding: 24px 32px; overflow-y: auto; }
.panel h2 { font-size: 17px; margin: 24px 0 12px; }
.panel h2:first-child { margin-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tenant-block { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.tenant-block h3 { margin: 0 0 12px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.ch { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.ch .name { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); margin-right: 6px; }
.dot.online { background: var(--wa); } .dot.error, .dot.logged_out, .dot.qr_expired { background: var(--danger); }
.dot.pending_qr, .dot.reconnecting, .dot.connecting { background: var(--mail); }
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
dialog { border: 0; border-radius: 12px; padding: 24px; background: var(--panel); color: var(--text); text-align: center; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.qr-box { width: 320px; height: 320px; max-width: 86vw; max-height: 86vw; display: grid; place-items: center; margin: 12px auto; background: #fff; color: #333; }
.qr-box img { width: 100%; height: 100%; }

@media (max-width: 760px) {
  .list { width: 100%; }
  .inbox.chat-open .list { display: none; }
  .inbox:not(.chat-open) .chat { display: none; }
  .msg { max-width: 90%; }
  .panel { padding: 16px; }
}

/* ---- v4：头像、媒体、引用、表情、状态 ---- */
.avatar { overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.chat-head { display: flex; align-items: center; gap: 10px; }
.chat-head #backBtn { padding: 2px 10px; display: none; }
.chat-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.chat-title span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loading { padding: 24px; text-align: center; color: var(--muted); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; opacity: .7; }
@keyframes spin { to { transform: rotate(360deg); } }
.conn-bar { background: #fde68a; color: #7c5a00; text-align: center; padding: 4px; font-size: 12px; }
.msg-list .more { align-self: center; font-size: 12px; padding: 4px 12px; }
.msg { position: relative; }
.msg.flash { outline: 2px solid var(--accent); }

.msg .acts { position: absolute; top: -14px; right: 6px; display: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 1px 4px; box-shadow: 0 2px 8px rgba(0,0,0,.12); z-index: 2; white-space: nowrap; }
.msg.in .acts { right: auto; left: 6px; }
.msg:hover .acts { display: flex; }
.msg .acts button { background: transparent; color: var(--text); padding: 2px 6px; font-size: 14px; border-radius: 10px; }
.msg .acts button:hover { background: var(--bg); }
.react-pop { position: absolute; top: -44px; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 8px; display: flex; gap: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.18); z-index: 3; font-size: 20px; }
.msg.in .react-pop { right: auto; left: 0; }
.react-pop span { cursor: pointer; transition: transform .1s; }
.react-pop span:hover { transform: scale(1.3); }
.reactions { position: absolute; bottom: -12px; right: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 5px; font-size: 13px; line-height: 20px; }
.msg:has(.reactions) { margin-bottom: 10px; }
.quoted { border-left: 3px solid var(--accent); background: rgba(0,0,0,.06); border-radius: 6px; padding: 4px 8px; margin-bottom: 6px;
  font-size: 12px; cursor: pointer; display: flex; flex-direction: column; max-height: 62px; overflow: hidden; }
.quoted b { color: var(--accent); }
.msg a.img { display: block; margin-bottom: 4px; }
.msg a.img img { max-width: 280px; max-height: 300px; border-radius: 8px; display: block; background: var(--bg); min-height: 40px; min-width: 60px; }
.msg a.img.sticker img { max-width: 130px; max-height: 130px; background: transparent; }
.msg a.img .broken-tip { display: none; font-size: 12px; color: var(--muted); }
.msg a.img.broken img { display: none; } .msg a.img.broken .broken-tip { display: inline; }
.msg video.vid { max-width: 300px; max-height: 320px; border-radius: 8px; display: block; margin-bottom: 4px; }
.msg audio { width: 250px; max-width: 100%; display: block; margin-bottom: 4px; }
.msg a.file, .msg .file { display: flex; gap: 10px; align-items: center; background: rgba(0,0,0,.06); border-radius: 8px; padding: 8px 10px;
  text-decoration: none; color: inherit; margin-bottom: 4px; }
.file-ico { font-size: 24px; } .file-meta { display: flex; flex-direction: column; min-width: 0; }
.file-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; } .file-meta small { color: var(--muted); }
.msg .body a { color: var(--accent); }
.tick { margin-left: 4px; letter-spacing: -3px; color: var(--muted); } .tick.read { color: #34b7f1; }
.composer { position: relative; }
.composer .bar { display: flex; justify-content: space-between; gap: 8px; align-items: center; background: var(--bg); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.composer .bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer .bar button { background: transparent; color: var(--muted); padding: 0 6px; }
.composer button.icon { background: transparent; color: var(--text); padding: 6px 8px; font-size: 18px; }
.composer button.icon:hover { background: var(--bg); }
.emoji-panel { position: absolute; bottom: 100%; left: 8px; width: 330px; max-width: calc(100% - 16px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px; display: flex; flex-wrap: wrap; gap: 2px; box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 5; }
.emoji-panel span { font-size: 22px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; border-radius: 6px; }
.emoji-panel span:hover { background: var(--bg); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 90vh; border-radius: 4px; }
.lightbox .dl { position: fixed; top: 16px; right: 20px; color: #fff; text-decoration: none; background: rgba(255,255,255,.15); padding: 6px 12px; border-radius: 6px; }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: #111; color: #fff; padding: 8px 16px; border-radius: 8px; z-index: 60; font-size: 13px; }
.toast.bad { background: var(--danger); }
@media (max-width: 760px) { .chat-head #backBtn { display: inline-block; } .msg .acts { display: flex; top: -12px; opacity: .85; } }

/* ---- v6：未读、客户详情、权限 ---- */
.rail button { position: relative; }
.rail-badge { position: absolute; top: 2px; right: 2px; background: var(--danger); color: #fff; border-radius: 9px; font-size: 10px; font-style: normal;
  min-width: 18px; height: 18px; line-height: 18px; padding: 0 4px; text-align: center; }
.unread-bar { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.unread-bar label { cursor: pointer; display: flex; gap: 4px; align-items: center; }
.conv.unread .conv-name { font-weight: 700; } .conv.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv.unread .conv-time { color: var(--wa); font-weight: 600; }
.badge { background: var(--wa); min-width: 20px; height: 20px; line-height: 20px; text-align: center; font-size: 12px; font-weight: 600; }
.conv .avatar { cursor: pointer; } .conv .avatar:hover { box-shadow: 0 0 0 2px var(--accent); }
.chat-head .who { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; padding: 2px 6px; border-radius: 8px; }
.chat-head .who:hover { background: var(--bg); }
.no-reply { border-top: 1px solid var(--line); background: var(--panel); padding: 12px; text-align: center; color: var(--muted); }
.detail { width: 320px; flex: none; border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; position: relative; }
.detail .close { position: absolute; top: 10px; right: 10px; padding: 2px 8px; }
.detail .d-head { text-align: center; margin: 12px 0 16px; } .detail h3 { margin: 10px 0 2px; word-break: break-all; }
.avatar.lg { width: 96px; height: 96px; font-size: 36px; margin: 0 auto; }
.detail dl { display: grid; grid-template-columns: 76px 1fr; gap: 6px 8px; margin: 0 0 16px; font-size: 13px; }
.detail dt { color: var(--muted); } .detail dd { margin: 0; word-break: break-all; }
.detail label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.detail input, .detail textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
.detail #dSave { margin-top: 10px; width: 100%; }
.user-form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.perm-box { display: grid; gap: 6px; margin: 4px 0 10px; }
.perm-box h4 { margin: 10px 0 2px; font-size: 13px; }
.perm-box label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.perm-box .chlist { display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 8px 10px; background: var(--bg); border-radius: 8px; }
.perm-box .chlist.dim { opacity: .45; pointer-events: none; }
.perm-box .pgroup { display: grid; gap: 4px; align-content: start; }
.tbl td { vertical-align: top; } .tbl .ops { white-space: nowrap; text-align: right; } .tbl .ops button { margin-left: 4px; padding: 4px 10px; }
.edit-row td { background: var(--bg); }
@media (max-width: 1100px) { .detail { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -6px 0 24px rgba(0,0,0,.2); max-width: 100%; } }

/* ---- v7：日夜切换、翻译 ---- */
#themeBtn .sun { display: none; } #themeBtn.is-dark .sun { display: inline; } #themeBtn.is-dark .moon { display: none; }
.msg .tr { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); white-space: pre-wrap; color: var(--text); opacity: .92; }
.msg .tr i { font-style: normal; font-size: 11px; background: var(--accent); color: #fff; border-radius: 4px; padding: 0 4px; margin-right: 6px; }
.msg.translating { opacity: .6; } .msg.translating::after { content: "翻译中…"; position: absolute; right: 8px; bottom: -16px; font-size: 11px; color: var(--muted); }
.msg .acts button[data-act=tr] { font-size: 12px; font-weight: 600; }
.tr-box { display: flex; flex-direction: column; gap: 4px; }
.tr-box select { padding: 3px 6px; font-size: 12px; max-width: 120px; } .tr-box button { padding: 4px 10px; }
.auto-tr { margin-left: auto; font-size: 12px; display: flex; gap: 4px; align-items: center; cursor: pointer; white-space: nowrap; color: var(--muted); }
.lightbox, .toast { color-scheme: dark; }
:root[data-theme=dark] .qr-box, .qr-box { color: #333; }

/* ---- v8：语言条、资料、AI ---- */
.lang-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 5px 16px; font-size: 12px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--muted); }
.lang-bar b { color: var(--text); } .lang-bar select { padding: 2px 6px; font-size: 12px; max-width: 130px; }
.lang-bar .auto-tr { margin-left: auto; }
.tr-box select { max-width: 150px; }
.md h4 { margin: 12px 0 4px; font-size: 13px; color: var(--accent); } .md h4:first-child { margin-top: 0; }
.md p { margin: 2px 0; } .md ul { margin: 2px 0; padding-left: 18px; } .md li { margin: 2px 0; }
.small { font-size: 11px; margin-top: 8px; }
.sum { background: var(--bg); border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.sum-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; } .sum-head button { padding: 2px 10px; font-size: 12px; }
.kb-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
#kbText { width: 100%; font: inherit; line-height: 1.6; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; resize: vertical; }
.dg-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px 16px; max-height: 300px; overflow-y: auto; padding: 8px; background: var(--bg); border-radius: 8px; }
.dg-list label { display: flex; gap: 6px; align-items: baseline; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dgOut .md { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; }
#dgOut .md h4 { font-size: 15px; margin-top: 18px; }
.dg-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .dg-meta button { padding: 3px 10px; }

/* ---- v9：AI 模型分配 ---- */
.task-row { display: grid; grid-template-columns: 80px minmax(160px, 260px) 170px auto 1fr; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.task-row .hint { font-size: 12px; } .task-row .result { grid-column: 2 / -1; font-size: 12px; } .task-row .result:empty { display: none; }
.task-row .result.err { color: var(--danger); } .task-row button { padding: 4px 12px; }
@media (max-width: 900px) { .task-row { grid-template-columns: 1fr 1fr; } .task-row .hint { grid-column: 1 / -1; } }

/* ---- v10：汇总选项与跳转链接 ---- */
.dg-form { display: grid; gap: 10px; }
.dg-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dg-line > b { width: 96px; flex: none; font-size: 13px; }
.dg-checks { display: flex; gap: 6px 16px; flex-wrap: wrap; } .dg-checks label { display: flex; gap: 4px; align-items: center; cursor: pointer; }
a.conv-link { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent); cursor: pointer; }
a.conv-link:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.dg-meta { align-items: flex-start; gap: 12px; }

/* ---- v11：录语音 ---- */
#micBtn.recording { background: var(--danger); color: #fff; font-size: 13px; border-radius: 16px; padding: 6px 10px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }

/* ---- v12：手机端 ---- */
html, body { height: 100dvh; overscroll-behavior: none; }
@media (max-width: 760px) {
  /* 整体：左侧栏变成底部标签栏 */
  .app { flex-direction: column-reverse; height: 100dvh; }
  .rail { width: 100%; height: auto; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; overflow-x: auto; }
  .rail .spacer { display: none; }
  .rail button { width: auto; min-width: 52px; height: 48px; flex: 1; font-size: 10px; border-radius: 6px; }
  .rail button svg { width: 20px; height: 20px; }
  .rail button.active { box-shadow: inset 0 3px 0 var(--accent); }
  .rail-badge { right: calc(50% - 22px); }
  .view { min-height: 0; flex: 1; overflow: hidden; }
  .view.panel { overflow-y: auto; padding: 14px 12px 24px; }
  /* 打开聊天时隐藏底部标签栏，把高度让给对话 */
  .app:has(.inbox.chat-open:not(.hidden)) .rail { display: none; }

  /* 输入框 16px，避免 iPhone 点输入框时页面被放大 */
  input, select, textarea, .composer textarea { font-size: 16px; }

  /* 会话列表 */
  .inbox { height: 100%; }
  .list { width: 100%; border-right: 0; }
  .list-head { padding: 8px 10px; gap: 6px; }
  .conv { padding: 12px; gap: 12px; }
  .avatar { width: 46px; height: 46px; font-size: 17px; }
  .conv-name { font-size: 15px; } .conv-preview { font-size: 14px; }
  .badge { min-width: 22px; height: 22px; line-height: 22px; }

  /* 聊天页 */
  .chat { height: 100%; }
  .chat-head { padding: 8px 10px; gap: 6px; position: sticky; top: 0; z-index: 4; }
  .chat-head #backBtn { display: inline-block; font-size: 22px; padding: 0 10px; border: 0; }
  .chat-title b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; display: block; }
  .lang-bar { padding: 4px 10px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  .lang-bar::-webkit-scrollbar { display: none; }
  .lang-bar select { font-size: 13px; } .lang-bar .auto-tr { margin-left: 0; }
  .msg-list { padding: 10px 8px 14px; gap: 10px; }
  .msg { max-width: 86%; font-size: 15px; padding: 8px 10px; } .msg.email { max-width: 94%; }
  .msg a.img img { max-width: 62vw; max-height: 46vh; } .msg video.vid { max-width: 70vw; } .msg audio { width: 62vw; }
  .file-meta b { max-width: 48vw; }
  /* 消息操作：手机上没有鼠标悬停，改为点一下消息显示 */
  .msg .acts { display: none; top: -34px; right: 0; opacity: 1; padding: 4px 6px; border-radius: 18px; }
  .msg.in .acts { left: 0; }
  .msg:hover .acts { display: none; }
  .msg.acts-on .acts { display: flex; }
  .msg .acts button { font-size: 18px; padding: 4px 10px; }
  .react-pop { top: -52px; font-size: 26px; gap: 8px; padding: 6px 12px; }

  /* 输入区 */
  .composer { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 4px; }
  .composer-row { gap: 2px; flex-wrap: wrap; align-items: center; }
  .composer textarea { order: 5; flex: 1 1 100%; min-height: 42px; max-height: 32vh; resize: none; padding: 9px 10px; }
  .composer button.icon { padding: 6px 8px; font-size: 20px; }
  .composer #sendBtn { order: 4; margin-left: auto; padding: 7px 18px; }
  .tr-box { flex-direction: row; align-items: center; order: 3; }
  .tr-box select { max-width: 34vw; font-size: 13px; padding: 5px 4px; }
  .composer .bar { font-size: 13px; }
  .emoji-panel { width: calc(100% - 16px); left: 8px; max-height: 40vh; overflow-y: auto; }
  .emoji-panel span { width: 12.5%; height: 42px; font-size: 24px; }
  .no-reply { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

  /* 客户详情：全屏 */
  .detail { position: fixed; inset: 0; width: 100%; z-index: 30; padding: 14px 14px calc(20px + env(safe-area-inset-bottom)); box-shadow: none; }
  .detail .close { position: sticky; top: 0; float: right; font-size: 18px; padding: 4px 12px; background: var(--panel); z-index: 1; }

  /* 管理页面 */
  .panel h2 { font-size: 16px; margin: 18px 0 10px; }
  .row { gap: 6px; } .row > input, .row > select { flex: 1 1 100%; min-width: 0 !important; width: auto !important; }
  .row > button { flex: 0 0 auto; }
  .tenant-block { padding: 12px; }
  .ch { flex-wrap: wrap; gap: 6px 10px; } .ch .name { flex: 1 1 60%; font-weight: 600; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; } .tbl thead { display: none; }
  .tbl tr { border-bottom: 1px solid var(--line); padding: 8px 0; } .tbl td { border: 0; padding: 3px 10px; }
  .tbl .ops { text-align: left; white-space: normal; } .tbl .ops button { margin: 4px 6px 0 0; }
  .perm-box label { align-items: flex-start; padding: 3px 0; } .perm-box .chlist { flex-direction: column; gap: 8px; }
  .task-row { grid-template-columns: 1fr; gap: 6px; } .task-row .result { grid-column: 1; }
  .dg-line > b { width: 100%; } .dg-line select, .dg-line input { flex: 1 1 100%; }
  .dg-list { grid-template-columns: 1fr; max-height: 40vh; } .dg-meta { flex-direction: column; }
  #dgOut .md { padding: 12px 14px; } .kb-tabs button { flex: 1 1 auto; } #kbText { min-height: 50vh; }
  .lightbox img { max-width: 100vw; max-height: 86dvh; }
  .toast { bottom: 110px; max-width: 86vw; text-align: center; }
  dialog { max-width: 94vw; padding: 18px; } .qr-box, .qr-box img { width: 250px; height: 250px; }
  .login-card { width: min(92vw, 340px); padding: 26px 22px; }
}

/* ---- v13：通知、超时、分配、标签、模板、安全 ---- */
.bar-ops { display: flex; gap: 4px; align-items: center; }
.bar-ops select { padding: 2px 4px; font-size: 12px; max-width: 120px; }
.icon-sm { background: transparent; color: var(--text); padding: 0 4px; font-size: 15px; }
.wait { color: var(--muted); } .wait.over { color: var(--danger); font-weight: 600; }
.chip { display: inline-block; font-style: normal; font-size: 11px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-radius: 8px; padding: 0 6px; margin-left: 4px; }
.conv .tag { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-ops { margin-left: auto; display: flex; gap: 6px; align-items: center; flex: none; } .head-ops button { padding: 3px 10px; font-size: 12px; }
.offline-bar { background: #fecaca; color: #7f1d1d; padding: 5px 14px; font-size: 13px; } .offline-bar a { color: inherit; font-weight: 600; }
.tpl-panel { position: absolute; bottom: 100%; left: 8px; width: 420px; max-width: calc(100% - 16px); max-height: 46vh; display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 5; padding: 8px; gap: 6px; }
#tplList { overflow-y: auto; } .tpl { padding: 7px 8px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; }
.tpl:hover { background: var(--bg); } .tpl span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.tpl-row p { margin: 4px 0 0; white-space: pre-wrap; color: var(--muted); } .tpl-row button { flex: none; padding: 3px 10px; }
#tplForm textarea, .user-form textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.tf-setup { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; align-items: flex-start; } .tf-setup img { background: #fff; border-radius: 8px; }
.tf-setup p { margin: 0 0 8px; } .tf-setup code { background: var(--bg); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
#genForm label { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#auditRows td { font-size: 13px; }
@media (max-width: 760px) { .tpl-panel { width: calc(100% - 16px); } .head-ops .chip { display: none; } .bar-ops select { font-size: 13px; } }

/* ---- v14：配对码、汇总历史 ---- */
.pair-box { margin: 10px 0; font-size: 13px; } .pair-box summary { cursor: pointer; color: var(--accent); }
.pair-code { font-size: 26px; letter-spacing: 3px; color: var(--text); font-family: Consolas, monospace; }
.dg-history { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 4px 0 10px; } .dg-history button { padding: 3px 10px; font-size: 12px; }
@media (max-width: 760px) { .qr-box, .qr-box img { width: 78vw !important; height: 78vw !important; } }

/* ---- v15：未读红标 ---- */
.badge { background: #ef4444; color: #fff; box-shadow: 0 0 0 2px var(--panel); }
.conv.unread .conv-time { color: #ef4444; }
.conv.unread .avatar::after { content: ""; position: absolute; top: -1px; right: -1px; width: 11px; height: 11px; border-radius: 50%; background: #ef4444; border: 2px solid var(--panel); z-index: 1; }
.conv .avatar { overflow: visible; } .conv .avatar img, .conv .avatar span { border-radius: 50%; } .conv .avatar img { overflow: hidden; }
.conv.unread { background: color-mix(in srgb, #ef4444 5%, transparent); }

/* ---- v16：拖拽与多文件 ---- */
.chat { position: relative; }
.drop-mask { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 16%, transparent); border: 3px dashed var(--accent); border-radius: 10px; margin: 6px; backdrop-filter: blur(2px); }
.drop-mask div { background: var(--panel); padding: 18px 28px; border-radius: 12px; text-align: center; box-shadow: 0 8px 28px rgba(0,0,0,.2); display: grid; gap: 4px; }
.drop-mask b { font-size: 17px; } .drop-mask span { color: var(--muted); font-size: 13px; }
.drop-mask.deny { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.file-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; max-height: 150px; overflow-y: auto; padding: 2px 0; }
.fchip { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px 4px 4px; max-width: 240px; }
.fchip img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex: none; }
.fchip .fico { width: 44px; height: 44px; display: grid; place-items: center; font-size: 24px; flex: none; }
.fchip .fname { display: flex; flex-direction: column; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fchip .fname small { color: var(--muted); }
.fchip button { background: transparent; color: var(--muted); padding: 0 4px; flex: none; } .fchip button:hover { color: var(--danger); }
.fhint { font-size: 12px; }

/* ---- v17：公司文件 ---- */
#libList { overflow-y: auto; display: grid; gap: 2px; }
.libitem { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.libitem:hover { background: var(--bg); }
.libitem img, .libcard img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex: none; background: var(--bg); }
.libitem .fico, .libcard .fico { width: 44px; height: 44px; display: grid; place-items: center; font-size: 26px; flex: none; }
.libitem div { display: flex; flex-direction: column; min-width: 0; } .libitem small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; }
.libcard { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.libcard img, .libcard .fico { width: 56px; height: 56px; }
.libmeta { display: flex; flex-direction: column; min-width: 0; gap: 1px; font-size: 13px; }
.libmeta b, .libmeta small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .libmeta a { color: var(--accent); text-decoration: none; }
#libForm.dragging { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* ---- v19：搜索结果、统计、客户资料 ---- */
.list { position: relative; }
.msg-hits { border-top: 2px solid var(--line); max-height: 46%; overflow-y: auto; background: var(--panel); flex: none; }
.hits-head { position: sticky; top: 0; background: var(--bg); padding: 4px 12px; font-size: 12px; color: var(--muted); }
.hit { padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; } .hit:hover { background: var(--bg); }
.hit-top { display: flex; justify-content: space-between; font-size: 13px; } .hit-top span { color: var(--muted); font-size: 12px; }
.hit-body { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hit-body i { font-style: normal; } mark { background: #fde047; color: #111; border-radius: 2px; }
.msg .tr.asr i { background: var(--mail); }
.chip.stage { background: color-mix(in srgb, var(--wa) 18%, transparent); color: #16803c; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; } .detail select { width: 100%; }
.d-export { display: block; margin-top: 12px; font-size: 13px; color: var(--accent); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.stat-cards div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
.stat-cards b { font-size: 22px; } .stat-cards span { color: var(--muted); font-size: 12px; }
.stat-cards .warn b { color: var(--mail); } .stat-cards .bad b { color: var(--danger); }
.panel h3 { font-size: 14px; margin: 18px 0 8px; }
.bars { display: flex; gap: 6px; align-items: flex-end; height: 150px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; min-width: 30px; flex: 1; font-size: 10px; color: var(--muted); }
.bar-pair { flex: 1; display: flex; gap: 2px; align-items: flex-end; width: 100%; justify-content: center; } .bar-pair i { width: 42%; max-width: 16px; min-height: 1px; border-radius: 3px 3px 0 0; }
.b-in { background: var(--accent); } .b-out { background: var(--wa); } .legend { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; }

/* ---- v21：账号页标签化 ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 20px; overflow-x: auto; }
.tabs button { background: transparent; color: var(--muted); border-radius: 0; padding: 10px 16px; font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--text); } .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pane-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.pane-head h2 { margin: 0 0 2px !important; font-size: 18px; } .pane-head p { margin: 0; }
.tab-pane { max-width: 1100px; }
.user-cards { display: grid; gap: 10px; }
.user-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.uc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.uc-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; background: var(--accent); flex: none; }
.uc-avatar.admin { background: #7c3aed; } .uc-avatar.tenant { background: var(--mail); }
.uc-name { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-size: 15px; }
.role { font-size: 11px; border-radius: 8px; padding: 1px 8px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.role.admin { background: color-mix(in srgb, #7c3aed 16%, transparent); color: #7c3aed; } .role.tenant { background: color-mix(in srgb, var(--mail) 20%, transparent); color: #b45309; }
.user-card .ops { display: flex; gap: 6px; flex: none; } .user-card .ops button { padding: 4px 12px; font-size: 13px; }
.danger-text { color: var(--danger) !important; }
.uc-line { display: flex; gap: 10px; align-items: flex-start; padding: 3px 0 3px 48px; font-size: 13px; flex-wrap: wrap; }
.uc-k { color: var(--muted); width: 60px; flex: none; } .uc-line .chip { margin-left: 0; margin-right: 4px; font-size: 12px; padding: 1px 8px; }
.chip.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.uc-perms { display: flex; flex-wrap: wrap; gap: 4px 14px; flex: 1; min-width: 0; } .uc-g b { color: var(--muted); font-weight: 500; margin-right: 6px; font-size: 12px; }
.uc-edit:not(:empty) { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.perm-step { display: flex; gap: 12px; margin-top: 12px; } .perm-step > div { flex: 1; min-width: 0; }
.step-no { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 12px; flex: none; margin-top: 1px; }
.perm-box h4 { margin: 0 0 8px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.presets { font-weight: 400; font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; flex-wrap: wrap; } .presets button { padding: 2px 10px; font-size: 12px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.perm-card { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; align-content: start; }
.perm-card > b { font-size: 12px; color: var(--muted); font-weight: 600; }
.perm-card label { align-items: flex-start !important; } .perm-card label span { display: flex; flex-direction: column; line-height: 1.35; }
.perm-card small { color: var(--muted); font-size: 11px; } .perm-card input { margin-top: 3px; }
#newUserBox { margin-bottom: 14px; }
@media (max-width: 760px) { .uc-head { flex-wrap: wrap; } .user-card .ops { width: 100%; padding-left: 48px; flex-wrap: wrap; } .uc-line { padding-left: 0; } .pane-head { flex-direction: column; } .tabs button { padding: 10px 12px; } }

/* ---- v22：免打扰、批量选择 ---- */
.conv.muted { opacity: .55; } .conv.muted:hover, .conv.muted.active { opacity: .85; }
.conv.muted .badge, .conv.muted .wait { display: none; }
.mini { padding: 1px 8px !important; font-size: 12px; }
.conv .pick { width: 18px; height: 18px; flex: none; align-self: center; pointer-events: none; }
.conv.picked { background: color-mix(in srgb, var(--accent) 14%, transparent) !important; }
.batch-bar { border-bottom: 1px solid var(--line); background: var(--bg); padding: 8px 10px; display: grid; gap: 6px; font-size: 13px; }
.bb-top { display: flex; justify-content: space-between; align-items: center; } .bb-top label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.bb-ops { display: flex; gap: 5px; flex-wrap: wrap; } .bb-ops button, .bb-ops select { padding: 3px 9px; font-size: 12px; }
#muteBtn { padding: 3px 10px; font-size: 12px; }

/* ---- v23：负责人角色 ---- */
.uc-avatar.manager { background: #0d9488; } .role.manager { background: color-mix(in srgb, #0d9488 18%, transparent); color: #0d9488; }

/* ---- v26：输入区重排，手机端防遮挡 ---- */
.tools { display: contents; } .input-row { display: contents; }
.composer-row textarea { order: 2; } .composer-row .tr-box { order: 3; } .composer-row #sendBtn { order: 4; }
.composer .bar span { min-width: 0; }
@media (max-width: 760px) {
  .app { height: var(--app-h, 100dvh); }
  html, body { height: var(--app-h, 100dvh); overflow: hidden; }
  /* 输入区：上面一排工具（可左右滑），下面是输入框 + 发送，发送按钮永远贴着输入框 */
  .composer { max-height: 62%; overflow: visible; }
  .composer-row { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 4px; }
  .tools { display: flex; align-items: center; gap: 0; overflow-x: auto; scrollbar-width: none; flex: none; }
  .tools::-webkit-scrollbar { display: none; }
  .tools > button.icon { flex: none; }
  .tools .tr-box { order: 0; margin-left: auto; flex: none; flex-direction: row; gap: 4px; padding-left: 6px; }
  .input-row { display: flex; align-items: flex-end; gap: 6px; }
  .input-row textarea, .composer .input-row textarea { order: 0; flex: 1 1 auto; min-width: 0; min-height: 44px; max-height: none; resize: none; }
  .input-row #sendBtn, .composer .input-row #sendBtn { order: 0; margin: 0; flex: none; height: 44px; padding: 0 16px; }
  /* 引用 / 原文 / 待发送文件：各自限高，不把输入框挤出屏幕 */
  .composer .bar { max-height: 30px; flex: none; }
  .composer .bar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .file-bar { max-height: 62px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; flex: none; }
  .fchip { flex: none; max-width: 200px; } .fchip img, .fchip .fico { width: 36px; height: 36px; } .fhint { flex: none; }
  #mailSubject { flex: none; }
  /* 弹层：从输入区上方弹出，限高并盖在消息之上 */
  .emoji-panel, .tpl-panel { max-height: min(44vh, calc(var(--app-h, 100dvh) - 220px)); bottom: calc(100% + 2px); z-index: 12; }
  /* 消息操作按钮：放到消息下面，不会被顶部栏或相邻消息挡住 */
  .msg .acts, .msg.in .acts { position: static; display: none; margin: 6px 0 0; box-shadow: none; border-radius: 12px; width: fit-content; }
  .msg.acts-on .acts { display: flex; flex-wrap: wrap; }
  .react-pop, .msg.in .react-pop { position: static; margin-top: 6px; width: fit-content; }
  /* 我方发的短消息：表情条比气泡宽，靠右对齐往左伸，不能伸出屏幕右边 */
  .msg.out .react-pop { position: relative; left: 100%; transform: translateX(-100%); max-width: calc(100vw - 20px); }
  .msg:has(.reactions) { margin-bottom: 14px; }
  /* 批量栏：按钮排成一行可左右滑 */
  .bb-ops { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; } .bb-ops::-webkit-scrollbar { display: none; }
  .bb-ops button, .bb-ops select { flex: none; }
  .unread-bar { gap: 6px; } .bar-ops select { max-width: 104px; }
  .head-ops { gap: 4px; } .head-ops button { padding: 3px 8px; }
  .chat-title b { max-width: 42vw; }
  .msg-hits { max-height: 50%; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 130px); }
  .detail, .lightbox { height: var(--app-h, 100dvh); }
  dialog { max-height: calc(var(--app-h, 100dvh) - 24px); overflow-y: auto; }
}

/* 输入区是网格布局：必须允许子项收缩，否则一行很长的原文/工具条会把整列撑宽，发送按钮被挤出屏幕 */
.composer { grid-template-columns: minmax(0, 1fr); }
.composer > * { min-width: 0; }
.composer .bar { overflow: hidden; }
@media (max-width: 760px) {
  /* 工具排一行放得下：图标收窄，语言下拉限宽，翻译按钮始终可见 */
  .tools > button.icon { padding: 6px 5px; font-size: 19px; }
  .tools .tr-box select { max-width: 24vw; font-size: 12px; padding: 5px 2px; }
  .tools .tr-box button { padding: 5px 9px; white-space: nowrap; }
}
@media (max-width: 345px) {
  .tools > button.icon { padding: 6px 3px; font-size: 18px; }
  .tools .tr-box { padding-left: 2px; } .tools .tr-box select { max-width: 19vw; } .tools .tr-box button { padding: 5px 6px; }
}

/* ---- v27：翻译调节 ---- */
.tr-box { flex-direction: row; align-items: center; gap: 4px; }
.tr-gear { padding: 4px 6px !important; font-size: 16px !important; }
.tr-opts { left: auto; right: 8px; width: 340px; padding: 12px 14px; gap: 6px; }
.tr-opts h4 { margin: 0 0 4px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.tr-opts label { font-size: 12px; color: var(--muted); margin-top: 6px; display: block; } .tr-opts label b { color: var(--text); font-size: 13px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { background: var(--bg); color: var(--text); border: 1px solid var(--line); padding: 5px 10px; font-size: 13px; border-radius: 16px; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tr-opts input[type=range] { width: 100%; padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
.range-ends { display: flex; justify-content: space-between; font-size: 11px; margin-top: -4px; }
.tr-opts select { width: 100%; }
@media (max-width: 760px) {
  .tr-opts { left: 8px; right: 8px; width: auto; }
  .tools .tr-box select { max-width: 20vw; }
  .tr-gear { padding: 4px 4px !important; }
}
@media (max-width: 345px) { .tools .tr-box select { max-width: 16vw; } .tools > button.icon { padding: 6px 2px; } }

/* ---- v28：手动已读回执 ---- */
#receiptBtn { padding: 3px 10px; font-size: 12px; background: #34b7f1; white-space: nowrap; }
.norc { color: #0e8fc7; }
@media (max-width: 760px) { #receiptBtn { padding: 3px 7px; } .chat-title b { max-width: 34vw; } }

/* ---- v30：只看不清未读、标为未读 ---- */
#peekBtn.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); border-color: var(--accent); }
#unreadBtn { padding: 3px 10px; font-size: 12px; white-space: nowrap; }
@media (max-width: 760px) {
  /* 顶部按钮多了：手机上单独占一行，标题不被挤没 */
  #chatHead { flex-wrap: wrap; row-gap: 4px; }
  .head-ops { flex: 1 0 100%; max-width: 100%; justify-content: flex-end; overflow-x: auto; scrollbar-width: none; } .head-ops::-webkit-scrollbar { display: none; }
  .head-ops > * { flex: none; }
  .unread-bar { flex-wrap: wrap; }
}

/* ---- v31：二维码放大、保持锐利 ---- */
.qr-box { width: 380px; height: 380px; } .qr-box img { image-rendering: pixelated; }
@media (max-width: 760px) { .qr-box, .qr-box img { width: 84vw !important; height: 84vw !important; max-width: 84vw; max-height: 84vw; } }

/* ---- v32：页面内输入 / 确认弹窗（替代浏览器自带的 prompt、confirm） ---- */
dialog.ask { width: 360px; max-width: calc(100vw - 32px); box-sizing: border-box; padding: 20px; text-align: left; }
dialog.ask p { margin: 0 0 14px; line-height: 1.6; white-space: pre-line; word-break: break-word; }
.ask-row { display: flex; gap: 8px; margin-bottom: 16px; } .ask-row input { flex: 1; min-width: 0; font-size: 16px; padding: 9px 10px; } .ask-row button { flex: none; }
.ask-btns { display: flex; justify-content: flex-end; gap: 10px; } .ask-btns button { min-width: 84px; padding: 9px 14px; }

/* ---- v33：资料页按账号归拢（介绍 + 文件） ---- */
.kb-tabs { margin-bottom: 14px; } .kb-tabs button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 7px 12px; text-align: left; }
.kb-tabs button small { font-size: 11px; opacity: .75; font-weight: 400; }
#view-kb h3 { margin: 18px 0 6px; font-size: 15px; } #view-kb h3 small { font-weight: 400; font-size: 12px; margin-left: 6px; }
.warn-text { color: var(--danger); font-weight: 500; }
.lib-filter { margin: 10px 0; gap: 8px; } .seg { display: inline-flex; gap: 4px; } .seg button { padding: 4px 12px; font-size: 13px; }
.libcard.img img { width: 72px; height: 72px; cursor: zoom-in; } .libcard.img > a { flex: none; line-height: 0; }
.lib-common { margin-top: 14px; } .lib-common summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
.ask-row select { flex: 1; min-width: 0; font-size: 16px; padding: 9px 10px; }
@media (max-width: 760px) { .lib-grid { grid-template-columns: minmax(0, 1fr); } .kb-tabs button { flex: 1 1 40%; } #libForm .row > * { flex: 1 1 100%; max-width: 100% !important; min-width: 0 !important; } }

/* ---- v33：单个会话转给其他账号团队 ---- */
.handed { color: var(--accent); white-space: nowrap; }
#dShare { width: 100%; }

/* ---- v34：登录页密码显示/隐藏，动态码直接填 ---- */
.pw-wrap { position: relative; display: block; } .pw-wrap input { width: 100%; box-sizing: border-box; padding-right: 64px; }
.pw-wrap button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 4px 10px; font-size: 13px; border: 0; background: transparent; color: var(--accent); }

/* ---- v36：公司文件多选、AI 报价、汇总板块排版 ---- */
.libck { width: 20px; height: 20px; flex: none; border: 1.5px solid var(--line); border-radius: 5px; display: grid; place-items: center; font-size: 13px; color: #fff; }
.libitem.sel { background: color-mix(in srgb, var(--accent) 10%, transparent); } .libitem.sel .libck { background: var(--accent); border-color: var(--accent); }
#libList { overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.lib-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px 2px; border-top: 1px solid var(--line); flex: none; font-size: 13px; }
.lib-foot:empty { display: none; } .libfoot-btns { display: flex; gap: 6px; flex: none; } .lib-foot button { padding: 6px 12px; }
dialog.quote { width: 640px; max-width: calc(100vw - 24px); box-sizing: border-box; padding: 18px; text-align: left; max-height: calc(var(--app-h, 100dvh) - 24px); }
dialog.quote[open] { display: flex; flex-direction: column; } dialog.quote h3 { margin: 0 0 10px; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-top { display: flex; gap: 8px; margin-bottom: 10px; flex: none; } .quote-top input { flex: 1; min-width: 0; } .quote-top button { flex: none; }
.quote-out { overflow-y: auto; min-height: 80px; flex: 1 1 auto; margin-bottom: 12px; overflow-wrap: anywhere; } .quote-out .md { white-space: normal; }
.quote-info { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); line-height: 1.7; }
.quote-hist { display: flex; gap: 8px; margin-bottom: 10px; flex: none; }
.quote-hist select { flex: 1; min-width: 0; font-size: 13px; } .quote-hist button { flex: none; padding: 6px 12px; font-size: 13px; }
.qtable { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.qtable th, .qtable td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.qtable th { font-weight: 600; color: var(--muted); font-size: 12px; white-space: nowrap; border-bottom: 1px solid var(--text); }
.qtable th:nth-child(1), .qtable td:nth-child(1) { width: 34%; }
.qtable th:nth-child(2), .qtable td:nth-child(2) { width: 26%; }
.qtable th:nth-child(3), .qtable td:nth-child(3) { width: 18%; }
.qtable tbody tr:last-child td { border-bottom: 0; }
.qmiss { margin-top: 10px; font-size: 13px; color: var(--muted); }
@media (max-width: 400px) {
  .qtable { font-size: 11.5px; table-layout: fixed; }
  .qtable th, .qtable td { padding: 6px 3px; }
  .qtable th { font-size: 11px; }
  .qtable th:nth-child(1), .qtable td:nth-child(1) { width: 27%; }
  .qtable th:nth-child(2), .qtable td:nth-child(2) { width: 31%; }
  .qtable th:nth-child(3), .qtable td:nth-child(3) { width: 15%; }
  .qtable th:nth-child(4), .qtable td:nth-child(4) { width: 27%; }
}
.dg-checks label { white-space: nowrap; }
@media (max-width: 760px) {
  .quote-top { flex-wrap: wrap; } .quote-top input { flex: 1 1 100%; font-size: 16px; } .quote-top button { flex: 1 1 100%; }
  .qtable { font-size: 12px; } .qtable th, .qtable td { padding: 6px 4px; }
  .quote-hist select { font-size: 12px; } .quote-hist button { font-size: 12px; padding: 5px 9px; }
  /* 汇总板块：以前这块被挤成一条窄列，字一个一行竖着排 */
  .dg-line { align-items: flex-start; } .dg-checks { flex: 1 1 100%; min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
  .dg-checks label { white-space: normal; align-items: flex-start; line-height: 1.35; min-width: 0; } .dg-checks input { flex: none; margin-top: 2px; }
}
/* 工具栏多了一个报价按钮：手机上图标收窄一点，翻译按钮才不会被挤出屏幕 */
@media (max-width: 760px) { .tools > button.icon { padding-left: 3px; padding-right: 3px; } }
@media (max-width: 420px) { .tools > button.icon { padding-left: 2px; padding-right: 2px; font-size: 18px; } .tools .tr-box select { max-width: 18vw; } }
@media (max-width: 345px) { .tools > button.icon { padding-left: 1px; padding-right: 1px; font-size: 17px; } .tools .tr-box select { max-width: 15vw; } }

/* ---- v37：草稿、转发 ---- */
.draft { color: var(--danger); font-weight: 500; }
dialog.fwd { width: 440px; } dialog.fwd #fwdSearch { flex: none; margin-bottom: 8px; font-size: 16px; }
.fwd-what { flex: none; background: var(--bg); border-left: 3px solid var(--accent); border-radius: 6px; padding: 6px 10px; margin-bottom: 10px; font-size: 13px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
#fwdList { min-height: 160px; margin-bottom: 8px; } #fwdList .libitem .avatar, #fwdList .libitem img { width: 36px; height: 36px; flex: none; }
#fwdHint { flex: none; margin-bottom: 10px; }

/* ---- v38：置顶 ---- */
.conv.pinned { background: color-mix(in srgb, var(--accent) 6%, transparent); } .conv.pinned.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pin-ico { font-size: 11px; margin-right: 3px; } #pinBtn.on { color: var(--accent); border-color: var(--accent); }
@media (max-width: 760px) {
  /* 顶部按钮靠右排；放不下时从右边溢出、可以左右滑，而不是把最左边的按钮挤出屏幕 */
  .head-ops { justify-content: flex-start; } .head-ops > :first-child { margin-left: auto; }
}
@media (max-width: 360px) { .head-ops { gap: 3px; } .head-ops button { padding: 3px 5px; font-size: 11px; } }
@media (max-width: 420px) { .pin-t { display: none; } #pinBtn.on { background: color-mix(in srgb, var(--accent) 16%, transparent); } }

/* ---- v39：聊天内搜索 ---- */
.in-search { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.in-search input { flex: 1 1 auto; min-width: 0; padding: 6px 10px; } .in-search #inCount { flex: none; font-size: 12px; white-space: nowrap; }
.in-search button { flex: none; padding: 4px 9px; }
.in-hits { position: absolute; left: 12px; right: 12px; top: 100%; z-index: 8; max-height: min(46vh, 380px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 0 0 10px 10px; box-shadow: 0 10px 24px rgba(0,0,0,.16); }
.in-hits .hit.cur { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.msg.hit-now { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

/* ---- v39：桌面端窗口变窄时的排版 ---- */
@media (min-width: 761px) {
  /* 输入区分两行：上面一排工具，下面输入框和发送。以前挤在一行里，窗口一窄输入框就被压成一条竖线 */
  .composer-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
  .tools > button.icon { flex: none; }
  .tools .tr-box { order: 0; margin-left: auto; flex: none; }
  .input-row { display: flex; align-items: flex-end; gap: 8px; min-width: 0; }
  .input-row textarea, .composer .input-row textarea { order: 0; flex: 1 1 auto; min-width: 120px; }
  .input-row #sendBtn, .composer .input-row #sendBtn { order: 0; flex: none; }
  /* 会话顶部：放不下就换行，不把名字挤没、不撑出横向滚动条 */
  #chatHead { flex-wrap: wrap; row-gap: 6px; }
  #chatHead .who { flex: 1 1 180px; } .chat-title { min-width: 0; } .chat-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .head-ops { flex: 0 1 auto; flex-wrap: wrap; justify-content: flex-end; row-gap: 4px; min-width: 0; }
  .lang-bar { flex-wrap: wrap; row-gap: 4px; }
}
/* 任何宽度下按钮上的字都不竖排 */
button, .tr-box select { white-space: nowrap; }
.chat, .list, .msg-list { min-width: 0; } .chat { overflow: hidden; }
@media (max-width: 420px) { .head-ops { flex-wrap: wrap; justify-content: flex-end; row-gap: 4px; overflow-x: visible; } .head-ops > :first-child { margin-left: 0; } }

/* ---- v40：撤回的消息保留原文、划线显示；编辑过的保留第一版 ---- */
.revoked-tag { font-size: 11px; color: var(--danger); margin-bottom: 3px; font-weight: 500; }
.msg.deleted .body, .msg.deleted .subj, .msg.deleted .tr, .msg.deleted .file { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 70%, transparent); color: var(--muted); }
.msg.deleted img, .msg.deleted video { opacity: .5; } .msg.deleted { opacity: .92; }
.edited-orig { font-size: 12px; color: var(--muted); margin-bottom: 3px; overflow-wrap: anywhere; } .edited-orig s { text-decoration-color: color-mix(in srgb, var(--muted) 70%, transparent); }
.mx-kept { background: color-mix(in srgb, var(--danger) 8%, transparent); border-left: 3px solid var(--danger); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; font-size: 13px; line-height: 1.6; }
/* 键盘弹出、屏幕很矮时：顶部按钮不换行（省高度），放不下就左右滑 */
@media (max-width: 420px) and (max-height: 480px) { .head-ops { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; } .head-ops > :first-child { margin-left: auto; } }

/* ---- v41：权限表单里勾不了的项 ---- */
.perm-card label.dim { opacity: .45; cursor: not-allowed; }

/* ---- v42：桌面端宽屏和长名字 ---- */
/* 列表栏头部：账号下拉框里有很长的账号名时，会把整排撑得比列表栏还宽、伸到聊天区上面。现在头部严格跟列表栏同宽 */
.list-head { grid-template-columns: minmax(0, 1fr); } .list-head > * { min-width: 0; }
.list-head select, .list-head input { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
.unread-bar { flex-wrap: wrap; gap: 6px 8px; } .unread-bar > span:first-child { min-width: 0; } .bar-ops { margin-left: auto; flex: none; max-width: 100%; }
.bar-ops select, .list-head .bar-ops select { width: auto; max-width: 120px; }
#tenantFilter { text-overflow: ellipsis; }
/* 会话列表每行第三排：账号名太长时只截账号名，等待时长、未回执、标签不再被挤掉，放不下就换行 */
.conv-main { min-width: 0; flex: 1 1 auto; }
.conv .tag { display: flex; flex-wrap: wrap; align-items: center; column-gap: 3px; row-gap: 2px; white-space: normal; overflow: visible; }
.conv .tag .tag-ch { flex: 0 1 auto; min-width: 40px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .tag .chip, .conv .tag .handed { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .tag .wait, .conv .tag .norc { white-space: nowrap; flex: none; }
@media (min-width: 761px) {
  /* 列表栏宽度固定不被挤，宽屏上适当加宽 */
  .list { flex: none; width: clamp(320px, 24vw, 440px); }
  /* 超宽屏：气泡和各管理页内容不再无限拉宽 */
  .msg { max-width: min(70%, 820px); } .msg.email { max-width: min(80%, 980px); }
  .view.panel { padding-left: max(32px, calc((100% - 1560px) / 2)); padding-right: max(32px, calc((100% - 1560px) / 2)); }
}
/* 客户详情：名字很长时不要压到右上角的关闭按钮 */
.detail .d-head { padding: 0 30px; overflow-wrap: anywhere; } .detail .d-head h3, .detail .d-head b { overflow-wrap: anywhere; word-break: break-word; }
/* 长账号名：下拉框和页签不能把页面撑出横向滚动 */
.panel select, .panel input, .dg-line select, dialog select { max-width: 100%; min-width: 0; }
.kb-tabs button { white-space: normal; overflow-wrap: anywhere; min-width: 0; max-width: 100%; }
@media (max-width: 760px) {
  /* 客户名、账号名很长时，名字那块跟返回按钮留在同一行（以前会被挤到下一行，顶部变成三行） */
  #chatHead .who { flex: 1 1 0; min-width: 0; } #chatHead .chat-title { min-width: 0; overflow: hidden; flex: 1 1 auto; }
  #chatHead .chat-title b { max-width: 100%; }
}
/* AI 汇总的表单：同样的问题，长账号名的下拉框会把整张表单撑宽 */
.dg-form { grid-template-columns: minmax(0, 1fr); } .dg-form > *, .dg-line > * { min-width: 0; }
/* 其余单列网格容器一并加固：内容再长也不能把容器撑宽 */
.batch-bar, .perm-box, .perm-box .pgroup, .user-cards, .perm-card { grid-template-columns: minmax(0, 1fr); }
.batch-bar > *, .user-cards > *, .perm-card > * { min-width: 0; }

/* ---- 统计和 AI 汇总：WhatsApp / 邮箱 分开 ---- */
.kind-tabs { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 0 0 14px; background: var(--panel); }
.kind-tabs button { border: 0; border-radius: 0; background: transparent; color: var(--text); padding: 8px 22px; font-size: 14px; }
.kind-tabs button.on { background: var(--accent); color: #fff; font-weight: 600; }
.kind-tabs button + button { border-left: 1px solid var(--line); }
.stat-note { margin: 6px 0 14px; }
#view-stats .tbl td, #view-stats .tbl th { overflow-wrap: anywhere; }
.tbl-wrap { overflow-x: auto; max-width: 100%; }
a.mail-link { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent); cursor: pointer; }
.label-chips { display: flex; flex-wrap: wrap; gap: 6px 8px; margin: 4px 0 12px; } .label-chips span { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-size: 13px; } .label-chips b { margin-left: 6px; }
@media (max-width: 760px) { .kind-tabs { display: flex; } .kind-tabs button { flex: 1; padding: 10px 8px; }
  #view-stats .tbl td[data-l]::before { content: attr(data-l) "："; color: var(--muted); } }

/* 资料页：只读时的说明 */
.kb-lock { margin: 0 0 8px; padding: 8px 12px; border-radius: 8px; background: rgba(255,170,0,.12); border: 1px solid rgba(255,170,0,.45); font-size: 14px; line-height: 1.6; }
#kbText[readonly] { opacity: .75; cursor: not-allowed; }

/* AI 用量和费用（统计页、我的账号） */
.ai-cost { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; background: var(--panel); }
.ai-cost-h { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 8px; } .ai-cost-h span { font-size: 12px; }
.ai-cost-g { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.ai-cost-g > div { background: var(--bg); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.ai-cost-g span, .ai-cost-g small { font-size: 12px; color: var(--muted); } .ai-cost-g b { font-size: 19px; overflow-wrap: anywhere; }
.ai-cost p { margin: 8px 0 0; font-size: 12px; }
@media (max-width: 760px) { .ai-cost-g { grid-template-columns: 1fr 1fr; } }

/* AI 接口列表 */
#pvBox { margin-bottom: 12px; }
.pv-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 8px; background: var(--panel); min-width: 0; }
.pv-card.off { opacity: .65; }
.pv-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; } .pv-head b { overflow-wrap: anywhere; }
.pv-st { font-size: 12px; color: var(--muted); } .pv-st.ok { color: #16a34a; } .pv-st.bad, .pv-err { color: var(--danger); } .pv-st.off { color: var(--muted); }
.pv-line { font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; } .pv-line select { max-width: 100%; }
.pv-ops { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; } .pv-ops button { padding: 4px 10px; } .pv-res { font-size: 12px; flex: 1 1 100%; } .pv-res:empty { display: none; }
.pv-form { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); } .pv-form input { min-width: 0; }
.pv-note { margin: 0 0 8px; padding: 8px 12px; border-radius: 8px; background: rgba(255,170,0,.12); border: 1px solid rgba(255,170,0,.45); font-size: 13px; }
.pv-auto { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; font-size: 14px; } .pv-auto input { margin-top: 3px; flex: none; }
select.pv-bad { border-color: var(--danger); }
.task-row select { min-width: 0; max-width: 100%; }
@media (max-width: 760px) { .pv-form .row input { flex: 1 1 100% !important; min-width: 0 !important; } }

/* 我的 AI 用量 */
.ai-cost h4 { margin: 12px 0 6px; font-size: 14px; }
.ai-use-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ai-use { width: 100%; border-collapse: collapse; font-size: 13px; } .ai-use th, .ai-use td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
.ai-use th { color: var(--muted); font-weight: 500; } .ai-use small { font-size: 12px; }
.ai-cost details { margin-top: 8px; } .ai-cost summary { cursor: pointer; color: var(--muted); font-size: 13px; }
