/* KefuCMS Agent — Crisp Inbox 风格 */
:root {
    --crisp-purple: #5b4ffd;
    --crisp-purple-hover: #4f45e8;
    --crisp-purple-light: #f0efff;
    --crisp-purple-muted: #e8e6ff;
    --crisp-bg: #f6f7fb;
    --crisp-surface: #ffffff;
    --crisp-border: #e8eaef;
    --crisp-text: #1c1d29;
    --crisp-text-secondary: #6b6f7a;
    --crisp-text-muted: #9ca0ab;
    --crisp-green: #22c55e;
    --crisp-rail-w: 56px;
    --crisp-inbox-w: 320px;
    --crisp-profile-w: 300px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
.agent-root { height: 100dvh; font-family: var(--font); color: var(--crisp-text); background: var(--crisp-bg); }

/* —— 登录 —— */
.agent-login-wrap {
    min-height: 100dvh; display: flex; align-items: center; justify-content: center;
    background: var(--crisp-bg); padding: 24px;
}
.agent-login {
    width: 100%; max-width: 400px; background: var(--crisp-surface);
    border-radius: 12px; padding: 40px 36px;
    box-shadow: 0 4px 24px rgba(28, 29, 41, .08);
    border: 1px solid var(--crisp-border);
}
.agent-login .logo {
    width: 48px; height: 48px; background: var(--crisp-purple);
    border-radius: 12px; display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 22px; margin-bottom: 24px;
}
.agent-login h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.agent-login p { margin: 0 0 28px; color: var(--crisp-text-secondary); font-size: 14px; line-height: 1.5; }
.agent-login label { display: block; margin-bottom: 16px; font-size: 13px; font-weight: 500; color: var(--crisp-text); }
.agent-login label input {
    margin-top: 6px; width: 100%; border: 1px solid var(--crisp-border);
    border-radius: 8px; padding: 10px 12px; font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
.agent-login label input:focus {
    outline: none; border-color: var(--crisp-purple);
    box-shadow: 0 0 0 3px var(--crisp-purple-muted);
}
.agent-login .btn-primary {
    width: 100%; padding: 12px; font-size: 15px; font-weight: 600; margin-top: 8px;
    background: var(--crisp-purple); border: none; border-radius: 8px; color: #fff; cursor: pointer;
}
.agent-login .btn-primary:hover { background: var(--crisp-purple-hover); }

/* —— 主布局 4 栏 —— */
.agent-desk {
    display: grid;
    grid-template-columns: var(--crisp-rail-w) var(--crisp-inbox-w) 1fr var(--crisp-profile-w);
    grid-template-rows: minmax(0, 1fr);
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}
.agent-desk > .crisp-rail,
.agent-desk > .crisp-inbox,
.agent-desk > .crisp-chat,
.agent-desk > .crisp-profile {
    min-height: 0;
    max-height: 100dvh;
    overflow: hidden;
}

/* ① 最左图标栏 */
.crisp-rail {
    background: var(--crisp-surface);
    border-right: 1px solid var(--crisp-border);
    display: flex; flex-direction: column; align-items: center;
    padding: 12px 0; gap: 4px;
}
.crisp-rail-logo {
    width: 36px; height: 36px; background: var(--crisp-purple);
    border-radius: 10px; color: #fff; font-weight: 700; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 16px;
}
.crisp-rail-btn {
    width: 40px; height: 40px; border: none; background: transparent;
    border-radius: 10px; cursor: pointer; color: var(--crisp-text-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; position: relative;
}
.crisp-rail-btn:hover { background: var(--crisp-bg); color: var(--crisp-text); }
.crisp-rail-btn.active { background: var(--crisp-purple-light); color: var(--crisp-purple); }
.crisp-rail-btn .tip {
    position: absolute; left: 100%; margin-left: 8px; background: var(--crisp-text);
    color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px;
    white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.crisp-rail-btn:hover .tip { opacity: 1; }
.crisp-rail-spacer { flex: 1; }
.crisp-rail-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--crisp-purple), #8b7fff);
    color: #fff; font-size: 13px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    cursor: default;
}

/* ② 会话列表 */
.crisp-inbox {
    background: var(--crisp-surface);
    border-right: 1px solid var(--crisp-border);
    display: flex; flex-direction: column; min-width: 0;
}
.crisp-inbox-head {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--crisp-border);
}
.crisp-inbox-head h2 {
    margin: 0 0 12px; font-size: 18px; font-weight: 600; letter-spacing: -.02em;
}
.crisp-search-wrap { position: relative; }
.crisp-search-wrap input {
    width: 100%; border: none; background: var(--crisp-bg);
    border-radius: 8px; padding: 9px 12px 9px 36px;
    font-size: 13px; color: var(--crisp-text);
}
.crisp-search-wrap input:focus { outline: none; box-shadow: 0 0 0 2px var(--crisp-purple-muted); }
.crisp-search-wrap::before {
    content: '⌕'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--crisp-text-muted); font-size: 14px;
}
.crisp-filters {
    display: flex; gap: 6px; padding: 10px 12px;
    border-bottom: 1px solid var(--crisp-border);
    overflow-x: auto;
}
.crisp-filter-btn {
    padding: 6px 12px; border: none; background: transparent;
    border-radius: 20px; font-size: 13px; color: var(--crisp-text-secondary);
    cursor: pointer; white-space: nowrap; font-weight: 500;
}
.crisp-filter-btn:hover { background: var(--crisp-bg); }
.crisp-filter-btn.active {
    background: var(--crisp-purple-light); color: var(--crisp-purple);
}
.crisp-filter-btn .count {
    display: inline-block; margin-left: 4px; font-size: 11px;
    background: var(--crisp-purple); color: #fff;
    padding: 1px 6px; border-radius: 10px; min-width: 18px; text-align: center;
}

