:root {
    --primary-color: #0d47a1;
    --primary-light: #1976d2;
    --main-bg-color: #EDF2F7;
    --accent-color: #4CAF50;
    --danger-color: #d32f2f;
    --warning-color: #ffa000;
    --text-color: #1A202C;
    --text-light: #718096;
    --border-color: #e0e0e0;
    --white-color: #ffffff;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --login-bg: #62a4f5;
    --login-button-bg: #4263EB;
}

/* --- GENERAL & TYPOGRAPHY --- */
body {
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    margin: 0;
    background-color: var(--main-bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%; /* Prevents font scaling on mobile */
}

/* --- LOGIN SCREEN --- */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    background: url('https://images.unsplash.com/photo-1644088379091-d574269d422f?q=80&w=2186&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D') no-repeat center center;
    background-size: cover;
	padding: 15px;
}
.login-container {
    background-color: rgba(255, 255, 255, 0.15); /* Nền trắng bán trong suốt */
    backdrop-filter: blur(5px); /* Hiệu ứng mờ */
    -webkit-backdrop-filter: blur(5px); /* Hỗ trợ trình duyệt Webkit */
    border: 1px solid rgba(255, 255, 255, 0.2); /* Viền mỏng, bán trong suốt */
    border-radius: 15px; /* Bo tròn góc */
    padding: 35px;
    box-shadow: 0 10px 40px 0 rgba(0, 0, 0, 0.2); /* Đổ bóng nhẹ */
    width: 70%;
    max-width: 330px;
    text-align: center;
    color: white; /* Đổi màu chữ sang trắng để nổi bật trên nền tối */
    position: relative; /* Dùng cho các hiệu ứng chi tiết hơn */
    overflow: hidden; /* Đảm bảo các lớp phủ không tràn ra ngoài */
}
.login-icon {
    color: #ffffff;
    margin-bottom: 20px;
}
.login-container h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 5px 0;
}
.login-container .subtitle {
    color: #f0b207;
    margin-bottom: 30px;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.login-container input {
    width: 100%;
    padding: 14px 18px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-sizing: border-box;
    background-color: #f8f9fa;
    transition: all 0.3s;
}
.login-container input:focus {
    outline: none;
    border-color: var(--login-button-bg);
    background-color: var(--white-color);
    box-shadow: 0 0 0 3px rgba(66, 99, 235, 0.2);
}
#login-form button {
    width: 100%;
    padding: 14px;
    background-color: var(--login-button-bg);
    color: var(--white-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
#login-form button:hover {
    opacity: 0.9;
    transform: none;
}
.login-container .helper-text {
    margin-top: 20px;
    font-size: 0.85rem;
    color: #fcfbfa;
}
#login-error {
    color: var(--danger-color);
    margin-top: 15px;
    font-size: 0.9em;
    display: none;
}

/* --- MAIN APP LAYOUT --- */
#main-app {
    display: none;
    flex-direction: column;
    width: 100%;
}

