/**
 * BCE Omni Chat - Frontend Styles
 * Phiên bản nâng cấp: Tương thích hoàn toàn với My Mobile Menu
 */

/* === KHAI BÁO BIẾN MÀU SẮC === */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chat-bg: #ffffff;
    --chat-header-text: #fff;
    --user-msg-bg: #667eea;
    --user-msg-text: #fff;
    --admin-msg-bg: #f1f2f6;
    --admin-msg-text: #333;
    --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* === 1. NÚT LAUNCHER (ICON MỞ CHAT) === */
.chat-launcher {
    position: fixed;
    /* NÂNG CẤP: Tự động tính toán khoảng cách dựa trên chiều cao của Mobile Menu */
    /* Vị trí mới = Chiều cao menu + Vùng an toàn đáy + Khoảng cách lề (30px) */
    bottom: calc(var(--my-mbm-height, 0px) + var(--my-mbm-safe-area-bottom, 0px) + 30px);
    right: 30px;
    width: 65px;
    height: 65px;
    background: var(--primary-gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    
    /* NÂNG CẤP: Z-index phải cao hơn Mobile Menu (2147483647) */
    z-index: 2147483648;
}

/* Hiệu ứng sóng lan tỏa */
.chat-launcher::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    z-index: -1;
    opacity: 0.6;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}

.chat-launcher:hover {
    transform: scale(1.1);
}

.chat-launcher i {
    font-size: 28px;
    transition: transform 0.3s;
}

.chat-launcher.active i {
    transform: rotate(90deg);
}

/* === 2. CỬA SỔ CHAT (CHAT WINDOW) === */
.chat-window {
    position: fixed;
    /* NÂNG CẤP: Đẩy cửa sổ chat lên tương ứng khi mở menu */
    /* Vị trí mới = Chiều cao menu + Vùng an toàn đáy + Khoảng cách lề mở rộng (110px) */
    bottom: calc(var(--my-mbm-height, 0px) + var(--my-mbm-safe-area-bottom, 0px) + 110px);
    right: 30px;
    width: 380px;
    height: 520px;
    background-color: var(--chat-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    
    /* NÂNG CẤP: Đảm bảo cửa sổ chat cũng nằm trên Menu */
    z-index: 2147483648;
    
    /* Animation ẩn hiện */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: bottom right;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* === 3. HEADER === */
.chat-header {
    background: var(--primary-gradient);
    color: var(--chat-header-text);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.avatar-box {
    position: relative;
}

.avatar-box img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid white;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 0;
    width: 12px;
    height: 12px;
    background-color: #2ecc71;
    border: 2px solid white;
    border-radius: 50%;
}

.header-info h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 2px 0;
    color: white;
}

.header-info span {
    font-size: 12px;
    opacity: 0.9;
    color: white;
}

.header-actions {
    margin-left: auto;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* === 4. BODY === */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fcfcfc;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}
.chat-body::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 10px;
}

/* === 5. MESSAGE STYLES === */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: messagePopIn 0.3s ease-out forwards;
    opacity: 0;
    transform: translateY(10px);
}

@keyframes messagePopIn {
    to { opacity: 1; transform: translateY(0); }
}

.message-row.user-row {
    justify-content: flex-end;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    position: relative;
    word-wrap: break-word;
}

/* Admin Styles */
.admin-row .message-content {
    background-color: var(--admin-msg-bg);
    color: var(--admin-msg-text);
    border-bottom-left-radius: 4px;
}

.admin-avatar-small {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-bottom: 5px;
    object-fit: cover;
}

/* User Styles */
.user-row .message-content {
    background: var(--primary-gradient);
    color: var(--user-msg-text);
    border-bottom-right-radius: 4px;
}

.msg-time {
    display: block;
    font-size: 10px;
    margin-top: 5px;
    opacity: 0.7;
    text-align: right;
}

/* Loader History */
.bce-loader-history {
    text-align: center;
    font-size: 12px;
    color: #999;
    padding: 5px;
}

/* Typing Animation */
.typing {
    font-size: 12px;
    color: #999;
    margin-left: 45px;
    margin-bottom: 10px;
    font-style: italic;
    display: none;
}

/* === 6. FOOTER === */
.chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #f0f0f0;
    border-bottom: none !important;
    border-left: none !important;
    border-right: none !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
    background: #f1f2f6;
    border-radius: 25px;
    padding: 5px 15px;
    display: flex;
    align-items: center;
    border: none !important;
    box-shadow: none !important;
}

.chat-footer input {
    flex: 1;
    border: none !important; 
    background: transparent;
    padding: 10px 5px;
    outline: none !important; 
    font-size: 14px;
    color: #333;
    width: 100%;
    box-shadow: none !important; 
}

.send-btn {
    background: var(--primary-gradient);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(118, 75, 162, 0.3);
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* === 7. MOBILE RESPONSIVE CỦA CHAT WINDOW === */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100% - 40px);
        right: 20px;
        /* Vẫn giữ logic tính toán vị trí đáy để không đè Menu */
        bottom: calc(var(--my-mbm-height, 0px) + var(--my-mbm-safe-area-bottom, 0px) + 100px);
    }
    .chat-launcher {
        right: 20px;
        bottom: calc(var(--my-mbm-height, 0px) + var(--my-mbm-safe-area-bottom, 0px) + 20px);
    }
}