/* --- CÁC STYLE CŨ --- */
/* Container chính */
.mci-container {
    position: fixed; /* Giữ cố định trên màn hình */
    z-index: 9999;
}

/* Icon */
.mci-icon-link img {
    display: block;
    border-radius: 50%; /* Đảm bảo hình tròn */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    cursor: pointer;
}

.mci-icon-link:hover img {
    transform: scale(1.1);
}

.mci-container.open .mci-icon-link img {
    transform: scale(0.9);
    box-shadow: none;
}


/* Bubble Message */
.mci-bubble {
    position: absolute; /* Định vị tuyệt đối so với container */
    bottom: calc(100% + 15px); /* Đặt bubble trên icon + 15px khoảng cách */
    background: #ffffff;
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    max-width: 320px;
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    animation: mci-fade-in 0.5s ease-out;
    width: max-content; /* Chiều rộng theo nội dung */
}

.mci-container.bottom-right .mci-bubble { right: 0; }
.mci-container.bottom-left .mci-bubble { left: 0; }

.mci-bubble::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
    bottom: -10px;
    border-width: 10px 10px 0 10px;
    border-color: #ffffff transparent transparent transparent;
}

.mci-container.bottom-right .mci-bubble::after { right: 20px; }
.mci-container.bottom-left .mci-bubble::after { left: 20px; }

@keyframes mci-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.mci-close-bubble {
    position: absolute;
    top: 3px;
    right: 8px;
    font-size: 20px;
    font-weight: bold;
    color: #888;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
}
.mci-close-bubble:hover { color: #000; }

/* --- CÁC STYLE MỚI CHO LIVE CHAT --- */

.mci-chat-window {
    position: absolute;
    bottom: calc(100% + 10px);
    width: 370px;
    height: 70vh;
    max-height: 600px;
    background-color: #fff;
    border-radius: 15px;
    box-shadow: 0 5px 40px rgba(0,0,0,.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.mci-container.open .mci-chat-window {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.mci-container.bottom-right .mci-chat-window { right: 0; }
.mci-container.bottom-left .mci-chat-window { left: 0; }

.mci-chat-header {
    background-color: #217b56;
    color: white;
    padding: 1px 20px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 50px;
    text-transform: uppercase;
}

.mci-close-chat-window {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding-left: 20px;
    padding-bottom: 10px;
    padding-top: 25px;
    padding-right: 0px;
    margin-right: 0px;
}

.mci-chat-body {
    flex-grow: 1;
    padding: 0px 0px 0px 0px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.mci-chat-screen {
    width: 100%;
    box-sizing: border-box;
}

/* Màn hình Welcome & Options */
#mci-welcome-screen p {
    text-align: center;
    margin-bottom: 20px;
    color: #555;
}

#mci-welcome-screen input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.mci-button-wrapper {
    margin-bottom: 10px;
    padding: 0px 20px;
}

.mci-message-welcome {
    margin-top: 20px;
}

.mci-button-hint {
    display: block;
    text-align: center;
    font-size: 12px;
    color: #777;
    margin-top: 4px;
}

#mci-start-chat-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background-color: #217b56;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 2px;
}

#mci-start-chat-btn:hover {
    background-color: #002930;
}

#mci-start-chat-directly-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background-color: #217b56;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 2px;
}

#mci-start-chat-directly-btn:hover {
    background-color: #002930;
}

.mci-secondary-btn {
    display: block;
    width: 100%;
    padding: 12px;
    border: 1px solid #217b56;
    border-radius: 8px;
    background-color: #fff;
    color: #217b56;
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    margin-top: 30px;
}

.mci-secondary-btn:hover {
    background-color: #f0f8ff;
    color: #002930;
}


/* Màn hình Chat */
#mci-chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.mci-messages-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    /* **SỬA LỖI Ở ĐÂY: Xóa dòng này** */
    /* justify-content: flex-end; */
}

/* **MỚI: Thêm rule này để thay thế** */
.mci-messages-list .mci-message:first-child {
    margin-top: auto;
}

.mci-message {
    max-width: 100%;
    padding: 10px 15px;
    border-radius: 18px;
    margin-bottom: 10px;
    line-height: 1.4;
    word-wrap: break-word;
}

.mci-message.user {
    background-color: #217b56;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.mci-message.bot {
    background-color: #f1f0f0;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.mci-message img {
    max-width: 100%;
    border-radius: 10px;
    display: block;
    cursor: pointer;
}

.mci-chat-form {
    display: flex;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    margin-bottom: 0px;
}

#mci-message-input {
    flex-grow: 1;
    border: none;
    padding: 10px;
    font-size: 15px;
    background-color: #f7f7f7;
    border-radius: 5px;
    padding-left: 15px;
    padding-right: 15px;
    margin-bottom: 0px;
}
#mci-message-input:focus {
    outline: none;
}

#mci-send-btn, .mci-image-upload-label {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #0073e6;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 5px 0px;
}
#mci-send-btn:disabled, #mci-message-input:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.mci-reset-chat {padding-top: 10px; margin-bottom: 0px; margin-left: 0px; padding-left: 0px;}

.powered-by-martechpro {text-align: center; font-size: 9px; font-style: italic;}

/* Typing indicator */
.mci-typing-indicator {
    padding: 10px 15px;
}
.mci-typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: #ccc;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: mci-typing-bounce 1.4s infinite ease-in-out both;
}
.mci-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.mci-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes mci-typing-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.mci-lightbox {
    display: none; /* Ẩn theo mặc định */
    position: fixed;
    z-index: 10000; /* Hiển thị trên tất cả */
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.9);
    cursor: pointer;
}

/* Nội dung ảnh */
.mci-lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90vh;
    animation-name: mci-zoom;
    animation-duration: 0.4s;
}

@keyframes mci-zoom {
    from {transform:scale(0)} 
    to {transform:scale(1)}
}

/* Nút đóng */
.mci-lightbox-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.mci-lightbox-close:hover,
.mci-lightbox-close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* Thêm con trỏ zoom cho ảnh trong chat */
.mci-message img {
    cursor: zoom-in;
}

/* --- RESPONSIVE CHO MOBILE --- */
@media (max-width: 768px) {
    .mci-container {
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100%;
        height: auto; 
    }

    .mci-icon-link {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 10000;
    }
    .mci-container.bottom-left .mci-icon-link {
        right: auto;
        left: 20px;
    }

    .mci-container.open .mci-icon-link {
        display: none;
    }

    .mci-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        bottom: 0;
        right: 0;
    }

    .mci-bubble {
        display: none !important; /* Ẩn bubble trên mobile để ưu tiên live chat */
    }
}