/* 
  -------------------------------------------------------
  Project: Educational Center Grades View
  Theme: Modern, Minimalist, Friendly
  Direction: RTL (Arabic)
  -------------------------------------------------------
*/

:root {
    /* 
       COLOR PALETTE MATRIX
       --------------------
       Based on the standard "Prussian Blue / Red / Orange" combination.
       PLEASE UPDATE THESE IF THEY DIFFER FROM YOUR ATTACHED IMAGE.
    */
    --col-primary-dark: #003049;
    /* Deep Blue - For Headers/Text */
    --col-primary: #D62828;
    /* Red - For Accents/Buttons */
    --col-secondary: #F77F00;
    /* Orange - For Highlights */
    --col-accent: #FCBF49;
    /* Gold - For Warning/Stars */
    --col-bg-light: #EAE2B7;
    /* Beige - Background */

    /* Functional Colors */
    --bg-main: #F9F9F9;
    /* Softer white for main background */
    --bg-surface: #FFFFFF;
    --text-primary: #003049;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;

    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Fonts */
    --font-main: 'Tajawal', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Layout Utilities --- */
.container {
    width: 90%;
    max-width: 1200px;
    margin: 0px auto;
    padding: 0 1rem;
    height: 94px;
}

.paper {
    margin: -15px auto;
}

.center-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

.screen {
    opacity: 0;
    transition: opacity 0.5s ease;
    width: 100%;
}

.screen.active {
    opacity: 1;
}

/* --- Typography --- */
h1,
h2,
h3 {
    font-weight: 700;
    color: var(--col-primary-dark);
}

/* --- Login Screen --- */
.login-card {
    background: var(--bg-surface);
    padding: 3rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 450px;
    text-align: center;
    border-top: 6px solid var(--col-primary);
    /* Red Top Border */
}

.logo-placeholder {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--col-primary-dark);
    margin-bottom: 2rem;
}

.description {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

/* Form Elements */
.input-group {
    margin-bottom: 1.5rem;
    text-align: right;
}

input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: all 0.3s ease;
    background-color: #FAFAFA;
}

input:focus {
    outline: none;
    border-color: var(--col-secondary);
    /* Orange Focus */
    background-color: #FFF;
    box-shadow: 0 0 0 4px rgba(247, 127, 0, 0.1);
}

.hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Button */
.btn {
    display: inline-block;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: var(--font-main);
}

.btn-primary {
    background-color: var(--col-primary-dark);
    color: #FFF;
}

.btn-primary:hover {
    background-color: #002233;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #FFF;
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.w-100 {
    width: 100%;
}

.privacy-note {
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert.error {
    background-color: #FEF2F2;
    color: var(--error);
    border: 1px solid #FEE2E2;
}

/* --- Grades Screen --- */
.app-header {
    background-color: var(--col-primary-dark);
    color: #FFF;
    padding: 1.5rem 0;
    box-shadow: var(--shadow-md);
}

.app-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    color: #FFF;
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.meta-info {
    font-size: 0.9rem;
    opacity: 0.9;
    color: var(--col-accent);
}

/* Summary Section */
.summary-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-top: -2rem;
    /* Overlap Header */
    margin-bottom: 2rem;
    position: relative;
    z-index: 10;
}

.summary-card {
    background: var(--bg-surface);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-bottom: 4px solid var(--col-secondary);
}

.summary-card .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.summary-card .value {
    font-size: 1.75rem;
    color: var(--col-primary-dark);
}

/* Grades Grid */
.grades-content {
    margin-bottom: 4rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.grades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.grade-card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid var(--border-color);
    position: relative;
    display: flex;
    flex-direction: column;
}

.grade-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.grade-card .card-header {
    padding: 1.25rem;
    background-color: #FAFAFA;
    border-bottom: 1px solid var(--border-color);
}

.grade-card h4 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--col-primary-dark);
}

.grade-card .card-body {
    padding: 1.5rem;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.25rem;
}

.score {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--col-primary-dark);
}

.max-score {
    font-size: 1rem;
    color: var(--text-secondary);
}

.grade-card .card-badge {
    text-align: center;
    padding: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Status Colors for Cards */
.status-success {
    border-top: 4px solid var(--success);
}

.status-success .score {
    color: var(--success);
}

.status-success .card-badge {
    background-color: #D1FAE5;
    color: #065F46;
}

.status-warning {
    border-top: 4px solid var(--warning);
}

.status-warning .score {
    color: var(--warning);
}

.status-warning .card-badge {
    background-color: #FEF3C7;
    color: #92400E;
}

.status-error {
    border-top: 4px solid var(--error);
}

.status-error .score {
    color: var(--error);
}

.status-error .card-badge {
    background-color: #FEE2E2;
    color: #991B1B;
}

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--col-secondary);
    border-bottom-color: transparent;
    border-radius: 50%;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 600px) {
    .summary-section {
        grid-template-columns: 1fr;
    }

    .app-header .container {
        align-items: flex-start;
        gap: 1rem;
    }
}

/* ---------------------------------------------------- */
/* --- NEW GRADE SHEET STYLES --- */
/* ---------------------------------------------------- */

