/* ================================================= */
/* 1. RESET VÀ CẤU HÌNH CHUNG */
/* ================================================= */

:root {
    --primary-color: #007bff; /* Màu chủ đạo: Xanh dương */
    --primary-hover: #0056b3;
    --secondary-color: #6c757d; /* Màu phụ: Xám */
    --secondary-hover: #5a6268;
    --background-light: #f8f9fa; /* Nền sáng */
    --background-dark: #e9ecef; /* Nền tối hơn (cho sidebar) */
    --text-color: #212529;
    --border-color: #dee2e6;
    --unread-bg: #fff3cd; /* Nền email chưa đọc (vàng nhạt) */
    --active-bg: #e2f0ff; /* Nền email đang chọn (xanh nhạt) */
    --sidebar-width: 250px;
    --list-width: 350px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-light);
    overflow: hidden; /* Ngăn cuộn trang chính */
}

/* ================================================= */
/* 2. CẤU TRÚC CHÍNH (3 CỘT LAYOUT) */
/* ================================================= */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

.main-layout {
    display: flex;
    flex: 1; /* Chiếm hết không gian còn lại */
    overflow: hidden; /* Quan trọng để cuộn các cột riêng */
}

/* 2.1. CỘT THƯ MỤC/NHÃN (ASIDE) */
.folder-column {
    width: var(--sidebar-width);
    background-color: #ffffff;
    border-right: 1px solid var(--border-color);
    padding: 15px 0;
    overflow-y: auto; /* Cho phép cuộn nội dung sidebar */
    flex-shrink: 0; /* Không co lại */
}

/* 2.2. CỘT DANH SÁCH EMAIL (SECTION) */
.list-column {
    width: var(--list-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--background-dark);
    flex-shrink: 0;
}

/* 2.3. CỘT NỘI DUNG EMAIL (MAIN) */
.content-column {
    flex: 1; /* Chiếm hết không gian còn lại */
    padding: 20px;
    background-color: #ffffff;
    overflow-y: auto; /* Cho phép cuộn nội dung email */
}

/* ================================================= */
/* 3. HEADER & THANH CÔNG CỤ (TOOLBAR) */
/* ================================================= */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.toolbar .logo {
    font-size: 1.5em;
    font-weight: 600;
    color: var(--primary-color);
    flex-grow: 1; /* Cho phép logo chiếm không gian */
}

.toolbar .actions {
    display: flex;
    gap: 10px;
    margin-right: 20px;
}

.toolbar .header-actions {
    display: flex;
    align-items: center;
}

/* ================================================= */
/* 4. NÚT (BUTTONS) */
/* ================================================= */

.btn {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--background-dark);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 10px; /* Nhỏ hơn cho các icon button */
}

.btn-secondary:hover {
    background-color: #dee2e6;
}

.btn-tertiary {
    background: none;
    color: var(--primary-color);
    font-weight: 500;
    padding: 5px 10px;
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Trong mục 4. LIST & CONTENT */
.email-item .star-btn {
    color: #ccc; /* Màu xám mặc định */
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 5px;
    transition: color 0.2s;
}

.email-item .star-btn.starred,
.folder[data-folder="starred"] i {
    color: #ffc107; /* Màu vàng khi được đánh dấu */
}

/* Style cho nút "Sao" trong thanh công cụ xem email */
#email-view-toolbar .star-btn {
    margin-right: 5px;
    font-size: 1.3em;
}

/* Trong mục 4. LIST & CONTENT */
.toolbar-view {
    display: flex;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    background-color: #fff;
    position: sticky; /* Giúp nó dính khi cuộn nội dung email */
    top: 0;
    z-index: 5;
}

.toolbar-view .btn {
    margin-right: 8px;
    font-size: 0.9em;
    height: 38px;
    width: 38px;
    padding: 0;
    line-height: 1;
}

.toolbar-view .star-btn.starred {
    color: #ffc107; 
}

/* ================================================= */
/* 5. SIDEBAR (THƯ MỤC VÀ NHÃN) */
/* ================================================= */

.folder-column a {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    color: var(--text-color);
    text-decoration: none;
    transition: background-color 0.15s;
    font-weight: 500;
    gap: 10px;
}