.app-header-container {
    position: sticky;
    top: 0;
    z-index: 999;
    background-color: var(--white-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 25px;
    border-bottom: 1px solid var(--border-color);
}
.user-info { font-size: 0.9em; color: var(--text-light); }
.user-info span { font-weight: 700; color: var(--primary-color); }

.header-title { 
    text-align: center; 
    padding: 20px 25px; 
    
    /* ✅ THÊM MỚI: Ép chiều cao tối thiểu phải bằng chiều cao Logo + lề */
    /* Logo cao 118px + top 10px = 128px. Ta để 130px cho thoáng */
    min-height: 130px; 
    
    /* Căn giữa nội dung chữ theo chiều dọc */
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.header-title h1 { color: var(--primary-color); margin: 0 0 5px 0; font-size: 1.8rem; }
.header-title h2 { font-size: 1.3rem; font-weight: 600; color: #f7931e; margin: 0; }

main {
    padding: 25px;
    flex-grow: 1;
}

/* --- TABS --- */
.tab-container {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 25px;
}
.tab-button {
    padding: 15px 25px;
    cursor: pointer;
    border: none;
    border-bottom: 3px solid transparent;
    background-color: transparent;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-light);
    transition: all 0.3s ease;
    margin-bottom: -1px;
    white-space: nowrap; /* Prevent tabs from breaking line */
}
.tab-button:hover {
    color: var(--primary-color);
    background-color: #f0f0f0;
}
.tab-button.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- CARD & SECTION STYLING --- */
.card {
    background: var(--white-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    overflow: hidden;
}
.card-header {
    background-color: #f7f9fc;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h2, .card-header h3 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.2rem;
    font-weight: 700;
}
.card-body {
    padding: 20px;
}

/* --- BUTTONS --- */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 10px;
    transition: all 0.2s;
}
button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}
button.primary { background-color: var(--primary-light); color: white; }
button.accent { background-color: var(--accent-color); color: white; }
button.danger { background-color: var(--danger-color); color: white; }
button.warning { background-color: var(--warning-color); color: var(--text-color); }
button.secondary { background-color: #BDBDBD; color: var(--text-color); }
button:disabled {
    background-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}
.header-buttons button { padding: 8px 12px; font-size: 12px; }

/* --- FORMS & LAYOUTS --- */
.form-group {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}
.form-group label {
    width: 200px;
    font-weight: 700;
    color: var(--text-light);
}
.form-group input, .form-group select, .form-group textarea {
    flex: 1;
    min-width: 250px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.3s, box-shadow 0.3s;
    background-color: #fcfeff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

.radio-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 8px 25px; /* Row and column gap */
}
.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
}
.radio-option label {
    width: auto;
    font-weight: 500;
    color: var(--text-color);
}

.stages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

fieldset {
    border: 1px solid var(--border-color);
    padding: 20px;
    margin-bottom: 0;
    border-radius: 5px;
    background-color: #fafafa;
}
legend {
    font-weight: 700;
    color: var(--primary-light);
    padding: 0 10px;
}
fieldset:disabled { opacity: 0.6; background-color: #f5f5f5; }
.child-ship-list { margin-left: 20px; list-style-type: disc; }
   
/* --- SEARCH & PAGINATION --- */
.search-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
}
.search-bar input {
    flex-grow: 1;
    padding: 14px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    margin-bottom: 0;
}
.search-bar button {
    flex-shrink: 0;
    padding: 10px 18px;
    margin-right: 0;
}
.pagination { 
    margin-top: 20px; 
    text-align: center; 
}
/* --- TABLES --- */
.table-container {
    width: 100%;
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}
th, td {
    border: 1px solid var(--border-color);
    padding: 12px 15px;
    text-align: left;
    vertical-align: middle;
}
th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.85em;
}
tr:nth-child(even) { background-color: #f9f9f9; }
tr:hover { background-color: #e3f2fd; }
tr.group-summary { background-color: #e8f5e9 !important; font-weight: 700; }
td.actions-cell {
    text-align: center;
}
td.actions-cell button {
    margin: 2px;
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* --- DASHBOARD --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
}
.status-column {
    display: flex;
    flex-direction: column;
}
.status-column .card-header {
    background-color: var(--primary-light);
}
 .status-column .card-header h3 {
     color: var(--white-color);
 }
.ship-count {
    background-color: rgba(255,255,255,0.3);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.9rem;
    margin-left: 10px;
}
.notification-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    height: 400px;
    overflow-y: auto;
    flex-grow: 1;
}
.notification-list li:first-child .notification-item { border-top: none; }
.notification-item {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
}
.notification-item span { font-weight: 700; color: var(--text-color); }
.notification-item br + * { font-size: 0.9em; color: var(--text-light); }

/* --- STATISTICS --- */
.stats-display {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    align-items: center;
}
.stats-info { flex: 2; min-width: 300px; }
.stats-info p { margin: 0 0 10px 0; font-size: 1.1rem; }
.stats-info strong { color: var(--primary-color); font-weight: 700; }
.stats-chart { flex: 1; max-width: 420px; max-height: 420px; margin: auto; }

/* --- MODAL --- */
.modal {
    display: none; position: fixed; z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    overflow: auto; background-color: rgba(0,0,0,0.5);
    align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
    background-color: var(--white-color);
    padding: 25px;
    border: none;
    width: 90%;
    max-width: 700px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-content h3, .modal-content h4 {
    color: var(--primary-color);
    margin-top: 0;
}
.close-button {
    color: #aaa; position: absolute; top: 10px; right: 15px;
    font-size: 28px; font-weight: bold;
}
.close-button:hover, .close-button:focus {
    color: black; text-decoration: none; cursor: pointer;
}

/* --- HISTORY MODAL SPECIFIC --- */
#history-content .history-item {
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 15px;
    background-color: #f9f9f9;
}
 #history-content .history-item h4 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
 }
#history-content p {
    margin: 5px 0;
    font-size: 0.95rem;
}


