/* luat-su-ai-chat/css/style.css */

body {
    /* Add padding to the body to prevent content from being hidden behind fixed elements */
    padding-bottom: 80px; /* Adjust based on the height of your #chat-input-area */
    padding-top: 20px; /* Or adjust a main content wrapper if you have a header */
}

#luat-su-ai-chat-container {
    display: flex;
    max-width: 800px;
    margin: 0 auto; /* Adjusted margin for better integration */
    
    overflow: visible; /* Changed from hidden to visible */
   
    background-color: #fcfcfc;
    min-height: calc(100vh - 40px); /* Make container at least viewport height minus body padding */
    position: relative; /* Needed for sticky/fixed children if contained within */
}

/* Sidebar - Fixed/Sticky on the left */
#sidebar {
    width: 280px;
    background-color: #f0f2f5;
    border-right: 1px solid #e0e0e0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Use position: sticky for a sidebar that scrolls with content until it hits the top */
    position: Fixed;
    top: 80px; /* Distance from the top of the viewport when it becomes sticky */
    height: calc(100vh - 40px); /* Fill available viewport height */
    overflow-y: auto; /* Allow sidebar content to scroll if it overflows */
    box-sizing: border-box; /* Include padding in height calculation */
    z-index: 10; /* Ensure sidebar is above other content */
}
#new-chat-button {
    font-size: 12px;
    background: #e1e1e1;
}
#new-chat-button:hover {
    background-color: #005177;
	color:#fff;
}

#thread-list {
    flex-grow: 1;
    overflow-y: auto; /* Allow thread list to scroll independently */
    margin-top: 10px;
    padding-right: 5px; /* Để tạo không gian cho thanh cuộn */
}

.thread-item {
    padding: 3px 12px;
    margin-bottom: 5px;
    background-color: #e6e9ed;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-item:hover {
    background-color: #dbe0e6;
}

.thread-item.active {
    background-color: #c9e6f2;
    font-weight: bold;
    color: #005177;
}

/* Chat Area */
#chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative; /* Needed for absolute positioning of input area if desired */
    min-height: 100%; /* Ensure chat area takes full height */
}

#chat-messages {
    flex-grow: 1;
    padding: 20px;
    /* Remove fixed height and overflow, let it expand with content */
    /* overflow-y: auto; */
    /* min-height: 450px; */
    /* max-height: 600px; */
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    /* justify-content: flex-end; /* Tin nhắn mới xuất hiện từ dưới lên - remove this if you want natural flow */
    border-bottom: 1px solid #eee;
    padding-bottom: 90px; /* Add padding to prevent messages from going under the fixed input area */
}

.chat-message {
    padding: 8px 12px;
    border-radius: 18px;
    margin-bottom: 10px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.6;
}

.chat-message.user {
    background-color: #0073aa;
    color: white;
    align-self: flex-end; /* Tin nhắn người dùng nằm bên phải */
    border-bottom-right-radius: 2px;
}

.chat-message.ai {
   
    color: #333;
    align-self: flex-start; /* Tin nhắn AI nằm bên trái */
    border-bottom-left-radius: 2px;
}

#loading-indicator {
    align-self: flex-start;
    padding: 8px 12px;
    color: #888;
    font-style: italic;
}

/* Input Area - Fixed at the bottom */
#chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 15px;
    gap: 10px;
    background-color: #fff;
   
    position: fixed; /* Fix at the bottom of the viewport */
    bottom: 0; /* Align to the bottom */
    left: 0;
    right: 0;
    width: 100%; /* Full width */
    max-width: 900px; /* Adjust to match your main content width */
    margin: 0 auto; /* Center it */
    box-sizing: border-box; /* Include padding in width */
    z-index: 100; /* Ensure it's above other content */
    /* padding-left: calc(15px + 280px);  Adjust padding to account for fixed sidebar width */
}

