@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Khmer:wght@400;500;600;700&display=swap');

/* =========================================================
   GLOBAL
========================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Noto Sans Khmer", sans-serif;
    background: #f4f6f8;
    color: #1f2937;
}


/* =========================================================
   DEFAULT STATE — NOT LOGGED IN
========================================================= */

.app-container .app-header,
.app-container .filter-section,
.app-container .table-section,
.app-container .action-section {
    display: none;
}

.app-container .login-container {
    display: flex;
}


/* =========================================================
   LOGGED-IN STATE
========================================================= */

.app-container.logged-in .login-container {
    display: none;
}

.app-container.logged-in .app-header,
.app-container.logged-in .filter-section,
.app-container.logged-in .table-section,
.app-container.logged-in .action-section {
    display: block;
}

/* =========================================================
   APP CONTAINER
========================================================= */

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}


/* =========================================================
   APP HEADER
========================================================= */

.app-header {
    background: white;
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-header h1 {
    font-size: 20px;
    margin-bottom: 6px;
}

.app-header h1 i {
    margin-right: 2px;
    color: #7c3aed;
}

.app-header p {
    color: #6b7280;
    font-size: 14px;
}

/* =========================================================
   FILTER SECTION
========================================================= */

.filter-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;

    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-size: 14px;
    font-weight: 600;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 11px 12px;

    border: 1px solid #cbd5e1;
    border-radius: 8px;

    background: #f8fafc;
    font-family: inherit;
    font-size: 15px;
    color: #1f2937;

    outline: none;

    transition: 
        background-color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.filter-group select:disabled {
    background: #e5e7eb;
    color: #6b7280;
    cursor: not-allowed;
    opacity: 1;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: #2563eb;
    background-color: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-group input:hover,
.filter-group select:hover {
    background: #f1f5f9;
}


/* =========================================================
   TABLE SECTION
========================================================= */

.table-section {
    background: white;
    border-radius: 12px;
    overflow: hidden;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

    margin-bottom: 20px;
}


/* =========================================================
   TABLE HEADER
========================================================= */

.table-header {
    padding: 18px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.table-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.table-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* =========================================================
   FREEZE STUDENT COLUMNS
========================================================= */

/* Photo column */
#attendanceTable th:nth-child(1),
#attendanceTable td:nth-child(1) {
    width: 60px;
    min-width: 60px;
    max-width: 60px;
    position: sticky;
    left: 0;
    z-index: 3;
    background: white;
}

/* Student ID column */
#attendanceTable th:nth-child(2),
#attendanceTable td:nth-child(2) {
    width: 60px;
    min-width: 60px;
    max-width: 60px;
    position: sticky;
    left: 60px;
    z-index: 3;
    background: white;
}

/* Student Name column */
#attendanceTable th:nth-child(3),
#attendanceTable td:nth-child(3) {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    position: sticky;
    left: 60px;
    z-index: 3;
    background: white;
}


/* Keep header above frozen student cells */
#attendanceTable thead th {
    position: sticky;
    top: 0;
    z-index: 4;
}


/* Frozen header cells need higher priority */
#attendanceTable thead th:nth-child(1),
#attendanceTable thead th:nth-child(2),
#attendanceTable thead th:nth-child(3) {
    z-index: 6;
    background: #f9fafb;
}

/* =========================================================
   ATTENDANCE PAGINATION
========================================================= */

.attendance-pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

button i {
    margin-right: 6px;
}

#nextDaysButton i {
    margin-right: 0;
    margin-left: 6px;
}

/* Previous / Next buttons */
.attendance-pagination button {
    min-width: 88px;
    height: 34px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 0 12px;

    border: 1px solid #cbd5e1;
    border-radius: 7px;

    background: #ffffff;
    color: #334155;

    font-family: Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;

    cursor: pointer;

    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);

    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.1s ease;
}

/* Hover */
.attendance-pagination button:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #94a3b8;

    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Click */
.attendance-pagination button:active:not(:disabled) {
    transform: translateY(1px);

    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Disabled */
.attendance-pagination button:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    border-color: #e2e8f0;

    cursor: not-allowed;

    box-shadow: none;
}


/* Week range */
#dayRangeLabel {
    min-width: 48px;

    text-align: center;

    font-family: Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;

    color: #475569;

    white-space: nowrap;
}