.crisp-inbox-actions {
    display: flex; gap: 8px; padding: 10px 12px;
    border-bottom: 1px solid var(--crisp-border); background: #fafbfc;
}
.btn-resolve-sm {
    flex: 1; padding: 8px 10px; border: 1px solid var(--crisp-border);
    background: var(--crisp-surface); border-radius: 8px; font-size: 13px;
    font-weight: 500; color: var(--crisp-text); cursor: pointer;
}
.btn-resolve-sm:hover { background: var(--crisp-purple-light); border-color: var(--crisp-purple); color: var(--crisp-purple); }
.btn-block-sm {
    flex: 1; padding: 8px 10px; border: 1px solid #fecaca;
    background: #fef2f2; border-radius: 8px; font-size: 13px;
    font-weight: 500; color: #dc2626; cursor: pointer;
}
.btn-block-sm:hover { background: #fee2e2; border-color: #f87171; }
.btn-danger-outline {
    padding: 7px 14px; border: 1px solid #fecaca; background: #fff;
    border-radius: 8px; font-size: 13px; color: #dc2626; cursor: pointer; font-weight: 500;
}
.btn-danger-outline:hover { background: #fef2f2; }
.btn-block-full {
    width: 100%; padding: 10px; border: 1px solid #fecaca;
    background: #fef2f2; border-radius: 8px; font-size: 13px;
    color: #dc2626; cursor: pointer; font-weight: 500;
}
.btn-block-full:hover { background: #fee2e2; }
.agent-conv-list { flex: 1; overflow-y: auto; }
.agent-conv-item {
    display: flex; gap: 12px; padding: 12px 16px; cursor: pointer;
    border-bottom: 1px solid var(--crisp-border);
    transition: background .12s; align-items: flex-start;
}
.agent-conv-item:hover { background: var(--crisp-bg); }
.agent-conv-item.active { background: var(--crisp-purple-light); }
.agent-conv-item.unread .title { font-weight: 600; color: var(--crisp-text); }
.agent-conv-item .avatar {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, #a8a0ff, var(--crisp-purple));
    color: #fff; font-size: 15px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
}
.agent-conv-item .meta { flex: 1; min-width: 0; }
.agent-conv-item .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.agent-conv-item .title {
    font-size: 14px; color: var(--crisp-text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-conv-item .time { font-size: 11px; color: var(--crisp-text-muted); flex-shrink: 0; }
.agent-conv-item .preview {
    font-size: 13px; color: var(--crisp-text-muted); margin-top: 3px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-conv-item .badge {
    width: 8px; height: 8px; background: var(--crisp-purple);
    border-radius: 50%; flex-shrink: 0; margin-top: 6px;
}
.agent-conv-item:not(.unread) .badge { display: none; }

/* ③ 聊天区 */
.crisp-chat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--crisp-surface);
}
.agent-main-empty {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    color: var(--crisp-text-muted);
    gap: 16px;
    padding: 40px;
    background: var(--crisp-bg);
}
.agent-main-empty .illus {
    width: 120px; height: 120px; background: var(--crisp-purple-light);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 48px;
}
.agent-main-empty h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--crisp-text-secondary); }
.agent-main-empty p { margin: 0; font-size: 14px; text-align: center; max-width: 280px; line-height: 1.5; }

#chatPanel {
    flex: 1 1 0;
    display: none;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--crisp-surface);
}
/* 头部 / 消息(可滚动) / 输入框 三行网格，防止消息把输入区顶出屏幕 */
#chatPanel.is-open {
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-columns: 1fr;
}

