/* Thiết lập biến màu sắc (Màu chủ đạo #16a15d) */
:root {
    --primary-color: #0c826f;
    --primary-hover: #16a15d;
    --primary-light: #e8f5ef;
    --bg-color: #f3f6fb;
    --sidebar-bg: #ffffff;
    --text-main: #1d1d1d;
    --text-muted: #6b7280;
    --border-color: #f5f5f5;
    --text-color: #ffffff
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Google Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, Tahoma, Verdana, sans-serif, "Geneva";

    /* 2. Thêm các thuộc tính tối ưu hóa font của Google Sans vào đây */
    font-optical-sizing: auto;
    font-variation-settings: "GRAD" 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;    
}

/* --- LAYOUT CHÍNH --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-color);    
    padding-top: 20px;
    padding-left: 20px;    
    padding-right: 0px;
    padding-bottom: 20px;      
    gap: 20px; /* Khoảng cách giữa sidebar và khu vực chat */    
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    height: 100%; /* Chiều cao lấp đầy khoảng trống sau khi trừ padding */
    background-color: var(--sidebar-bg);
    border-radius: 24px; /* Bo góc tròn cho toàn bộ sidebar */
    display: flex;
    flex-direction: column;
    padding: 10px 15px;
    transition: width 0.3s ease, padding 0.3s ease, margin 0.3s ease;
    z-index: 10;
    /* box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03); Thêm bóng đổ nhẹ để sidebar nổi lên */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);       
       
}

/* Khi Sidebar bị ẩn */
.sidebar.collapsed {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    overflow: hidden;
    border: none;    
}

/* --- Các thành phần con trong Sidebar giữ nguyên --- */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;      
   
    height: 40px; /* <--- KHÓA CỨNG CHIỀU CAO CHO HEADER */   
   
}

.brand-logo {
    font-size: 16.5px;  
    font-weight: 500;    
    color: #32465a;
}

.brand-logo span {
    color: #4285f4; /* Chữ Ai màu xanh dương giống hình */
}

