/* chatbot.css */
* { box-sizing: border-box; }
@import url('https://fonts.googleapis.com/css2?family=Fira+Code&display=swap');

#chatbot-container {
    position: fixed;
    bottom: 90px;
    right: 30px;
    z-index: 9999;
    font-family: inherit;
}

#chatbot-toggle {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 3px solid #e9c349;
    position: relative;
    padding: 0;
    overflow: visible;
}

#chatbot-toggle:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.chatbot-toggle-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4d4d;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.chatbot-badge.show {
    opacity: 1;
    transform: scale(1);
    animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7); }
    70% { transform: scale(1.2); box-shadow: 0 0 0 10px rgba(255, 77, 77, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

#chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: 80vh;
    border-radius: 16px;
    background: rgba(28, 27, 27, 0.9);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

#chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chatbot-header {
    background: rgba(0, 0, 0, 0.2);
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.chatbot-avatar-container {
    position: relative;
    width: 40px;
    height: 40px;
}

.chatbot-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e9c349;
}

.chatbot-status-indicator {
    width: 12px;
    height: 12px;
    background-color: #10b981;
    border-radius: 50%;
    position: absolute;
    bottom: -2px;
    right: -2px;
    border: 2px solid #1c1b1b;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.chatbot-title {
    color: #fff;
    font-weight: 600;
    font-size: 16px;
    display: flex;
    flex-direction: column;
}

.chatbot-subtitle {
    font-size: 11px;
    color: #10b981;
    font-weight: 400;
}

.chatbot-controls {
    display: flex;
    gap: 10px;
}

.chatbot-controls button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.chatbot-controls button:hover {
    color: #e9c349;
    background: rgba(255, 255, 255, 0.1);
}

.chatbot-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* New Wrapper Layout */
.chatbot-message-wrapper {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

.chatbot-message-wrapper.user {
    justify-content: flex-end;
}

.chatbot-message-wrapper.bot {
    justify-content: flex-start;
}

.chatbot-message {
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 16px; /* Tăng lên 16px cho to rõ */
    line-height: 1.6;
    word-wrap: break-word;
}

.chatbot-message.bot {
    background: rgba(45, 45, 45, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #ffffff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: 98%; /* Sát lề phải nhất có thể */
    overflow-x: auto; /* Ngăn bảng tràn ra ngoài khung chat */
}

.chatbot-message.user {
    background: #e9c349;
    color: #131313;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    max-width: 80%;
}

/* Markdown spacing improvements */
.chat-markdown ul, .chat-markdown ol {
    margin-left: 20px !important;
    margin-bottom: 12px !important;
    list-style-position: outside !important;
}

.chat-markdown ul {
    list-style-type: disc !important;
}

.chat-markdown ol {
    list-style-type: decimal !important;
}

.chat-markdown li {
    margin-bottom: 8px !important;
    display: list-item !important;
    color: #ffffff !important;
    padding-left: 4px !important;
}

.chat-markdown li::marker {
    color: #ffffff !important;
    font-size: 1.1em;
}

/* Table Styles - Định dạng bảng TRONG KHUNG CHAT (Kiểu cũ Dark Mode) */
.chat-markdown table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
    background: rgba(45, 45, 45, 0.9); /* Quay về nền tối kiểu cũ */
    color: #ffffff;
    border-radius: 8px;
    overflow-x: auto;
    display: block; /* Hỗ trợ cuộn ngang nếu bảng 8 cột quá rộng */
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: zoom-in;
}

.chat-markdown th, .chat-markdown td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-markdown th {
    background: rgba(233, 195, 73, 0.2);
    color: #e9c349;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

/* Các cột giá tiền vẫn căn vàng cho chuyên nghiệp */
.chat-markdown td:nth-child(5), 
.chat-markdown td:nth-child(7) {
    white-space: nowrap;
    font-weight: bold;
    color: #d32f2f; /* Màu đỏ cho giá để khách dễ thấy */
}

/* Các cột STT và SL căn giữa cho đẹp */
.chat-markdown th:nth-child(1), .chat-markdown td:nth-child(1),
.chat-markdown th:nth-child(4), .chat-markdown td:nth-child(4) {
    text-align: center;
}

.chat-markdown th {
    background: rgba(233, 195, 73, 0.2);
    color: #e9c349;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

.chat-markdown tr:last-child td {
    border-bottom: none;
}

.chat-markdown tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.chatbot-footer {
    padding: 15px;
    background: rgba(0,0,0,0.1);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px;
    color: #fff;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 16px; /* Đồng bộ kích thước chữ */
}

#send-btn, #upload-btn {
    background: #e9c349;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

#upload-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #e9c349;
}

#send-btn:hover:not(:disabled), #upload-btn:hover {
    transform: scale(1.1);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    align-self: flex-start;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #8e9192;
    border-radius: 50%;
    animation: typing 1s infinite alternate;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    from { opacity: 0.3; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1.1); }
}

.typing-text {
    font-size: 11px;
    color: #8e9192;
    margin-left: 8px;
}

/* Image zoom styling */
.chat-markdown img {
    cursor: zoom-in;
    max-width: 100%;
    border-radius: 8px;
    margin-top: 10px;
}

/* Modal Table - Bản phóng to của bảng */
#modal-table-container {
    background: #1c1b1b;
    padding: 30px;
    border-radius: 16px;
    color: #fff;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
}

#modal-table-container table {
    width: 100% !important;
    min-width: 900px !important; /* Luôn giữ bảng to rộng khi Zoom */
    font-size: 15px;
    background: #ffffff; /* Nền trắng kiểu Excel chuyên nghiệp */
    color: #333;
    border-collapse: collapse;
    border: 1px solid #000000;
    table-layout: auto;
}

#modal-table-container th, #modal-table-container td {
    padding: 12px 10px;
    border: 1px solid #000000; /* Viền đen đúng form Excel */
    text-align: left;
    word-break: keep-all;
}

#modal-table-container th {
    background: #b6d7a8; /* Màu xanh pistachio */
    color: #000 !important;
    font-weight: bold;
}

#modal-table-container th {
    background: #b6d7a8;
    color: #000 !important;
    font-weight: bold;
}

/* Lightbox Modal for Zooming Images & Tables */
.chatbot-image-modal {
    display: none;
    position: fixed;
    z-index: 100000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.chatbot-image-modal.active {
    display: flex;
}

.modal-content-container {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#modal-img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    border: 3px solid rgba(255, 255, 255, 0.1);
}

.close-modal {
    position: absolute;
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
}

@media (max-width: 768px) {
    #chatbot-container { bottom: 85px; right: 20px; }
    #chatbot-window { 
        width: calc(100vw - 30px); 
        right: -10px; 
        bottom: 70px;
        height: 70vh;
    }
    
    /* Optimize Lightbox for Mobile & Tablet */
    .modal-content-container {
        width: 95% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        padding: 0;
        margin: auto;
    }
    
    #modal-table-container {
        padding: 15px 10px;
        width: 100%;
        max-width: 100vw;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
    }
    
    #modal-table-container table {
        min-width: 650px !important; /* Độ rộng vừa đủ để đọc rõ nhưng giảm bớt gánh nặng kéo ngang */
        font-size: 12px;
    }
    
    .close-modal {
        top: -45px;
        right: 5px;
        background: rgba(255, 255, 255, 0.2);
    }
}