.crisp-chat-head {
    flex-shrink: 0;
    padding: 12px 20px; border-bottom: 1px solid var(--crisp-border);
    display: flex; align-items: center; gap: 12px; background: var(--crisp-surface);
    min-height: 60px;
}
.agent-back {
    display: none; width: 36px; height: 36px; border: none;
    background: var(--crisp-bg); border-radius: 8px; cursor: pointer;
    font-size: 18px; color: var(--crisp-text);
}
.crisp-chat-head .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, #a8a0ff, var(--crisp-purple));
    color: #fff; font-size: 14px; font-weight: 600;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.crisp-chat-head .info { flex: 1; min-width: 0; }
.crisp-chat-head .info h3 { margin: 0; font-size: 15px; font-weight: 600; }
.crisp-chat-head .info span { font-size: 12px; color: var(--crisp-green); display: flex; align-items: center; gap: 5px; }
.crisp-chat-head .info span::before {
    content: ''; width: 6px; height: 6px; background: var(--crisp-green); border-radius: 50%;
}
.crisp-chat-actions {
    display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.crisp-chat-actions .btn-block-sm {
    flex: none; min-width: 72px; padding: 8px 12px;
}

.btn-status {
    flex: none; min-width: 88px; padding: 8px 16px;
    border-radius: 20px; font-size: 13px; font-weight: 600;
    cursor: pointer; border: none; transition: all .15s;
}
.btn-status:disabled { cursor: default; opacity: 1; }
.btn-status.status-waiting {
    background: #dbeafe; color: #1d4ed8;
}
.btn-status.status-pending {
    background: #fee2e2; color: #dc2626;
}
.btn-status.status-pending:not(:disabled):hover {
    background: #fecaca; box-shadow: 0 0 0 2px rgba(220, 38, 38, .2);
}
.btn-status.status-resolved {
    background: #dcfce7; color: #16a34a;
}

.agent-messages {
    min-height: 0;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--crisp-bg);
    -webkit-overflow-scrolling: touch;
}
.agent-msg-row {
    display: flex; gap: 10px; max-width: 70%; margin-bottom: 12px;
}
.agent-msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
.agent-msg-row .msg-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, #a8a0ff, var(--crisp-purple));
    color: #fff; font-size: 11px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    align-self: flex-end;
}
.agent-msg-row.out .msg-avatar { background: #6b6f7a; }
.agent-msg-row .msg-body { display: flex; flex-direction: column; }
.agent-msg-row .bubble {
    padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5;
    word-break: break-word; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.agent-msg-row.in .bubble {
    background: var(--crisp-surface); color: var(--crisp-text);
    border-bottom-left-radius: 4px; border: 1px solid var(--crisp-border);
}
.agent-msg-row.out .bubble {
    background: var(--crisp-purple); color: #fff;
    border-bottom-right-radius: 4px;
}
.agent-msg-row .time {
    font-size: 11px; color: var(--crisp-text-muted); margin-top: 4px; padding: 0 4px;
}
.agent-msg-row.out .time { text-align: right; }
.agent-date-divider {
    text-align: center; font-size: 12px; color: var(--crisp-text-muted);
    margin: 16px 0; position: relative;
}
.agent-date-divider span {
    background: var(--crisp-bg); padding: 0 12px; position: relative; z-index: 1;
}
.agent-date-divider::before {
    content: ''; position: absolute; left: 0; right: 0; top: 50%;
    height: 1px; background: var(--crisp-border);
}

/* 输入区 — Crisp 圆角大框（始终贴在聊天区底部） */
.agent-composer {
    flex-shrink: 0;
    padding: 12px 20px 16px;
    background: var(--crisp-surface);
    border-top: 1px solid var(--crisp-border);
    position: relative;
    z-index: 5;
    box-shadow: 0 -4px 12px rgba(28, 29, 41, .06);
}
.crisp-composer-box {
    border: 1px solid var(--crisp-border); border-radius: 12px;
    background: var(--crisp-surface); overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.crisp-composer-box:focus-within {
    border-color: var(--crisp-purple);
    box-shadow: 0 0 0 3px var(--crisp-purple-muted);
}
.agent-composer textarea {
    width: 100%; border: none; resize: none; min-height: 44px; max-height: 120px;
    padding: 12px 14px 4px; font-size: 14px; font-family: inherit;
    background: transparent;
}
.agent-composer textarea:focus { outline: none; }
.crisp-composer-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 8px 8px 10px;
}
.crisp-composer-tools { display: flex; gap: 2px; }
.crisp-composer-tools button {
    width: 32px; height: 32px; border: none; background: transparent;
    border-radius: 8px; cursor: pointer; font-size: 17px;
    display: flex; align-items: center; justify-content: center;
    color: var(--crisp-text-muted);
}
.crisp-composer-tools button:hover { background: var(--crisp-bg); color: var(--crisp-text); }
.crisp-composer-tools button.active { color: var(--crisp-purple); background: var(--crisp-purple-light); }
.btn-send-crisp {
    padding: 7px 16px; border: none; background: var(--crisp-purple);
    color: #fff; border-radius: 8px; font-size: 13px; font-weight: 600;
    cursor: pointer;
}
.btn-send-crisp:hover { background: var(--crisp-purple-hover); }
.btn-send-crisp:disabled { opacity: .5; cursor: not-allowed; }

/* 快捷回复选择器 */
.canned-picker {
    position: absolute; left: 20px; right: 20px; bottom: calc(100% - 4px);
    max-height: 240px; overflow-y: auto;
    background: var(--crisp-surface); border: 1px solid var(--crisp-border);
    border-radius: 12px; box-shadow: 0 8px 24px rgba(28, 29, 41, .12);
    z-index: 50; padding: 6px;
}
.canned-picker-item {
    display: block; width: 100%; text-align: left; border: none; background: transparent;
    border-radius: 8px; padding: 10px 12px; cursor: pointer; font-family: inherit;
}
.canned-picker-item:hover { background: var(--crisp-bg); }
.canned-picker-title {
    display: block; font-size: 13px; font-weight: 600; color: var(--crisp-text);
    margin-bottom: 2px;
}
.canned-picker-preview {
    display: block; font-size: 12px; color: var(--crisp-text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.canned-picker-empty {
    padding: 20px; text-align: center; font-size: 13px; color: var(--crisp-text-muted);
}
.canned-picker-empty a { color: var(--crisp-purple); }

/* 访客浏览记录 */
.crisp-profile-pages { list-style: none; margin: 0; padding: 0; }
.crisp-profile-page-item {
    padding: 10px 0; border-bottom: 1px solid var(--crisp-border);
    font-size: 13px;
}
.crisp-profile-page-item:last-child { border-bottom: none; }
.crisp-profile-page-item .page-title {
    font-weight: 500; color: var(--crisp-text);
    margin-bottom: 3px; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.crisp-profile-page-item .page-url {
    color: var(--crisp-text-muted); font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crisp-profile-page-item .page-time {
    color: var(--crisp-text-muted); font-size: 11px; margin-top: 4px;
}
.crisp-profile-pages-empty {
    font-size: 13px; color: var(--crisp-text-muted); padding: 8px 0;
}

/* ④ 右侧访客资料 */
.crisp-profile {
    background: var(--crisp-surface);
    border-left: 1px solid var(--crisp-border);
    display: flex; flex-direction: column; overflow-y: auto;
}
.crisp-profile-empty {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--crisp-text-muted); font-size: 13px; padding: 24px; text-align: center;
}
.crisp-profile-content { padding: 20px; display: none; }
.crisp-profile-content.visible { display: block; }
.crisp-profile-hero {
    text-align: center; padding-bottom: 20px;
    border-bottom: 1px solid var(--crisp-border); margin-bottom: 16px;
}
.crisp-profile-hero .big-avatar {
    width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 12px;
    background: linear-gradient(135deg, #a8a0ff, var(--crisp-purple));
    color: #fff; font-size: 24px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
}
.crisp-profile-hero h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.crisp-profile-hero p { margin: 0; font-size: 12px; color: var(--crisp-text-muted); }
.crisp-profile-section { margin-bottom: 20px; }
.crisp-profile-section h4 {
    margin: 0 0 10px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em; color: var(--crisp-text-muted);
}
.crisp-profile-field {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--crisp-border);
}
.crisp-profile-field:last-child { border-bottom: none; }
.crisp-profile-field .label { color: var(--crisp-text-muted); }
.crisp-profile-field .value { color: var(--crisp-text); font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 表情 */
.kefu-emoji-picker {
    position: absolute; bottom: calc(100% + 4px); left: 20px;
    background: var(--crisp-surface); border: 1px solid var(--crisp-border);
    border-radius: 12px; padding: 10px;
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
    box-shadow: 0 8px 32px rgba(28, 29, 41, .12); z-index: 200; max-width: 304px;
}
.kefu-emoji-picker[hidden] {
    display: none !important;
}
.agent-msg-row .bubble .msg-img {
    max-width: 240px; max-height: 200px; border-radius: 10px; display: block;
}
.agent-msg-row .bubble .msg-file {
    color: var(--crisp-purple); text-decoration: underline; font-weight: 500;
}
.agent-msg-row.out .bubble .msg-file { color: #fff; }
.agent-msg-row .bubble .msg-text { margin-top: 6px; }
.kefu-emoji-btn {
    width: 34px; height: 34px; border: none; background: transparent;
    border-radius: 8px; cursor: pointer; font-size: 20px; line-height: 1;
}
.kefu-emoji-btn:hover { background: var(--crisp-bg); }

/* 隐藏旧结构 */
.agent-sidebar, .agent-main { display: contents; }

/* 响应式 */
@media (max-width: 1100px) {
    .agent-desk { grid-template-columns: var(--crisp-rail-w) var(--crisp-inbox-w) 1fr; }
    .crisp-profile { display: none; }
}
@media (max-width: 768px) {
    .agent-desk {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }
    .crisp-rail { display: none; }
    .crisp-inbox {
        position: fixed; inset: 0; z-index: 40; max-width: 100%;
        transform: translateX(0); transition: transform .2s;
    }
    .crisp-chat {
        position: fixed; inset: 0; z-index: 30;
        height: 100%; height: 100dvh;
    }
    .agent-desk.chat-open .crisp-inbox { transform: translateX(-100%); }
    .agent-desk.chat-open .crisp-chat { z-index: 50; }
    .agent-back { display: inline-flex !important; }
    .crisp-profile { display: none; }
}
