/* ============================================================
   客服在线聊天 - 样式表
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --green: #10b981;
    --text: #1e293b;
    --text-soft: #64748b;
    --text-mute: #94a3b8;
    --border: #e5e9f0;
    --bg: #f5f7fb;
    --white: #fff;
    --danger: #ef4444;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    color: var(--text);
    font-size: 14px;
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.btn-primary {
    border: 0;
    background: var(--primary);
    color: #fff;
    border-radius: 9px;
    padding: 0 20px;
    height: 40px;
    font-size: 14px;
    transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-ghost {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-soft);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 13px;
    transition: all .15s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* ==================== 登录页 ==================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eff6ff 0%, #eef2ff 100%);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(37, 99, 235, .12);
    overflow: hidden;
}
.login-hd {
    padding: 32px 32px 8px;
    text-align: center;
}
.login-hd h1 { margin: 0; font-size: 21px; }
.login-hd p { margin: 8px 0 0; color: var(--text-mute); font-size: 13px; }
.login-form { padding: 20px 32px 34px; }
.login-form label {
    display: block;
    font-size: 13px;
    color: var(--text-soft);
    margin: 16px 0 7px;
}
.login-form input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: all .15s;
    background: #fbfcfe;
}
.login-form input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.login-form .btn-primary { width: 100%; height: 46px; margin-top: 26px; font-size: 15px; }
.login-err {
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
    margin-top: 12px;
    text-align: center;
}

/* ==================== 客服工作台 ==================== */
.admin-body { overflow: hidden; }

.app { display: flex; height: 100vh; }

.sidebar {
    width: 320px;
    min-width: 320px;
    background: #fff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.side-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.brand { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.me { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}
.me-info { flex: 1; min-width: 0; }
.me-info b { display: block; font-size: 13px; }
.me-info small { color: var(--text-mute); font-size: 12px; }

.tabs { display: flex; padding: 10px 12px 0; gap: 6px; }
.tabs button {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text-soft);
    padding: 8px 0;
    font-size: 13px;
    border-radius: 8px;
    position: relative;
}
.tabs button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tabs .badge {
    display: none;
    font-style: normal;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    border-radius: 9px;
    padding: 1px 6px;
    margin-left: 4px;
}
.tabs .badge.show { display: inline-block; }

