:root{font-family:system-ui,"Microsoft YaHei",sans-serif;color:#1f2937;background:#f3f4f6}*{box-sizing:border-box}body{margin:0}.login-card{width:min(360px,calc(100% - 32px));margin:14vh auto;background:#fff;padding:28px;border-radius:12px;box-shadow:0 8px 28px #0002}.login-card h1{margin:0 0 6px}.login-card label{display:block;margin:16px 0 0;font-size:14px}.login-card input,.composer textarea{width:100%;margin-top:6px;padding:10px;border:1px solid #d1d5db;border-radius:7px;font:inherit}button{border:0;border-radius:7px;padding:9px 14px;background:#2563eb;color:white;cursor:pointer;font:inherit}button.quiet{background:#64748b}button.danger{background:#dc2626}.error{color:#dc2626;min-height:20px}header{height:56px;background:#111827;color:white;display:flex;align-items:center;gap:16px;padding:0 20px}header strong{font-size:18px}header #identity{margin-right:auto;color:#cbd5e1}.layout{display:grid;grid-template-columns:260px 260px 1fr;height:calc(100vh - 56px);gap:1px;background:#d1d5db}.layout>aside,.chat{background:white;min-width:0}.layout h2{font-size:15px;padding:12px;margin:0;border-bottom:1px solid #e5e7eb}.layout small{color:#6b7280}.list{overflow:auto;max-height:calc(100vh - 110px)}.item{padding:12px;border-bottom:1px solid #eef2f7;cursor:pointer}.item:hover,.item.selected{background:#eff6ff}.item b,.item span{display:block}.item span{font-size:12px;color:#64748b;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:4px}.chat{display:flex;flex-direction:column}.empty{margin:auto;color:#64748b}.chat-head{padding:12px;border-bottom:1px solid #e5e7eb;display:flex;gap:8px;align-items:center}.chat-head strong{margin-right:auto}.messages{flex:1;overflow:auto;padding:18px;background:#f8fafc}.msg{max-width:70%;padding:9px 11px;margin:8px 0;border-radius:9px;background:white;box-shadow:0 1px 2px #0001}.msg.agent{margin-left:auto;background:#dbeafe}.msg small{display:block;color:#64748b;margin-bottom:3px}.composer{padding:12px;border-top:1px solid #e5e7eb;display:flex;gap:10px}.composer textarea{margin:0;resize:none}.composer button{align-self:end}@media(max-width:900px){.layout{grid-template-columns:190px 1fr}.layout>aside:nth-child(2){display:none}}.admin-grid{padding:20px;display:grid;grid-template-columns:1fr 1fr;gap:18px}.panel{background:white;border-radius:10px;padding:16px;box-shadow:0 2px 10px #0001}.panel h2{margin-top:0}.form-row{display:flex;gap:8px;margin-bottom:14px}.form-row input{min-width:0;flex:1;padding:8px;border:1px solid #d1d5db;border-radius:6px}.admin-row{display:flex;justify-content:space-between;gap:10px;padding:10px 0;border-top:1px solid #e5e7eb}.admin-row button{padding:5px 9px}@media(max-width:800px){.admin-grid{grid-template-columns:1fr}.form-row{flex-wrap:wrap}}
.hint{font-size:13px;color:#6b7280;margin:0 0 12px}.hint b{color:#1f2937}.muted{font-size:12.5px;color:#6b7280;line-height:1.7}.mono{font-family:ui-monospace,Consolas,monospace;font-size:13px;background:#f8fafc;color:#334155}.tok-code{font-family:ui-monospace,Consolas,monospace;background:#0f172a;color:#dbeafe;padding:10px 12px;border-radius:8px;word-break:break-all;margin:4px 0 10px;cursor:text}#tok-new{margin-bottom:6px}#tok-list .admin-row span{overflow-wrap:anywhere}
html,body{height:100%;overflow:hidden}.chat{position:relative}#messages{scrollbar-width:thin;scrollbar-color:#cbd5e1 transparent}#messages::-webkit-scrollbar{width:8px}#messages::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:8px}.jumpbtns{position:absolute;right:14px;bottom:96px;display:flex;flex-direction:column;gap:8px;z-index:9}.jumpbtns button{width:34px;height:34px;border-radius:50%;padding:0;font-size:16px;line-height:1;background:#ffffff;color:#1f2937;border:1px solid #d1d5db;box-shadow:0 2px 8px #0002;opacity:.85}.jumpbtns button:hover{opacity:1;background:#eff6ff}
html,body{height:100%;overflow:hidden;margin:0}main#desk{height:100%;display:flex;flex-direction:column}main#desk>header{flex:none}main#desk .layout{flex:1 1 0;min-height:0;height:auto;display:grid;grid-template-columns:260px 260px minmax(0,1fr);grid-template-rows:minmax(0,1fr)}.layout>aside,.layout>.chat{min-width:0;min-height:0;overflow:hidden}.layout>aside{display:flex;flex-direction:column}aside h2{flex:none;padding:12px}aside .list{flex:1 1 0;min-height:0;max-height:none;overflow-y:auto}.chat{display:flex;flex-direction:column}.chat-head{flex:none}.messages{flex:1 1 0;min-height:0;overflow-y:auto;overflow-x:hidden}.composer{flex:none}
#conversation[hidden]{display:none}#conversation:not([hidden]){display:flex;flex-direction:column;flex:1 1 0;min-height:0;overflow:hidden}.chat #empty{flex:none;margin:auto}
.newpill{position:absolute;left:50%;transform:translateX(-50%);bottom:128px;background:#2563eb;color:#fff;padding:8px 18px;border-radius:999px;font-size:13px;box-shadow:0 3px 12px #0003;cursor:pointer;z-index:9;user-select:none;transition:opacity .15s;white-space:nowrap}.newpill:hover{opacity:1;background:#1d4ed8}.newpill.hot{background:#eff6ff;color:#1d4ed8;border:1px solid #93c5fd}.newpill.hot:hover{background:#dbeafe}
main#desk[hidden],main#login[hidden]{display:none!important}
dialog{border:0;border-radius:12px;padding:0;width:min(680px,92vw);box-shadow:0 12px 40px #0003}
dialog::backdrop{background:rgba(15,23,42,.45)}
.dhead{display:flex;align-items:center;gap:10px;padding:12px 16px;border-bottom:1px solid #e5e7eb}
.dhead b{flex:none;font-size:14px}
.dhead .muted{flex:1;font-size:12.5px}
.dbody{padding:14px 16px;overflow:auto;max-height:70vh}
.dhint{padding:8px;text-align:center}
.hist-conv{border:1px solid #e5e7eb;border-radius:10px;margin-bottom:12px;background:#fff;overflow:hidden}
.hist-head{display:block;cursor:pointer;font-size:12.5px;color:#475569;padding:11px 12px;line-height:1.55}
.hist-conv[open] .hist-head{border-bottom:1px dashed #e5e7eb;background:#f8fafc}
.hist-messages{padding:4px 12px 10px}
.hist-msg{max-width:85%;margin:6px 0;padding:6px 9px;border-radius:8px;background:#f1f5f9;font-size:13px}
.hist-msg small{display:block;color:#64748b;font-size:11.5px;margin-bottom:2px}
.hist-msg.hist-user{background:#eef6ff}
.hist-msg.hist-agent{background:#dbeafe;margin-left:auto}
.hist-msg.hist-system{background:transparent;color:#64748b;text-align:center;max-width:100%}
.chat-head #back-list { display:none; }
.context-summary { flex-basis:100%; padding:7px 9px; border-radius:6px; background:#fff7ed; color:#9a3412; font-size:12px; line-height:1.5; max-height:58px; overflow:auto; }

/* 移动端：工作台改为“列表 → 会话”单栏流程，保留所有操作但减少横向拥挤。 */
@media (max-width: 640px) {
  html, body { overflow: hidden; }
  header { height: 52px; padding: 0 10px; gap: 8px; }
  header strong { font-size: 16px; }
  header #identity { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  header button { padding: 7px 9px; }
  main#desk .layout { display: block; height: calc(100vh - 52px); }
  .layout > aside { height: 50%; min-height: 0; }
  .layout > aside h2 { padding: 9px 12px; }
  .layout > aside .list { max-height: none; }
  .layout > .chat { height: 50%; min-height: 0; }
  /* 选中会话后只显示聊天区；返回按钮由标题栏的客户历史旁操作完成前，点击列表项可重新进入 */
  .layout:has(#conversation:not([hidden])) > aside { display: none; }
  .layout:has(#conversation:not([hidden])) > .chat { height: 100%; }
  .chat-head { padding: 8px 10px; gap: 5px; flex-wrap: wrap; }
  .chat-head #back-list { display:block; }
  .chat-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-head button { padding: 7px 8px; font-size: 12px; }
  .messages { padding: 10px; }
  .msg { max-width: 88%; padding: 8px 10px; }
  .composer { padding: 8px; gap: 6px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .composer textarea { min-height: 42px; max-height: 110px; font-size: 16px; }
  .composer button { min-width: 54px; min-height: 42px; padding: 8px 10px; }
  .jumpbtns { right: 8px; bottom: 84px; }
  dialog { width: calc(100vw - 16px); max-height: calc(100vh - 20px); }
  .dbody { padding: 10px; max-height: calc(100vh - 70px); }
  .login-card { margin: 10vh auto; padding: 22px; }
  .admin-grid { padding: 10px; gap: 10px; }
  .panel { padding: 12px; }
  .admin-row { align-items: flex-start; flex-wrap: wrap; }
  .admin-row button { min-height: 38px; }
  .form-row input, .form-row button { min-height: 42px; }
}
.attachments{display:flex;flex-direction:column;gap:6px;margin-top:6px}.attachment{display:flex;flex-direction:column;gap:3px;font-size:12px}.attachment a{color:#2563eb;text-decoration:underline;overflow-wrap:anywhere}.attachment img{display:block;max-width:240px;max-height:180px;border:1px solid #cbd5e1;border-radius:6px;object-fit:contain;cursor:zoom-in;background:#fff}
.password-dialog{width:min(440px,92vw)}.password-dialog label{display:block;margin-top:14px;font-size:14px}.password-dialog input{display:block;width:100%;margin-top:6px;padding:10px;border:1px solid #d1d5db;border-radius:7px;font:inherit}.password-actions{display:flex;justify-content:flex-end;gap:8px}.password-dialog button:disabled{opacity:.6;cursor:wait}

.support-upload-list{display:flex;flex-direction:column;gap:4px;margin:4px 0;font-size:11px;max-height:120px;overflow:auto}.support-upload-item{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:6px;align-items:center;padding:3px 5px;border:1px solid #dbe4ee;border-radius:5px;background:#fff}.support-upload-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.support-upload-status{color:#64748b}.support-upload-item.failed .support-upload-status{color:#dc2626}.support-upload-item progress{grid-column:1/-1;width:100%;height:5px}.support-upload-item button{padding:2px 5px;font-size:10px;background:transparent;color:#2563eb;border:0}.support-upload-remove{color:#64748b!important}
.attach-actions{display:flex;gap:4px;flex:none}.attach-actions button{padding:8px 9px;font-size:12px;white-space:nowrap}.composer input[type=file]{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none}
@media (max-width:640px){.composer{flex-wrap:wrap;align-items:stretch}.attach-actions{order:2}.attach-actions button{min-height:40px;min-width:48px}.composer textarea{order:1;flex:1 1 calc(100% - 62px);min-width:0}.composer>#send{order:3;min-width:54px}.composer>.support-upload-list,.support-upload-list{order:4;flex-basis:100%;margin:0;max-height:94px}}

.mobile-nav{display:none}
.mobile-menu{display:none}
@media (max-width:640px){
  .mobile-menu{display:block;flex:none;width:34px;height:34px;padding:0;background:#334155;font-size:20px;line-height:1}
  .mobile-nav{position:fixed;z-index:30;top:52px;left:0;bottom:0;width:min(82vw,280px);padding:12px 10px;flex-direction:column;gap:8px;background:#fff;border-right:1px solid #cbd5e1;box-shadow:8px 0 24px #0003;overflow:auto}
  body.mobile-drawer-open .mobile-nav{display:flex}
  .mobile-nav button{flex:none;width:100%;min-height:44px;padding:9px 12px;text-align:left;background:#f1f5f9;color:#475569;border:1px solid #cbd5e1;font-size:14px;white-space:nowrap}
  .mobile-nav button.active{background:#2563eb;color:#fff;border-color:#2563eb}
  .mobile-nav button:disabled{opacity:.55;cursor:default}
  .mobile-nav b{margin-left:3px}
  main#desk .layout{height:calc(100vh - 52px)}
  main#desk .layout>.chat, main#desk .layout>aside{display:none}
  body[data-mobile-view="awaiting"] main#desk .layout>aside:nth-child(1),
  body[data-mobile-view="assigned"] main#desk .layout>aside:nth-child(2),
  body[data-mobile-view="conversation"] main#desk .layout>.chat{display:flex;height:100%;width:100%}
  body[data-mobile-view="conversation"] main#desk .layout>.chat #empty{display:none}
}