.grade-sheet {
    background: #fff;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 3rem;
    margin-bottom: 2rem;
    position: relative;
    border-top: 41px solid var(--col-primary);
}

/* Sheet Header */
.sheet-header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--col-secondary);
}

.sheet-header h2 {
    font-size: 2rem;
    color: var(--col-primary-dark);
    margin-bottom: 0.25rem;
}

.sheet-header .subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

/* Student Details Grid */
.student-details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    background: #f9fafb;
    padding: 1.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.student-details-grid .detail-item {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    align-content: stretch;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
}

.detail-item .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-item .value {
    font-size: 1.1rem;
    color: var(--col-primary-dark);
    font-weight: 700;
}

/* Table Styles */
.table-container {
    margin-bottom: 2rem;
    overflow-x: auto;
}

.grade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
    min-width: 600px;
    /* Ensure table doesn't squish too much */
}

.grade-table th,
.grade-table td {
    padding: 1rem;
    border: 1px solid var(--border-color);
    text-align: center;
}

.grade-table th {
    background-color: var(--col-primary-dark);
    color: #fff;
    font-weight: 600;
}

.grade-table tbody tr:nth-child(even) {
    background-color: #fafafa;
}

.grade-table tbody tr:hover {
    background-color: #f0fdf4;
    /* Slight green hint on hover */
}

.grade-table tfoot tr {
    background-color: #f3f4f6;
    font-weight: bold;
}

.grade-table tfoot td {
    border-top: 2px solid var(--col-primary);
}

.text-center {
    text-align: center;
}

.bold {
    font-weight: 700;
}

/* Status Colors in Table */
.status-text-success {
    color: var(--success);
    font-weight: bold;
}

.status-text-warning {
    color: var(--warning);
    font-weight: bold;
}

.status-text-error {
    color: var(--error);
    font-weight: bold;
}

/* Sheet Footer */
.sheet-footer {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px dashed var(--border-color);
}

.sheet-footer .signature-section {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2rem;
}

.sig-box {
    text-align: center;
    width: 200px;
    margin-top: 2rem;
}

.sig-box span {
    display: block;
    border-top: 1px solid #000;
    padding-top: 0.5rem;
    font-weight: 600;
}

/* Actions Bar */
.actions-bar {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

/* Responsive Tweaks */
@media (max-width: 600px) {
    .grade-sheet {
        padding: 1rem;
        margin-bottom: 5rem;
        /* Space for fixed bottom buttons if needed */
    }

    .sheet-header h2 {
        font-size: 1.5rem;
    }

    .student-details-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 1rem;
    }

    .detail-item {
        flex-direction: row;
        justify-content: space-between;
        border-bottom: 1px dashed var(--border-color);
        padding-bottom: 0.25rem;
    }

    .detail-item .label {
        font-weight: bold;
    }

    /* Table Responsive */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1.5rem;
    }

    .grade-table {
        min-width: 100%;
        /* Allow scroll only if needed */
        font-size: 0.9rem;
    }

    .grade-table th,
    .grade-table td {
        padding: 0.75rem 0.5rem;
    }

    /* Hide # and Remarks columns on small mobile */
    .grade-table th:nth-child(1),
    .grade-table td:nth-child(1),
    .grade-table th:nth-child(5),
    .grade-table td:nth-child(5) {
        display: none;
    }

    .sheet-footer .signature-section {
        flex-direction: column;
        gap: 2rem;
        align-items: center;
    }
}

/* Print Styles */
@media print {
    @page {
        margin: 0;
        size: auto;
        /* auto is the initial value */
    }

    /* Hide Browser Defaults (Header/Footer with URL/Page Num) */
    html,
    body {
        height: auto !important;
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible;
    }

    body {
        margin: 1.6cm !important;
        /* Margin on paper only for body content */
        background-color: #fff;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Reset Layout for Print */
    .screen {
        opacity: 1 !important;
        display: block !important;
        width: 100%;
    }

    /* Hide UI Elements completely to avoid blank pages */
    #loginScreen,
    .app-header,
    /* Top Bar */
    .actions-bar,
    /* Bottom Buttons */
    .print-btn,
    /* Any inline print buttons */
    #logoutBtn,
    .loading-overlay {
        display: none !important;
        height: 0;
        width: 0;
        overflow: hidden;
    }

    /* Ensure Grade Sheet takes full width */
    .container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .grade-sheet {
        box-shadow: none;
        border: none;
        margin: 0;
        padding: 0;
        width: 100%;
        border-top: 0;
        /* Remove colored top border if desired, or keep it */
        page-break-inside: avoid;
    }

    /* Ensure specific colors print */
    .grade-table,
    .sheet-header,
    .student-details-grid,
    .sheet-footer {
        page-break-inside: avoid;
    }

    .grade-table th {
        background-color: var(--col-primary-dark) !important;
        color: #fff !important;
    }

    .student-details-grid {
        background-color: #f9fafb !important;
    }

    .grade-table tbody tr:nth-child(even) {
        background-color: #fafafa !important;
    }
}