/* MOBILE RESPONSIVE STYLES */
@media (max-width: 768px) {
    main { padding: 15px; }
    .header-title h1 { font-size: 1.4rem; }
    .header-title h2 { font-size: 0.9rem; }
    .app-header { flex-direction: column; gap: 10px; padding: 15px; }
    .tab-container {
        overflow-x: auto;
        padding: 0 15px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .tab-container::-webkit-scrollbar { display: none; }
    .tab-button { padding: 12px 15px; font-size: 0.9rem; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .card-header h2, .card-header h3 { font-size: 1.1rem; }
    .card-body { padding: 15px; }
    .form-group { flex-direction: column; align-items: stretch; gap: 5px; }
    .form-group label { width: 100%; margin-bottom: 2px; }
    .stages-grid { grid-template-columns: 1fr; }
    .stats-display { flex-direction: column; }
    th, td { padding: 10px 8px; font-size: 0.9em; }
    .login-container { padding: 25px; }
    .modal-content { width: 95%; }
    .search-bar { flex-wrap: wrap; }
}
#demdes-forecast th {
    text-align: center;
    vertical-align: middle;
}
/* Bỏ padding dưới của container header */
.app-header-container {
    position: relative;
    padding-top: 10px;    /* Thêm khoảng trống ở trên */
    padding-bottom: 30px; /* Tăng khoảng trống ở dưới */
    border-bottom: 1px solid #dee2e6; /* Thêm đường viền mỏng để phân tách */
}

/* Định vị lại header chứa thông tin user và nút logout */
.app-header {
    position: absolute;
    top: 20px;      /* Căn lề trên */
    right: 20px;     /* Căn lề phải */
    width: auto;
    padding: 0;
    background-color: transparent;
    border-top: none;
    display: flex;         /* Sắp xếp các mục bên trong theo hàng ngang */
    align-items: center; /* Căn giữa các mục theo chiều dọc */
}

/* Định vị lại header chứa thông tin user và nút logout */
.app-header {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column; /* Xếp các mục theo chiều dọc */
    align-items: flex-end;  /* Căn các mục về phía bên phải */
}

/* Tạo khoảng cách giữa dòng chữ và nút Logout */
.app-header .user-info {
    margin-bottom: 8px; 
}
/* Định vị logo ở góc trên bên trái */
.app-logo {
    position: absolute;
    top: 10px;
    left: 10px;
    height: 118px; /* Điều chỉnh chiều cao logo theo ý muốn */
    width: 125px;  /* Tự động điều chỉnh chiều rộng theo tỷ lệ */
}
/* Điều chỉnh kích thước và cỡ chữ của nút Logout */
#logout-button {
    padding: 4px 8px;  /* Thay đổi kích thước nút (nhỏ hơn) */
    font-size: 8px;    /* Thay đổi cỡ chữ (nhỏ hơn) */
}
/* Canh giữa tiêu đề cho bảng Than Nhập Khẩu */
#imported-table th {
    text-align: center;
    vertical-align: middle;
}

/* Canh giữa tiêu đề cho bảng Giám định cảng dỡ */
#unloading-table th {
    text-align: center;
    vertical-align: middle;
}
/* Canh giữa tiêu đề cho bảng Than Nội Địa */
#domestic-table th {
    text-align: center;
    vertical-align: middle;
}
/* Làm nổi bật chữ trên các tab điều hướng */
.tab-container .tab-button {
    color: #1a237e; /* Màu xanh đậm (thay thế màu xám mờ hiện tại) */
    font-weight: 900;   /* Tăng độ đậm của chữ */
}
/* Canh giữa tiêu đề và nội dung cho bảng Dem/Des */
#demdes-table th, 
#demdes-table td {
    text-align: center;
    vertical-align: middle;
}

