/* --- CÀI ĐẶT CHUNG & VỊ TRÍ --- */
#tuvan-ai-widget,
#tuvan-ai-bubble {
    position: fixed;
    right: 20px;
    z-index: 9999;
    bottom: 20px;
}

/* --- WIDGET CHAT CHÍNH --- */
#tuvan-ai-widget {
    width: 370px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 90px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out, visibility 0.2s;
}

/* --- BONG BÓNG CHAT (BUBBLE) --- */
#tuvan-ai-bubble {
    width: 60px;
    height: 60px;
    background-color: #0073aa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}
#tuvan-ai-bubble:hover {
    transform: scale(1.1);
}
#tuvan-ai-bubble .dashicons {
    color: white;
    font-size: 30px;
    width: auto;
    height: auto;
}

/* --- TRẠNG THÁI MỞ/ĐÓNG --- */
#tuvan-ai-widget.collapsed .chat-body,
#tuvan-ai-widget.collapsed .chat-input-wrapper {
    display: none;
}
#tuvan-ai-widget.closed {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateY(10px);
}

/* --- CÁC THÀNH PHẦN BÊN TRONG WIDGET --- */
.chat-header {
    background-color: #0073aa;
    color: white;
    padding: 10px 15px;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer;
}
.chat-header .header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
#widget-header-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}
#close-chat-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 5px;
    opacity: 0.8;
}

/* Khung nội dung chat */
.chat-body {
    height: 450px;
    padding: 15px;
    background-color: #f9f9f9;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-message {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 90%;
}
.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #e0e0e0;
}
.message-content {
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
}
.chat-message.assistant {
    align-self: flex-start;
}
.chat-message.assistant .message-content {
    background-color: #e5e5ea;
    color: #333;
    border-bottom-left-radius: 4px;
}
.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-message.user .message-content {
    background-color: #0084ff;
    color: white;
    border-bottom-right-radius: 4px;
}
.chat-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 42px; /* Căn lề với tin nhắn của bot */
}
.choice-button {
    background: #fff;
    border: 1px solid #0073aa;
    color: #0073aa;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
}
.choice-button:hover {
    background: #0073aa;
    color: #fff;
}

/* Khung nhập liệu */
.chat-input-wrapper {
    display: flex;
    border-top: 1px solid #ddd;
    padding: 10px;
    background: #fff;
    flex-shrink: 0;
}
#chat-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
}
#chat-send {
    background-color: #0073aa;
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 20px;
    margin-left: 10px;
    cursor: pointer;
    font-weight: bold;
}

/* --- LOGIC HIỂN THỊ PC / MOBILE --- */
/* Mặc định trên PC */
#tuvan-ai-bubble {
    display: none;
}
#tuvan-ai-widget {
    display: flex;
}

/* --- TRẠNG THÁI MỞ RỘNG --- */
#expand-chat-btn {
    line-height: 1;
}
#expand-chat-btn.hidden {
    display: none;
}
.chat-header > div {
    display: flex;
    align-items: center;
}
.chat-header > div > button {
    margin-left: 5px;
}
#tuvan-ai-widget.expanded {
    /* PC */
    width: 800px;
    height: 90vh;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%);
    max-width: 95vw;
    max-height: 95vh;
}
#tuvan-ai-widget.expanded .chat-body,
#tuvan-ai-widget.expanded .chat-input-wrapper {
    display: flex;
}
#tuvan-ai-widget.expanded .chat-body {
    flex-grow: 1;
    height: auto;
    flex-direction: column; /* Thêm lại để đảm bảo đúng hướng */
}

/* Quy tắc cho màn hình Mobile */
@media (max-width: 768px) {
    #tuvan-ai-bubble {
        display: flex !important;
    }
    #tuvan-ai-widget {
        bottom: 90px;
        display: flex; /* Đảm bảo nó có thể hiển thị */
    }
    #tuvan-ai-widget.expanded {
        width: 100%;
        height: 90vh;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        transform: translateY(0);
        border-radius: 10px 10px 0 0;
    }
}