/* AI 超级客服 - 后台样式（浅色主题） */
:root{
  --brand:#2563eb;
  --brand-600:#1d4ed8;
  --brand-soft:#eff4ff;
  --bg:#f4f6fb;
  --panel:#fff;
  --text:#111827;
  --text-2:#4b5563;
  --text-3:#8b93a3;
  --line:#e7eaf1;
  --line-2:#f2f4f9;
  --green:#16a34a;
  --green-soft:#ecfdf3;
  --amber:#d97706;
  --amber-soft:#fffbeb;
  --red:#dc2626;
  --red-soft:#fef2f2;
  --radius:14px;
  --shadow-sm:0 1px 2px rgba(16,24,40,.04);
  --shadow:0 1px 3px rgba(16,24,40,.06), 0 10px 28px rgba(16,24,40,.06);
  --sidebar-w:216px;
}
*{box-sizing:border-box}
/* 必须保留：hidden 属性只是 UA 样式表里的 [hidden]{display:none}（优先级最低），
   任何作者样式里的 .xxx{display:flex} 都会把它覆盖掉 —— 于是「设了 hidden 却照样显示」。
   工作台的 .live-chat / .live-empty 就是这么同时冒出来、各占一半高度的。 */
[hidden]{display:none !important}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
  background:var(--bg);color:var(--text);font-size:14px;line-height:1.6;-webkit-font-smoothing:antialiased;
}
a{color:var(--brand);text-decoration:none}
h1,h2,h3,h4{margin:0;font-weight:600}

/* ---------- 布局 ---------- */
/* 外层限宽 + 居中：以前只有 .content 限了 1280px 且没有 margin:auto，
   于是 1920 屏右边空 448px、2560 屏空 1088px，整块内容挤在左边。
   现在把「侧栏 + 内容」当成一个整体居中，侧栏始终紧贴内容，
   1920 及以下基本铺满，超宽屏两侧才是对称留白。 */