.toggle-btn {
    background: transparent;
    border: none;
    /*color: var(--text-muted);*/
    color: #32465a;
    cursor: pointer;
    padding-left: 6px;
    padding-right: 6px;
    padding-top: 4px;
    padding-bottom: 5px;
    border-radius: 8px;
}
.toggle-btn:hover { background: #f3f4f6; color: var(--primary-color); }

/* Nút New Chat */
.new-chat-btn {
    background-color: var(--primary-color);
    border: 0px solid var(--primary-color);   
    color: var(--text-color);    
    padding: 7px;
    border-radius: 25px;  
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    margin-bottom: 30px;
    transition: 0.2s;
    font-size: 13.5px;  

    transition: all 0.3s ease
    
}
.new-chat-btn:hover {
    background-color: color-mix(in srgb, var(--primary-color, #0c826f) 95%, transparent);
    transform: scale(1.03); 
}
.new-chat-btn:active {
    transform: scale(0.94);    /* Nhấn nhẹ xuống tạo cảm giác bấm thật */
    
}



/* Lịch sử Chat */
.history-section {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 0px;    
}
.history-section::-webkit-scrollbar { width: 3px; }
.history-section::-webkit-scrollbar-thumb { background-color: #ffffff; border-radius: 0px; }

.history-header {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    color: #3f5368;
    margin-bottom: 10px;   
    font-weight: 500;   
}

.history-header a {
    color: var(--primary-color);
    text-decoration: none; 
    font-weight: 400;     
}

.history-list {
    list-style: none;
    display: block;
    list-style-type: disc;
    margin-block-start: 1em;
    margin-block-end: 1em;
    padding-inline-start: 0px;
    unicode-bidi: isolate;      
}

.history-list li {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    /*color: var(--text-main);*/
    color: black;
    cursor: pointer;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-list li i.fa-comment-o { color: var(--text-muted); }

.history-list li:hover { background-color: #f3f4f6; }
.history-list li.active {    
    background-color: color-mix(in srgb, var(--primary-color, #0c826f) 8%, transparent);
    color: var(--primary-color);    
    position: relative;
}
.history-list li.active i { color: var(--primary-color); }

.history-list li.active .actions {
    position: absolute;
    right: 10px;
    display: flex;
    gap: 10px;
    background: color-mix(in srgb, var(--primary-color, #0c826f) 0%, transparent);  
    padding-left: 10px;
}

/* Sidebar Footer (Settings / User) */
.sidebar-footer {       
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 10px;
    padding-bottom: 10px;   
}

.footer-btn {
    background: transparent;
    border: 1px solid var(--border-color);      
    border-radius: 20px;  
    font-size: 13.5px;   
    color: #32465a;  
    width: 100%;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    flex-shrink: 0; 
    font-weight: 500;   
}

.footer-btn span {
    display: block;
    flex: 1;
    text-align: left;
}

.footer-btn:hover { background: #f9fafb; }
.footer-btn img {
    width: 13px;        
    margin-left: 5px;       
}

/* --- MAIN CONTENT (KHU VỰC CHAT) --- */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}

.top-nav {
    padding: 15px;
    position: absolute;
    top: 0; left: 0;
}

/* Khu vực hiển thị nội dung chat */
.chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 40px 10%;
    display: flex;
    flex-direction: column;
    gap: 30px;
    padding-bottom: 150px; /* Chừa chỗ cho khung input */
}

.message {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

/* Tin nhắn User */
/* Khung bọc tin nhắn lớn */
.user-message {
    display: flex;
    justify-content: flex-end; 
    margin-bottom: 15px;
    background: transparent;
}

/* Phần khung chứa text (Bong bóng chat) */
.user-message .message-header {
    display: flex;
    flex-direction: column; 
    max-width: 65%; 
    background-color: #e9f1fd; 
    
    /* SỬA DÒNG NÀY: Giảm padding bottom xuống chỉ còn 10px (bằng với padding top) */
    padding: 10px 15px 10px 15px; 
    min-width: 100px;    
    border-radius: 20px; 
    color: black;
    font-size: 15.5px;    
    line-height: 1.7;
    white-space: pre-wrap; 
    position: relative;
}

/* Ép chữ của User mặc định chỉ hiển thị tối đa 5 dòng */
.user-message .text {
    line-height: 1.7;
    word-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    line-clamp: 5; 
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out; 
}

/* Khi bấm nút, JS thêm class này vào để hiển thị full nội dung */
.user-message .text.expanded {
    display: block !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
}

/* KHAY CHỨA NÚT BẤM: Đẩy kịch về góc phải dưới như Gemini */
.user-message .user-message-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-end; 
    gap: 8px;                  
    
    /* CHUYỂN THÀNH ABSOLUTE: Nút sẽ tự động bay lên trên, không chiếm diện tích dòng nữa */
    position: absolute;
    bottom: 6px;    /* Cách cạnh dưới bong bóng chat 6px */
    right: 12px;    /* Cách cạnh phải bong bóng chat 12px */
    width: auto;    /* Co dãn tự động theo số lượng nút hiển thị */
}

/* Thiết kế cho nút Mở rộng / Thu gọn dạng icon tròn tối giản */
.user-message .toggle-msg-btn,
.user-message .copy_user-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    color: #3f5368;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.2s;
    background-color: rgba(255, 255, 255, 0.4);

    /* Hiệu ứng làm mờ nền phía sau để nổi bật chữ/icon lên */
    backdrop-filter: blur(0.5px);
    -webkit-backdrop-filter: blur(0.5px); /* Hỗ trợ trình duyệt Safari */
    
    /* Hiệu ứng chuyển đổi mượt mà */
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}

/* Hiệu ứng hover vòng tròn xám mờ giống hệt Gemini */
.user-message .toggle-msg-btn:hover,
.user-message .copy_user-btn:hover {
    background-color: rgba(255, 255, 255, 1); /* Trong suốt đổi từ 0.1 đến 1 tùy bạn chỉnh độ đậm nhạt */
    color: var(--primary-color, #0c826f);     
    transform: scale(1.1); /* Phóng to nhẹ để tạo cảm giác tương tác */ 
}

/* Ẩn bớt các thành phần phụ theo thiết kế của bạn */
.user-message .avatar, .user-message .edit-msg-btn {
    display: none;
}

.text {
    /* Giữ nguyên các thuộc tính cũ của bạn (display: -webkit-box, line-clamp: 5...) */
    display: -webkit-box;
    -webkit-line-clamp: 5;
    line-clamp: 5; 
    -webkit-box-orient: vertical;
    overflow: hidden;
    
    /* THÊM DÒNG NÀY: Tạo hiệu ứng chuyển động mượt mà trong 0.4 giây */
    transition: max-height 0.4s ease-in-out; 
}

.text.expanded {
    /* Khi mở rộng, bắt buộc chuyển về block và hủy clamp để JS tính toán và trượt mượt */
    display: block !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
}

/* Tin nhắn Bot */
.bot-message {
    padding-left: 15px; /* Thụt lề so với avatar user */   
    color: black;
    font-size: 15.5px;   
    line-height: 1.7; 
}
.bot-message ol, .bot-message ul { padding-left: 20px; margin: 10px 0; }
.bot-message li { margin-bottom: 8px; }

/* Container tổng cho các nút hành động của Bot */
.bot-actions-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 10px;
}

.left-actions {
    display: flex;
    gap: 8px;
     
    
    color: #e084ab
}

/* Các nút nhỏ xám nhạt bên trái */
.action-btn-sm {
    background-color: #ffffff; 
    border: none;
    color: #5f6368;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
}

.action-btn-sm:hover {
    background-color: #e4e6e9;
    color: #16a15d;
}

/* Nút Regenerate hình viên thuốc bên phải */
.regenerate-btn-new {
    background-color: transparent; /* Xóa nền trắng cũ */
    color: #8e8e8f;               /* Đổi thành màu xám nhẹ mặc định giống ChatGPT */
    border: none;                  /* Xóa border nếu có */
    padding: 6px;                  /* Thu nhỏ padding lại để ôm vừa icon */
    border-radius: 6px;            /* Bo góc nhẹ kiểu hiện đại */
    width: 32px;                   /* Khóa cứng chiều rộng vuông */
    height: 32px;                  /* Khóa cứng chiều cao vuông */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

/* Thêm hiệu ứng hover cho đẹp mắt */
.regenerate-btn-new:hover {
    background-color: #f4f4f4;    /* Xuất hiện nền xám nhạt khi di chuột vào */
    color: #0c826f;               /* Icon đậm lên hẳn */
   
}

.bot-actions button:hover { color: var(--primary-color); }
.regenerate-btn { margin-left: auto; border: 1px solid var(--border-color) !important; padding: 5px 10px; border-radius: 5px; }

/* --- INPUT TEXTAREA (KHUNG NHẬP CHAT) --- */
.input-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--bg-color) 80%, transparent);  
    padding-top: 20px;  
    padding-bottom: 0px;    
    padding-left: 20px;
    padding-right: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.input-box {
    background: white;
    width: 100%;
    max-width: 800px;
    border-radius: 30px;
    padding: 10px 20px;
    display: flex;
    align-items: center; /* Canh giữa icon, text, button */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 0px solid var(--border-color);
}

.input-icon {
    width: 25px;
    height: 25px;
    margin-right: 15px;
}

#textInput {
    flex-grow: 1;
    border: none;
    outline: none;
    resize: none; /* Không cho user tự kéo giãn */
    background: transparent;
    font-size: 15.5px;
    color: black;
    color: var(--text-main);
    height: 26px;
    line-height: 26px;
    overflow-y: hidden;
}
#textInput::placeholder { color: #a0aab5; }

.send-btn {
    background-color: var(--primary-color); /* Đổi màu xanh */
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
    margin-left: 10px;
}
.send-btn:hover {  
    background-color: color-mix(in srgb, var(--primary-color, #0c826f) 95%, transparent);
    transform: scale(1.1); 
}

/* Định dạng nút dừng giống hệt nút gửi của bạn */
.stop-input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #008060; /* Màu xanh lá đậm giống nút gửi trong ảnh */
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

/* Hiệu ứng khi rê chuột vào nút dừng (chuyển sang tông màu đỏ cảnh báo nhẹ) */
.stop-input-btn:hover {
    background-color: #d32f2f; 
}

.stop-input-btn:active {
    transform: scale(0.95);
}

.footer-text {
    font-size: 13.5px;
    color: #3f5368;
    margin-top: 15px;
}

/* Loading Spinner Text */
#loadingSpinner { display: none; margin-bottom: 10px; }
.typing-indicator span {
    display: inline-block;
    width: 6px; height: 6px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite both;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/*-------màn hình dọc------*/
@media screen and (max-width: 735px) {
    .input-container {                    
        padding-left: 0px;
        padding-right: 30px;

        /* Thêm 2 dòng này để cố định vị trí ở giữa trên mọi thiết bị */
        width: 100% !important;
        box-sizing: border-box;        
    }
    
}