/* Import Google Fonts for Khmer and English text */
@import url('https://fonts.googleapis.com/css2?family=Khmer+OS+Battambang:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap');

@font-face {
    font-family: KhmerOSMuollight;
    src: url(../font/KhmerOSmuollight.ttf);
    /* Optimization: Ensures text is visible while the font loads */
    font-display: swap;
}

/*
    ==============================================
    CSS Custom Properties (Variables)
    ==============================================
    Defining a consistent design system for colors, fonts, and spacing.
*/
:root {
    --primary-blue: #2A63F6;
    --primary-blue-light: #EAF0FE;
    --text-dark: #1c1c1e;
    --text-light: #6d6d72;
    --bg-color: #F7F8FC;
    --card-bg: #ffffff;
    --border-color: #EAEBF0;
    --shadow-color: rgba(90, 99, 120, 0.08);
    --green: #28a745;
    --green-light: #eaf6ec;
    --red: #dc3545;
    --red-light: #fceced;
    --font-family-en: 'Poppins', sans-serif;
    --font-family-km: 'Khmer OS Battambang', sans-serif;
    --font-family-moul: KhmerOSMuollight;
    --transition-speed: 0.3s;
    --border-radius: 20px;
}

/*
    ==============================================
    Global Resets & Base Styles
    ==============================================
*/
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-en);
    background-color: var(--bg-color);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Center login card vertically */
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    transition: justify-content var(--transition-speed) ease;
    overflow-x: hidden;
}

/* When the dashboard is active, align content to the top */
body.dashboard-active {
    justify-content: flex-start;
}

.khmer-font {
    font-family: var(--font-family-km);
}

.khmer-font-moul {
    font-family: var(--font-family-moul);
}

/* Utility class to hide elements */
.hidden {
    display: none !important;
}

/* Responsive image best practice */
img {
    max-width: 100%;
    height: auto;
    display: block;
    /* Removes bottom space under the image */
}

/*
    ==============================================
    Card Styles
    ==============================================
    Base styles for all card-like containers.
*/
.attendance-log-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    /* Using clamp for responsive padding: min, preferred, max */
    padding: clamp(1.5rem, 5vw, 2rem);
    box-shadow: 0 8px 40px var(--shadow-color);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 420px;
    /* Max width for login card on larger screens */
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/*
    ==============================================
    Main Application Header
    ==============================================
*/
.main-app-header {
    display: flex;
    justify-content: center;
    /* Changed from space-between */
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 1.5rem;
    background-color: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 40px var(--shadow-color);
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
    /* Allow wrapping on medium-small screens if needed */
    gap: .5rem;
    /* Add gap for wrapped items */
}

.header-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
}

.header-title img {
    height: 60px;
    /* The width/height in HTML sets the aspect ratio box, CSS can still control the rendered size */
}

.header-title h2 {
    /* Fluid font size */
    font-size: clamp(1.1rem, 2.5vw, 1.25rem);
    font-weight: 600;
}

/* USER-PROFILE AND LOGOUT-BTN STYLES REMOVED */

/*
    ==============================================
    Dashboard Layout
    ==============================================
    Mobile-first: single-column layout.
*/
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr;
    /* Single column layout */
    gap: 1.5rem;
    width: 100%;
    max-width: 1200px;
}

.attendance-log-card {
    max-width: 100%;
    /* Adjust max-width for a wider form */
    margin: 0 auto;
    /* Center the card */
}

.card-header {
    margin-bottom: 1.5rem;
    text-align: left;
}

.card-header h1 {
    font-size: clamp(1.3rem, 5vw, 1.5rem);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.card-header h2 {
    font-size: clamp(1.5rem, 6vw, 2rem);
    font-weight: 600;
    line-height: 1.2;
    margin-top: .3rem;
    text-align: center;
}

.card-header p {
    color: var(--text-light);
    font-size: 0.9rem;
}

/*
    ==============================================
    Form Styles
    ==============================================
*/
#attendance-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

#form-message {
    min-height: 1.2em;
    text-align: center;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

#form-message {
    color: var(--green);
}

/* Form Row Grid - Mobile-first (1 column) */
.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Grid spanning for larger screens - Default to 1 span */
.grid-span-2 {
    grid-column: span 1;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group label:has(input) {
    margin-bottom: unset;
}

/* Icons inside input fields */
.form-group>i {
    position: absolute;
    left: 1rem;
    top: 60%;
    color: var(--text-light);
    font-size: 1.2rem;
    pointer-events: none;
    z-index: 1;
}

.form-group input,
.form-group textarea,
.form-group .dropdown-selected {
    padding: 0.8rem 1rem 0.8rem 3rem;
    /* Left padding for icon */
    border-radius: 12px;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    background-color: var(--bg-color);
    color: var(--text-dark);
    transition: all var(--transition-speed) ease;
    max-width: 100%;
    min-width: 100%;
    height: 50px;
    /* Changed from min-width for consistency */
}

.form-group textarea {
    padding: 0.8rem 1rem;
    resize: vertical;
    min-height: 80px;
}

.form-group input[type="date"] {
    padding-right: 1rem;
    min-height: 30px;
    height: 100%;
    max-height: 50px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group .dropdown-selected:focus,
.custom-dropdown.open .dropdown-selected {
    outline: none;
    border-color: var(--primary-blue);
    background-color: var(--card-bg);
    box-shadow: 0 0 0 3px var(--primary-blue-light);
}

/* Error Styling for Inputs */
.input-error,
.input-error .dropdown-selected {
    border: 1px solid var(--red) !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.2) !important;
}

/*
    ==============================================
    Autocomplete & Dropdown Styles
    ==============================================
*/
.suggestions-container,
.dropdown-options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
}

