/* ============ 基础 ============ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --cyan: #0891b2;
    --ink: #0f172a;
    --text: #334155;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #e5edf7;
    --bg: #f3f6fb;
    --card: #ffffff;
    --danger: #ef4444;
    --green: #10b981;
    --shadow: 0 18px 45px rgba(15, 23, 42, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d5e1f0; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #bccde3; }
::-webkit-scrollbar-track { background: transparent; }

.avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 600;
    flex: none;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
}
.brand-logo {
    width: 48px; height: 48px;
    border-radius: 15px;
    display: flex; align-items: center; justify-content: center;
    font-size: 21px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #2563eb, #06b6d4);
    box-shadow: 0 12px 26px rgba(37, 99, 235, .28);
    flex: none;
}
.brand-logo.small { width: 40px; height: 40px; border-radius: 13px; font-size: 18px; }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid #dbeafe;
    border-top-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    left: 50%; bottom: 34px;
    transform: translate(-50%, 20px);
    background: rgba(15, 23, 42, .92);
    color: #fff;
    font-size: 13px;
    padding: 10px 18px;
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transition: .22s ease;
    z-index: 3000;
    max-width: min(82vw, 420px);
    text-align: center;
    backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 20px;
    border: 0;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 24px rgba(37, 99, 235, .22);
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-soft {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid #d7e3f5;
    background: #fff;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
}
.btn-soft:hover { background: #f4f8ff; }
.btn-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid #dbe5f2;
    background: #fff;
    color: #3b5b8a;
    font-size: 12px;
    font-weight: 600;
}
.btn-mini:hover { background: #f4f8ff; border-color: #bfd3ef; }
.btn-mini.danger { color: var(--danger); border-color: #fecaca; background: #fff7f7; }

.icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: #51637a;
    transition: .16s;
}
.icon-btn:hover { background: #eef4fc; color: var(--primary); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.disabled { opacity: .35; pointer-events: none; }

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    display: inline-block;
    background: #cbd5e1;
    flex: none;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .14); }
.status-dot.offline { background: #94a3b8; }

/* ============ 登录页 ============ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 26px 16px;
    background:
        radial-gradient(circle at 12% 12%, rgba(37, 99, 235, .14), transparent 38%),
        radial-gradient(circle at 88% 82%, rgba(6, 182, 212, .14), transparent 40%),
        #f4f7fc;
}
.auth-shell { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: 13px; margin: 0 4px 20px; }
.auth-brand h1 { margin: 0; font-size: 18px; color: var(--ink); }
.auth-brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.auth-card {
    background: #fff;
    border-radius: 22px;
    padding: 30px 28px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, .8);
}
.auth-card h2 { margin: 0 0 6px; font-size: 21px; color: var(--ink); }
.auth-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: #3b4a60; margin: 15px 0 7px; }
.form-input {
    width: 100%; height: 44px;
    border: 1px solid #dbe4f1;
    border-radius: 11px;
    background: #fbfdff;
    padding: 0 13px;
    font-size: 14px;
    color: var(--ink);
    outline: none;
    transition: .18s;
}
.form-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.auth-submit { width: 100%; margin-top: 22px; }
.auth-tip { text-align: center; color: var(--faint); font-size: 12px; margin-top: 18px; }
.auth-footer { text-align: center; color: #9aabc0; font-size: 12px; margin-top: 20px; }
.form-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 13px;
    border-radius: 10px;
    padding: 10px 13px;
    margin-bottom: 4px;
}
.form-alert { border-radius: 12px; padding: 12px 15px; font-size: 13.5px; margin-bottom: 18px; }
.form-alert.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.form-alert.err { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

/* ============ 客户端 ============ */
.customer-page {
    background:
        radial-gradient(circle at 15% 8%, rgba(37, 99, 235, .10), transparent 32%),
        radial-gradient(circle at 85% 92%, rgba(6, 182, 212, .12), transparent 36%),
        #eef3fa;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 22px 14px;
}
.customer-shell { width: 100%; max-width: 520px; display: flex; flex-direction: column; align-items: center; }
.customer-app {
    width: 100%;
    height: min(820px, calc(100vh - 80px));
    min-height: 520px;
    background: #f7f9fd;
    border-radius: 26px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 70px rgba(15, 23, 42, .14);
    border: 1px solid rgba(255, 255, 255, .9);
    position: relative;
}
.customer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 17px;
    background: rgba(255, 255, 255, .93);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid #e8eff9;
    flex: none;
    z-index: 5;
}
.customer-identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.customer-identity .agent-avatar { width: 42px; height: 42px; font-size: 16px; }
.identity-text { min-width: 0; }
.identity-name { font-size: 15.5px; font-weight: 650; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.identity-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.header-actions { display: flex; gap: 4px; flex: none; }
.header-actions .icon-btn { color: var(--primary); background: #eff5ff; }
.header-actions .icon-btn:hover { background: #e2edff; }
.https-warning {
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    color: #b45309;
    font-size: 11.5px;
    padding: 7px 16px;
    text-align: center;
    flex: none;
}
.customer-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 13px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}
.customer-footer { margin-top: 12px; font-size: 11.5px; color: #9aabc0; text-align: center; }

.customer-composer {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #e8eff9;
    flex: none;
}
.customer-composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid #e2eaf5;
    background: #f7faff;
    border-radius: 13px;
    padding: 10px 12px;
    max-height: 120px;
    min-height: 40px;
    line-height: 1.5;
    font-size: 14px;
    color: var(--ink);
    outline: none;
    transition: .16s;
}
.customer-composer textarea:focus { border-color: #b9d2f7; background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .07); }
.composer-icon {
    width: 38px; height: 38px;
    border: 0; border-radius: 11px;
    background: transparent;
    color: #71829a;
    display: flex; align-items: center; justify-content: center;
    flex: none;
}
.composer-icon:hover { background: #eff5ff; color: var(--primary); }
.composer-icon svg { width: 22px; height: 22px; }
.send-btn {
    height: 38px;
    padding: 0 17px;
    border: 0;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    flex: none;
    transition: .16s;
}
.send-btn:disabled { opacity: .38; cursor: not-allowed; }
.send-btn:not(:disabled):hover { filter: brightness(1.05); }

/* 消息气泡 */
.msg-row { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; }
.msg-row.theirs { justify-content: flex-start; }
.msg-row.mine { justify-content: flex-end; }
.msg-avatar { width: 32px; height: 32px; font-size: 12px; margin-top: 2px; }
.msg-body { max-width: 76%; display: flex; flex-direction: column; }
.msg-row.mine .msg-body { align-items: flex-end; }
.bubble {
    padding: 10px 13px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 7px rgba(15, 23, 42, .035);
}
.bubble-theirs { background: #fff; border: 1px solid #e9eff8; color: #26364b; border-top-left-radius: 5px; }
.bubble-mine { background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; border-top-right-radius: 5px; }
.bubble.recalled { background: #eef2f7; color: #94a3b8; font-size: 12.5px; box-shadow: none; border: 0; font-style: italic; }
.bubble-sticker { background: transparent; padding: 0; border: 0; box-shadow: none; }
.sticker-img { width: 104px; height: 104px; display: block; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(15, 23, 42, .10)); }
.msg-meta { display: flex; align-items: center; gap: 7px; margin: 4px 3px 0; font-size: 10.5px; color: #9aabc0; flex-wrap: wrap; }
.msg-row.mine .msg-meta { justify-content: flex-end; }
.read-state { color: #9aabc0; }
.read-state.read { color: #0f9f6e; }
.recall-link { border: 0; background: transparent; color: #9aabc0; font-size: 10.5px; padding: 0; }
.recall-link:hover { color: var(--primary); }
.sender-label { color: #7c8ea6; }
.date-separator { align-self: center; margin: 16px 0 4px; font-size: 10.5px; color: #9fb0c4; background: rgba(255, 255, 255, .75); padding: 3px 10px; border-radius: 999px; }
.call-log {
    align-self: center;
    margin: 12px 0 2px;
    font-size: 11.5px;
    color: #7d8fa7;
    background: #edf2f9;
    border-radius: 999px;
    padding: 5px 12px;
    text-align: center;
}
.chat-loading, .list-placeholder, .chat-empty-tip {
    display: flex; align-items: center; justify-content: center; gap: 9px;
    color: #93a4ba; font-size: 13px; padding: 34px 14px; text-align: center;
}
.chat-error { padding: 40px 20px; text-align: center; color: #b91c1c; }
.chat-error p { margin: 0 0 14px; font-size: 13.5px; }

/* 表情选择 */
.picker-panel {
    background: #fff;
    border-top: 1px solid #e8eff9;
    padding: 12px 14px 14px;
    flex: none;
    max-height: 240px;
    overflow-y: auto;
    animation: panelUp .18s ease;
}
@keyframes panelUp { from { transform: translateY(8px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }
.picker-title { font-size: 12px; font-weight: 600; color: #64748b; margin-bottom: 10px; }
.sticker-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.sticker-item {
    border: 1px solid transparent;
    background: #f7faff;
    border-radius: 12px;
    padding: 5px;
    display: flex; align-items: center; justify-content: center;
    transition: .15s;
}
.sticker-item:hover { border-color: #cfe0f8; background: #eef5ff; transform: translateY(-1px); }
.sticker-item .sticker-img { width: 48px; height: 48px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-item { border: 0; background: transparent; font-size: 23px; padding: 3px 0; border-radius: 8px; }
.emoji-item:hover { background: #eff5ff; }

/* 通话浮层 */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(8, 15, 30, .72);
    backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.call-card {
    width: min(430px, 100%);
    background: linear-gradient(160deg, #16233a, #0b1526);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 26px;
    padding: 26px 22px 24px;
    color: #fff;
    box-shadow: 0 40px 90px rgba(0, 0, 0, .45);
    text-align: center;
    position: relative;
    overflow: hidden;
}
.call-header { display: flex; align-items: center; gap: 13px; text-align: left; position: relative; z-index: 2; }
.call-avatar {
    width: 56px; height: 56px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    font-size: 21px; font-weight: 600;
    flex: none;
    box-shadow: 0 0 0 6px rgba(59, 130, 246, .13);
}
.call-name { font-size: 17px; font-weight: 600; }
.call-status { font-size: 12.5px; color: #9fb1c9; margin-top: 4px; }
.call-videos {
    position: relative;
    margin-top: 20px;
    border-radius: 18px;
    overflow: hidden;
    background: #081120;
    height: 300px;
    display: none;
}
.call-videos.visible { display: block; }
.call-videos video { width: 100%; height: 100%; object-fit: cover; background: #081120; }
#localVideo {
    position: absolute;
    right: 10px; top: 10px;
    width: 96px; height: 130px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, .2);
    object-fit: cover;
    z-index: 3;
    background: #0b1526;
}
.call-timer { margin-top: 18px; font-size: 24px; font-weight: 300; letter-spacing: 2px; font-variant-numeric: tabular-nums; color: #e2e8f0; }
.call-actions { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.call-btn {
    min-width: 74px;
    height: 42px;
    padding: 0 17px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .09);
    color: #e8eef7;
    font-size: 13px;
    font-weight: 600;
}
.call-btn:hover { background: rgba(255, 255, 255, .15); }
.call-btn.accept { background: #16a34a; border-color: #16a34a; }
.call-btn.reject, .call-btn.end { background: #e11d48; border-color: #e11d48; }
.call-btn.off { opacity: .55; }
.mode-incoming .call-card { box-shadow: 0 0 0 1px rgba(59, 130, 246, .4), 0 40px 90px rgba(0, 0, 0, .5); }
.mode-incoming .call-avatar { animation: pulseRing 1.5s infinite; }
@keyframes pulseRing {
    0% { box-shadow: 0 0 0 6px rgba(59, 130, 246, .13); }
    50% { box-shadow: 0 0 0 14px rgba(59, 130, 246, .04); }
    100% { box-shadow: 0 0 0 6px rgba(59, 130, 246, .13); }
}

/* 入口错误页 */
.entry-error { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.entry-error-card {
    width: min(440px, 100%);
    background: #fff;
    border-radius: 24px;
    padding: 38px 30px;
    text-align: center;
    box-shadow: var(--shadow);
}
.entry-error-card .brand-logo { margin: 0 auto 18px; }
.entry-error-card h1 { font-size: 20px; color: var(--ink); margin: 0 0 10px; }
.entry-error-card p { font-size: 13.5px; line-height: 1.8; color: var(--muted); margin: 0 0 22px; }

/* ============ 工作台 ============ */
.admin-page { overflow: hidden; }
.dashboard { display: grid; grid-template-columns: 356px minmax(0, 1fr); height: 100vh; background: var(--bg); }
.sidebar {
    background: #fff;
    border-right: 1px solid #e6edf7;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; gap: 10px; }
.side-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.side-brand-name { font-size: 14.5px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.side-brand-sub { font-size: 11px; color: var(--faint); margin-top: 2px; }
.logout-btn { flex: none; }

.me-card {
    margin: 4px 16px 12px;
    background: linear-gradient(135deg, #f4f9ff, #f2fbfa);
    border: 1px solid #e5f0fb;
    border-radius: 15px;
    padding: 11px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.me-avatar { width: 38px; height: 38px; font-size: 15px; }
.me-info { flex: 1; min-width: 0; }
.me-name { font-size: 13.5px; font-weight: 650; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role { font-size: 10.5px; color: #7c8ea6; margin-top: 2px; }
.online-toggle {
    display: flex; align-items: center; gap: 5px;
    border: 1px solid #dbe7f4;
    background: #fff;
    color: #64748b;
    font-size: 11px;
    border-radius: 999px;
    padding: 5px 9px;
    flex: none;
}
.online-toggle.on { color: #047857; border-color: #bbf7d0; background: #f0fdf4; }

.side-qr {
    margin: 0 16px 14px;
    border: 1px dashed #dbe6f4;
    border-radius: 15px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 11px;
    background: #fbfdff;
}
.side-qr-code { width: 64px; height: 64px; flex: none; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 8px; overflow: hidden; }
.side-qr-code canvas, .side-qr-code img { width: 60px !important; height: 60px !important; }
.side-qr-info { min-width: 0; }
.side-qr-title { font-size: 12.5px; font-weight: 650; color: #26364b; }
.side-qr-desc { font-size: 10.5px; color: #94a3b8; margin-top: 2px; }
.link-btn { border: 0; background: transparent; color: var(--primary); font-size: 11px; padding: 3px 0 0; font-weight: 600; }

.session-head { padding: 0 16px 10px; flex: none; }
.session-head-title { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; color: #45566e; margin-bottom: 9px; }
.unread-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    font-weight: 600;
}
.session-search {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    border: 1px solid #e3ebf5;
    background: #f8fbff;
    border-radius: 10px;
    padding: 0 10px;
    color: #93a4ba;
}
.session-search svg { width: 15px; height: 15px; flex: none; }
.session-search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 12.5px; color: var(--ink); min-width: 0; }
.agent-filter {
    width: 100%;
    height: 34px;
    border: 1px solid #e3ebf5;
    background: #fff;
    border-radius: 9px;
    padding: 0 9px;
    font-size: 12px;
    color: #51637a;
    margin-top: 7px;
    outline: none;
}
.session-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; min-height: 0; }
.session-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    text-align: left;
    transition: .15s;
    position: relative;
}
.session-item:hover { background: #f5f9ff; }
.session-item.active { background: linear-gradient(135deg, #eef5ff, #edfbf9); }
.session-avatar { width: 40px; height: 40px; font-size: 14px; position: relative; }
.session-avatar.has-unread::after {
    content: "";
    position: absolute;
    right: -1px; top: -1px;
    width: 9px; height: 9px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
}
.session-main { flex: 1; min-width: 0; }
.session-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.session-name-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.session-name { font-size: 13.5px; font-weight: 650; color: #26364b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-agent-tag {
    font-size: 9.5px;
    color: #2563eb;
    background: #eaf2ff;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 500;
    white-space: nowrap;
    flex: none;
}
.session-time { font-size: 10px; color: #a3b2c5; flex: none; }
.session-preview { font-size: 11.5px; color: #93a4ba; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-unread {
    min-width: 19px; height: 19px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    flex: none;
}
.sidebar-foot { display: flex; gap: 4px; padding: 8px 12px 12px; border-top: 1px solid #eef3fa; flex: none; flex-wrap: wrap; }
.foot-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0;
    background: transparent;
    color: #607089;
    font-size: 11.5px;
    padding: 6px 7px;
    border-radius: 8px;
}
.foot-link:hover { background: #f1f6fd; color: var(--primary); }
.foot-link svg { width: 14px; height: 14px; }

.workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #8fa1b7;
    padding: 30px;
    text-align: center;
}
.empty-graphic { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.empty-bubble {
    width: 68px; height: 54px;
    border-radius: 18px 18px 18px 6px;
    background: #fff;
    border: 1px solid #e1ebf7;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #3b82f6;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .06);
}
.empty-lines { display: flex; flex-direction: column; gap: 7px; }
.empty-lines span { display: block; height: 9px; border-radius: 999px; background: #e3ebf6; }
.empty-lines span:nth-child(1) { width: 84px; }
.empty-lines span:nth-child(2) { width: 64px; }
.empty-lines span:nth-child(3) { width: 42px; }
.chat-empty h2 { font-size: 18px; color: #344760; margin: 0 0 8px; }
.chat-empty p { font-size: 13px; margin: 0 0 20px; line-height: 1.8; max-width: 360px; }

.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #f7f9fd; }
.chat-header {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e8eff9;
    flex: none;
    z-index: 4;
}
.chat-avatar { width: 42px; height: 42px; font-size: 16px; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 650; color: var(--ink); flex-wrap: wrap; }
.source-badge {
    font-size: 10px;
    font-weight: 500;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 999px;
    padding: 2px 8px;
}
.source-badge.mine { color: #1d4ed8; background: #eaf2ff; }
.chat-header-meta { font-size: 11px; color: #93a4ba; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-actions { display: flex; gap: 4px; flex: none; }
.chat-header-actions .icon-btn { color: var(--primary); background: #eff5ff; }
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 24px 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    scroll-behavior: smooth;
}
.chat-composer { background: #fff; border-top: 1px solid #e8eff9; padding: 8px 20px 16px; flex: none; }
.composer-toolbar { display: flex; gap: 4px; margin-bottom: 6px; }
.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0;
    background: transparent;
    color: #6b7d94;
    font-size: 11.5px;
    padding: 5px 8px;
    border-radius: 8px;
}
.tool-btn:hover { background: #f1f6fd; color: var(--primary); }
.tool-btn svg { width: 15px; height: 15px; }
.composer-row { display: flex; align-items: flex-end; gap: 9px; }
.composer-row textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 140px;
    border: 1px solid #e1eaf6;
    background: #f8fbff;
    border-radius: 12px;
    padding: 11px 13px;
    line-height: 1.55;
    font-size: 13.5px;
    color: var(--ink);
    outline: none;
    transition: .16s;
}
.composer-row textarea:focus { border-color: #b9d2f7; background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .06); }
.composer-row .send-btn { height: 44px; padding: 0 24px; }
.mobile-back { display: none; }

/* 弹窗 */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(15, 23, 42, .42);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-card {
    width: min(560px, 100%);
    max-height: min(80vh, 680px);
    overflow-y: auto;
    background: #fff;
    border-radius: 20px;
    padding: 22px;
    box-shadow: 0 30px 80px rgba(15, 23, 42, .25);
    display: flex;
    flex-direction: column;
    animation: modalIn .18s ease;
}
@keyframes modalIn { from { transform: translateY(12px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex: none; }
.modal-head h3 { margin: 0; font-size: 17px; color: var(--ink); }
.modal-head p { margin: 5px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.modal-close { flex: none; }
.quick-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; min-height: 120px; padding-right: 2px; }
.quick-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid #e8eff9;
    background: #fbfdff;
    border-radius: 11px;
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    color: #334155;
    transition: .15s;
}
.quick-item:hover { border-color: #c8dcf7; background: #f4f9ff; }
.quick-text { flex: 1; line-height: 1.55; }
.quick-tag { font-size: 9.5px; color: #64748b; background: #eef2f7; border-radius: 999px; padding: 2px 7px; flex: none; }
.quick-del { font-size: 10.5px; color: #c0cad7; flex: none; padding: 3px 4px; border-radius: 5px; }
.quick-del:hover { color: var(--danger); background: #fef2f2; }
.quick-add-box { display: flex; gap: 8px; align-items: center; padding-top: 14px; border-top: 1px solid #eef3fa; margin-top: 12px; flex: none; flex-wrap: wrap; }
.quick-add-box input[type=text] {
    flex: 1;
    min-width: 180px;
    height: 38px;
    border: 1px solid #e1eaf6;
    border-radius: 9px;
    padding: 0 11px;
    font-size: 12.5px;
    outline: none;
}
.quick-add-box input[type=text]:focus { border-color: var(--primary); }
.quick-global { font-size: 12px; color: #64748b; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.qr-big { display: flex; justify-content: center; padding: 12px 0 4px; }
.qr-big canvas, .qr-big img { width: 232px !important; height: 232px !important; }
.qr-link-text { font-size: 11.5px; color: #64748b; text-align: center; word-break: break-all; line-height: 1.7; margin: 10px 4px 0; }
.modal-actions { display: flex; justify-content: center; gap: 9px; margin-top: 16px; }

/* 客服管理子页 */
.admin-subpage { background: #f3f6fb; min-height: 100vh; }
.subpage-header {
    height: 70px;
    background: #fff;
    border-bottom: 1px solid #e8eff9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.subpage-brand { display: flex; align-items: center; gap: 11px; }
.subpage-title { font-size: 15px; font-weight: 700; color: var(--ink); }
.subpage-sub { font-size: 11px; color: var(--faint); margin-top: 2px; }
.subpage-actions { display: flex; gap: 8px; }
.subpage-main { max-width: 1180px; margin: 0 auto; padding: 24px 22px 50px; }
.panel-card { background: #fff; border-radius: 18px; border: 1px solid #e8eff9; box-shadow: 0 10px 30px rgba(15, 23, 42, .04); padding: 22px; }
.panel-head h2 { margin: 0 0 6px; font-size: 17px; color: var(--ink); }
.panel-head p { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: #3b4a60; }
.form-submit { margin-top: 16px; }
.agent-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.agent-card { background: #fff; border: 1px solid #e8eff9; border-radius: 18px; padding: 18px; box-shadow: 0 8px 24px rgba(15, 23, 42, .04); }
.agent-card-head { display: flex; align-items: center; gap: 11px; }
.agent-card-avatar { width: 44px; height: 44px; font-size: 17px; }
.agent-card-title { min-width: 0; }
.agent-card-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14.5px; font-weight: 650; color: var(--ink); }
.tag { font-size: 9.5px; border-radius: 999px; padding: 2px 7px; font-weight: 500; }
.tag.admin { color: #1d4ed8; background: #eaf2ff; }
.tag.ok { color: #047857; background: #ecfdf5; }
.tag.off { color: #b91c1c; background: #fef2f2; }
.agent-card-account { font-size: 11px; color: #93a4ba; margin-top: 3px; }
.agent-stats { display: flex; gap: 8px; margin: 14px 0; }
.agent-stats > div { flex: 1; background: #f8fbff; border: 1px solid #eef4fc; border-radius: 10px; padding: 8px; text-align: center; }
.agent-stats b { display: block; font-size: 14px; color: #1d4ed8; font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.agent-stats span { font-size: 10px; color: #93a4ba; }
.agent-qr-wrap { display: flex; gap: 13px; align-items: center; background: #fbfdff; border: 1px dashed #e0eaf7; border-radius: 13px; padding: 11px; }
.agent-qr { width: 122px; height: 122px; flex: none; background: #fff; border-radius: 8px; padding: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.agent-qr canvas, .agent-qr img { width: 116px !important; height: 116px !important; }
.agent-qr-side { min-width: 0; flex: 1; }
.agent-link { font-size: 10.5px; color: #7c8ea6; line-height: 1.5; word-break: break-all; max-height: 32px; overflow: hidden; }
.agent-qr-actions { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.agent-settings { margin-top: 12px; border-top: 1px solid #f0f5fb; padding-top: 10px; }
.agent-settings summary { cursor: pointer; font-size: 12px; color: #607089; list-style: none; }
.agent-settings summary::-webkit-details-marker { display: none; }
.agent-settings summary::before { content: "▸ "; color: #94a3b8; }
.agent-settings[open] summary::before { content: "▾ "; }
.agent-form { display: flex; flex-direction: column; gap: 5px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed #eef3fa; }
.agent-form label { font-size: 11px; color: #64748b; }
.agent-form .form-input { height: 36px; font-size: 12.5px; }
.agent-form .btn-mini { align-self: flex-start; margin-top: 5px; }

/* 图片消息与灯箱 */
.bubble-image { background: transparent; border: 0; padding: 0; box-shadow: none; }
.msg-image { display: block; max-width: 230px; max-height: 260px; border-radius: 13px; cursor: zoom-in; border: 1px solid #e5edf8; background: #f8fafc; object-fit: cover; }
.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(5, 10, 20, .88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    cursor: zoom-out;
}
.image-viewer img { max-width: 94vw; max-height: 92vh; border-radius: 8px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }

/* 表情搜索 */
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.picker-head .picker-title { margin: 0; }
.picker-search {
    width: min(240px, 62%);
    height: 30px;
    border: 1px solid #e1eaf6;
    border-radius: 8px;
    padding: 0 10px;
    font-size: 12px;
    outline: none;
    background: #f8fbff;
}
.picker-search:focus { border-color: #b9d2f7; background: #fff; }
.sticker-empty { grid-column: 1 / -1; text-align: center; color: #93a4ba; font-size: 12px; padding: 18px 0; }
.auto-tag { font-size: 9px; color: #0f766e; background: #ccfbf1; border-radius: 999px; padding: 1px 6px; margin-left: 5px; vertical-align: 1px; }

/* 管理弹窗扩展 */
.icon-btn.danger { color: #dc2626; background: #fef2f2; }
.icon-btn.danger:hover { color: #b91c1c; background: #fee2e2; }
.foot-state { margin-left: auto; font-size: 10px; color: #16a34a; background: #ecfdf5; border-radius: 999px; padding: 1px 7px; }
.foot-state.off { color: #94a3b8; background: #f1f5f9; }
.modal-wide { width: min(680px, 100%); }
.check-line { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: #475569; line-height: 1.6; margin: 10px 0; cursor: pointer; }
.check-line input[type=checkbox] { width: auto; padding: 0; border: 0; margin-top: 2px; flex: none; accent-color: var(--primary); }
.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: #64748b; margin-top: 10px; }
.field-label input, .field-label textarea, .auto-rule-form input[type=text], .auto-rule-form textarea, .auto-rule-form select {
    width: 100%;
    border: 1px solid #e1eaf6;
    border-radius: 9px;
    padding: 9px 11px;
    font-size: 12.5px;
    color: var(--ink);
    outline: none;
    background: #fbfdff;
    font-family: inherit;
}
.field-label textarea, .auto-rule-form textarea { resize: vertical; line-height: 1.6; }
.field-label input:focus, .field-label textarea:focus, .auto-rule-form input[type=text]:focus, .auto-rule-form textarea:focus, .auto-rule-form select:focus { border-color: #b9d2f7; background: #fff; }
.btn-danger {
    height: 38px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: #dc2626;
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
}
.btn-danger:hover { background: #b91c1c; }
.divider { height: 1px; background: #eef3fa; margin: 16px 0; }
.form-row { display: flex; gap: 8px; margin-bottom: 8px; }
.form-row input[type=text] { flex: 1; width: auto; }
.form-row select { width: 130px; flex: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.auto-rule-form { background: #f8fbff; border: 1px solid #eef4fc; border-radius: 12px; padding: 12px; }
.auto-list, .blacklist-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; min-height: 90px; max-height: 260px; margin-top: 12px; padding-right: 2px; }
.auto-item, .blacklist-item { border: 1px solid #e8eff9; background: #fbfdff; border-radius: 10px; padding: 9px 11px; font-size: 12px; color: #334155; }
.auto-item-head { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.auto-keyword { font-weight: 600; color: #1d4ed8; }
.auto-match { font-size: 9.5px; color: #64748b; background: #eef2f7; border-radius: 999px; padding: 1px 7px; }
.auto-reply-text { color: #64748b; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.auto-item-actions { display: flex; gap: 8px; margin-top: 7px; }
.mini-link { border: 0; background: transparent; color: #64748b; font-size: 11px; padding: 0; }
.mini-link:hover { color: var(--primary); }
.mini-link.danger:hover { color: #dc2626; }
.blacklist-item { display: flex; align-items: center; gap: 10px; }
.blacklist-info { flex: 1; min-width: 0; }
.blacklist-title { font-weight: 600; color: #334155; margin-bottom: 3px; }
.blacklist-meta { font-size: 10.5px; color: #93a4ba; line-height: 1.6; word-break: break-all; }
.empty-tip { text-align: center; color: #93a4ba; font-size: 12px; padding: 22px 0; }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
    .admin-page { overflow: auto; }
    .dashboard { display: block; height: 100vh; }
    .sidebar { width: 100%; height: 100vh; border-right: 0; }
    .workspace { display: none; }
    .dashboard.chat-open .sidebar { display: none; }
    .dashboard.chat-open .workspace { display: flex; height: 100vh; height: 100dvh; }
    .chat-panel { height: 100vh; height: 100dvh; }
    .chat-empty { display: none; }
    .mobile-back { display: flex; }
    .chat-header { padding: 10px 12px; }
    .chat-messages { padding: 14px 12px 8px; }
    .chat-composer { padding: 7px 12px calc(10px + env(safe-area-inset-bottom)); }
    .side-brand-name { max-width: 220px; }
    .agent-grid, .form-grid { grid-template-columns: 1fr; }
    .subpage-header { padding: 0 16px; }
    .subpage-main { padding: 18px 14px 40px; }
}
@media (max-width: 560px) {
    .customer-page { padding: 0; display: block; background: #f7f9fd; }
    .customer-shell { max-width: none; height: 100vh; }
    .customer-app { height: 100vh; height: 100dvh; min-height: 0; border-radius: 0; border: 0; box-shadow: none; }
    .customer-footer { display: none; }
    .customer-messages { padding: 14px 11px 6px; }
    .msg-body { max-width: 80%; }
    .sticker-grid { grid-template-columns: repeat(5, 1fr); }
    .sticker-img { width: 92px; height: 92px; }
    .emoji-grid { grid-template-columns: repeat(7, 1fr); }
    .modal-card { padding: 18px; border-radius: 17px; }
    .call-card { border-radius: 22px; padding: 22px 18px; }
    .call-videos { height: 260px; }
    .toast { bottom: 26px; }
    .quick-add-box input[type=text] { min-width: 120px; }
}