.search { padding: 10px 12px; }
.search input {
    width: 100%;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0 12px;
    font-size: 13px;
    outline: none;
    background: #fbfcfe;
}
.search input:focus { border-color: var(--primary); background: #fff; }

.conv-list { flex: 1; overflow-y: auto; }
.conv-list .empty { text-align: center; color: var(--text-mute); font-size: 13px; padding: 40px 0; }

.conv-item {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f2f5f9;
    cursor: pointer;
    transition: background .12s;
}
.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: var(--primary-soft); }
.conv-avatar {
    width: 38px; height: 38px; border-radius: 10px;
    background: #e2e8f0; color: #475569;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600; flex-shrink: 0;
    position: relative;
}
.conv-avatar .online {
    position: absolute; right: -2px; bottom: -2px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--green); border: 2px solid #fff;
}
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.conv-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-mute); flex-shrink: 0; }
.conv-last {
    font-size: 12.5px; color: var(--text-soft);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 3px;
}
.conv-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.tag-order {
    font-size: 11px; color: #b45309;
    background: #fffbeb; border-radius: 5px; padding: 1px 6px;
}
.tag-closed { font-size: 11px; color: var(--text-mute); background: #f1f5f9; border-radius: 5px; padding: 1px 6px; }
.unread-dot {
    background: var(--danger); color: #fff;
    font-size: 11px; border-radius: 9px;
    padding: 0 6px; min-width: 18px; text-align: center; line-height: 17px;
}

.side-foot { border-top: 1px solid var(--border); padding: 12px 14px; }
.foot-title { font-size: 12px; color: var(--text-mute); margin-bottom: 7px; }
.foot-link { display: flex; gap: 6px; }
.foot-link input {
    flex: 1; min-width: 0;
    height: 32px; border: 1px solid var(--border);
    border-radius: 7px; padding: 0 9px;
    font-size: 12px; color: var(--text-soft);
    background: #f8fafc; outline: none;
}

/* ---------- 右侧聊天区 ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f7f9fc; }

.chat-head {
    height: 62px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}
.chat-head-empty { color: var(--text-mute); font-size: 14px; }
.chat-head-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-head-info .name { font-size: 15px; font-weight: 600; }
.chat-head-info .sub { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.chat-head-actions { display: flex; gap: 8px; }

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px;
}
.chat-placeholder, .chat-body .empty {
    color: var(--text-mute); text-align: center; margin-top: 80px; font-size: 14px;
}

.chat-foot {
    border-top: 1px solid var(--border);
    background: #fff;
    padding: 12px 20px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}
.chat-foot textarea {
    flex: 1;
    height: 44px;
    max-height: 120px;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 14px;
    outline: none;
    line-height: 20px;
    background: #fbfcfe;
}
.chat-foot textarea:focus { border-color: var(--primary); background: #fff; }
.chat-foot .btn-primary { height: 44px; }

/* ---------- 消息气泡 ---------- */
.msg-row { display: flex; margin-bottom: 16px; gap: 10px; }
.msg-row.agent { flex-direction: row-reverse; }
.msg-avatar {
    width: 34px; height: 34px; border-radius: 9px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
    background: #e2e8f0; color: #475569;
}
.msg-row.agent .msg-avatar { background: var(--primary); color: #fff; }
.msg-block { max-width: 62%; }
.msg-name { font-size: 11.5px; color: var(--text-mute); margin-bottom: 4px; }
.msg-row.agent .msg-name { text-align: right; }
.msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.msg-row.agent .msg-bubble {
    background: var(--primary);
    color: #fff;
}
.msg-time { font-size: 11px; color: var(--text-mute); margin-top: 5px; }
.msg-row.agent .msg-time { text-align: right; }

.msg-system { text-align: center; margin: 14px 0; }
.msg-system span {
    display: inline-block;
    background: rgba(100, 116, 139, .1);
    color: var(--text-mute);
    font-size: 12px;
    padding: 3px 12px;
    border-radius: 10px;
}

.msg-order { display: flex; justify-content: center; margin: 14px 0; }
.order-card {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 13px;
    color: #9a3412;
    min-width: 220px;
}
.order-card .oc-title { font-size: 12px; color: #c2410c; margin-bottom: 5px; }
.order-card .oc-no { font-size: 15px; font-weight: 700; letter-spacing: .5px; }

/* ==================== 客户端页面 ==================== */
.client-body-page { background: #eef1f6; }

.client-app {
    max-width: 680px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f7f9fc;
    position: relative;
}

.client-head {
    height: 60px;
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}
.ch-left { display: flex; align-items: center; gap: 10px; }
.ch-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: #cbd5e1;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.ch-dot.online { background: #4ade80; }
.ch-title { font-size: 15px; font-weight: 600; }
.ch-status { font-size: 12px; opacity: .85; margin-top: 1px; }
.ch-order-btn {
    border: 1px solid rgba(255, 255, 255, .5);
    background: rgba(255, 255, 255, .12);
    color: #fff;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12.5px;
}

.order-bar {
    background: #fff7ed;
    color: #9a3412;
    font-size: 12.5px;
    padding: 8px 16px;
    border-bottom: 1px solid #fed7aa;
}

.client-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
.client-loading { text-align: center; color: var(--text-mute); margin-top: 60px; }

.client-foot {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.client-foot input {
    flex: 1;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 21px;
    padding: 0 16px;
    font-size: 14px;
    outline: none;
    background: #f6f8fb;
}
.client-foot input:focus { border-color: var(--primary); background: #fff; }
.client-foot button {
    height: 42px;
    padding: 0 20px;
    border: 0;
    border-radius: 21px;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
}
.client-foot button:disabled { opacity: .5; }

/* 客户页气泡：客户在右，客服在左 */
.client-messages .msg-row { gap: 8px; }
.client-messages .msg-block { max-width: 78%; }
/* 客户页里“自己”是 customer，靠右；客服是对方，靠左 */
.client-messages .msg-row.customer { flex-direction: row-reverse; }
.client-messages .msg-row.agent { flex-direction: row; }
.client-messages .msg-row.customer .msg-bubble { background: var(--primary); color: #fff; }
.client-messages .msg-row.agent .msg-bubble { background: #fff; color: var(--text); }
.client-messages .msg-row.customer .msg-name,
.client-messages .msg-row.customer .msg-time { text-align: right; }
.client-messages .msg-row.agent .msg-name,
.client-messages .msg-row.agent .msg-time { text-align: left; }
.client-messages .msg-avatar { width: 32px; height: 32px; font-size: 12px; }
.client-messages .msg-row.agent .msg-avatar { background: #64748b; }

/* ==================== 弹窗 ==================== */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-mask.show { display: flex; }
.modal-box {
    width: 100%;
    max-width: 340px;
    background: #fff;
    border-radius: 16px;
    padding: 22px;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-desc { font-size: 12.5px; color: var(--text-mute); margin: 8px 0 14px; }
.modal-box input {
    width: 100%;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 13px;
    font-size: 14px;
    outline: none;
    background: #fbfcfe;
}
.modal-box input:focus { border-color: var(--primary); background: #fff; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn-ghost,
.modal-actions .btn-primary { flex: 1; height: 42px; }

@media (max-width: 720px) {
    .sidebar { width: 100%; min-width: 0; }
    .app.mobile-list .chat { display: none; }
}
