/* General Chatbot Styles */
.chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 35px;
    width: 380px;
    height: 500px;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 998;
    transform: scale(0.5);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.chatbot-container.show-chatbot {
    transform: scale(1);
    opacity: 1;
    pointer-events: all;
}

.chatbot-header {
    background: #007bff;
    color: #fff;
    padding: 12px 15px; /* Giảm padding header một chút */
    text-align: center;
    font-size: 14px; /* Điều chỉnh font-size header */
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    position: relative;
}

.chatbot-header .close-btn {
    position: absolute;
    top: 8px; /* Điều chỉnh vị trí nút đóng */
    right: 12px; /* Điều chỉnh vị trí nút đóng */
    background: none;
    border: none;
    color: #fff;
    font-size: 14px; /* Điều chỉnh kích thước icon đóng */
    cursor: pointer;
    line-height: 1;
    padding: 5px;
}

.chatbox {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
}

/* Định dạng tin nhắn */
.chat-message {
    display: flex;
    align-items: flex-start;
    margin-bottom: 10px;
    max-width: 100%;
}

/* Avatar của bot */
.chat-avatar {
    flex-shrink: 0;
    width: 28px; /* Giảm kích thước avatar một chút */
    height: 28px; /* Giảm kích thước avatar một chút */
    border-radius: 50%;
    overflow: hidden;
    margin-right: 8px; /* Giảm khoảng cách với tin nhắn */
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
}

/* Thêm quy tắc để favicon hiển thị đẹp hơn */
.chat-avatar img.bot-avatar {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: transparent;
    padding: 2px;
}


.chat-message p {
    padding: 8px 12px; /* Giảm padding của bong bóng chat */
    border-radius: 16px; /* Giảm border-radius để phù hợp */
    line-height: 1.4;
    word-wrap: break-word;
    font-size: 14px; /* Cỡ chữ 14px (14/16 = 0.875) */
}

.chat-message.outgoing {
    justify-content: flex-end;
}

.chat-message.outgoing .chat-avatar {
    display: none;
}

.chat-message.outgoing p {
    background-color: #007bff;
    color: #fff;
    border-bottom-right-radius: 5px;
    margin-left: auto;
    margin-right: 0;
}

.chat-message.incoming p {
    background-color: #e2e6ea;
    color: #333;
    border-bottom-left-radius: 5px;
    max-width: calc(100% - 36px); /* Điều chỉnh max-width dựa trên avatar 28px + margin 8px */
}

.chat-input-wrapper {
    display: flex;
    padding: 10px 15px;
    border-top: 1px solid #eee;
    background-color: #fff;
}

.chat-input {
    flex-grow: 1;
    border: 1px solid #ced4da;
    border-radius: 18px; /* Giảm border-radius input */
    padding: 8px 12px; /* Giảm padding input */
    font-size: 14px; /* Cỡ chữ 14px cho input */
    outline: none;
    margin-right: 10px;
    height: 38px; /* Điều chỉnh chiều cao input */
}

.send-btn {
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px; /* Điều chỉnh kích thước nút gửi */
    height: 38px; /* Điều chỉnh kích thước nút gửi */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px; /* Kích thước icon gửi */
    flex-shrink: 0;
}

/* Chatbot Toggler Button: GIỮ NGUYÊN VỊ TRÍ VÀ KÍCH THƯỚC */
.chatbot-toggler {
    position: fixed;
    bottom: 30px;
    right: 35px;
    width: 55px;
    height: 55px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    font-size: 14px;
}

.chatbot-toggler:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* --- PHẦN CSS VÒNG TRÒN SUY NGHĨ (CHỈNH SỬA KÍCH THƯỚC ĐỂ PHÙ HỢP AVATAR MỚI) --- */

.chat-message.incoming .chat-avatar::before {
    content: '';
    position: absolute;
    /* Vòng tròn 36x36px, avatar 28x28px. Cần lùi 4px từ mỗi cạnh để căn giữa (36-28)/2 = 4 */
    top: -4px;
    left: -4px;
    width: 36px; /* Kích thước vòng tròn (lớn hơn avatar một chút) */
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top: 2px solid #3498db;
    /* Debug outline - XÓA DÒNG NÀY KHI MỌI THỨ HOẠT ĐỘNG */
    outline: 1px dashed rgba(255, 0, 0, 0.5);
    animation: none;
    opacity: 0;
    z-index: 2;
    box-sizing: border-box;
    transition: opacity 0.2s ease;
}

.chat-message.incoming.typing-indicator .chat-avatar::before {
    animation: spin 1s linear infinite;
    opacity: 1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.chat-message.incoming.typing-indicator p {
    display: none;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .chatbot-container {
        width: 90%;
        height: 80%;
        bottom: 10%;
        right: 5%;
        left: 5%;
        margin: auto;
    }
    .chatbot-toggler {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }
}
