@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    /* Premium Dark Theme */
    --primary-gradient: linear-gradient(135deg, #a8c0ff 0%, #3f2b96 100%);
    /* Lighter purple/blue for contrast */
    --bg-gradient: linear-gradient(135deg, #1e2024 0%, #232526 100%);

    --primary-color: #8c7ae6;
    --secondary-color: #00cec9;
    --accent-color: #fab1a0;

    --success-color: #00b894;
    --danger-color: #ff7675;

    --dark-bg: #2d3436;
    --component-bg: #2d3436;
    --component-bg-hover: #353b48;

    --text-main: #dfe6e9;
    --text-muted: #b2bec3;

    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.5);

    --radius: 12px;
}

body {
    font-family: 'Cairo', sans-serif;
    background: #1e272e;
    /* Use uploaded background image with overlay */
    background-image: linear-gradient(rgba(30, 39, 46, 0.7), rgba(30, 39, 46, 0.8)), url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    margin: 0;
    padding: 0;
    direction: rtl;
    text-align: right;
    color: var(--text-main);
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: rgba(30, 39, 46, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

header .container {
    max-width: 1200px;
    margin: 0 auto;
    /* Flex properties are inline in HTML for simplicity,
       but we keep padding here */
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

header nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.3s;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 15px;
    border-radius: 20px;
}

header nav a:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

/* Auth & Search Box */
.auth-box {
    background: var(--component-bg);
    padding: 3rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 450px;
    margin: 4rem auto;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.auth-box h2 {
    color: var(--text-main);
    margin-bottom: 2rem;
    font-size: 1.8rem;
}

form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

input[type="text"],
input[type="password"],
input[type="file"],
select {
    padding: 15px;
    background: #3d464d;
    border: 2px solid #576574;
    border-radius: var(--radius);
    font-size: 1.1rem;
    color: #fff;
    outline: none;
    transition: border-color 0.3s;
    font-family: 'Cairo', sans-serif;
}

input::placeholder {
    color: #a4b0be;
}

input:focus {
    border-color: var(--primary-color);
    background: #4b545c;
}

button {
    background: linear-gradient(135deg, #6c5ce7 0%, #3f2b96 100%);
    color: #fff;
    padding: 15px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 700;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
    font-family: 'Cairo', sans-serif;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(108, 92, 231, 0.6);
    filter: brightness(1.2);
}

/* Stats Cards */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 25px;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--component-bg);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    text-align: center;
    transition: transform 0.3s;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-card:hover {
    transform: translateY(-5px);
    background: var(--component-bg-hover);
}

.stat-card h3 {
    margin: 0 0 15px;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.stat-card .number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--white);
    text-shadow: 0 2px 10px rgba(140, 122, 230, 0.5);
}

/* Result Card */
.result-card {
    background: var(--component-bg);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    margin-top: 3rem;
    animation: fadeIn 0.5s ease-out;
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.result-card h2,
.result-card h3,
.result-card p {
    color: var(--text-main);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.student-info {
    border-bottom: 2px dashed #636e72;
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: var(--radius);
}

.student-info div {
    font-size: 1.1rem;
    margin: 5px 0;
}

.student-info strong {
    color: var(--secondary-color);
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #353b48;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 1rem;
}

th,
td {
    padding: 16px 20px;
    border-bottom: 1px solid #2f3640;
    text-align: center;
    color: var(--text-main);
}

th {
    background: #2f3542;
    color: var(--secondary-color);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #3d464d;
}

.grade-pass {
    color: #55efc4;
    font-weight: 800;
    background: rgba(0, 184, 148, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
}

.grade-fail {
    color: #ff7675;
    font-weight: 800;
    background: rgba(214, 48, 49, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
}

code {
    background: #2f3640 !important;
    color: #dfe6e9 !important;
    border: 1px solid #576574;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4rem;
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.2rem;
    }

    header nav a {
        padding: 5px 10px;
        font-size: 0.9rem;
    }

    .auth-box {
        margin: 2rem auto;
        padding: 2rem;
    }

    .result-card {
        padding: 1.5rem;
    }

    /* Responsive Table */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    th,
    td {
        padding: 12px 10px;
        font-size: 0.9rem;
    }

    .dashboard-stats {
        grid-template-columns: 1fr;
    }
}

/* Print Styles */
@media print {
    body {
        background: none;
        color: black;
    }

    header,
    footer,
    .auth-box,
    button:not([onclick]) {
        display: none;
    }

    .result-card,
    table,
    th,
    td {
        background: white !important;
        color: black !important;
        box-shadow: none;
        border: 1px solid #ddd;
    }

    .student-info {
        background: none;
        color: black;
        border: none;
        border-bottom: 1px solid #000;
        margin-bottom: 10px;
    }

    .grade-pass,
    .grade-fail {
        background: none;
        border: 1px solid #000;
        color: black;
    }

    /* Ensure table fits on paper */
    table {
        width: 100%;
        overflow: visible;
        display: table;
    }
}

/* Certificate Design (Themed) */
.certificate-container {
    background: var(--component-bg);
    color: var(--text-main);
    padding: 3rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 3px solid var(--primary-color);
    position: relative;
    max-width: 900px;
    margin: 2rem auto;
    overflow: hidden;
}

.certificate-container::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 2px dashed var(--secondary-color);
    pointer-events: none;
    border-radius: 8px;
}

.cert-header {
    text-align: center;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 20px;
    margin-bottom: 30px;
}

.cert-header h2 {
    color: var(--text-main);
    font-size: 2rem;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.cert-header h3 {
    color: var(--secondary-color);
    font-size: 1.2rem;
    margin: 5px 0 0;
}

.cert-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 8px;
    border-right: 5px solid var(--secondary-color);
    border-left: none;
    /* Switch side for RTL */
}

.cert-info-item {
    display: flex;
    flex-direction: column;
}

.cert-info-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: bold;
}

.cert-info-value {
    font-size: 1.2rem;
    color: var(--white);
    font-weight: 700;
}

/* Certificate Table */
.cert-table {
    width: 100%;
    margin-bottom: 30px;
    border-collapse: collapse;
    background: rgba(0, 0, 0, 0.2);
}

.cert-table th {
    background: rgba(0, 0, 0, 0.3);
    color: var(--secondary-color);
    padding: 15px;
    text-align: center;
    font-size: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.cert-table td {
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
    font-weight: 600;
    color: var(--text-main);
}

.cert-table tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Summary Section */
.cert-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.summary-item {
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--secondary-color);
}

/* Print Enhancements */
@media print {
    @page {
        size: A4;
        margin: 0;
        /* Remove default page margins */
    }

    body {
        margin: 0;
        padding: 0;
        background: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        /* Ensure top-alignment */
        min-height: 100vh;
    }

    .container,
    .result-card {
        width: 100%;
        max-width: none;
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    /* Hide everything except print area */
    body>*:not(.container),
    .container>*:not(#print-area) {
        display: none !important;
    }

    /* Force show print area */
    #print-area {
        display: block !important;
        position: relative;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0 auto;
        padding: 20px;
        /* Reduced padding */
        border: 2px solid var(--primary-color) !important;
        page-break-inside: avoid;
        /* Scale down to ensure fit */
        transform: scale(0.95);
        transform-origin: top center;
    }

    /* Make text slightly smaller for print */
    .cert-table th,
    .cert-table td {
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    .cert-info-item {
        margin-bottom: 5px;
    }

    .certificate-container {
        box-shadow: none;
        border: 5px double var(--primary-color) !important;
        /* Use Primary Color */
        background: white;
        /* Keep white bg for paper */
        color: #2d3436;
        /* Dark text for readability */
        margin: 0;
        width: 100%;
        max-width: 100%;
        padding: 20px;
        box-sizing: border-box;
    }

    .certificate-container::before {
        display: none;
    }

    .cert-header {
        border-bottom: 2px solid var(--secondary-color) !important;
        margin-bottom: 20px;
        padding-bottom: 10px;
    }

    .cert-header h2 {
        color: var(--primary-color) !important;
        /* Colored Title */
        text-shadow: none;
        font-size: 24pt;
        margin-bottom: 10px;
    }

    .cert-header h3 {
        color: var(--secondary-color) !important;
        /* Colored School Name */
        font-size: 18pt;
    }

    .cert-info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        background: none !important;
        border: 1px solid #ddd;
        border-right: 5px solid var(--secondary-color) !important;
        /* Colored Accent */
        page-break-inside: avoid;
    }

    .cert-info-item {
        break-inside: avoid;
    }

    .cert-info-label {
        color: #636e72;
        font-size: 10pt;
    }

    .cert-info-value {
        color: #2d3436;
        font-size: 12pt;
    }

    .cert-table {
        background: none !important;
        page-break-inside: auto;
    }

    .cert-table th {
        background: #f1f2f6 !important;
        color: var(--primary-color) !important;
        /* Colored Headers */
        border: 1px solid #ddd;
        font-size: 11pt;
    }

    .cert-table td {
        border: 1px solid #ddd;
        color: #2d3436;
        font-size: 11pt;
    }

    /* Colored Badges */
    .grade-pass {
        color: #00b894 !important;
        border: 1px solid #00b894 !important;
        background: rgba(0, 184, 148, 0.1) !important;
    }

    .grade-fail {
        color: #d63031 !important;
        border: 1px solid #d63031 !important;
        background: rgba(214, 48, 49, 0.1) !important;
    }

    .cert-summary {
        background: #f8f9fa !important;
        color: #2d3436 !important;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    .summary-label {
        color: #636e72;
    }

    .summary-value {
        color: var(--primary-color) !important;
        font-size: 14pt;
    }
}