:root { --bg:#0f1419; --panel:#1a2129; --line:#2a3441; --fg:#dce3ea; --muted:#8b98a8; --ok:#3fb27f; --bad:#e05c5c; --warn:#e0a75c; --pri:#3d7fe0; }
* { box-sizing:border-box; }
[hidden] { display:none !important; }
body { margin:0; font-family:"Microsoft YaHei",system-ui,sans-serif; background:var(--bg); color:var(--fg); font-size:14px; }
.gate { display:flex; align-items:center; justify-content:center; height:100vh; }
.gate-card { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:32px; width:340px; display:flex; flex-direction:column; gap:12px; }
.shell { display:flex; min-height:100vh; }
aside { width:200px; background:var(--panel); border-right:1px solid var(--line); padding:16px 12px; display:flex; flex-direction:column; gap:6px; }
.brand { display:flex; flex-direction:column; padding:6px 10px 16px; }
.brand strong { font-size:18px; }
.brand span { color:var(--muted); font-size:12px; }
.nav { background:none; border:none; color:var(--muted); text-align:left; padding:9px 12px; border-radius:6px; cursor:pointer; font-size:14px; }
.nav:hover { background:#222b35; color:var(--fg); }
.nav.active { background:var(--pri); color:#fff; }
.nav-group { display:flex; flex-direction:column; gap:2px; }
.nav-group-title { color:var(--muted); font-size:11px; letter-spacing:2px; padding:10px 12px 3px; }
.nav.sub { font-size:13px; padding:7px 12px 7px 26px; }
main { flex:1; padding:24px; max-width:1200px; }
h1 { font-size:20px; margin:0 0 16px; }
h2 { font-size:16px; margin:20px 0 10px; }
.muted { color:var(--muted); }
button { background:#2a3441; color:var(--fg); border:none; border-radius:6px; padding:7px 14px; cursor:pointer; }
button.primary { background:var(--pri); color:#fff; }
button.small { padding:3px 10px; font-size:12px; }
input, textarea, select { background:#12181f; border:1px solid var(--line); color:var(--fg); border-radius:6px; padding:8px 10px; font-size:13px; width:100%; }
textarea { min-height:90px; font-family:Consolas,monospace; }
label { display:block; margin:8px 0 4px; color:var(--muted); font-size:12px; }
table { width:100%; border-collapse:collapse; margin-top:10px; font-size:13px; }
th, td { text-align:left; padding:7px 10px; border-bottom:1px solid var(--line); vertical-align:top; }
th { color:var(--muted); font-weight:normal; }
code { background:#12181f; padding:2px 6px; border-radius:4px; }
.cards { display:flex; flex-wrap:wrap; gap:12px; }
.card { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:14px 18px; min-width:150px; }
.card .num { font-size:26px; font-weight:600; }
.card .lbl { color:var(--muted); font-size:12px; margin-top:4px; }
.banner { padding:10px 14px; border-radius:6px; margin:10px 0; }
.banner.bad { background:#3a2226; color:#f0a8a8; }
.banner.good { background:#1f3329; color:#8fd8b3; }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:0 16px; background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:16px; margin-bottom:16px; }
.form-grid .full { grid-column:1 / -1; }
.tag { display:inline-block; padding:2px 8px; border-radius:10px; font-size:12px; }
.tag.ok { background:#1f3329; color:var(--ok); }
.tag.bad { background:#3a2226; color:var(--bad); }
.tag.warn { background:#3a2f1f; color:var(--warn); }
.tag.info { background:#1f2b3d; color:#8fb8f0; }
.mono { font-family:Consolas,monospace; font-size:12px; }
tr:hover td { background:#161d25; }
.row-actions { display:flex; gap:8px; margin:10px 0; align-items:center; flex-wrap:wrap; }
pre.result { background:#0b0f14; border:1px solid var(--line); border-radius:6px; padding:12px; overflow:auto; max-height:400px; font-size:12px; }

/* ---------------- 聊天记录 ---------------- */
.chat-wrap { display:flex; gap:16px; align-items:flex-start; }
.chat-list { width:300px; flex-shrink:0; background:var(--panel); border:1px solid var(--line); border-radius:8px; overflow:hidden; }
.chat-list .item { padding:10px 12px; border-bottom:1px solid var(--line); cursor:pointer; }
.chat-list .item:hover { background:#222b35; }
.chat-list .item.active { background:#1f2b3d; border-left:3px solid var(--pri); }
.chat-list .item .name { font-weight:600; }
.chat-list .item .preview { color:var(--muted); font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:3px; }
.chat-list .item .meta { color:var(--muted); font-size:11px; margin-top:3px; display:flex; justify-content:space-between; }
.chat-main { flex:1; min-width:0; }
.chat-msgs { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:16px; min-height:400px; max-height:65vh; overflow-y:auto; display:flex; flex-direction:column; gap:10px; }
.bubble { max-width:70%; padding:8px 12px; border-radius:10px; font-size:13px; line-height:1.6; white-space:pre-wrap; word-break:break-word; }
.bubble .b-meta { display:block; font-size:11px; color:var(--muted); margin-bottom:3px; }
.bubble.in { align-self:flex-start; background:#222b35; border:1px solid var(--line); }
.bubble.out { align-self:flex-end; background:#1f3329; border:1px solid #2a4a3a; }
.bubble.unknown { align-self:center; background:#12181f; border:1px dashed var(--line); color:var(--muted); text-align:center; }

.chat-sendbar { display:flex; gap:8px; }
.chat-sendbar input { flex:1; }

/* AI 规则参考对话选择器 */
.ref-tags { margin: 4px 0; }
.ref-tag { display: inline-block; background: #e8f0fe; color: #1a56db; border-radius: 10px; padding: 2px 10px; margin: 0 6px 6px 0; font-size: 12px; }
.ref-tag a { color: #999; margin-left: 6px; text-decoration: none; cursor: pointer; }
.ref-picker { display: flex; gap: 10px; border: 1px solid #ddd; border-radius: 8px; margin-top: 8px; height: 320px; }
.ref-picker-list { width: 260px; overflow-y: auto; border-right: 1px solid #eee; padding: 8px; }
.ref-conv { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.ref-conv:hover, .ref-conv.active { background: #f0f4ff; }
.ref-conv-check { font-size: 12px; color: #1a56db; cursor: pointer; }
.ref-conv-name { font-weight: 600; font-size: 13px; margin: 2px 0; }
.ref-picker-chat { flex: 1; overflow-y: auto; padding: 12px; background: #f7f7f8; }
.bubble-row { display: flex; margin-bottom: 10px; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-who { font-size: 11px; color: #999; margin: 0 6px; align-self: flex-end; }
.bubble { max-width: 65%; padding: 8px 12px; border-radius: 10px; background: #fff; border: 1px solid #e5e5e5; white-space: pre-wrap; word-break: break-all; }
.bubble-row.mine .bubble { background: #95ec69; border-color: #95ec69; }

.ref-auto-label { display: block; font-size: 13px; color: #444; margin: 4px 0; cursor: pointer; }
.ref-auto-label input[type=number] { margin: 0 4px; }

.ref-tag-excl { background: #fde8e8; color: #c0392b; }
.ref-excl-btn { float: right; font-size: 12px; padding: 1px 8px; }
.ref-conv.excluded { opacity: 0.55; }
.ref-conv.excluded .ref-conv-name { text-decoration: line-through; }

/* 多选下拉（会话范围/发件人过滤） */
.msel { position: relative; display: inline-block; min-width: 200px; }
.msel-btn { width: 100%; text-align: left; padding: 6px 10px; background: #fff; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; }
.msel-panel { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; max-height: 220px; overflow-y: auto; background: #fff; border: 1px solid #ccc; border-radius: 4px; margin-top: 2px; box-shadow: 0 2px 8px rgba(0,0,0,.12); padding: 4px 0; }
.msel-item { display: block; padding: 5px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msel-item:hover { background: #f0f4ff; }
.msel-item input { margin-right: 6px; }

/* 暗色主题修正：下拉面板/参考选择器/聊天气泡（覆盖上方浅色样式） */
.msel-btn { background: #12181f; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; }
.msel-panel { background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.msel-item { color: var(--fg); }
.msel-item:hover { background: #222b35; }
.ref-picker { border-color: var(--line); }
.ref-picker-list { background: var(--panel); border-right-color: var(--line); }
.ref-conv-name { color: var(--fg); }
.ref-conv:hover, .ref-conv.active { background: #222b35; }
.ref-conv-check { color: #8fb8f0; }
.ref-excl-btn { background: #3a2226; color: #f0a8a8; }
.ref-picker-chat { background: #0b0f14; }
.bubble { background: #222b35; color: var(--fg); border-color: var(--line); }
.bubble-row.mine .bubble { background: #1f3329; border-color: #2a4a3a; }
.bubble-who { color: var(--muted); }
.ref-auto-label { color: var(--muted); }

/* 修复：全局 input 100% 宽度导致 checkbox 占满整行、挤掉后面的文字 */
input[type=checkbox], input[type=radio] { width: auto; }

/* 聊天图片 */
.b-img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; margin-top: 4px; border: 1px solid var(--line); cursor: pointer; }

/* ---------------- 账号/角色管理 ---------------- */
.side-user { margin-top:auto; padding:10px; border-top:1px solid var(--line); }
.side-user .su-name { font-weight:600; font-size:13px; }
.side-user .su-role { color:var(--muted); font-size:12px; margin:2px 0 6px; }
.perm-grid { display:flex; flex-wrap:wrap; gap:6px 16px; padding:6px 0; }
.perm-grid-compact { gap:2px 10px; }
.perm-item { display:inline-flex; align-items:center; gap:4px; margin:0; color:var(--fg); font-size:13px; }
td input, td select { width:auto; min-width:110px; padding:4px 8px; }

/* 监听名单管理 */
.listen-panel { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:14px 16px; margin-top:16px; }
.listen-panel h2 { margin-top:0; }
.lp-tags { display:flex; flex-wrap:wrap; gap:6px; margin:8px 0 10px; }
.ref-tag { display:inline-flex; align-items:center; gap:6px; background:#1f2b3d; border:1px solid var(--line); border-radius:12px; padding:3px 10px; font-size:12px; font-family:Consolas,monospace; }
.ref-tag a { color:var(--bad); text-decoration:none; font-weight:600; }

/* 模拟对话：纠正入口 */
.rt-fix { color:var(--warn); text-decoration:none; font-size:11px; margin-left:6px; border:1px solid var(--line); border-radius:8px; padding:1px 8px; }
.rt-fix:hover { background:#222b35; }

/* 客户画像卡片 */
.cp-card { background:var(--panel); border:1px solid var(--line); border-left:3px solid var(--pri); border-radius:8px; padding:8px 12px; margin-bottom:8px; }

/* 站内确认、错误与成功弹窗 */
.site-dialog { width:min(480px,calc(100vw - 32px)); max-height:85vh; overflow:auto; padding:24px; border:1px solid var(--line); border-radius:14px; background:var(--panel); color:var(--fg); box-shadow:0 24px 80px #0009; }
.site-dialog::backdrop { background:rgba(0,0,0,.62); }
.site-dialog-heading { display:flex; gap:12px; align-items:center; }
.site-dialog h2 { margin:0; font-size:19px; }
.site-dialog-icon { display:grid; place-items:center; flex-shrink:0; width:32px; height:32px; border-radius:50%; background:#3a2f1f; color:var(--warn); font-size:20px; font-weight:bold; }
.site-dialog[data-kind=success] .site-dialog-icon { background:#1f3329; color:var(--ok); }
.site-dialog[data-kind=danger] .site-dialog-icon, .site-dialog[data-kind=error] .site-dialog-icon { background:#3a2226; color:var(--bad); }
#site-dialog-message { line-height:1.8; white-space:pre-wrap; overflow-wrap:anywhere; margin:18px 0; }
.site-dialog-actions { display:flex; gap:12px; justify-content:flex-end; margin-top:24px; }
.site-dialog-ok { background:var(--pri); color:white; }
.site-dialog[data-kind=danger] .site-dialog-ok { background:#b83e48; }
.site-dialog button:focus-visible, .site-dialog input:focus-visible { outline:3px solid #8fb8f0; outline-offset:3px; }
.site-dialog-field input { display:block; margin-top:8px; }

/* 登录密码框：右侧眼睛按钮（显示/隐藏明文） */
.pwd-wrap { position: relative; display: flex; }
.pwd-wrap input { padding-right: 40px; }
.pwd-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; background: none; border: none; border-radius: 6px; color: var(--muted); cursor: pointer; }
.pwd-eye:hover { color: var(--fg); background: #1c2530; }
.pwd-eye.on { color: var(--pri); }
/* AI 自动回复总开关（聊天记录页顶部） */
.ai-switch { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; background: var(--panel); }
.ai-switch.on { border-color: #1f6feb66; box-shadow: 0 0 0 3px #1f6feb14; }
.ai-switch.off { border-color: #c0392b66; box-shadow: 0 0 0 3px #c0392b14; }
.ai-switch-label { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--fg); }
.ai-switch-label input { width: auto; }
/* 引用回复气泡：被引用内容 + 回复正文 */
.quote-box { border-left: 3px solid var(--line); padding: 4px 8px; margin: 2px 0 6px; background: #00000014; border-radius: 4px; font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.quote-who { color: var(--pri); }
.quote-reply { white-space: pre-wrap; word-break: break-word; }