/* Override for smaller screens when sidebar might not be fixed */
@media (max-width: 768px) {
    body {
        padding-bottom: 80px; /* Keep for mobile input */
        padding-top: 10px; /* Less top padding if sidebar isn't sticky */
    }

    #luat-su-ai-chat-container {
        flex-direction: column;
        margin: 10px auto;
        border-radius: 0;
        box-shadow: none;
        min-height: auto; /* Allow height to adjust */
    }
    #sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        padding: 10px;
        position: relative; /* Remove sticky on small screens */
        top: auto;
        height: auto;
        overflow-y: visible;
        max-height: 200px; /* Limit height for mobile sidebar if it becomes too long */
    }
    #chat-messages {
        min-height: 300px; /* Keep a minimum height for chat area */
        max-height: none; /* Remove max-height for main scroll */
        padding-bottom: 90px; /* Keep padding for fixed input */
    }
    #chat-input-area {
        padding: 10px;
        padding-left: 10px; /* Reset padding for full width on mobile */
        max-width: 100%; /* Take full width on mobile */
    }
}


#chat-input {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 15px;
    resize: none;
    min-height: 150px;
    max-height: 350px;
    overflow-y: auto;
}

#send-message-button,
#upload-image-button {
    background-color: #0073aa;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

#send-message-button:hover,
#upload-image-button:hover {
    background-color: #005177;
}

/* Markdown Specifics */
.chat-message.ai pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.9em;
    line-height: 1.4;
    margin-top: 10px;
    margin-bottom: 10px;
}

.chat-message.ai code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.9em;
}
.chat-message.ai pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
}

.chat-message.ai h1, .chat-message.ai h2, .chat-message.ai h3,
.chat-message.ai h4, .chat-message.ai h5, .chat-message.ai h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
    line-height: 1.2;
}
.chat-message.ai h1 { font-size: 1.8em; }
.chat-message.ai h2 { font-size: 1.5em; }
.chat-message.ai h3 { font-size: 1.3em; }

.chat-message.ai ul, .chat-message.ai ol {
    margin-left: 25px;
    margin-bottom: 1em;
    padding: 0;
}
.chat-message.ai ul li {
    list-style-type: disc;
    margin-bottom: 5px;
}
.chat-message.ai ol li {
    list-style-type: decimal;
    margin-bottom: 5px;
}

.chat-message.ai blockquote {
    border-left: 4px solid #ccc;
    padding-left: 15px;
    color: #666;
    font-style: italic;
    margin: 1em 0;
}

.chat-message.ai table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}
.chat-message.ai th, .chat-message.ai td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}
.chat-message.ai th {
    background-color: #f2f2f2;
}
#image-previews-container {
    display: flex;
    flex-wrap: wrap; /* Cho phép các ảnh xuống dòng */
    gap: 10px; /* Khoảng cách giữa các ảnh */
    padding: 5px;
    border-top: 1px solid #eee;
    background-color: #f9f9f9;
    max-height: 120px; /* Giới hạn chiều cao của khung preview */
    overflow-y: auto; /* Thêm thanh cuộn nếu quá nhiều ảnh */
    margin-bottom: 10px; /* Khoảng cách với ô nhập liệu */
    border-radius: 5px;
}

.image-preview-item {
    position: relative;
    width: 80px; /* Kích thước thumbnail */
    height: 80px;
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden; /* Đảm bảo ảnh không tràn ra ngoài khung */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Ngăn không cho item bị co lại */
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Đảm bảo ảnh lấp đầy khung mà không bị méo */
}

.image-preview-item .remove-image {
    position: absolute;
    top: -5px; /* Điều chỉnh vị trí nút X */
    right: -5px; /* Điều chỉnh vị trí nút X */
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    line-height: 1; /* Căn giữa chữ X */
    padding: 0;
    transition: background-color 0.2s ease;
}

.image-preview-item .remove-image:hover {
    background-color: rgba(255, 0, 0, 0.8);
}
/* Responsive adjustments */
/* No major changes to responsive, as primary fixed elements are handled above */