.folder-column a:hover {
    background-color: var(--background-dark);
}

.folder-column .active {
    background-color: var(--active-bg);
    color: var(--primary-color);
}

.folder-column .count {
    margin-left: auto;
    background-color: var(--primary-color);
    color: white;
    font-size: 0.8em;
    padding: 2px 7px;
    border-radius: 12px;
    min-width: 25px;
    text-align: center;
}

.labels-section {
    padding: 0 15px;
    margin-top: 15px;
}

.labels-section h4 {
    font-size: 0.9em;
    color: var(--secondary-color);
    margin-bottom: 10px;
    text-transform: uppercase;
}

.label-item {
    padding-left: 15px !important; /* Lệch vào trong một chút */
}

/* ================================================= */
/* 6. CỘT DANH SÁCH EMAIL (EMAIL LIST) */
/* ================================================= */

.list-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background-color: #ffffff;
}

.list-header h2 {
    font-size: 1.2em;
    margin-bottom: 10px;
}

.search-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

#email-list {
    overflow-y: auto; /* Cuộn danh sách email */
    flex: 1;
}

.email-item {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.15s;
    position: relative;
    background-color: #ffffff;
}

.email-item:hover {
    background-color: var(--background-dark);
}

.email-item.unread {
    background-color: var(--unread-bg);
    border-left: 3px solid var(--primary-color); /* Dấu hiệu chưa đọc */
}

.email-item.active {
    background-color: var(--active-bg);
    border-left: 3px solid var(--primary-color);
}

