/* ============ 在线客服 · 前台聊天页 ============ */

#page-chat {
    padding-bottom: 0;
}

/* 作用域内的盒模型重置：不依赖 tailwind preflight */
#page-chat,
#page-chat *,
#page-chat *::before,
#page-chat *::after {
    box-sizing: border-box;
}

body.chat-mode .page-container {
    padding-bottom: 0;
}

.chat-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 8px);
    background: #f5f5f7;
    overflow: hidden;
}

/* 顶部 */
.chat-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

.chat-back {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border: none;
    border-radius: 50%;
    background: #f3f4f6;
    color: #111;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.chat-back:active {
    background: #e5e7eb;
}

.chat-peer {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 50%;
    overflow: hidden;
    background: #eef2ff;
    color: #6C5CE7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-peer-meta {
    min-width: 0;
}

.chat-peer-name {
    font-size: 15px;
    font-weight: 600;
    color: #111;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-peer-status {
    font-size: 12px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.3;
}

.chat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

.chat-dot.off {
    background: #9ca3af;
}

.chat-alt-link {
    flex: 0 0 auto;
    font-size: 12px;
    color: #6C5CE7;
    text-decoration: none;
    padding: 5px 9px;
    border-radius: 8px;
    background: #f5f3ff;
    white-space: nowrap;
}

/* 消息区 */
.chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
}

.chat-msg.me {
    align-items: flex-end;
}

.chat-msg.peer {
    align-items: flex-start;
}

.chat-msg.sys {
    align-items: center;
}

.chat-bubble {
    max-width: 80%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.chat-msg.me .chat-bubble {
    background: linear-gradient(145deg, #121212, #333);
    color: #fff;
    border-top-right-radius: 4px;
}

.chat-msg.peer .chat-bubble {
    background: #fff;
    color: #111;
    border-top-left-radius: 4px;
}

.chat-msg.sys .chat-bubble {
    background: #eef2ff;
    color: #4b5563;
    font-size: 12.5px;
    border-radius: 10px;
    max-width: 90%;
    box-shadow: none;
}

.chat-time {
    font-size: 10.5px;
    color: #b0b4bb;
    margin-top: 3px;
    padding: 0 4px;
}

.chat-tip {
    text-align: center;
    font-size: 11.5px;
    color: #9ca3af;
    padding: 4px 0 8px;
}

/* 快捷问题 */
.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 12px;
    scrollbar-width: none;
}

.chat-quick::-webkit-scrollbar {
    display: none;
}

.chat-chip {
    flex: 0 0 auto;
    font-size: 12.5px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #374151;
    white-space: nowrap;
}

.chat-chip:active {
    background: #eef2ff;
}

/* 输入区 */
.chat-inputbar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    min-width: 0;
}

#chatInput {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    resize: none;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    line-height: 1.4;
    max-height: 110px;
    outline: none;
    background: #fafafa;
    color: #111;
    font-family: inherit;
}

#chatInput:focus {
    border-color: #c7c9ff;
    background: #fff;
}

#chatSendBtn {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, #121212, #333);
    color: #fff;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#chatSendBtn:disabled {
    opacity: .45;
}

/* 首页按钮上的新消息红点 */
.nav-action-button.chat-has-unread {
    position: relative;
}

.nav-action-button.chat-has-unread::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px #fff;
}

@media (min-width: 768px) {
    .chat-page {
        max-width: 720px;
        margin: 0 auto;
        border-left: 1px solid #eee;
        border-right: 1px solid #eee;
    }
}

/* ============ 弹窗模式（右下角悬浮） ============ */
.chat-widget {
    position: fixed;
    right: 20px;
    bottom: 92px;
    width: 380px;
    height: min(620px, calc(100vh - 130px));
    background: #f5f5f7;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 90;
    opacity: 0;
    transform: translateY(16px) scale(.98);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}

.chat-widget.open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.chat-widget > .chat-page {
    height: 100%;
    max-width: none;
    border: 0;
}

.chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, #121212, #333);
    color: #fff;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
    z-index: 91;
}

.chat-launcher.hide {
    display: none;
}

.chat-launcher-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 640px) {
    .chat-widget {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }
    .chat-launcher {
        right: 16px;
        bottom: 16px;
    }
}