/* Student Name Search Suggestions */
.suggestions-container {
    display: none;
}

.suggestions-container.open {
    display: block;
}

.suggestion-item {
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
}

.suggestion-item:hover {
    background-color: var(--primary-blue-light);
}

/* Custom Dropdown Styles */
.custom-dropdown {
    position: relative;
    cursor: pointer;
}

.dropdown-selected {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-selected span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 1rem;
}

.dropdown-arrow {
    transition: transform var(--transition-speed) ease;
    flex-shrink: 0;
}

.custom-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-options {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

.custom-dropdown.open .dropdown-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-option {
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.dropdown-option:hover {
    background-color: var(--primary-blue-light);
}

.dropdown-option.selected {
    background-color: var(--primary-blue-light);
    color: var(--primary-blue);
    font-weight: 600;
}

/*
    ==============================================
    Radio Button Group Styles
    ==============================================
*/
.status-options {
    display: flex;
    flex-wrap: wrap;
    /* Key for responsiveness */
    gap: 0.75rem;
    border-radius: 8px;
}

.status-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.6rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) ease;
    user-select: none;
    font-size: 0.9rem;
}

.status-options input[type="radio"] {
    /* Optimization: Use more accessible hiding technique */
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* Style the label when the radio is checked */
.status-options input[type="radio"]:checked+* {
    /* Note: This won't work with the current HTML. The :has selector is better. Keeping original. */
}

.status-options label:has(input[type="radio"]:checked) {
    background-color: var(--primary-blue-light);
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

/*
    ==============================================
    Buttons & Loaders
    ==============================================
*/
.submit-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0.9rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    margin-top: 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50px;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(42, 99, 246, 0.4);
}

.submit-btn:disabled {
    background: #a0c3ff;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-loader {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid #fff;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/*
    ==============================================
    Pay Section Specific Styles
    ==============================================
*/
#bank-section .status-options {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
}

#bank-section .status-options label {
    border-radius: 99999px;
    padding: 1rem;
    position: relative;
    overflow: hidden;
}

#bank-section .status-options label img {
    width: 50px;
    aspect-ratio: 1/1;
    border-radius: 100%;
}

#bank-section .status-options label strong {
    font-size: 0.9rem;
}

#bank-section .status-options label .hole {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    aspect-ratio: 1/1;
    width: 20px;
    background: white;
    border-radius: 100%;
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) ease;
}

#bank-section label:has(input[type="radio"]:checked) .hole {
    background-color: var(--primary-blue);
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px white, 0 0 0 3px var(--primary-blue);
}

#bank-section label:has(input[type="radio"]:checked) {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px var(--primary-blue-light);
}


/*
    ==============================================
    RESPONSIVE DESIGN (Media Queries)
    ==============================================
*/

@media (min-width: 435px) {
    .header-title {
        flex-direction: row;
        gap: 1rem;
    }

    .header-title img {
        height: 70px;
    }

    .main-app-header {
        gap: 1rem;
    }
}

@media (max-width: 767.98px) {
    .main-app-header {
        flex-direction: column;
        text-align: center;
    }

    /* USER-PROFILE RESPONSIVE STYLES REMOVED */

    .form-group input,
    .form-group textarea,
    .form-group .dropdown-selected {
        padding-top: 0.7rem;
        padding-bottom: 0.7rem;
    }
}

@media (min-width: 768px) {
    body {
        padding: 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .grid-span-2 {
        grid-column: span 2;
    }
}

@media (min-width: 1200px) {
    body {
        padding: 2rem;
    }
}

/*
    ==============================================
    Success Message Overlay Styles
    ==============================================
*/
.overlay-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeInOverlay 0.3s ease-out;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.success-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: clamp(1.5rem, 5vw, 2.5rem);
    text-align: center;
    width: 100%;
    max-width: 400px;
    animation: slideInUp 0.4s ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.success-icon {
    width: 80px;
    height: 80px;
    background-color: var(--green-light);
    border-radius: 50%;
    margin: 0 auto 1.5rem auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.success-icon i {
    color: var(--green);
    font-size: 3rem;
}

.success-card h2 {
    font-size: clamp(1.5rem, 5vw, 1.8rem);
    margin-bottom: 0.5rem;
}

.success-card p {
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.success-card .submit-btn {
    background-color: var(--green);
    margin-inline: auto;
}

.success-card .submit-btn:hover {
    background-color: #218838;
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.loader-overlay.hidden-loader {
    opacity: 0;
    visibility: hidden;
}

.breathing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.breathing-logo {
    width: 60px;
    height: auto;
    animation: breathe 2s ease-in-out infinite;
}

.loading-text {
    color: var(--text-light);
    font-size: 0.9rem;
    animation: pulseText 2s ease-in-out infinite;
}

/* The Breathing Animation (Scale + Glow) */
@keyframes breathe {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 0 rgba(42, 99, 246, 0));
    }

    50% {
        transform: scale(1.15);
        filter: drop-shadow(0 0 15px rgba(42, 99, 246, 0.5));
        /* Glow using your primary blue */
    }

    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 0 rgba(42, 99, 246, 0));
    }
}

@keyframes pulseText {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}