/* =================================================================
   CSS CHO EMS CHATBOX - PHIÊN BẢN ĐẦY ĐỦ
   Thiết kế theo hướng Mobile-First, tối ưu cho cả Mobile và Desktop.
   ================================================================= */

/* --- Reset và Box-Sizing (Quan trọng cho mọi dự án) --- */
*, *::before, *::after {
    box-sizing: border-box;
}

/* --- Biến màu sắc chủ đề --- */
:root {
    --wa-green: #25d366;
    --wa-dark-green: #128c7e;
    --wa-bg: #ece5dd;
    --wa-panel-bg: #f0f2f5;
    --wa-msg-bg-sent: #dcf8c6;
    --wa-msg-bg-received: #ffffff;
    --wa-text-color: #111b21;
    --wa-text-color-light: #667781;
    --wa-icon-color: #54656f;
    --wa-input-bg: #ffffff;
    --font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}

/* =================================================================
   PHẦN 1: STYLE CHO MOBILE (Mobile-First - Gốc)
   ================================================================= */
body {
    font-family: var(--font-family);
    background-color: var(--wa-bg);
    margin: 0;
    padding: 0;
    color: var(--wa-text-color);
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Ngăn thanh cuộn của body */
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: var(--wa-bg);
    border-radius: 0; /* Không bo tròn trên mobile */
}

/* --- Header Styles --- */
.chat-header {
    background-color: var(--wa-green);
    color: white;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Ngăn header bị co lại */
}

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

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0; /* Ngăn avatar bị co lại */
}

.ai-avatar {
    background-color: #e9ebeb;
    color: var(--wa-icon-color);
}

.header-text h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 400;
}

.status {
    font-size: 13px;
    opacity: 0.8;
}

/* --- Chat Box Styles --- */
.chat-box {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-size: cover;
}

/* Custom Scrollbar */
.chat-box::-webkit-scrollbar {
    width: 6px;
}
.chat-box::-webkit-scrollbar-track {
    background: transparent;
}
.chat-box::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

/* --- Message Styles --- */
.message {
    display: flex;
    gap: 8px;
    max-width: 75%;
    margin-bottom: 8px;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.ai {
    align-self: flex-start;
}

.message-content {
    padding: 8px 12px;
    border-radius: 7.5px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.05);
    max-width: 100%; /* Ngăn text bị tràn trên mobile */
}

.message.user .message-content {
    background-color: var(--wa-msg-bg-sent);
    border-top-right-radius: 0;
}

.message.ai .message-content {
    background-color: var(--wa-msg-bg-received);
    border-top-left-radius: 0;
}

.message-content p {
    margin: 0;
    font-size: 14.2px;
}

.message-content a {
    color: var(--wa-dark-green);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-timestamp {
    font-size: 11px;
    color: var(--wa-text-color-light);
    margin-top: 4px;
    text-align: right;
}

.message.user .message-timestamp {
    text-align: right;
}

.message.ai .message-timestamp {
    text-align: left;
}

/* --- Typing Indicator Styles --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: #999;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1.0);
    }
}

/* --- Input Area Styles --- */
.chat-input-container {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    background-color: var(--wa-bg);
    border-top: 1px solid #ddd;
    gap: 8px;
}

.attachment-button, #send-btn {
    background: none;
    border: none;
    color: var(--wa-icon-color);
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn {
    color: white;
    background-color: var(--wa-green);
    width: 40px;
    height: 40px;
}

.attachment-button:hover {
    background-color: #f0f2f2;
}

#chat-input {
    flex-grow: 1;
    border: none;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 15px;
    background-color: var(--wa-input-bg);
    transition: box-shadow 0.2s;
}

#chat-input:focus {
    outline: none;
    box-shadow: 0 0 0 1px var(--wa-green);
}


/* =================================================================
   PHẦN 2: TÙY CHỈNH CHO DESKTOP (GHI ĐÈ HOÀN TOÀN)
   Áp dụng cho màn hình có chiều rộng từ 768px trở lên
   ================================================================= */
@media (min-width: 768px) {
    
    /* GHI ĐÈ HOÀN TOÀN THÂN PHẦN BODY */
    body {
        background-color: var(--wa-panel-bg); /* Nền xám của trang */
        /* Dùng Flexbox để canh giữa container */
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        width: 100vw;
    }

    /* GHI ĐÈ HOÀN TOÀN CHAT CONTAINER */
    .chat-container {
        width: 450px; /* Chiều rộng cố định */
        height: 700px; /* Chiều cao cố định */
        border-radius: 8px; /* Bo tròn góc */
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2); /* Bóng đổ đậm hơn */
        overflow: hidden; /* Đảm bảo nội dung không lọt ra ngoài */
        flex-shrink: 0; /* Ngăn container co giãn */
    }

    /* Tăng padding một chút cho trông thoáng hơn trên desktop */
    .chat-box {
        padding: 20px 10px;
    }
}