/* =========================================================
   TABLE CONTAINER
========================================================= */

.table-container {
    overflow-x: auto;
    width: 100%;
}


/* =========================================================
   ATTENDANCE TABLE
========================================================= */

#attendanceTable {
    width: 100%;
    border-collapse: collapse;
}

#attendanceTable th,
#attendanceTable td {
    padding: 12px 14px;

    border-bottom: 1px solid #e5e7eb;

    text-align: center;
    white-space: nowrap;
}

#attendanceTable th {
    background: #f9fafb;

    font-size: 13px;
    font-weight: 600;
}

#attendanceTable td {
    font-size: 14px;
}

#attendanceTable tbody tr:hover {
    background: #f9fafb;
}


/* =========================================================
   STUDENT PHOTO / AVATAR
========================================================= */

.student-avatar-cell {
    width: 60px;
    min-width: 60px;
    text-align: center !important;
}

.student-photo,
.student-avatar {
    width: 40px;
    height: 40px;

    border-radius: 50%;

    transition: transform 0.2s ease;

    cursor: pointer;
}

.student-photo {
    object-fit: cover;
    display: block;
    margin: 0 auto;
}

.student-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: white;

    font-size: 13px;
    font-weight: 600;
}

.photo-zoom {
    transform: scale(1.5);

    position: relative;
    z-index: 100;
}


/* =========================================================
   DAY HEADER
========================================================= */

.day-number {
    font-weight: bold;
}

.day-name {
    margin-top: 2px;

    font-size: 12px;
    font-weight: normal;
}


/* =========================================================
   SUNDAY
========================================================= */

#attendanceTable th.sunday-header {
    background: #fee2e2 !important;
    color: red;
}

#attendanceTable td.sunday-cell {
    background: #fef2f2 !important;
    color: red;
}


/* =========================================================
   DAY OFF
========================================================= */

#attendanceTable th.day-off-header {
    background: #f8e9d9 !important;
    color: red;
}

#attendanceTable td.day-off-cell {
    background: #faf4ef !important;
    color: red;
}

/* =========================================================
   Outside Month Heade
========================================================= */

#attendanceTable th.outside-month-header {
    background: #f3f4f6 !important;
    color: #9ca3af;
}

#attendanceTable td.outside-month-cell {
    background: #f3f4f6 !important;
    color: #9ca3af;
}

.outside-month-cell .attendance-status {
    background: transparent;
    border-color: transparent;
    color: #9ca3af;
    cursor: not-allowed;
}

/* =========================================================
   ATTENDANCE SELECT
========================================================= */

.attendance-status {
    min-width: 48px;

    padding: 6px 4px;

    border: 1px solid #cbd5e1;
    border-radius: 6px;

    background: #f8fafc;
    color: #1f2937;

    font-size: 14px;
    font-weight: 500;
    text-align: center;

    cursor: pointer;
    outline: none;

    transition: 
        background-color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.attendance-status:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.attendance-status:focus {
    background: white;
    border-color: #2563eb;

    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.1);
}

.attendance-status:disabled {
    background: transparent;
    border-color: transparent;

    cursor: not-allowed;

    opacity: 0.6;
}


/* =========================================================
   ATTENDANCE TOOLTIP
========================================================= */

.attendance-tooltip {
    position: fixed;

    z-index: 99999;

    background: #1f2937;
    color: white;

    padding: 7px 12px;

    border-radius: 6px;

    font-size: 13px;
    line-height: 1.4;

    white-space: nowrap;

    pointer-events: none;

    opacity: 0;
    visibility: hidden;

    transition: opacity 0.15s ease;
}

.attendance-tooltip.show {
    opacity: 1;
    visibility: visible;
}


/* =========================================================
   EMPTY MESSAGE
========================================================= */

.empty-message {
    text-align: center !important;

    padding: 40px !important;

    color: #6b7280;

    font-size: 14px;
}


/* =========================================================
   ACTION SECTION
========================================================= */

.action-section {
    display: flex;
    justify-content: flex-end;

    margin-top: 20px;
}


/* =========================================================
   SAVE BUTTON
========================================================= */

#saveAttendanceButton {
    border: none;
    border-radius: 8px;

    padding: 12px 22px;

    background: #2563eb;
    color: white;

    font-size: 15px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background-color 0.2s ease,
        transform 0.1s ease;
}

