:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e5e9f2;
  --line-strong: #d6dce9;
  --text: #1b2436;
  --text-2: #47536a;
  --muted: #8490a5;
  --primary: #5b5bf0;
  --primary-dark: #4646d8;
  --primary-soft: #eef0ff;
  --cyan: #0ea5e9;
  --green: #10b981;
  --green-soft: #e8f8f1;
  --amber: #f59e0b;
  --amber-soft: #fff5e3;
  --red: #ef4444;
  --red-soft: #feecec;
  --sidebar: #151d30;
  --sidebar-2: #1e2942;
  --sidebar-text: #aab6ce;
  --shadow: 0 2px 4px rgba(22, 34, 60, .02), 0 8px 24px rgba(22, 34, 60, .05);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); font-size: 12px; font-weight: 400; }

/* ── 骨架 ───────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 238px; flex: none; background: linear-gradient(170deg, var(--sidebar) 0%, #101727 100%);
  color: var(--sidebar-text); display: flex; flex-direction: column; padding: 22px 14px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 26px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6d6bff, #a855f7); color: #fff; box-shadow: 0 6px 18px rgba(105, 91, 255, .35);
}
.brand-mark svg { width: 21px; height: 21px; stroke-width: 1.6; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: .3px; }
.brand-text span { font-size: 10px; color: #7382a0; letter-spacing: 1.4px; text-transform: uppercase; }
.nav-caption { font-size: 10px; letter-spacing: 1.6px; color: #5f6d88; padding: 0 12px 10px; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 12px; border: 0; border-radius: 9px;
  background: transparent; color: var(--sidebar-text); font-size: 13.5px; text-align: left; transition: .16s;
}
.nav-item svg { width: 17px; height: 17px; }
.nav-item:hover { background: rgba(255, 255, 255, .055); color: #e9eefb; }
.nav-item.active { background: linear-gradient(90deg, rgba(99, 99, 255, .28), rgba(99, 99, 255, .1)); color: #fff; box-shadow: inset 2px 0 0 #7c7cff; }
.nav-item em { margin-left: auto; font-style: normal; font-size: 11px; color: #8b9ab8; background: rgba(255,255,255,.07); padding: 1px 7px; border-radius: 20px; }
.nav-item em.badge-hot { background: rgba(239, 68, 68, .2); color: #ffb4b4; }
.sidebar-foot { margin-top: auto; }
.status-card { background: var(--sidebar-2); border: 1px solid rgba(255,255,255,.06); border-radius: 11px; padding: 12px; }
.status-row { display: flex; align-items: center; gap: 8px; }
.status-row strong { color: #e4ebfa; font-size: 12.5px; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }
.status-dot.online { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.15); }
.status-dot.offline { background: #f87171; box-shadow: 0 0 0 3px rgba(248,113,113,.15); }
.status-card p { font-size: 11px; color: #7f8dab; margin-top: 5px; line-height: 1.5; }
.side-meta { font-size: 10.5px; color: #55647f; text-align: center; margin-top: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 74px; flex: none; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 26px; gap: 20px;
}
.topbar h1 { font-size: 19px; font-weight: 650; letter-spacing: -.2px; }
.topbar p { font-size: 12px; color: var(--muted); margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.model-picker { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.model-picker select { max-width: 168px; }
.views { flex: 1; overflow: auto; padding: 20px 24px 28px; }
.view { display: none; }
.view.active { display: block; }

/* ── 通用组件 ───────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-panel { min-width: 0; display: flex; flex-direction: column; }
/* 会话列表 / 智能辅助面板同理：纵向 flex 才能让内部列表区域正确滚动 */
.session-panel, .insight-panel { display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); flex: none; }
.panel-head h3 { font-size: 14px; font-weight: 650; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500; transition: .15s; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: #b9c2d6; background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(91,91,240,.22); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: transparent; }
.btn-mini { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn-mini svg { width: 13px; height: 13px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: #f6b6b6; }
.input, .select, .search-box input {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 9px;
  padding: 9px 11px; outline: none; transition: .15s; font-size: 13px;
}
.input:focus, .select:focus, .search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,91,240,.1); }
textarea.input { resize: vertical; line-height: 1.6; }
.select { width: auto; min-width: 126px; cursor: pointer; }
.search-box { position: relative; display: flex; align-items: center; margin: 12px 14px; }
.search-box svg { position: absolute; left: 11px; width: 15px; height: 15px; color: var(--muted); }
.search-box input { padding-left: 34px; background: var(--surface-2); }
.search-box.wide { margin: 0; width: 300px; max-width: 100%; }
.search-box.wide input { background: var(--surface); }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar.standalone { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.toolbar-spacer { flex: 1; }
.count-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.live-pill { font-size: 10.5px; color: var(--green); background: var(--green-soft); padding: 2px 9px; border-radius: 20px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap; }
.tag.green { background: var(--green-soft); color: #0d9668; border-color: #c7eddd; }
.tag.amber { background: var(--amber-soft); color: #b7791f; border-color: #f8e0b5; }
.tag.red { background: var(--red-soft); color: #d63b3b; border-color: #f7cccc; }
.tag.indigo { background: var(--primary-soft); color: var(--primary-dark); border-color: #dcdcff; }

/* ── 多应用统一后台 ───────────────────────────────────── */
.app-picker { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.app-picker > span { padding: 4px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.app-picker select { max-width: 210px; border-color: #c9c9ff; }
.tag.app { background: #eaf4ff; color: #1769aa; border-color: #c9e2fa; }
.scope-note { background: #f5f6ff; border: 1px solid #dcdcff; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-size: 12.5px; color: var(--text-2); }
.scope-note b { color: var(--primary-dark); }
.scope-note code { background: #e7e9ff; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.scope-note small { display: block; color: var(--muted); margin-top: 5px; font-size: 11.5px; }
.dash-grid .span-2 { grid-column: 1 / -1; }
.app-breakdown { padding: 8px 18px 16px; }
.app-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); margin-top: 8px; cursor: pointer; text-align: left; font-size: 12.5px; transition: background .12s, border-color .12s; }
.app-row:hover { background: #f8f9fd; border-color: #d6dce9; }
.app-row.active { background: var(--primary-soft); border-color: #c9c9ff; }
.app-row .ar-name { flex: 1; min-width: 0; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-row .ar-name code { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.app-row .ar-num { flex: none; color: var(--text-2); font-size: 11.5px; }
.app-row .ar-num.warn { color: #d63b3b; font-weight: 600; }
.app-row .ar-go { flex: none; color: var(--primary-dark); font-size: 11.5px; }

/* ── 对话页 ─────────────────────────────────────────── */
.chat-layout { display: grid; grid-template-columns: 226px minmax(0, 1fr) 262px; gap: 14px; height: calc(100vh - 122px); min-height: 540px; }
.session-list { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 0 8px 12px; }
.session-item {
  display: block; width: 100%; text-align: left; border: 1px solid transparent; border-radius: 10px;
  background: transparent; padding: 10px 11px; margin-bottom: 4px; transition: .15s;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--primary-soft); border-color: #dcdcff; }
.session-item .s-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.session-item .s-name { font-size: 12.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .s-time { font-size: 10.5px; color: var(--muted); flex: none; }
.session-item .s-preview { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.session-item .s-meta { display: flex; gap: 5px; margin-top: 6px; }

/* 面板内部为纵向 flex：让消息区/会话列表获得确定高度，overflow 滚动才能生效
   （此前 .chat-scroll 的 flex:1 在普通块容器里无效，长对话被 .panel 的 overflow:hidden 截断） */
.chat-panel { min-width: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 11px; padding: 13px 18px; border-bottom: 1px solid var(--line); flex: none; }
.bot-avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6d6bff, #38bdf8); }
.bot-avatar svg { width: 20px; height: 20px; }
.chat-head-info { display: flex; flex-direction: column; line-height: 1.4; }
.chat-head-info strong { font-size: 14px; }
.chat-head-info span { font-size: 11.5px; color: var(--muted); }
.dot-live { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--green); margin-right: 5px; vertical-align: 1px; }
.chat-head-tag { margin-left: auto; font-size: 11px; color: var(--primary-dark); background: var(--primary-soft); border: 1px solid #dcdcff; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.chat-scroll { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 20px 22px 8px; scroll-behavior: smooth; }
.chat-date { text-align: center; font-size: 11px; color: var(--muted); margin: 4px 0 20px; }
.msg { display: flex; gap: 10px; margin-bottom: 20px; align-items: flex-start; }
.msg.player { flex-direction: row-reverse; }
.msg-avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; font-size: 12px; font-weight: 700; }
.msg.bot .msg-avatar { background: linear-gradient(135deg, #6d6bff, #38bdf8); color: #fff; }
.msg.bot .msg-avatar svg { width: 16px; height: 16px; }
.msg.player .msg-avatar { background: #e6eaf4; color: var(--text-2); }
.msg-body { max-width: 78%; min-width: 0; }
.msg.player .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { padding: 11px 14px; border-radius: 4px 14px 14px 14px; background: #f3f5fa; border: 1px solid #ebeff6; font-size: 13.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.msg.player .bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-radius: 14px 4px 14px 14px; }
.msg.system-bot .bubble { background: #fffaf0; border-color: #f7e8c8; }
/* 人工接入后折叠的兜底提示 */
.msg-note { margin: 0 0 16px 40px; font-size: 11.5px; color: var(--muted); background: #f7f8fc; border: 1px dashed var(--line-strong); border-radius: 8px; padding: 7px 11px; }
.chat-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 18px; font-size: 11px; color: #1a9e5c; }
.chat-divider::before, .chat-divider::after { content: ''; height: 1px; flex: 1; background: #d6f0e0; }
.bubble.typing::after { content: '▌'; color: var(--primary); animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg-meta { display: flex; align-items: center; gap: 7px; margin-top: 6px; font-size: 10.5px; color: var(--muted); flex-wrap: wrap; }
.msg.player .msg-meta { justify-content: flex-end; }
.feedback { display: inline-flex; gap: 5px; margin-left: 4px; }
.feedback button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 2px 7px; font-size: 10.5px; color: var(--muted); }
.feedback button:hover { border-color: var(--primary); color: var(--primary); }
.feedback button.picked { background: var(--primary-soft); border-color: #dcdcff; color: var(--primary-dark); }
.bubble .ref-list { margin-top: 10px; padding-top: 9px; border-top: 1px dashed #dfe4ee; font-size: 11.5px; color: var(--text-2); }
.bubble .ref-list b { color: var(--primary-dark); font-weight: 600; }
.quick-asks { display: flex; gap: 7px; flex-wrap: wrap; padding: 8px 18px 12px; border-top: 1px solid var(--line); flex: none; max-height: 132px; overflow-y: auto; }
/* hidden 属性优先级最高：后台靠它隐藏玩家专属元素，避免被 display:flex 覆盖 */
[hidden] { display: none !important; }
.quick-chip.manage { border-style: dashed; color: var(--primary-dark); background: var(--primary-soft); border-color: #dcdcff; }
.quick-chip { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); border-radius: 20px; padding: 5px 11px; font-size: 11.5px; transition: .15s; }
.quick-chip:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }
.composer-wrap { border-top: 1px solid var(--line); padding: 10px 16px 12px; background: var(--surface-2); flex: none; }
.human-btn { border: 0; background: transparent; color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; padding: 0 2px 9px; }
.human-btn:hover { color: var(--primary); }
.human-btn.connected { color: #1a9e5c; cursor: default; }
.human-btn.connected:hover { color: #1a9e5c; }
.human-btn svg { width: 14px; height: 14px; }
.composer { display: flex; align-items: flex-end; gap: 9px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line-strong); border-radius: 11px; padding: 11px 13px; outline: none; background: var(--surface); max-height: 120px; min-height: 44px; line-height: 1.6; }
.composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,91,240,.09); }
.composer .btn { height: 44px; }
.btn-stop { height: 44px; padding: 0 12px; border-radius: 9px; border: 1px solid #f3c7c7; background: var(--red-soft); color: var(--red); display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; }
.btn-stop svg { width: 14px; height: 14px; }
.composer-hint { display: flex; justify-content: space-between; gap: 12px; font-size: 10.5px; color: var(--muted); padding-top: 8px; }

/* ── 图片消息：入口按钮 / 待发送预览 / 气泡内缩略图 / 大图查看 ── */
.attach-btn { width: 44px; height: 44px; flex: none; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 11px; display: grid; place-items: center; color: var(--muted); transition: .15s; }
.attach-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.attach-btn svg { width: 18px; height: 18px; }
.img-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-bottom: 9px; }
.img-preview .thumb { position: relative; width: 58px; height: 58px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line-strong); background: var(--surface); }
.img-preview .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-preview .thumb.busy img { opacity: .4; }
.img-preview .thumb-ph { display: block; width: 100%; height: 100%; background: repeating-linear-gradient(45deg, #f0f2f8, #f0f2f8 6px, #f7f8fc 6px, #f7f8fc 12px); }
.img-preview .thumb-spin { position: absolute; inset: 0; display: grid; place-items: center; }
.img-preview .thumb-spin::after { content: ''; width: 15px; height: 15px; border: 2px solid #d9dcff; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.img-preview .thumb-del { position: absolute; top: 2px; right: 2px; width: 16px; height: 16px; border: 0; border-radius: 50%; background: rgba(20, 26, 40, .62); color: #fff; font-size: 11px; line-height: 1; display: grid; place-items: center; padding: 0; }
.img-preview .thumb-del:hover { background: rgba(20, 26, 40, .85); }
.img-preview .thumb-hint { font-size: 10.5px; color: var(--muted); }

.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-imgs img { width: 168px; height: 168px; object-fit: cover; border-radius: 10px; border: 1px solid rgba(15, 23, 42, .07); cursor: zoom-in; display: block; background: #eef1f7; }
.msg.player .msg-imgs img { border-color: rgba(255, 255, 255, .38); }
.msg.img-only .bubble { padding: 0; background: transparent; border: 0; }
.msg.img-only .msg-imgs { margin-top: 0; }
.chat-panel.drop-active { outline: 2px dashed var(--primary); outline-offset: -8px; border-radius: 12px; }

.lightbox { position: fixed; inset: 0; z-index: 9999; background: rgba(10, 14, 24, .86); display: grid; place-items: center; padding: 28px; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.lightbox-close { position: absolute; top: 18px; right: 22px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .16); color: #fff; font-size: 20px; line-height: 1; display: grid; place-items: center; }
.lightbox-close:hover { background: rgba(255, 255, 255, .3); }
@media (max-width: 560px) {
  .msg-imgs img { width: 132px; height: 132px; }
  .msg-body { max-width: 86%; }
  .attach-btn { width: 40px; height: 40px; }
}

.insight-content { padding: 14px 16px; overflow-y: auto; flex: 1 1 0; min-height: 0; }
.insight-block { margin-bottom: 20px; }
.insight-label { font-size: 10.5px; letter-spacing: .8px; color: var(--muted); text-transform: uppercase; margin-bottom: 9px; }
.intent-card { background: var(--primary-soft); border: 1px solid #dcdcff; border-radius: 11px; padding: 12px; }
.intent-card strong { display: block; font-size: 15px; color: var(--primary-dark); margin-bottom: 6px; }
.conf-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-2); }
.conf-bar { flex: 1; height: 6px; border-radius: 6px; background: #dfe1fb; overflow: hidden; }
.conf-bar i { display: block; height: 100%; background: linear-gradient(90deg, #6d6bff, #38bdf8); border-radius: 6px; }
.kb-hit { border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; margin-bottom: 8px; background: var(--surface-2); }
.kb-hit .h-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 4px; }
.kb-hit strong { font-size: 12px; line-height: 1.5; }
.kb-hit p { font-size: 11px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.source-flow { display: flex; flex-direction: column; gap: 0; }
.flow-step { display: flex; gap: 10px; font-size: 11.5px; color: var(--text-2); }
.flow-step .f-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-top: 6px; flex: none; box-shadow: 0 0 0 3px var(--green-soft); position: relative; }
.flow-step:not(:last-child) .f-dot::after { content: ''; position: absolute; left: 3px; top: 12px; width: 2px; height: 26px; background: var(--line); }
.flow-step .f-body { padding-bottom: 16px; }
.flow-step .f-body b { display: block; color: var(--text); font-size: 12px; font-weight: 600; }
.insight-note { font-size: 11px; color: var(--muted); background: var(--surface-2); border-radius: 9px; padding: 10px 11px; line-height: 1.65; }

/* ── 总览 ───────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent, var(--primary)); }
.kpi .k-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .k-value { font-size: 27px; font-weight: 700; letter-spacing: -.8px; margin: 6px 0 2px; line-height: 1.2; }
.kpi .k-sub { font-size: 11.5px; color: var(--muted); }
.kpi .k-icon { position: absolute; right: 16px; top: 16px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft, var(--primary-soft)); color: var(--accent, var(--primary)); }
.kpi .k-icon svg { width: 17px; height: 17px; }
.dash-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; }
.trend-chart { padding: 18px 20px 12px; }
.trend-svg { width: 100%; height: 200px; overflow: visible; }
.category-chart { padding: 16px 20px 20px; }
.cat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 12px; }
.cat-name { width: 72px; flex: none; color: var(--text-2); }
.cat-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.cat-fill { height: 100%; border-radius: 8px; background: linear-gradient(90deg, #6d6bff, #8b8bff); }
.cat-num { width: 28px; text-align: right; color: var(--muted); font-size: 11.5px; }
.top-questions { padding: 8px 18px 16px; }
.tq-item { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tq-item:last-child { border-bottom: 0; }
.tq-rank { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); flex: none; }
.tq-item:nth-child(-n+3) .tq-rank { background: var(--primary-soft); color: var(--primary-dark); }
.tq-text { flex: 1; min-width: 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tq-num { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.recent-activity { padding: 6px 18px 14px; }
.ra-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.ra-item:last-child { border-bottom: 0; }
.ra-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-top: 6px; flex: none; }
.ra-dot.warn { background: var(--amber); }
.ra-body { flex: 1; min-width: 0; }
.ra-body strong { font-weight: 600; }
.ra-body p { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ra-time { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ── 表格 ───────────────────────────────────────────── */
.table-wrap { overflow: auto; max-height: calc(100vh - 220px); }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th { background: var(--surface-2); color: var(--muted); font-weight: 600; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid #eef1f7; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: #f8f9fd; }
.table .cell-strong { font-weight: 600; color: var(--text); }
.table .cell-clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.table .row-actions { display: flex; gap: 5px; }
.icon-btn { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; color: var(--muted); }
.icon-btn:hover { color: var(--primary); border-color: #c9c9ff; background: var(--primary-soft); }
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { color: var(--red); border-color: #f3c7c7; background: var(--red-soft); }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; cursor: pointer; }
.switch input { display: none; }
.switch i { width: 28px; height: 16px; border-radius: 20px; background: #d7dde9; position: relative; transition: .18s; }
.switch i::after { content: ''; position: absolute; width: 12px; height: 12px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.16); }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { left: 14px; }

/* ── 工单 ───────────────────────────────────────────── */
.ticket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
/* 知识库缺口：兜底问题清单 */
.kb-gaps { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; padding: 14px 18px 18px; }
.gap-item { border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.gap-q { font-size: 13px; line-height: 1.6; color: var(--text); word-break: break-word; }
.gap-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.gap-item .btn-mini { align-self: flex-start; }
.ticket-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 17px; }
.tc-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.tc-id { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tc-q { font-size: 13.5px; font-weight: 600; line-height: 1.65; margin-bottom: 10px; }
.tc-meta { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
.tc-reply { background: var(--surface-2); border-radius: 9px; padding: 10px 11px; font-size: 12px; color: var(--text-2); line-height: 1.6; margin-bottom: 12px; }
.tc-reply b { color: var(--text); font-size: 11.5px; display: block; margin-bottom: 2px; }
.tc-actions { display: flex; gap: 7px; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; }
.tc-actions .btn { padding: 6px 10px; font-size: 12px; }
.tc-actions select { margin-left: auto; min-width: 104px; padding: 6px 8px; font-size: 12px; }

/* ── 设置 ───────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-grid .span-2 { grid-column: 1 / -1; }
.form-body { padding: 18px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field small { display: block; font-size: 11px; color: var(--muted); margin-top: 5px; }
.field .input, .field .select { width: 100%; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch-row span { display: flex; flex-direction: column; }
.switch-row strong { font-size: 13px; font-weight: 600; }
.switch-row small { font-size: 11px; color: var(--muted); }
.switch-row input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.setting-note { display: flex; gap: 9px; align-items: flex-start; background: var(--primary-soft); border: 1px solid #dcdcff; border-radius: 10px; padding: 11px 12px; font-size: 11.5px; color: var(--text-2); line-height: 1.65; margin-top: 4px; }
.setting-note svg { color: var(--primary); width: 16px; height: 16px; margin-top: 2px; }
.connection-info { padding: 16px 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.ci-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; }
.ci-item span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.ci-item strong { font-size: 13px; word-break: break-all; }
.settings-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ── 弹窗 / 提示 ─────────────────────────────────────── */
.modal-mask { position: fixed; inset: 0; background: rgba(17, 25, 43, .46); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; width: min(620px, 100%); max-height: 88vh; overflow: auto; box-shadow: 0 24px 70px rgba(15, 23, 42, .26); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); }
.modal .field { margin-bottom: 14px; }
.conv-detail { max-height: 380px; overflow: auto; background: var(--surface-2); border-radius: 10px; padding: 14px; }
.cd-msg { margin-bottom: 14px; }
.cd-msg .cd-role { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.cd-msg .cd-text { font-size: 12.5px; line-height: 1.7; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; white-space: pre-wrap; word-break: break-word; }
.cd-msg.bot .cd-text { background: var(--primary-soft); border-color: #dcdcff; }
.cd-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cd-imgs img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; display: block; background: #eef1f7; }
/* 工单卡片 / 回填弹窗里的玩家图片 */
.tk-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tk-imgs img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; display: block; background: #eef1f7; }
.toast-root { position: fixed; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 9px; z-index: 200; }
.toast { background: #1c2740; color: #eef2fb; border-radius: 10px; padding: 11px 15px; font-size: 12.5px; box-shadow: 0 12px 32px rgba(15,23,42,.25); animation: toastIn .22s ease-out; max-width: 340px; }
.toast.ok { background: #0f766e; }
.toast.err { background: #b91c1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── 应用管理 ─────────────────────────────────────────── */
.app-admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.app-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.ac-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ac-title { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ac-title strong { font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-title code { font-size: 11.5px; color: var(--muted); }
.ac-note { margin-top: 8px; font-size: 12px; color: var(--text-2); }
.ac-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.ac-meta code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.ac-warn { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--red-soft); color: #b91c1c; font-size: 11.5px; }
.ac-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.btn-danger { color: #b91c1c; border-color: #f3c9c9; background: #fff5f5; }
.btn-danger:hover { background: #ffe9e9; }
.btn-primary.btn-danger { color: #fff; background: #c0392b; border-color: #c0392b; }
.apps-help-panel { margin-top: 16px; }
.apps-help { padding: 14px 20px 18px; font-size: 12.5px; color: var(--text-2); line-height: 1.8; }
.apps-help ol { margin: 0 0 10px; padding-left: 20px; }
.apps-help li { margin-bottom: 4px; }
.apps-help code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.hint-box { background: var(--primary-soft); border: 1px solid #dcdcff; border-radius: 9px; padding: 10px 12px; font-size: 12px; color: var(--text-2); line-height: 1.7; margin-bottom: 16px; }
.danger-box { background: #fff4f4; border: 1px solid #f6cccc; border-radius: 9px; padding: 11px 13px; font-size: 12px; color: #9f2b2b; line-height: 1.75; margin-bottom: 16px; }
.danger-box b { color: #b91c1c; }
.key-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 11.5px !important; line-height: 1.55; white-space: pre; overflow-x: auto; }
.key-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 16px; }
.key-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 11.5px; color: var(--muted); margin-bottom: 14px; }
.key-meta code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 1280px) {
  .chat-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .insight-panel { display: none; }
}
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .span-2, .dash-grid .span-2 { grid-column: auto; }
}
@media (max-width: 780px) {
  .sidebar { width: 62px; padding: 16px 8px; }
  .brand-text, .nav-caption, .nav-item span, .nav-item em, .status-card, .side-meta { display: none; }
  .brand { justify-content: center; padding: 0 0 20px; }
  .nav-item { justify-content: center; padding: 11px; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .session-panel { display: none; }
  .chat-panel { height: calc(100vh - 190px); min-height: 480px; }
  .topbar { padding: 0 14px; }
  .model-picker { display: none; }
  .views { padding: 14px; }
  .app-admin-grid { grid-template-columns: 1fr; }
}

/* ── 账户系统：顶栏用户区 + 账户管理 ─────────────────── */
.user-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface-2);
  font-size: 12.5px; color: var(--text-2); max-width: 220px;
}
.user-chip svg { width: 15px; height: 15px; color: var(--muted); }
.user-chip-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-role { font-style: normal; font-size: 10.5px; padding: 1px 7px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.user-chip.is-admin .user-chip-role { background: var(--primary-soft); color: var(--primary-dark); border-color: #dcdcff; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-mini.danger { color: var(--red); }
.btn-mini.danger:hover { background: var(--red-soft); }

/* ── 玩家历史咨询弹窗 ─────────────────────────────────── */
.ph-item {
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
  background: var(--surface); overflow: hidden;
}
.ph-item summary {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; cursor: pointer; font-size: 13px; list-style: none;
  user-select: none;
}
.ph-item summary::-webkit-details-marker { display: none; }
.ph-item summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.ph-item[open] summary::before { transform: rotate(90deg); }
.ph-item[open] summary { border-bottom: 1px solid var(--line); background: var(--surface-2); }
.ph-item .conv-detail { margin: 0; border-radius: 0; max-height: 340px; overflow-y: auto; }

/* ── 未读标记：新玩家消息红点（微信风格）───────────────── */
.session-item.has-unread { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--red); }
.session-item.has-unread .s-name { font-weight: 700; color: var(--text); }
.session-item.has-unread .s-preview { color: var(--text); font-weight: 600; }
.session-item.has-unread.active { background: var(--primary-soft); }
.session-item .s-right { display: flex; align-items: center; gap: 6px; flex: none; }
.session-item .s-name { flex: 1 1 auto; min-width: 0; }
.s-unread {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700;
  line-height: 1; letter-spacing: .2px; flex: none;
  box-shadow: 0 1px 3px rgba(239, 68, 68, .4);
}
.s-unread.is-more { padding: 0 6px; }
td .s-unread { margin-right: 5px; vertical-align: 1px; }

/* ── 人工客服回复：与机器人回复视觉区分 ────────────────── */
.msg.agent .bubble {
  background: #eefbf3;
  border: 1px solid #bfe9cf;
  color: var(--text);
}
.msg.agent .msg-avatar { color: #1a9e5c; }
.msg.agent .msg-meta { color: #1a9e5c; }

/* ── 玩家正在输入提示 ─────────────────────────────────── */
.typing-hint {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: auto; font-size: 11.5px; color: #1a9e5c;
  background: #eefbf3; border: 1px solid #bfe9cf; border-radius: 20px;
  padding: 3px 10px; white-space: nowrap;
}
.typing-hint[hidden] { display: none; }
.typing-hint i {
  width: 4px; height: 4px; border-radius: 50%; background: #1a9e5c;
  display: inline-block; animation: typingDot 1.2s infinite ease-in-out;
}
.typing-hint i:nth-child(2) { animation-delay: .18s; }
.typing-hint i:nth-child(3) { animation-delay: .36s; margin-right: 3px; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}