.layout{display:flex;min-height:100vh;width:100%;max-width:1920px;margin:0 auto}
.sidebar{
  width:var(--sidebar-w);flex:0 0 var(--sidebar-w);background:#fff;border-right:1px solid var(--line);
  display:flex;flex-direction:column;position:sticky;top:0;height:100vh;
}
.brand{display:flex;align-items:center;gap:10px;padding:18px 18px 16px;border-bottom:1px solid var(--line-2)}
.brand-logo{
  width:34px;height:34px;border-radius:10px;background:linear-gradient(135deg,#2563eb,#4f7cf7);color:#fff;
  display:grid;place-items:center;flex:0 0 auto;font-weight:700;font-size:14px;letter-spacing:.5px;
}
.brand-text{min-width:0}
.brand-name{font-size:15px;font-weight:600;letter-spacing:.2px}
.brand-sub{font-size:11.5px;color:var(--text-3);margin-top:-2px}
.nav{padding:12px 10px;display:flex;flex-direction:column;gap:2px;overflow-y:auto;flex:1}
.nav-group{font-size:11px;color:var(--text-3);padding:12px 10px 4px;letter-spacing:.6px}
.nav a{
  display:flex;align-items:center;gap:10px;padding:9px 11px;border-radius:9px;color:var(--text-2);
  font-size:13.5px;transition:.14s;
}
.nav a:hover{background:var(--line-2);color:var(--text)}
.nav a.active{background:var(--brand-soft);color:var(--brand);font-weight:600}
.nav a svg{width:17px;height:17px;flex:0 0 auto;stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.nav-badge{margin-left:auto;font-size:11px;background:var(--line-2);color:var(--text-2);border-radius:999px;padding:1px 7px}
.nav a.active .nav-badge{background:#fff;color:var(--brand)}
.nav-badge-alert{background:#ef4444 !important;color:#fff !important;animation:navPulse 1.6s ease-in-out infinite}
@keyframes navPulse{0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.5)}50%{box-shadow:0 0 0 4px rgba(239,68,68,0)}}
@media (prefers-reduced-motion: reduce){.nav-badge-alert{animation:none}}
.sidebar-foot{padding:12px 14px;border-top:1px solid var(--line-2);font-size:11.5px;color:var(--text-3)}

.main{flex:1;min-width:0;display:flex;flex-direction:column}
.topbar{
  height:58px;display:flex;align-items:center;gap:14px;padding:0 24px;background:#fff;
  border-bottom:1px solid var(--line);position:sticky;top:0;z-index:20;
}
.topbar h1{font-size:16px}
.topbar .sub{font-size:12.5px;color:var(--text-3);margin-left:2px}
.topbar-right{margin-left:auto;display:flex;align-items:center;gap:10px}
/* 不再单独限制内容宽度：限宽交给 .layout（这样侧栏和内容始终是一个整体，
   不会出现「侧栏贴左边、内容居中」的割裂感）。1920 及以下铺满，
   超宽屏由 .layout 的 1920px 上限居中留白。 */
.content{padding:22px 24px 40px;width:100%}

/* ---------- 组件 ---------- */
.card{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow-sm);margin-bottom:18px}
.card-head{display:flex;align-items:center;gap:10px;padding:14px 18px;border-bottom:1px solid var(--line-2)}
.card-head h3{font-size:14.5px}
.card-head .desc{font-size:12.5px;color:var(--text-3)}
.card-head .right{margin-left:auto;display:flex;gap:8px;align-items:center}
.card-body{padding:18px}
.card-body.tight{padding:10px 12px}

.btn{
  display:inline-flex;align-items:center;gap:6px;border:1px solid var(--line);background:#fff;color:var(--text);
  border-radius:9px;padding:7px 13px;font-size:13px;cursor:pointer;font-family:inherit;transition:.14s;white-space:nowrap;
}
.btn:hover{border-color:#cfd6e4;background:#fafbfe}
.btn:disabled{opacity:.5;cursor:not-allowed}
.btn-primary{background:var(--brand);border-color:var(--brand);color:#fff}
.btn-primary:hover{background:var(--brand-600);border-color:var(--brand-600)}
.btn-danger{color:var(--red);border-color:#f3c9c9}
.btn-danger:hover{background:var(--red-soft);border-color:#eaa}
.btn-sm{padding:4px 9px;font-size:12.5px;border-radius:8px}
.btn-ghost{border-color:transparent;background:transparent;color:var(--text-2)}
.btn-ghost:hover{background:var(--line-2)}
.btn svg{width:15px;height:15px;stroke:currentColor;fill:none;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}

.input,.select,.textarea{
  width:100%;border:1px solid var(--line);border-radius:9px;padding:8px 11px;font-size:13.5px;
  font-family:inherit;background:#fff;color:var(--text);transition:.14s;outline:0;
}
.input:focus,.select:focus,.textarea:focus{border-color:#9fbaf7;box-shadow:0 0 0 3px var(--brand-soft)}
.textarea{resize:vertical;min-height:90px;line-height:1.65}
.input::placeholder,.textarea::placeholder{color:#b6bcc9}
.form-row{margin-bottom:14px}
.form-row>label{display:block;font-size:13px;font-weight:500;margin-bottom:6px;color:var(--text)}
.hint{font-size:12px;color:var(--text-3);margin-top:5px;line-height:1.6}
.grid{display:grid;gap:14px}
.grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}
.grid-4{grid-template-columns:repeat(4,minmax(0,1fr))}
@media (max-width:1100px){.grid-4{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-3{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media (max-width:820px){.grid-2,.grid-3,.grid-4{grid-template-columns:1fr}}

.stat{background:#fff;border:1px solid var(--line);border-radius:var(--radius);padding:16px 16px 14px;box-shadow:var(--shadow-sm)}
.stat-label{font-size:12.5px;color:var(--text-3);display:flex;align-items:center;gap:6px}
.stat-value{font-size:25px;font-weight:650;margin-top:6px;letter-spacing:-.4px;font-variant-numeric:tabular-nums}
.stat-foot{font-size:12px;color:var(--text-3);margin-top:4px}

table{width:100%;border-collapse:collapse;font-size:13.5px}
th{text-align:left;font-weight:600;color:var(--text-2);font-size:12.5px;padding:10px 12px;border-bottom:1px solid var(--line);background:#fafbfe;white-space:nowrap}
td{padding:11px 12px;border-bottom:1px solid var(--line-2);vertical-align:middle}
tr:last-child td{border-bottom:0}
tbody tr:hover{background:#fcfdff}
.table-wrap{overflow-x:auto}
.nowrap{white-space:nowrap}
.muted{color:var(--text-3)}
.mono{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12.5px}
.truncate{max-width:340px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.badge{display:inline-flex;align-items:center;gap:4px;font-size:11.5px;border-radius:999px;padding:2px 9px;line-height:1.7;white-space:nowrap}
.badge-ok{background:var(--green-soft);color:var(--green)}
.badge-warn{background:var(--amber-soft);color:var(--amber)}
.badge-err{background:var(--red-soft);color:var(--red)}
.badge-gray{background:var(--line-2);color:var(--text-2)}
.badge-blue{background:var(--brand-soft);color:var(--brand)}
.dot{width:6px;height:6px;border-radius:50%;background:currentColor;display:inline-block}

.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin-bottom:18px;flex-wrap:wrap}
.tab{
  padding:9px 14px;font-size:13.5px;color:var(--text-2);cursor:pointer;border:0;background:transparent;
  border-bottom:2px solid transparent;font-family:inherit;margin-bottom:-1px;
}
.tab:hover{color:var(--text)}
.tab.active{color:var(--brand);border-bottom-color:var(--brand);font-weight:600}
.tab-pane{display:none}
.tab-pane.active{display:block}

.modal-mask{
  position:fixed;inset:0;background:rgba(17,24,39,.42);display:none;align-items:flex-start;justify-content:center;
  z-index:1000;padding:40px 16px;overflow-y:auto;backdrop-filter:blur(2px);
}
.modal-mask.open{display:flex}
.modal{background:#fff;border-radius:16px;width:100%;max-width:660px;box-shadow:0 24px 60px rgba(16,24,40,.24);animation:pop .16s ease}
@keyframes pop{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}
.modal-head{display:flex;align-items:center;padding:16px 20px;border-bottom:1px solid var(--line-2)}
.modal-head h3{font-size:15px}
.modal-head .close{margin-left:auto;border:0;background:transparent;font-size:22px;line-height:1;cursor:pointer;color:var(--text-3);padding:0 4px}
.modal-body{padding:20px;max-height:calc(100vh - 220px);overflow-y:auto}
.modal-foot{display:flex;gap:10px;justify-content:flex-end;padding:14px 20px;border-top:1px solid var(--line-2)}

.toast-wrap{position:fixed;top:18px;left:50%;transform:translateX(-50%);z-index:2000;display:flex;flex-direction:column;gap:8px;align-items:center}
.toast{
  background:#111827;color:#fff;font-size:13px;padding:9px 16px;border-radius:10px;box-shadow:0 10px 30px rgba(0,0,0,.2);
  animation:slideDown .2s ease;max-width:80vw;
}
.toast.ok{background:#15803d}
.toast.err{background:#b91c1c}
@keyframes slideDown{from{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:none}}

.progress{height:7px;background:var(--line-2);border-radius:999px;overflow:hidden}
.progress>i{display:block;height:100%;background:var(--brand);width:0;transition:width .25s ease}
.log-box{
  background:#0f172a;color:#cbd5e1;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;
  border-radius:10px;padding:12px;max-height:240px;overflow-y:auto;line-height:1.75;white-space:pre-wrap;
}
.log-box .ok{color:#86efac}
.log-box .err{color:#fca5a5}
.log-box .warn{color:#fcd34d}

.empty{padding:44px 20px;text-align:center;color:var(--text-3)}
.empty svg{width:40px;height:40px;stroke:#c7cddb;fill:none;stroke-width:1.5;margin-bottom:10px}
.empty p{margin:0;font-size:13.5px}

.code-box{
  background:#f7f8fc;border:1px solid var(--line);border-radius:9px;padding:10px 12px;font-family:ui-monospace,Menlo,Consolas,monospace;
  font-size:12px;color:var(--text-2);word-break:break-all;line-height:1.7;position:relative;
}
.copy-line{display:flex;gap:8px;align-items:center;margin-bottom:10px}
.copy-line .code-box{flex:1}
.switch{position:relative;display:inline-block;width:40px;height:22px;flex:0 0 auto}
.switch input{opacity:0;width:0;height:0}
.switch span{position:absolute;inset:0;background:#d6dae4;border-radius:999px;transition:.18s;cursor:pointer}
.switch span::before{content:"";position:absolute;width:16px;height:16px;left:3px;top:3px;background:#fff;border-radius:50%;transition:.18s}
.switch input:checked+span{background:var(--brand)}
.switch input:checked+span::before{transform:translateX(18px)}
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{
  border:1px solid var(--line);background:#fff;border-radius:999px;padding:3px 11px;font-size:12.5px;cursor:pointer;
  color:var(--text-2);font-family:inherit;transition:.14s;
}
.chip:hover{border-color:#b9c8ee;color:var(--brand)}
.chip.on{background:var(--brand);border-color:var(--brand);color:#fff}
.kv{display:grid;grid-template-columns:auto 1fr;gap:6px 16px;font-size:13px}
.kv dt{color:var(--text-3)}
.split{display:flex;gap:18px;align-items:flex-start}
.split .col-main{flex:1;min-width:0}
.split .col-side{width:300px;flex:0 0 300px}
@media (max-width:980px){.split{flex-direction:column}.split .col-side{width:100%;flex:1 1 auto}}
.login-wrap{min-height:100vh;display:grid;place-items:center;background:linear-gradient(160deg,#eef3ff,#f7f9ff 55%,#fff)}
.login-card{width:100%;max-width:380px;background:#fff;border:1px solid var(--line);border-radius:18px;padding:30px 28px;box-shadow:var(--shadow)}
.login-card .brand-logo{width:44px;height:44px;border-radius:13px;font-size:16px;margin:0 auto 14px}
.login-card h2{text-align:center;font-size:18px}
.login-card .sub{text-align:center;font-size:12.5px;color:var(--text-3);margin:6px 0 22px}
.alert{border-radius:10px;padding:10px 13px;font-size:13px;margin-bottom:14px;line-height:1.65}
.alert-warn{background:var(--amber-soft);color:#92400e;border:1px solid #fde68a}
.alert-err{background:var(--red-soft);color:#991b1b;border:1px solid #fecaca}
.alert-info{background:var(--brand-soft);color:#1e40af;border:1px solid #c7d9fd}
.alert-ok{background:var(--green-soft);color:#166534;border:1px solid #bbf7d0}
.bar-chart{display:flex;align-items:flex-end;gap:10px;height:130px;padding:8px 4px 0}
.bar-chart .bar{flex:1;display:flex;flex-direction:column;align-items:center;gap:6px;height:100%;justify-content:flex-end}
.bar-chart .bar i{width:100%;max-width:38px;background:linear-gradient(180deg,#5b8def,#2563eb);border-radius:6px 6px 3px 3px;min-height:3px;transition:.3s}
.bar-chart .bar span{font-size:11px;color:var(--text-3)}
.bar-chart .bar b{font-size:11.5px;color:var(--text-2);font-weight:600}
.msg-pair{border:1px solid var(--line-2);border-radius:11px;padding:12px 14px;margin-bottom:10px;background:#fff}
.msg-pair .q{font-size:13.5px;font-weight:600;margin-bottom:6px}
.msg-pair .a{font-size:13px;color:var(--text-2);white-space:pre-wrap;line-height:1.7}
.msg-pair .meta{font-size:11.5px;color:var(--text-3);margin-top:8px;display:flex;gap:12px;flex-wrap:wrap}

/* ---------- 人工客服工作台 ---------- */
/* 高度不写死 calc(100vh - 268px)：那个 268 是按「统计卡片刚好一行」量出来的，
   窗口一矮、卡片换行、顶栏高度一变，工作台就戳出视口、把输入框顶到屏幕外。
   改由 live.php 的 fitHeight() 实测剩余空间写进 --live-h，这里只留兜底值。 */
.live-wrap{display:flex;gap:16px;height:var(--live-h,calc(100vh - 268px));min-height:360px}
.live-stats{margin-bottom:16px}
/* 矮屏（笔记本 768 / 720 高）顶部占用太大会把工作台挤没，收紧统计卡片换高度 */
@media (max-height:820px){
  .live-stats{margin-bottom:10px}
  .live-stats .stat{padding:11px 13px 10px}
  .live-stats .stat-value{font-size:21px;margin-top:3px}
  .live-stats .stat-foot{display:none}
  .live-compose .hint{display:none}
}
/* 再矮就只有靠滚动，但至少保证工作台本身不会把输入框顶出屏幕 */
@media (max-height:640px){
  .live-wrap{min-height:320px}
}
.live-side{width:318px;flex:0 0 318px;background:#fff;border:1px solid var(--line);border-radius:var(--radius);display:flex;flex-direction:column;overflow:hidden;box-shadow:var(--shadow-sm)}
.live-side-head{padding:12px;border-bottom:1px solid var(--line-2)}
.live-scope{display:flex;gap:3px;background:var(--line-2);border-radius:9px;padding:3px}
.live-scope-btn{flex:1;border:0;background:transparent;font-size:12.5px;padding:5px 0;border-radius:7px;cursor:pointer;color:var(--text-2);font-family:inherit;transition:.14s}
.live-scope-btn:hover{color:var(--text)}
.live-scope-btn.active{background:#fff;color:var(--brand);font-weight:500;box-shadow:var(--shadow-sm)}
.live-list{flex:1;overflow-y:auto}
.live-item{padding:11px 13px;border-bottom:1px solid var(--line-2);cursor:pointer;transition:background .12s}
.live-item:hover{background:#fafbfe}
.live-item.active{background:var(--brand-soft);box-shadow:inset 3px 0 0 var(--brand)}
.live-item-top{display:flex;align-items:center;gap:8px}
.live-item-title{flex:1;min-width:0;font-size:13.5px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.live-dot{background:#ef4444;color:#fff;font-size:11px;border-radius:999px;padding:1px 7px;line-height:1.65;flex:0 0 auto}
.live-item-last{font-size:12.5px;color:var(--text-3);margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.live-item-meta{display:flex;align-items:center;gap:7px;margin-top:6px;font-size:11.5px;color:var(--text-3)}
.live-main{flex:1;min-width:0;background:#fff;border:1px solid var(--line);border-radius:var(--radius);display:flex;flex-direction:column;overflow:hidden;box-shadow:var(--shadow-sm)}
.live-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;color:var(--text-3);gap:4px;text-align:center;padding:20px}
.live-empty p{margin:0;font-size:13.5px}
.live-chat{flex:1;display:flex;flex-direction:column;min-height:0}
.live-chat-head{display:flex;align-items:center;gap:12px;padding:12px 16px;border-bottom:1px solid var(--line-2);flex:0 0 auto}
.live-chat-title{font-size:14px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.live-chat-sub{font-size:11.5px;color:var(--text-3);margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.live-chat-actions{margin-left:auto;display:flex;gap:7px;align-items:center;flex:0 0 auto}
.live-msgs{flex:1;overflow-y:auto;padding:16px 18px;background:#fbfcfe;min-height:0}
.live-msg{max-width:78%;margin-bottom:14px}
.live-msg.them{margin-right:auto}
.live-msg.ai,.live-msg.agent{margin-left:auto}
.live-msg-who{font-size:11px;color:var(--text-3);margin-bottom:4px}
.live-msg.them .live-msg-who{text-align:left}
.live-msg.ai .live-msg-who,.live-msg.agent .live-msg-who{text-align:right}
.live-bubble{padding:9px 13px;border-radius:12px;font-size:13.5px;line-height:1.7;white-space:pre-wrap;word-break:break-word}
.live-msg.them .live-bubble{background:#fff;border:1px solid var(--line);color:var(--text)}
.live-msg.ai .live-bubble{background:var(--brand-soft);color:#1e40af;border:1px solid #dbe6fd}
.live-msg.agent .live-bubble{background:#e7f7ef;color:#116b45;border:1px solid #c3ebd9}
.live-src{font-size:11.5px;color:var(--text-3);margin-top:4px;text-align:right}
.live-sys{display:block;font-size:12px;color:var(--text-3);line-height:1.6;text-align:center;background:#f4f6fb;border-radius:8px;padding:5px 10px;max-width:520px;margin:12px auto}
.live-compose{flex:0 0 auto;border-top:1px solid var(--line-2);padding:10px 14px 12px;background:#fff}
/* 快捷回复 + 「编辑」按钮同一行：按钮曾作为独立子元素独占一行，白白吃掉 30px 高度 */
.live-quick{display:flex;align-items:flex-start;gap:8px;margin-bottom:8px}
.live-quick-chips{display:flex;flex-wrap:wrap;gap:6px;flex:1;min-width:0}
/* 快捷语按钮。
   注意：这个类以前**没有任何样式定义**（全局只搜到一条字号调整），
   所以外观完全来自浏览器默认 button —— 灰底、系统圆角、文字被 JS 硬砍 18 字再加「…」，
   看着很粗糙。这里补齐完整样式：闪电图标 + 单行省略 + 明确的悬停/按下反馈。 */
.live-quick .qchip{
  display:inline-flex;align-items:center;gap:6px;max-width:236px;
  border:1px solid var(--line);background:#fff;border-radius:9px;
  padding:6px 11px 6px 9px;font-size:12.5px;line-height:1.3;font-family:inherit;
  color:var(--text-2);cursor:pointer;
  transition:border-color .15s,background .15s,color .15s,box-shadow .15s,transform .12s;
}
.live-quick .qchip svg{
  width:13px;height:13px;flex:0 0 auto;stroke:currentColor;fill:none;
  stroke-width:2.1;stroke-linecap:round;stroke-linejoin:round;
  opacity:.6;transition:opacity .15s;
}
/* 用 CSS 省略号截断，不再由 JS 砍字 —— 宽度不同也能截得刚好 */
.live-quick .qchip span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.live-quick .qchip:hover{
  border-color:#bcd0f7;background:var(--brand-soft);color:var(--brand);
  box-shadow:0 2px 8px rgba(37,99,235,.10);transform:translateY(-1px);
}
.live-quick .qchip:hover svg{opacity:1}
.live-quick .qchip:active{transform:translateY(0);box-shadow:none;background:#e3ebfd}
.live-quick .qchip:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
/* 快捷语多到换行时给个上限，别把聊天区挤没了；超出就滚动 */
.live-quick-chips{max-height:96px;overflow-y:auto;padding-right:2px}
.live-quick-edit{flex:0 0 auto;font-size:12px;padding:6px 10px;margin-top:0;border-radius:9px}
.live-input-row{display:flex;gap:9px;align-items:flex-end}
.live-input-row textarea{flex:1;border:1px solid var(--line);border-radius:11px;padding:9px 12px;font-family:inherit;font-size:13.5px;line-height:1.65;resize:none;min-height:44px;max-height:150px;outline:0;transition:.14s}
.live-input-row textarea:focus{border-color:#9fbaf7;box-shadow:0 0 0 3px var(--brand-soft)}
.live-input-row .btn{height:40px;padding:0 20px}
@media (max-width:1080px){
  .live-wrap{flex-direction:column;height:auto}
  /* 堆叠布局下必须给「聊天区」一个确定高度，否则 .live-chat{flex:1} → .live-msgs{flex:1}
     这条链拿不到可分配高度，overflow-y:auto 就形同虚设 ——
     历史消息一长，时间线会被内容整个撑开（实测涨到 7400px，整页变一条长龙，
     得滚好久才到底）。给它一个基于视口的高度，滚动就回到聊天框内部。 */
  .live-side{width:100%;flex:0 0 auto;max-height:240px}
  .live-main{flex:0 0 auto;height:calc(100dvh - 110px);min-height:400px}
}

/* 侧栏筛选控件：select/input 的 min-width:auto 会把 318px 的侧栏撑破 */
.live-side-head .select,.live-side-head .input{min-width:0}
/* 中等窗口下「状态徽标 + 3 个操作按钮」会挤不下，允许换行而不是被裁掉 */
.live-chat-head{flex-wrap:wrap}
.live-chat-head>div:first-child{flex:1 1 200px}

/* ---------- 移动端 / 窄屏适配 ---------- */
/* 后台原先只有桌面布局：侧栏固定 216px + 内容区左右各 24px 内边距，
   768px 以下内容区只剩 100~200px，各页面横向溢出 130~535px（按钮被挤出屏幕外，
   看起来就像"被遮挡"）。这里把侧栏改成顶部横向导航，把宽度还给内容区。 */
@media (max-width:820px){
  .layout{flex-direction:column}
  .sidebar{
    width:100%;flex:0 0 auto;height:auto;position:static;flex-direction:row;align-items:center;
    border-right:0;border-bottom:1px solid var(--line);overflow:hidden;min-width:0;
  }
  .brand{padding:10px 12px;border-bottom:0;flex:0 0 auto}
  .brand-text{display:none}
  /* min-width:0 是关键：flex item 默认 min-width:auto 会被内容撑开，
     结果横排导航把文档宽度顶到 886px（页面横向溢出、右边按钮看不见）。
     设成 0 之后导航才能收缩，并由自身 overflow-x 滚动。 */
  .nav{flex-direction:row;flex:1;min-width:0;padding:6px;gap:2px;overflow-x:auto;overflow-y:hidden}
  .nav-group{display:none}
  .nav a{padding:8px 11px;flex:0 0 auto}
  .nav a svg{width:18px;height:18px}
  .nav a.active{background:var(--brand-soft)}
  .sidebar-foot{display:none}

  .topbar{height:52px;padding:0 13px;gap:10px}
  .topbar h1{font-size:15px}
  .topbar .sub{display:none}
  .topbar-right{gap:7px}
  .topbar-right .badge{display:none}      /* 用户名在窄屏没地方放，也不重要 */
  .content{padding:13px 13px 26px}

  .card-head{flex-wrap:wrap}
  .card-body{padding:14px}
  .kv{grid-template-columns:1fr}          /* 键值对改上下排，长值不再顶破卡片 */
  .kv dt{margin-top:2px}
  .mono{word-break:break-all}
  .grid{gap:11px}
  .stat{padding:13px 13px 11px}
  .stat-value{font-size:22px}
  .modal-mask{padding:16px 10px}
  .modal-body{max-height:calc(100vh - 180px)}
  .split .col-side{width:100%;flex:1 1 auto}
}

/* 表格：即使外层容器尺寸被压，也要在容器内滚动而不是顶破页面 */
.table-wrap{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}

/* 工作台在窄屏堆叠后更紧凑一些 */
@media (max-width:820px){
  .live-side{width:100%;max-height:220px}
  .live-chat-actions{width:100%;justify-content:flex-start}
  .live-msg{max-width:90%}
  .live-msgs{padding:12px 12px}
  .live-bubble{font-size:13px}
}

/* 会话页筛选控件的宽度（原来写在内联 style 上，内联样式窄屏无法被覆盖） */
.card-head .right .filter-select{width:170px}
.card-head .right .filter-input{width:200px}
@media (max-width:820px){
  .card-head .right{width:100%;flex-wrap:wrap;margin-left:0}
  .card-head .right .filter-select,
  .card-head .right .filter-input{width:auto;flex:1 1 120px;min-width:0}
}

/* .split 在窄屏改纵向堆叠时必须把 align-items 从 flex-start 改成 stretch：
   flex-start 会让子项按「内容宽度」排布，长表格/图表把 col-main 撑到 685px，
   在 390px 屏幕上直接横向溢出（实测溢出 308px）。 */
@media (max-width:980px){
  .split{align-items:stretch}
  .split .col-main{min-width:0;width:100%}
}

/* scrollIntoView 落到 sticky 顶栏下面会看不见，留出顶栏高度（窄屏 52px） */
@media (max-width:820px){
  .live-chat,.live-main{scroll-margin-top:64px}
}

/* 「← 会话列表」只在窄屏（堆叠布局）出现：桌面两栏并排，不需要返回按钮 */
.live-back{display:none}
@media (max-width:1080px){
  .live-back{display:inline-flex;flex:0 0 auto}
}

/* 超宽屏下聊天区会很宽（2560 屏约 1370px），气泡按 78% 算出一行 1000+px 难以阅读。
   宽度放开的同时给气泡一个绝对上限，保持一行 60~90 字的舒适阅读区间。 */
@media (min-width:1600px){
  .live-msg{max-width:min(72%,860px)}
}

/* 有新排队 / 新消息时，左侧「人工客服」整项变红并让图标呼吸 ——
   客服在知识库、设置页干活时也能一眼扫到，不用一直盯着工作台那一页。 */
.nav a.has-alert{background:var(--red-soft);color:var(--red)}
.nav a.has-alert:hover{background:#fee2e2}
.nav a.has-alert svg{color:var(--red);animation:navIconPulse 1.8s ease-in-out infinite}
@keyframes navIconPulse{
  0%,100%{opacity:1;transform:scale(1)}
  50%{opacity:.5;transform:scale(.9)}
}
@media (prefers-reduced-motion: reduce){
  .nav a.has-alert svg{animation:none}
}

/* 人工客服头像设置：预览 + 上传 */
.avatar-set{display:flex;gap:14px;align-items:flex-start}
.avatar-preview{
  width:68px;height:68px;flex:0 0 auto;border-radius:15px;border:1px dashed var(--line);
  background:#fafbfe;display:grid;place-items:center;overflow:hidden;
  color:var(--text-3);font-size:11.5px;text-align:center;line-height:1.3;
}
.avatar-preview img{width:100%;height:100%;object-fit:cover;display:block}
.avatar-set-main{flex:1;min-width:0}
.avatar-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
@media (max-width:520px){
  .avatar-set{flex-direction:column}
  .avatar-preview{width:60px;height:60px}
}