#saveAttendanceButton:hover:not(:disabled) {
    background: #1d4ed8;
}

#saveAttendanceButton:active:not(:disabled) {
    transform: translateY(1px);
}

#saveAttendanceButton:disabled {
    background: #9ca3af;
    color: #f3f4f6;

    cursor: not-allowed;
}

/* =========================================================
   LOGOUT BUTTON
========================================================= */
#logoutButton {
    padding: 8px 12px;
    border: 1px solid #ef4444;
    border-radius: 8px;

    background: transparent;
    color: #ef4444;

    font-size: 12px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        transform 0.1s ease;
}

#logoutButton:hover {
    background: #ef4444;
    color: white;
}

#logoutButton:active {
    transform: scale(0.97);
}

#logoutButton:focus-visible {
    outline: 3px solid rgba(239, 68, 68, 0.3);
    outline-offset: 2px;
}
/* =========================================================
   SHOW TOAST
========================================================= */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index:9999;

    min-width: 260px;
    max-width: 350;

    padding: 14px 18px;
    border-radius: 10px;

    background: #222;
    color: white;

    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);

    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;

    transition:
        opacity 0.3s ease,
        transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: #16a34a;
}

.toast.error {
    background: #dc2626;
}

.toast.warning {
    background: #d97706;
}



/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 700px) {

    .app-container {
        padding: 12px;
    }


    /* -------------------------
       Header
    ------------------------- */

    .app-header {
        padding: 18px;
        border-radius: 10px;
    }

    .app-header h1 {
        font-size: 18px;
    }

    .app-header h1 i {
        margin-right: 2px;
        color: #7c3aed;
    }

    .app-header p {
        font-size: 13px;
    }


    /* -------------------------
       Filters
    ------------------------- */

    .filter-section {
        grid-template-columns: 1fr;

        gap: 14px;

        padding: 16px;

        border-radius: 10px;
    }


    /* -------------------------
       Table Header
    ------------------------- */

    .table-header {
        padding: 14px 16px;
    }

    .table-title-row {
        gap: 8px;
    }

    .table-header h2 {
        font-size: 16px;
    }


    /* -------------------------
       Pagination
    ------------------------- */

    .attendance-pagination { gap: 4px; } 
    .attendance-pagination button { min-width: 76px; height: 32px; padding: 0 8px; font-size: 12px; } 
    #dayRangeLabel { min-width: 40px; font-size: 12px; }


    /* -------------------------
       Table
    ------------------------- */

    #attendanceTable th,
    #attendanceTable td {
        padding: 10px;
    }

    #attendanceTable th {
        font-size: 12px;
    }

    #attendanceTable td {
        font-size: 13px;
    }


    /* -------------------------
       Student Photo
    ------------------------- */

    .student-avatar-cell {
        width: 50px;
        min-width: 50px;
    }

    .student-photo,
    .student-avatar {
        width: 36px;
        height: 36px;
    }

    .student-avatar {
        font-size: 12px;
    }


    /* -------------------------
       Attendance Select
    ------------------------- */

    .attendance-status {
        min-width: 44px;

        padding: 5px 3px;

        font-size: 13px;
    }


    /* -------------------------
       Save Button
    ------------------------- */

    .action-section {
        margin-top: 16px;
    }

    #saveAttendanceButton {
        width: 100%;

        padding: 12px 18px;
    }
}

/* -------------------------
    LOGOUT Button
------------------------- */
#logoutButton {
    padding: 7px 11px;
    margin-right: 6px;
    font-size: 14px;

}

/* =========================================================
   VERY SMALL MOBILE
========================================================= */

@media (max-width: 400px) {

    .app-container {
        padding: 8px;
    }

    .app-header {
        padding: 16px;
    }

    .table-header {
        padding: 12px;
    }

    .table-title-row {
        gap: 6px;
    }

    .table-header h2 {
        font-size: 15px;
    }

    .attendance-pagination {
        gap: 3px;
    }

    .attendance-pagination button {
        width: 28px;
        height: 28px;

        font-size: 13px;
    }

    #dayRangeLabel {
        min-width: 34px;

        font-size: 11px;
    }

    #attendanceTable th,
    #attendanceTable td {
        padding: 8px;
    }
}
