/**
 * CloudSpect 在线聊天系统 - 样式
 * 基于17TRACK设计风格
 */

/* ============================================
   聊天控件容器
   ============================================ */

.chat-widget {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 9999;
    font-family: 'Inter', sans-serif;
}

/* ============================================
   聊天按钮 - 右下角浮动
   ============================================ */

.chat-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(6, 182, 212, 0.5);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.chat-toggle:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.6);
}

.chat-toggle:active {
    transform: translateY(0) scale(0.98);
}

/* 未读消息徽章 */
.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.chat-badge.show {
    opacity: 1;
    transform: scale(1);
}

/* ============================================
   聊天窗口
   ============================================ */

.chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 150px);
    border-radius: 16px;
    background: white;
    color: #1e293b; /* 确保默认文字颜色为深色 */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    z-index: 9998;
}

.chat-window.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.chat-window.show {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* ============================================
   聊天头部
   ============================================ */

.chat-header {
    background: linear-gradient(135deg, #1e3a8a, #1e40af);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-agent {
    display: flex;
    align-items: center;
    gap: 12px;
}

.agent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    object-fit: cover;
}

.agent-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

.agent-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
}

.agent-status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   消息区域
   ============================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
    color: #1e293b !important; /* 确保消息区域默认文字颜色为深色 */
    scroll-behavior: smooth;
}

/* 确保所有消息文字可见 */
.chat-messages * {
    color: inherit;
}

.chat-messages .chat-message.admin .message-bubble,
.chat-messages .chat-message.admin .message-sender,
.chat-messages .chat-message.admin .message-time {
    color: #1e293b !important;
}

/* 自定义滚动条 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 日期分隔符 */
.chat-date-separator {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

.chat-date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e2e8f0;
    z-index: 0;
}

.chat-date-separator span {
    position: relative;
    background: #f8fafc;
    padding: 4px 12px;
    font-size: 12px;
    color: #64748b !important; /* 确保日期分隔符可见 */
    z-index: 1;
}

/* 消息气泡 */
.chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.admin {
    flex-direction: row;
}

.chat-message.visitor {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    margin: 0 8px;
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.message-content-wrapper {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

.message-sender {
    font-size: 11px;
    color: #64748b !important; /* 确保发送者名称可见 */
    margin-bottom: 4px;
    padding: 0 12px;
}

.chat-message.visitor .message-sender {
    text-align: right;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    color: inherit; /* 继承父元素颜色 */
}

.chat-message.admin .message-bubble {
    background: white;
    color: #1e293b !important; /* 确保admin消息文字为深色 */
    border-bottom-left-radius: 4px;
}

.chat-message.visitor .message-bubble {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #94a3b8 !important; /* 确保时间戳可见 */
    margin-top: 4px;
    padding: 0 12px;
}

.chat-message.visitor .message-time {
    text-align: right;
}

/* 消息链接 */
.message-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.chat-message.admin .message-bubble a {
    color: #0891b2 !important; /* admin消息中的链接颜色 */
}

.chat-message.visitor .message-bubble a {
    color: rgba(255, 255, 255, 0.9) !important; /* visitor消息中的链接颜色（白色背景上的深色链接） */
}

/* 加载中动画 */
.chat-loading {
    display: flex;
    justify-content: center;
    padding: 12px;
}

.chat-loading-dots {
    display: flex;
    gap: 4px;
}

.chat-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e1;
    animation: bounce-dot 1.4s infinite ease-in-out;
}

.chat-loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce-dot {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-8px);
    }
}

/* ============================================
   输入区域
   ============================================ */

.chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    color: #1e293b; /* 确保输入区域文字颜色为深色 */
}

.chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.2s ease;
    background: white;
    color: #1e293b; /* 输入框文字颜色为深色 */
}

.chat-input:focus {
    border-color: #06b6d4;
    color: #1e293b !important; /* 聚焦时确保文字颜色为深色 */
}

.chat-input::placeholder {
    color: #94a3b8 !important;
}

.chat-input:disabled {
    color: #64748b !important; /* 禁用状态文字颜色 */
    background: #f1f5f9;
}

.chat-emoji-btn,
.chat-attach-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-emoji-btn:hover,
.chat-attach-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.chat-send-btn {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(6, 182, 212, 0.4);
}

.chat-send-btn:active {
    transform: scale(0.98);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   移动端适配
   ============================================ */

@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-toggle {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        font-size: 22px;
    }
}

/* ============================================
   无障碍和暗色模式支持（预留）
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .chat-window,
    .chat-message,
    .chat-toggle {
        animation: none;
        transition-duration: 0.01ms;
    }
}

/* 暗色模式（可选） */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1e293b;
    }
    
    .chat-messages {
        background: #0f172a;
    }
    
    .message-bubble.admin {
        background: #334155;
        color: #e2e8f0;
    }
    
    .chat-input-area {
        background: #1e293b;
        border-top-color: #334155;
    }
    
    .chat-input {
        background: #334155;
        border-color: #475569;
        color: #e2e8f0;
    }
}
