/* ============================================
   在线聊天组件样式 - Chat Widget CSS
   用于前台访客端 + 后台客服端
   ============================================ */

/* ---- 聊天触发按钮 ---- */
.chat-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    border: none;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 16px rgba(26, 115, 232, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s, box-shadow 0.3s;
    animation: chat-pulse 2s infinite;
}

.chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(26, 115, 232, 0.6);
}

.chat-trigger svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}

@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(26, 115, 232, 0.4); }
    50% { box-shadow: 0 4px 28px rgba(26, 115, 232, 0.7); }
}

/* 未读消息徽章 */
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 6px rgba(229, 57, 53, 0.5);
    display: none;
}

.chat-badge.show {
    display: flex;
}

/* ---- 聊天窗口 ---- */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.chat-window.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* 窗口头部 */
.chat-header {
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chat-header-text h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.chat-header-text small {
    font-size: 11px;
    opacity: 0.85;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* 头部链接按钮（绑定/恢复） */
.chat-header-btn-link {
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
    transition: background 0.2s;
}

.chat-header-btn-link:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c5cad3;
    border-radius: 3px;
}

/* 消息气泡 */
.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: msg-fade-in 0.3s ease;
}

@keyframes msg-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.visitor {
    align-self: flex-end;
}

.chat-msg.admin {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.chat-msg.visitor .chat-msg-bubble {
    background: linear-gradient(135deg, #1a73e8, #1565c0);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.admin .chat-msg-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chat-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-msg.visitor .chat-msg-time {
    text-align: right;
}

/* 系统消息 */
.chat-msg.system {
    align-self: center;
    max-width: 90%;
}

.chat-msg.system .chat-msg-bubble {
    background: #e8eaf0;
    color: #888;
    font-size: 12px;
    text-align: center;
    border-radius: 10px;
    padding: 6px 14px;
}

/* 欢迎消息 */
.chat-welcome {
    text-align: center;
    padding: 20px 0;
    color: #999;
    font-size: 13px;
}

.chat-welcome p {
    margin: 4px 0;
}

/* 输入区域 */
.chat-input-area {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #1a73e8;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 10px rgba(26, 115, 232, 0.4);
}

.chat-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 名称设置区域 */
.chat-name-area {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: #f0f4ff;
    border-top: 1px solid #dce6f5;
    flex-shrink: 0;
    display: none;
}

.chat-name-area.show {
    display: flex;
}

.chat-name-input {
    flex: 1;
    border: 1px solid #d0d0d0;
    border-radius: 14px;
    padding: 6px 12px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}

.chat-name-input:focus {
    border-color: #1a73e8;
}

.chat-name-save {
    padding: 6px 16px;
    border-radius: 14px;
    border: none;
    background: #1a73e8;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

/* 正在输入提示 */
.chat-typing {
    font-size: 12px;
    color: #999;
    padding: 0 4px;
    display: none;
    align-items: center;
    gap: 4px;
}

.chat-typing.show {
    display: flex;
}

.chat-typing-dots {
    display: flex;
    gap: 3px;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: typing-bounce 1.4s infinite;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ---- 绑定 & 恢复面板 ---- */
.chat-bind-panel,
.chat-restore-panel {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 16px 18px;
    background: #f8f9fb;
    border-top: 1px solid #e8ecf1;
    flex-shrink: 0;
}

.chat-bind-panel.show,
.chat-restore-panel.show {
    display: flex;
}

.chat-bind-header {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    text-align: center;
    margin-bottom: 2px;
}

.chat-bind-input {
    width: 100%;
    border: 1px solid #d0d5dd;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.chat-bind-input:focus {
    border-color: #1a73e8;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.chat-bind-btns {
    display: flex;
    gap: 10px;
}

.chat-bind-btn {
    flex: 1;
    padding: 9px 0;
    border-radius: 12px;
    border: 1px solid #d0d5dd;
    background: #fff;
    color: #555;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.chat-bind-btn:hover {
    background: #f0f2f5;
}

.chat-bind-btn.primary {
    background: #1a73e8;
    color: #fff;
    border-color: #1a73e8;
}

.chat-bind-btn.primary:hover {
    background: #1557b0;
}

.chat-bind-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-bind-msg {
    font-size: 12px;
    text-align: center;
    min-height: 18px;
    color: #999;
}

.chat-bind-msg.error {
    color: #e53935;
}

.chat-bind-msg.success {
    color: #2e7d32;
}

/* ---- 移动端适配 ---- */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 160px);
        max-height: calc(100vh - 160px);
        right: 8px;
        bottom: 88px;
        border-radius: 12px 12px 0 0;
    }
    
    .chat-trigger {
        bottom: 16px;
        right: 16px;
    }
}

/* ==================== 后台客服端样式 ==================== */
.admin-chat-container {
    display: flex;
    height: calc(100vh - 180px);
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* 会话列表 */
.admin-chat-list {
    width: 300px;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.admin-chat-list-header {
    padding: 14px 16px;
    background: #f8f9fb;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-chat-list-header .unread-badge {
    background: #e53935;
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    display: none;
}

.admin-chat-list-scroll {
    flex: 1;
    overflow-y: auto;
}

.admin-chat-list-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-chat-list-item:hover {
    background: #f5f7fa;
}

.admin-chat-list-item.active {
    background: #e8f0fe;
    border-left: 3px solid #1a73e8;
}

.admin-chat-list-item .conversation-name {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-chat-list-item .conversation-unread {
    background: #e53935;
    color: #fff;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.admin-chat-list-item .conversation-preview {
    color: #999;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-chat-list-item .conversation-time {
    color: #bbb;
    font-size: 11px;
}

/* 聊天区域 */
.admin-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.admin-chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-size: 16px;
}

.admin-chat-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    opacity: 0.3;
}

/* 通知权限提示 */
.chat-notify-prompt {
    text-align: center;
    padding: 8px;
    background: #fff9c4;
    color: #f57f17;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid #ffe082;
}

.chat-notify-prompt:hover {
    background: #fff59d;
}