/* Giữ màu xanh sáng cho tab đang được chọn */
.tab-container .tab-button.active {
    color: #007bff; /* Màu xanh sáng của tab đang active */
}
/* Canh giữa tiêu đề cho bảng Lightship */
#lightship-table th {
    text-align: center;
    vertical-align: middle;
}
/* ============================================================
   AUTO ZOOM CHO MÀN HÌNH LAPTOP (13 inch - 15 inch)
   Mục tiêu: Mô phỏng mức Zoom 80-85%
   ============================================================ */

@media screen and (min-width: 992px) and (max-width: 1600px) {
    /* 1. Thu nhỏ cỡ chữ toàn trang xuống 85% (Tương đương Zoom out) */
    html {
        font-size: 13.5px; /* Mặc định trình duyệt là 16px */
    }

    /* 2. Ép Bảng tin (Dashboard) luôn chia thành 4 cột đều nhau */
    /* Ngăn không cho nó tự xuống dòng khi màn hình hẹp */
    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 15px; /* Giảm khoảng cách giữa các cột */
    }

    /* 3. Thu gọn các khoảng trắng thừa (Padding/Margin) */
    main {
        padding: 10px 15px; /* Giảm lề của phần nội dung chính */
    }

    .app-header-container {
        padding-bottom: 10px; /* Thu gọn header */
    }

    .header-title {
        padding: 5px 10px;
        
        /* ✅ THÊM MỚI: Ở chế độ Zoom nhỏ, Logo chỉ cao 85px */
        /* Nên ta để min-height thấp hơn cho đỡ trống */
        min-height: 90px !important; 
    }
    
    .header-title h1 {
        font-size: 1.5rem; /* Giảm cỡ chữ tiêu đề chính */
    }

    /* 4. Thu nhỏ Logo cho đỡ chiếm diện tích */
    .app-logo {
        height: 85px !important;
        width: auto !important;
    }

    /* 5. Thu gọn chiều cao các ô Input và Nút bấm */
    .form-group input, 
    .form-group select, 
    button, 
    .tab-button {
        padding: 8px 12px; /* Nút nhỏ gọn hơn */
        font-size: 0.9rem;
    }

    /* 6. Tối ưu hóa bảng dữ liệu */
    th, td {
        padding: 8px 10px; /* Giảm độ dày ô bảng */
        font-size: 0.9rem;
    }
    
    /* Giảm chiều cao danh sách thông báo ở Dashboard */
    .notification-list {
        height: 300px; 
    }
}
/* --- MÀU SẮC NHÓM TÀU NHẬP KHẨU --- */

/* Nhóm lẻ (1, 3, 5...): Màu trắng */
tr.group-odd {
    background-color: #ffffff !important;
}

/* Nhóm chẵn (2, 4, 6...): Màu xám xanh nhạt để phân biệt */
tr.group-even {
    background-color: #f2f7fc !important;
}

/* Hàng tổng kết: Màu xanh lá nhạt nổi bật (giữ nguyên hoặc chỉnh lại) */
tr.group-summary {
    background-color: #e8f5e9 !important; 
    font-weight: 700;
    border-top: 2px solid #4CAF50; /* Thêm viền trên để ngắt đoạn rõ hơn */
}
/* ============================================================
   LOADING SPINNER (HIỆU ỨNG CHỜ)
   ============================================================ */

.loading-overlay {
    position: fixed;       /* Cố định vị trí so với màn hình */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Màu đen mờ 50% */
    z-index: 9999;         /* Đảm bảo luôn nổi lên trên tất cả các cửa sổ khác */
    display: flex;         /* Dùng flexbox để căn giữa */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
}

.spinner {
    border: 5px solid #f3f3f3; /* Viền xám nhạt */
    border-top: 5px solid #4CAF50; /* Viền trên màu xanh (hoặc màu var(--accent-color) của bạn) */
    border-radius: 50%;        /* Bo tròn thành hình tròn */
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite; /* Hiệu ứng xoay */
    margin-bottom: 15px;
}

/* Định nghĩa chuyển động xoay */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