.email-item h4 {
    font-size: 1em;
    margin: 0 0 5px 0;
    font-weight: 600; /* Chưa đọc thì đậm */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item.unread h4 {
    font-weight: 700;
}

.email-item p {
    font-size: 0.9em;
    color: #666;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item span {
    display: block;
    font-size: 0.8em;
    color: var(--secondary-color);
    margin-top: 5px;
    text-align: right;
}

/* Label Tags trong danh sách email */
.email-labels {
    margin-top: 5px;
}
.label-tag {
    display: inline-block;
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 3px;
    margin-right: 5px;
    color: white;
}
.label-tag[data-color="blue"] { background-color: #007bff; }
.label-tag[data-color="green"] { background-color: #28a745; }
.label-tag[data-color="red"] { background-color: #dc3545; }
.label-tag[data-color="yellow"] { background-color: #ffc107; color: #333; }

/* ================================================= */
/* 7. CỘT NỘI DUNG EMAIL */
/* ================================================= */

.placeholder {
    text-align: center;
    padding-top: 50px;
    color: var(--secondary-color);
    font-size: 1.2em;
}

.placeholder i {
    font-size: 3em;
    display: block;
    margin-bottom: 15px;
}

.email-header h3 {
    font-size: 1.6em;
    margin-bottom: 10px;
}

.email-meta {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-size: 0.95em;
    line-height: 1.8;
}

.action-buttons {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.email-body {
    padding-top: 15px;
    white-space: pre-wrap; /* Giữ định dạng xuống dòng, khoảng trắng */
}

/* ================================================= */
/* 8. MODAL CHUNG */
/* ================================================= */

.modal {
    position: fixed; 
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto; /* Sử dụng auto để cuộn khi cần */
    
    /* Thiết lập ẩn/hiện mặc định: JS sẽ điều chỉnh thuộc tính display */
    display: none; 
    
    z-index: 1000; 
    background-color: rgba(0,0,0,0.6); /* Đen hơn một chút để nổi bật modal */
    
    /* Hiệu ứng chuyển đổi khi mở/đóng modal */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-content {
    background-color: var(--background-light, #fefefe);
    /* Căn giữa mặc định: margin: 5% auto; là tốt cho màn hình lớn */
    margin: 5% auto; 
    padding: 25px; /* Tăng padding */
    border: 1px solid var(--border-color, #e0e0e0);
    width: 90%; /* Tăng độ rộng mặc định để responsive tốt hơn */
    max-width: 650px; /* Tăng max-width cho modal content */
    border-radius: 8px;
    position: relative;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2); /* Box shadow rõ nét hơn */
}

/* ---------------------------------------------------- */
/* Login Modal */
/* ---------------------------------------------------- */
#loginModal {
    /* ... (Giữ nguyên các thuộc tính background và z-index) ... */
    display: none; /* JS sẽ điều chỉnh thành 'flex' khi mở */
    z-index: 900; 
    
    background-image: url('./images/1021.png'); 
    background-size: cover; 
    background-position: center; 
    background-repeat: no-repeat;
    backdrop-filter: blur(5px); 

    /* Căn chỉnh nội dung */
    align-items: stretch; /* Đảm bảo .modal-content kéo dãn chiều cao */
    justify-content: flex-end; /* === THAY ĐỔI: Căn form sang phải === */
}

/* Nội dung của Login Modal (Form) */
#loginModal .modal-content {
    /* === THAY ĐỔI: Đặt chiều cao thành 100% và loại bỏ bo góc nếu muốn sắc nét === */
    width: 350px; /* Đặt độ rộng cố định cho form */
    max-width: 350px; 
    height: 100%; /* === THAY ĐỔI: Chiếm toàn bộ chiều cao === */
    margin: 0; 
    
    background-image: none;
    background-color: rgba(255, 255, 255, 1); /* Màu nền trắng đầy đủ */

    padding: 60px 30px; /* Tăng padding trên dưới cho phù hợp với chiều cao */
    border-radius: 0; /* === THAY ĐỔI: Loại bỏ bo góc để form sắc nét full height === */
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25); /* Đổ bóng sang trái */
    text-align: center;
}

#loginModal h3 {
    color: var(--primary-color, #007bff); 
    font-size: 1.8em; /* Tăng kích thước */
    margin-bottom: 30px; /* Tăng khoảng cách */
    font-weight: 700;
}

#loginModal input {
    width: 100%;
    padding: 14px; /* Tăng padding cho dễ bấm */
    margin-bottom: 20px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box; 
    font-size: 16px; /* Tăng kích thước font */
}

#loginModal input:focus {
    border-color: var(--primary-color, #007bff);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.2);
    outline: none;
}

/* ---------------------------------------------------- */
/* Close Button & Form Styling cho Compose/Settings */
/* ---------------------------------------------------- */

.close-btn {
    position: absolute; /* Thêm position absolute */
    top: 10px;
    right: 20px;
    color: #6c757d; /* Màu xám đậm hơn */
    font-size: 28px;
    font-weight: normal; /* Giảm độ đậm */
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover,
.close-btn:focus {
    color: var(--danger-color, #dc3545); /* Đổi màu khi hover */
    text-decoration: none;
}

/* Compose/Settings Form Styling */
.compose-form label,
.settings-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-color, #333);
}

.compose-form input,
.compose-form textarea,
.settings-form input:not(.inline-input), /* Loại trừ các input nhỏ */
.settings-form select,
.settings-form textarea {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color, #ccc);
    border-radius: 4px;
    font-size: 15px; /* Tăng font size */
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.compose-form input:focus,
.compose-form textarea:focus,
.settings-form input:focus,
.settings-form select:focus,
.settings-form textarea:focus {
    border-color: var(--primary-color, #007bff);
    outline: none;
}

.settings-form h4, .settings-form h5 {
    margin-top: 20px; /* Tăng khoảng cách */
    margin-bottom: 10px;
    font-size: 1.2em; /* Tăng kích thước */
    color: var(--primary-color, #007bff);
    border-bottom: 1px solid var(--border-color, #eee);
    padding-bottom: 5px;
}

.settings-form .server-settings {
    display: flex;
    gap: 15px; /* Tạo khoảng cách giữa các cột */
    align-items: flex-end; /* Căn chỉnh các trường theo hàng dưới */
    margin-bottom: 15px;
}

.settings-form .server-settings > div {
    flex: 1;
}

/* Kiểu dáng cho phần quản lý nhãn */
#settingsLabelsList div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px; /* Tăng padding */
    border-bottom: 1px solid var(--border-color, #ddd);
    background-color: var(--background-light, #fff);
    margin-bottom: 5px;
    border-radius: 4px;
}

#settingsLabelsList div:hover {
    background-color: var(--background-hover, #f1f1f1);
}

/* Nút Xóa/Gỡ nhãn */
.delete-label-btn {
    background: none;
    border: none;
    color: var(--danger-color, #dc3545);
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 5px;
    transition: opacity 0.2s;
}

.delete-label-btn:hover {
    opacity: 0.8;
}

/* Responsive cho Login Modal trên màn hình rất nhỏ */
@media (max-width: 480px) {
    #loginModal .modal-content {
        padding: 30px 15px;
        box-shadow: none; /* Loại bỏ box-shadow trên mobile để trông gọn hơn */
    }
}

/* ---------------------------------------------------- */
/* Notification Modal (Modal Thông báo) */
/* ---------------------------------------------------- */

/* Điều chỉnh kích thước riêng cho modal thông báo */
.small-modal {
    max-width: 400px; /* Kích thước nhỏ gọn */
    margin: 15% auto; /* Đẩy modal xuống giữa màn hình */
    text-align: center;
    padding-bottom: 20px;
}

#notificationModal .modal-content h3 {
    color: var(--primary-color, #007bff);
    margin-bottom: 15px;
    font-size: 1.4em;
}

#notificationModal .modal-content p {
    margin-bottom: 25px;
    font-size: 1em;
    line-height: 1.5;
}

#notificationCloseBtn {
    /* Sử dụng kiểu dáng nút chính (btn-primary) đã định nghĩa trước đó */
    padding: 10px 30px;
}

/* ================================================= */
/* 9. RESPONSIVE DESIGN (Cho màn hình nhỏ) */
/* ================================================= */

@media (max-width: 1024px) {
    /* Trên màn hình tablet/laptop nhỏ, thu hẹp các cột */
    :root {
        --sidebar-width: 200px;
        --list-width: 300px;
    }
}

@media (max-width: 768px) {
    /* Trên màn hình di động, chuyển sang giao diện 2 cột hoặc 1 cột */
    
    .main-layout {
        flex-direction: column; /* Xếp chồng các cột */
    }

    .folder-column, .list-column, .content-column {
        width: 100% !important; 
        flex-shrink: 1;
        border-right: none;
    }
    
    .folder-column {
        height: auto; /* Cho phép cuộn */
        max-height: 250px; /* Chiều cao tối đa khi mở */
        display: none; /* Ban đầu ẩn sidebar */
    }
    
    .list-column {
        height: 50vh; /* Danh sách email chiếm nửa màn hình */
    }
    
    .content-column {
        flex: none;
        height: 50vh; /* Nội dung email chiếm nửa màn hình */
    }
    
    /* Toolbar trên di động */
    .toolbar {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .toolbar .logo {
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
    }
    
    .toolbar .actions, .toolbar .header-actions {
        width: 100%;
        justify-content: center;
    }
}

/* ================================================= */
/* 9. FOOTER STYLES  */
/* ================================================= */

.app-footer { 
    /* Đảm bảo footer luôn neo cố định vào đáy viewport */
    position: fixed; 
    bottom: 0;
    left: 0;
    width: 100%;    
    /* Z-index cao để nằm trên Login Modal */
    z-index: 1000; 
    background-color: #1a1a1a; /* Màu nền tối (ví dụ: đen đậm) */    
    padding: 20px 0;
    color: white; 
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative; 
    z-index: 2; /* Giữ nguyên z-index để nằm trên nền .app-footer */
}

.footer-copyright p {
    margin: 0;
    font-size: 0.9em;
}

.footer-nav a {
    color: #b0b0b0; /* Màu xám nhạt */
    text-decoration: none;
    margin-left: 15px;
    font-size: 0.9em;
    transition: color 0.3s;
}

.footer-nav a:hover {
    color: var(--primary-color);
}

/* Responsive cho footer */
@media (max-width: 768px) {
    .footer-container {
        flex-direction: column;
        text-align: center;
    }
    .footer-nav {
        margin-top: 10px;
    }
    .footer-nav a {
        display: block;
        margin: 5px 0;
    }
}