:root {
    --ink: #12261f;
    --deep: #0e3b2e;
    --deep-2: #154a3a;
    --emerald: #1f6f52;
    --emerald-l: #e9f3ee;
    --gold: #b3862c;
    --gold-l: #f4e8cc;
    --paper: #faf8f2;
    --paper-2: #f2efe4;
    --card: #ffffff;
    --line: #e2ddca;
    --danger: #a4342a;
    --danger-l: #fbeae8;
    --muted: #6c7a72;
    --shadow: 0 8px 24px rgba(15,40,30,.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'Tajawal', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

h1,
h2,
h3,
.display {
    font-family: 'Amiri', serif;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input,
select,
textarea {
    font-family: inherit;
}

a {
    text-decoration: none;
}


/* =========================================================
   LOGIN
   ========================================================= */

.login-body-bg {
    background: radial-gradient(circle at 15% 20%, rgba(179,134,44,.14), transparent 40%), radial-gradient(circle at 85% 80%, rgba(31,111,82,.16), transparent 45%), var(--deep);
}

#loginScreen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--paper);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    overflow: hidden;
}

.login-top {
    background: linear-gradient( 160deg, var(--deep) 0%, var(--deep-2) 60%, var(--emerald) 130% );
    color: #fff8e8;
    padding: 34px 28px 26px;
    text-align: center;
}

    .login-top .badge {
        width: 64px;
        height: 64px;
        margin: 0 auto 12px;
        border: 2px solid var(--gold);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Amiri', serif;
        font-size: 30px;
        color: var(--gold-l);
        background: rgba(255,255,255,.05);
    }

    .login-top .login-logo {
        width: 64px;
        height: 64px;
        margin: 0 auto 12px;
        border: 2px solid var(--gold);
        border-radius: 50%;
        object-fit: cover;
        background: #fff;
        display: block;
    }

    .login-top h1 {
        margin: 0 0 4px;
        font-size: 24px;
        font-weight: 700;
    }

    .login-top p {
        margin: 0;
        font-size: 13px;
        color: #cfe3d9;
        letter-spacing: .5px;
    }

.login-body {
    padding: 26px 28px 30px;
}

.field {
    margin-bottom: 16px;
}

    .field label {
        display: block;
        font-size: 13px;
        color: var(--muted);
        margin-bottom: 6px;
        font-weight: 700;
    }

    .field input,
    .field select,
    .field textarea {
        width: 100%;
        padding: 11px 13px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fff;
        font-size: 15px;
        color: var(--ink);
        outline: none;
        transition: border-color .15s, box-shadow .15s;
    }

        .field input:focus,
        .field select:focus,
        .field textarea:focus {
            border-color: var(--emerald);
            box-shadow: 0 0 0 3px var(--emerald-l);
        }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    font-size: 14.5px;
    transition: transform .12s ease, box-shadow .12s ease, background .15s;
}

    .btn:active {
        transform: translateY(1px);
    }

.btn-primary {
    background: linear-gradient(160deg, var(--emerald), var(--deep-2));
    color: #fff;
    box-shadow: 0 6px 16px rgba(15,59,46,.28);
}

    .btn-primary:hover {
        box-shadow: 0 8px 20px rgba(15,59,46,.38);
    }

.btn-gold {
    background: linear-gradient(160deg, var(--gold), #8f6a1f);
    color: #fff8e8;
}

.btn-ghost {
    background: transparent;
    color: var(--deep);
    border: 1px solid var(--line);
}

    .btn-ghost:hover {
        background: var(--paper-2);
    }

.btn-danger {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-block {
    width: 100%;
}

.login-err {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 14px;
}

.login-hint {
    margin-top: 14px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
}


/* =========================================================
   APP SHELL
   ========================================================= */

#app-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
}

.sidebar {
    background: linear-gradient( 180deg, var(--deep) 0%, var(--deep-2) 100% );
    color: #eaf3ee;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 20px;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 16px;
}

    .brand .mark {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        border: 1.5px solid var(--gold);
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Amiri', serif;
        font-size: 18px;
        color: var(--gold-l);
        flex: none;
    }

    .brand .brand-logo {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        border: 1.5px solid var(--gold);
        object-fit: cover;
        background: #fff;
        flex: none;
    }

    .brand .txt {
        line-height: 1.35;
    }

        .brand .txt .name {
            font-weight: 700;
            font-size: 14.5px;
            color: #fff;
        }

        .brand .txt .yr {
            font-size: 11.5px;
            color: #a9c7ba;
        }

.navgroup {
    margin-bottom: 6px;
}

.navlabel {
    font-size: 11px;
    color: #8fb0a1;
    letter-spacing: 1px;
    margin: 16px 10px 6px;
    text-transform: uppercase;
}

.navbtn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: #dcece3;
    font-size: 14.5px;
    font-weight: 500;
    text-align: right;
    margin-bottom: 3px;
}

    .navbtn .ic {
        width: 20px;
        text-align: center;
        font-size: 15px;
        flex: none;
    }

    .navbtn:hover {
        background: rgba(255,255,255,.06);
    }

    .navbtn.active {
        background: rgba(179,134,44,.22);
        color: #fff;
        font-weight: 700;
        box-shadow: inset 3px 0 0 var(--gold);
    }

.side-foot {
    margin-top: 22px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.12);
}

    .side-foot .who {
        font-size: 12px;
        color: #a9c7ba;
        margin-bottom: 10px;
        line-height: 1.7;
    }

        .side-foot .who b {
            color: #fff;
            display: block;
            font-size: 13px;
        }

.main {
    padding: 26px 30px 60px;
    max-width: 1400px;
    width: 100%;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

    .topbar h2 {
        margin: 0;
        font-size: 22px;
        color: var(--deep);
    }

    .topbar .sub {
        font-size: 13px;
        color: var(--muted);
        margin-top: 3px;
    }

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}


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

.mobile-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    background: var(--deep);
    color: #fff;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 30;
}

    .mobile-topbar .hamburger {
        background: transparent;
        border: none;
        color: #fff;
        font-size: 22px;
        padding: 4px 10px;
        border-radius: 8px;
        line-height: 1;
    }

        .mobile-topbar .hamburger:hover {
            background: rgba(255,255,255,.12);
        }

    .mobile-topbar .mobile-topbar-title {
        font-weight: 700;
        font-size: 15px;
    }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10,20,16,.5);
    z-index: 35;
}

    .sidebar-overlay.show {
        display: block;
    }


/* =========================================================
   CARDS
   ========================================================= */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

    .card h3 {
        margin: 0 0 14px;
        font-size: 17px;
        color: var(--deep);
    }

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.grid3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
}


/* =========================================================
   STATS
   ========================================================= */

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
}

    .stat .num {
        font-family: 'Amiri', serif;
        font-size: 32px;
        color: var(--deep);
        font-weight: 700;
    }

    .stat .lbl {
        font-size: 13px;
        color: var(--muted);
        margin-top: 2px;
    }

    .stat .ic {
        position: absolute;
        left: 14px;
        top: 14px;
        font-size: 26px;
        opacity: .18;
    }


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

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}

table.grid {
    border-collapse: collapse;
    width: 100%;
    min-width: 1400px;
    font-size: 13px;
}

    table.grid th,
    table.grid td {
        border: 1px solid var(--line);
        padding: 7px 8px;
        text-align: center;
        white-space: nowrap;
    }

    table.grid thead th {
        background: var(--deep);
        color: #fff;
        position: sticky;
        top: 0;
        z-index: 2;
        font-weight: 700;
        font-size: 12.5px;
    }

    table.grid thead tr.grp th {
        background: var(--deep-2);
        font-size: 12px;
    }

    table.grid tbody tr:nth-child(even) {
        background: #faf9f3;
    }

    table.grid tbody tr:hover {
        background: var(--emerald-l);
    }

    table.grid td.name-cell {
        text-align: right;
        font-weight: 700;
        min-width: 160px;
        position: sticky;
        right: 0;
        background: inherit;
    }

    table.grid thead th.name-cell {
        position: sticky;
        right: 0;
        z-index: 3;
    }

    table.grid input.cellnum {
        width: 52px;
        padding: 4px;
        border: 1px solid transparent;
        border-radius: 6px;
        text-align: center;
        background: transparent;
        font-size: 13px;
    }

        table.grid input.cellnum:hover {
            border-color: var(--line);
        }

        table.grid input.cellnum:focus {
            border-color: var(--emerald);
            background: #fff;
            outline: none;
            box-shadow: 0 0 0 2px var(--emerald-l);
        }

    table.grid td.calc {
        background: var(--gold-l);
        font-weight: 700;
        color: #6b4e14;
    }

    table.grid td.fail {
        background: var(--danger-l);
        color: var(--danger);
        font-weight: 700;
    }

    table.grid td.pass {
        color: var(--emerald);
        font-weight: 700;
    }

.rowActions {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.iconbtn {
    border: none;
    background: transparent;
    border-radius: 7px;
    padding: 5px 7px;
    font-size: 14px;
    color: var(--muted);
}

    .iconbtn:hover {
        background: var(--paper-2);
        color: var(--ink);
    }

    .iconbtn.del:hover {
        background: var(--danger-l);
        color: var(--danger);
    }


/* =========================================================
   SEARCH
   ========================================================= */

.searchbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

    .searchbar input,
    .searchbar select {
        padding: 9px 11px;
        border: 1px solid var(--line);
        border-radius: 9px;
        font-size: 13.5px;
        min-width: 140px;
    }

        .searchbar input:focus,
        .searchbar select:focus {
            outline: none;
            border-color: var(--emerald);
        }

.pill {
    background: var(--emerald-l);
    color: var(--deep);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
}


/* =========================================================
   EMPTY / FLASH
   ========================================================= */

.empty {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
}

    .empty .ic {
        font-size: 40px;
        margin-bottom: 10px;
        opacity: .5;
    }

.flash {
    border-radius: 10px;
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 13.5px;
    font-weight: 700;
}

.flash-ok {
    background: var(--emerald-l);
    color: var(--deep);
    border: 1px solid #cfe4d9;
}

.flash-err {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
}


/* =========================================================
   FORM
   ========================================================= */

fieldset {
    border: 1px dashed var(--line);
    border-radius: 10px;
    margin: 0 0 16px;
    padding: 14px;
}

    fieldset legend {
        padding: 0 8px;
        font-weight: 700;
        color: var(--deep);
        font-size: 13.5px;
    }


/* =========================================================
   SEARCHABLE DROPDOWN
   ========================================================= */

.search-results {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 230px;
    overflow-y: auto;
    z-index: 20;
    display: none;
}

    .search-results.show {
        display: block;
    }

    .search-results .item {
        padding: 9px 12px;
        cursor: pointer;
        font-size: 14px;
        border-bottom: 1px solid var(--paper-2);
    }

        .search-results .item:last-child {
            border-bottom: none;
        }

        .search-results .item:hover,
        .search-results .item.active {
            background: var(--emerald-l);
        }

    .search-results .empty-msg {
        padding: 10px 12px;
        color: var(--muted);
        font-size: 13px;
    }


/* =========================================================
   SWITCH
   ========================================================= */

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
}

    .switch input {
        width: 18px;
        height: 18px;
        accent-color: var(--emerald);
    }


/* =========================================================
   CERTIFICATE
   ========================================================= */

.print-plain-bg {
    background: var(--paper);
}

.certificate {
    background: #fffdf6;
    border: 10px double var(--gold);
    border-radius: 10px;
    padding: 34px 30px;
    max-width: 640px;
    margin: 0 auto;
    position: relative;
    text-align: center;
}

    .certificate::before {
        content: "";
        position: absolute;
        inset: 8px;
        border: 1.5px solid var(--emerald);
        border-radius: 6px;
        pointer-events: none;
    }

    .certificate .cert-school {
        font-size: 14px;
        color: var(--muted);
        letter-spacing: .5px;
    }

    .certificate .cert-title {
        font-family: 'Amiri', serif;
        font-size: 30px;
        color: var(--deep);
        margin: 8px 0 2px;
        font-weight: 700;
    }

    .certificate .cert-sub {
        font-size: 13px;
        color: var(--gold);
        font-weight: 700;
        margin-bottom: 18px;
    }

    .certificate .cert-name {
        font-family: 'Amiri', serif;
        font-size: 24px;
        color: var(--ink);
        margin: 14px 0;
        padding-bottom: 8px;
        border-bottom: 2px solid var(--gold-l);
        display: inline-block;
        min-width: 260px;
    }

    .certificate table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 18px;
        font-size: 13.5px;
    }

        .certificate table th,
        .certificate table td {
            border: 1px solid var(--line);
            padding: 9px;
            text-align: center;
        }

        .certificate table th {
            background: var(--emerald-l);
            color: var(--deep);
        }

    .certificate .cert-total {
        margin-top: 16px;
        font-size: 16px;
        font-weight: 700;
        color: var(--deep);
    }

    .certificate .cert-sign {
        display: flex;
        justify-content: space-between;
        margin-top: 34px;
        font-size: 12.5px;
        color: var(--muted);
    }

        .certificate .cert-sign div {
            text-align: center;
        }

        .certificate .cert-sign b {
            display: inline !important;
            color: var(--ink);
            margin-top: 22px;
            border-top: 1px solid var(--line);
            padding-top: 6px;
            min-width: 120px;
        }

    .certificate .print-logo-corner {
        top: 14px;
        left: 14px;
        max-height: 60px;
        max-width: 110px;
    }


/* =========================================================
   HINT / TAG
   ========================================================= */

.hintbox {
    background: var(--emerald-l);
    border: 1px solid #cfe4d9;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12.8px;
    color: #2c5744;
    line-height: 1.9;
}

.tag {
    display: inline-block;
    background: var(--gold-l);
    color: #6b4e14;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11.5px;
    margin: 2px;
}

.msg-inline {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}


/* =========================================================
   PLAIN PRINT PAGES
   لا نعدل تنسيق الطباعة المجمعة
   ========================================================= */

.p-head {
    position: relative;
    text-align: center;
    margin-bottom: 14px;
}

    .p-head h2 {
        margin: 0;
        color: #000;
    }

    .p-head .meta {
        font-size: 12px;
        color: #333;
        margin-top: 4px;
    }

.print-plain-bg table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

    .print-plain-bg table th,
    .print-plain-bg table td {
        border: 1px solid #999;
        padding: 4px;
        text-align: center;
    }

.p-foot {
    display: flex;
    justify-content: space-between;
    margin-top: 26px;
    font-size: 11.5px;
}


/* =========================================================
   LOGO
   ========================================================= */

.print-logo-corner {
    position: absolute;
    top: 0;
    left: 0;
    max-height: 72px;
    max-width: 130px;
    object-fit: contain;
}


/* =========================================================
   CERTIFICATE SCREEN
   الشهادة الفردية فقط - A4 أفقي
   ========================================================= */

@media screen {

    body.print-plain-bg .certificate.certificate-landscape {
        width: 297mm !important;
        min-width: 297mm !important;
        max-width: 297mm !important;
        height: 210mm !important;
        min-height: 210mm !important;
        max-height: 210mm !important;
        margin: 20px auto !important;
        padding: 9mm 12mm 10mm 12mm !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        position: relative !important;
        transform: none !important;
        writing-mode: horizontal-tb !important;
        direction: rtl !important;
        background: #fffdf6 !important;
        border: 3px double var(--gold) !important;
        border-radius: 0 !important;
        box-shadow: 0 8px 30px rgba(0,0,0,.20);
    }

        body.print-plain-bg .certificate.certificate-landscape table {
            width: 100% !important;
            max-width: 100% !important;
        }
}


/* =========================================================
   PRINT - INDIVIDUAL CERTIFICATE
   A4 LANDSCAPE FULL PAGE
   ========================================================= */

@media print {

    /* =====================================================
       A4 أفقي
       ===================================================== */

    @page {
        size: A4 landscape;
        margin: 0 !important;
    }


    /* =====================================================
       إخفاء أدوات الشاشة
       ===================================================== */

    .no-print,
    .toolbar,
    nav,
    header,
    footer,
    .topbar,
    .mobile-topbar,
    .sidebar,
    .sidebar-overlay,
    .certificate-print-options,
    .hintbox,
    .searchbar,
    .flash,
    .empty {
        display: none !important;
    }


    /* =====================================================
       الصفحة
       ===================================================== */

    html,
    body {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: #fff !important;
        zoom: 1 !important;
        transform: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }


    /* =====================================================
       APP SHELL
       ===================================================== */

    #app-shell {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

        #app-shell > * {
            width: 100% !important;
            min-width: 0 !important;
            max-width: none !important;
            margin: 0 !important;
            padding: 0 !important;
        }


    /* =====================================================
       MAIN
       ===================================================== */

    .main {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

        .main > * {
            width: 100% !important;
            min-width: 0 !important;
            max-width: none !important;
            margin: 0 !important;
            padding: 0 !important;
        }


    /* =====================================================
       CARD
       ===================================================== */

    .card {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }


    /* =====================================================
       CERTIFICATE WRAPPER
       ===================================================== */

    .cert-wrap {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100vh !important;
        min-height: 0 !important;
        max-height: 100vh !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }


    /* =====================================================
       الشهادة الفردية فقط
       ===================================================== */

    body.print-plain-bg .certificate.certificate-landscape {
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
        width: 297mm !important;
        min-width: 297mm !important;
        max-width: 297mm !important;
        height: 210mm !important;
        min-height: 210mm !important;
        max-height: 210mm !important;
        margin: 0 !important;
        padding: 9mm 12mm 10mm 12mm !important;
        box-sizing: border-box !important;
        background: #fffdf6 !important;
        border: 3px double #b3862c !important;
        border-radius: 0 !important;
        overflow: hidden !important;
        text-align: center !important;
        direction: rtl !important;
        writing-mode: horizontal-tb !important;
        page-break-after: always !important;
        break-after: page !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }


        /* =====================================================
       الإطار الداخلي
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape::before {
            content: "" !important;
            position: absolute !important;
            top: 5mm !important;
            right: 5mm !important;
            bottom: 5mm !important;
            left: 5mm !important;
            border: 1px solid var(--emerald) !important;
            border-radius: 0 !important;
            pointer-events: none !important;
            z-index: 1 !important;
        }

        body.print-plain-bg .certificate.certificate-landscape > * {
            position: relative !important;
            z-index: 2 !important;
        }


        /* =====================================================
       الشعار
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .print-logo-corner {
            position: relative !important;
            top: auto !important;
            left: auto !important;
            right: auto !important;
            width: 30mm !important;
            height: 30mm !important;
            max-width: 30mm !important;
            max-height: 30mm !important;
            object-fit: contain !important;
            display: block !important;
            margin: 0 auto 2mm auto !important;
            flex: none !important;
        }


        /* =====================================================
       اسم المدرسة
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-school {
            font-family: 'Amiri', serif !important;
            font-size: 31px !important;
            font-weight: 700 !important;
            color: var(--deep) !important;
            line-height: 1.2 !important;
            margin: 0 0 2mm 0 !important;
        }


        /* =====================================================
       عنوان الشهادة
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-title {
            font-family: 'Amiri', serif !important;
            font-size: 42px !important;
            font-weight: 700 !important;
            color: var(--deep) !important;
            line-height: 1.15 !important;
            margin: 1mm 0 2mm !important;
        }


        /* =====================================================
       العام
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-sub {
            font-size: 17px !important;
            font-weight: 700 !important;
            color: var(--gold) !important;
            margin: 1mm 0 5mm !important;
        }


        /* =====================================================
       اسم الطالب
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-name {
            display: inline-block !important;
            min-width: 140mm !important;
            max-width: 220mm !important;
            padding: 3mm 12mm !important;
            margin: 0 0 4mm !important;
            font-family: 'Amiri', serif !important;
            font-size: 36px !important;
            font-weight: 700 !important;
            color: var(--ink) !important;
            line-height: 1.2 !important;
            border-bottom: 3px solid var(--gold) !important;
        }


        /* =====================================================
       بيانات الطالب
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .msg-inline {
            width: 100% !important;
            font-size: 17px !important;
            font-weight: 600 !important;
            color: var(--muted) !important;
            line-height: 1.6 !important;
            margin: 1mm 0 6mm !important;
            white-space: nowrap !important;
        }


        /* =====================================================
       جدول الدرجات
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape table {
            width: 100% !important;
            max-width: 100% !important;
            margin: 2mm auto 0 !important;
            border-collapse: collapse !important;
            table-layout: fixed !important;
            font-size: 17px !important;
            page-break-inside: avoid !important;
            break-inside: avoid !important;
        }

            body.print-plain-bg .certificate.certificate-landscape table th,
            body.print-plain-bg .certificate.certificate-landscape table td {
                border: 2px solid #555 !important;
                padding: 3mm 2mm !important;
                height: 15mm !important;
                text-align: center !important;
                vertical-align: middle !important;
                line-height: 1.3 !important;
                word-wrap: break-word !important;
                overflow-wrap: break-word !important;
            }

            body.print-plain-bg .certificate.certificate-landscape table th {
                background: var(--emerald-l) !important;
                color: var(--deep) !important;
                font-size: 17px !important;
                font-weight: 700 !important;
            }

            body.print-plain-bg .certificate.certificate-landscape table td {
                font-size: 17px !important;
                font-weight: 600 !important;
            }


        /* =====================================================
       TOTAL
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-total {
            display: inline-block !important;
            min-width: 85mm !important;
            padding: 3mm 12mm !important;
            margin-top: 4mm !important;
            border: 3px solid var(--gold) !important;
            border-radius: 4px !important;
            font-family: 'Amiri', serif !important;
            font-size: 28px !important;
            font-weight: 700 !important;
            color: var(--deep) !important;
            line-height: 1.2 !important;
            background: var(--gold-l) !important;
        }


        /* =====================================================
       ملاحظة الحساب
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .calc-note {
            font-size: 12px !important;
            margin-top: 3mm !important;
            color: var(--muted) !important;
            line-height: 1.4 !important;
        }


        /* =====================================================
       التوقيعات
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape .cert-sign {
            position: absolute !important;
            right: 12mm !important;
            left: 12mm !important;
            bottom: 7mm !important;
            width: auto !important;
            display: flex !important;
            justify-content: space-between !important;
            align-items: flex-end !important;
            gap: 15mm !important;
            margin: 0 !important;
            font-size: 16px !important;
            font-weight: 600 !important;
            color: var(--ink) !important;
            text-align: center !important;
        }

            body.print-plain-bg .certificate.certificate-landscape .cert-sign > div {
                flex: 1 !important;
                min-width: 0 !important;
                padding-top: 5mm !important;
                border-top: 2px solid #555 !important;
                line-height: 1.35 !important;
            }


        /* =====================================================
       منع تقسيم الشهادة
       ===================================================== */

        body.print-plain-bg .certificate.certificate-landscape,
        body.print-plain-bg .certificate.certificate-landscape table,
        body.print-plain-bg .certificate.certificate-landscape tr {
            page-break-inside: avoid !important;
            break-inside: avoid !important;
        }
}


/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 880px) {

    .mobile-topbar {
        display: flex;
    }

    #app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 270px;
        max-width: 82vw;
        transform: translateX(100%);
        transition: transform .25s ease;
        z-index: 40;
        box-shadow: -12px 0 30px rgba(0,0,0,.3);
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .main {
        padding: 16px 14px 40px;
    }

    .topbar {
        margin-bottom: 16px;
    }

    .card {
        padding: 16px;
    }
}


@media (max-width: 760px) {

    .grid2,
    .grid3 {
        grid-template-columns: 1fr;
    }
}


@media (max-width: 480px) {

    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .topbar h2 {
        font-size: 19px;
    }
}


/* =========================================================
   SCROLLBAR
   ========================================================= */

::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cfc9ae;
    border-radius: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}
/* =========================================================
   FIX - شهادة فردية فقط
   ========================================================= */

/* المعاينة على الشاشة */
body.print-plain-bg {
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden !important;
}

    body.print-plain-bg .certificate-individual-print {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        transform: none !important;
        position: relative !important;
        left: auto !important;
        right: auto !important;
        overflow: hidden !important;
    }


/* =========================================================
   الطباعة الفعلية
   ========================================================= */

/*@media print {

    @page {
        size: A4 landscape;
        margin: 0 !important;
    }

    html,
    body {
        width: 297mm !important;
        height: 210mm !important;
        min-width: 297mm !important;
        min-height: 210mm !important;
        max-width: 297mm !important;
        max-height: 210mm !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

        body.print-plain-bg {
            width: 297mm !important;
            height: 210mm !important;
            margin: 0 !important;
            padding: 0 !important;
            overflow: hidden !important;
        }

            body.print-plain-bg .certificate-individual-print {*/
                /* الحجم الحقيقي للورقة */
                /*width: 297mm !important;
                height: 210mm !important;
                min-width: 297mm !important;
                min-height: 210mm !important;
                max-width: 297mm !important;
                max-height: 210mm !important;*/
                /* أهم جزء */
                /*margin: 0 !important;
                position: relative !important;
                left: 0 !important;
                right: auto !important;
                top: 0 !important;
                transform: none !important;
                box-sizing: border-box !important;
                overflow: hidden !important;
                page-break-after: always !important;
                break-after: page !important;
                page-break-inside: avoid !important;
                break-inside: avoid !important;
            }*/

                /* إلغاء أي تحديد عرض سابق */
                /*body.print-plain-bg .certificate-individual-print table {
                    width: 100% !important;
                    max-width: 100% !important;
                }*/

                /* إلغاء أي عنصر يسبب خروج الشهادة */
                /*body.print-plain-bg .certificate-individual-print * {
                    max-width: 100% !important;
                    box-sizing: border-box !important;
                }

    .no-print,
    .toolbar {
        display: none !important;
    }
}*/

:root {
    --ink: #12261f;
    --deep: #0e3b2e;
    --deep-2: #154a3a;
    --emerald: #1f6f52;
    --emerald-l: #e9f3ee;
    --gold: #b3862c;
    --gold-l: #f4e8cc;
    --paper: #faf8f2;
    --paper-2: #f2efe4;
    --card: #ffffff;
    --line: #e2ddca;
    --danger: #a4342a;
    --danger-l: #fbeae8;
    --muted: #6c7a72;
    --shadow: 0 8px 24px rgba(15,40,30,.08);
}


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

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'Tajawal',sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

h1,
h2,
h3,
.display {
    font-family: 'Amiri',serif;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    cursor: pointer;
}

a {
    text-decoration: none;
}


/* =========================================================
   LOGIN
   ========================================================= */

.login-body-bg {
    background: radial-gradient( circle at 15% 20%, rgba(179,134,44,.14), transparent 40% ), radial-gradient( circle at 85% 80%, rgba(31,111,82,.16), transparent 45% ), var(--deep);
}

#loginScreen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--paper);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    overflow: hidden;
}

.login-top {
    background: linear-gradient( 160deg, var(--deep) 0%, var(--deep-2) 60%, var(--emerald) 130% );
    color: #fff8e8;
    padding: 34px 28px 26px;
    text-align: center;
}

    .login-top .badge {
        width: 64px;
        height: 64px;
        margin: 0 auto 12px;
        border: 2px solid var(--gold);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Amiri',serif;
        font-size: 30px;
        color: var(--gold-l);
        background: rgba(255,255,255,.05);
    }

    .login-top .login-logo {
        width: 64px;
        height: 64px;
        margin: 0 auto 12px;
        border: 2px solid var(--gold);
        border-radius: 50%;
        object-fit: cover;
        background: #fff;
        display: block;
    }

    .login-top h1 {
        margin: 0 0 4px;
        font-size: 24px;
        font-weight: 700;
    }

    .login-top p {
        margin: 0;
        font-size: 13px;
        color: #cfe3d9;
        letter-spacing: .5px;
    }

.login-body {
    padding: 26px 28px 30px;
}

.field {
    margin-bottom: 16px;
}

    .field label {
        display: block;
        font-size: 13px;
        color: var(--muted);
        margin-bottom: 6px;
        font-weight: 700;
    }

    .field input,
    .field select,
    .field textarea {
        width: 100%;
        padding: 11px 13px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fff;
        font-size: 15px;
        color: var(--ink);
        outline: none;
        transition: border-color .15s,box-shadow .15s;
    }

        .field input:focus,
        .field select:focus,
        .field textarea:focus {
            border-color: var(--emerald);
            box-shadow: 0 0 0 3px var(--emerald-l);
        }


/* =========================================================
   BUTTONS
   ========================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
    font-size: 14.5px;
    transition: transform .12s ease, box-shadow .12s ease, background .15s;
}

    .btn:active {
        transform: translateY(1px);
    }

.btn-primary {
    background: linear-gradient( 160deg, var(--emerald), var(--deep-2) );
    color: #fff;
    box-shadow: 0 6px 16px rgba(15,59,46,.28);
}

    .btn-primary:hover {
        box-shadow: 0 8px 20px rgba(15,59,46,.38);
    }

.btn-gold {
    background: linear-gradient( 160deg, var(--gold), #8f6a1f );
    color: #fff8e8;
}

.btn-ghost {
    background: transparent;
    color: var(--deep);
    border: 1px solid var(--line);
}

    .btn-ghost:hover {
        background: var(--paper-2);
    }

.btn-danger {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-block {
    width: 100%;
}


/* =========================================================
   LOGIN MESSAGES
   ========================================================= */

.login-err {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 14px;
}

.login-hint {
    margin-top: 14px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
}


/* =========================================================
   APP SHELL
   ========================================================= */

#app-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
}

.sidebar {
    background: linear-gradient( 180deg, var(--deep) 0%, var(--deep-2) 100% );
    color: #eaf3ee;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 20px;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 16px;
}

    .brand .mark {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        border: 1.5px solid var(--gold);
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Amiri',serif;
        font-size: 18px;
        color: var(--gold-l);
        flex: none;
    }

    .brand .brand-logo {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        border: 1.5px solid var(--gold);
        object-fit: cover;
        background: #fff;
        flex: none;
    }

    .brand .txt {
        line-height: 1.35;
    }

        .brand .txt .name {
            font-weight: 700;
            font-size: 14.5px;
            color: #fff;
        }

        .brand .txt .yr {
            font-size: 11.5px;
            color: #a9c7ba;
        }

.navgroup {
    margin-bottom: 6px;
}

.navlabel {
    font-size: 11px;
    color: #8fb0a1;
    letter-spacing: 1px;
    margin: 16px 10px 6px;
    text-transform: uppercase;
}

.navbtn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: #dcece3;
    font-size: 14.5px;
    font-weight: 500;
    text-align: right;
    margin-bottom: 3px;
}

    .navbtn .ic {
        width: 20px;
        text-align: center;
        font-size: 15px;
        flex: none;
    }

    .navbtn:hover {
        background: rgba(255,255,255,.06);
    }

    .navbtn.active {
        background: rgba(179,134,44,.22);
        color: #fff;
        font-weight: 700;
        box-shadow: inset 3px 0 0 var(--gold);
    }

.side-foot {
    margin-top: 22px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.12);
}

    .side-foot .who {
        font-size: 12px;
        color: #a9c7ba;
        margin-bottom: 10px;
        line-height: 1.7;
    }

        .side-foot .who b {
            color: #fff;
            display: block;
            font-size: 13px;
        }


/* =========================================================
   MAIN
   ========================================================= */

.main {
    padding: 26px 30px 60px;
    max-width: 1400px;
    width: 100%;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

    .topbar h2 {
        margin: 0;
        font-size: 22px;
        color: var(--deep);
    }

    .topbar .sub {
        font-size: 13px;
        color: var(--muted);
        margin-top: 3px;
    }

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}


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

.mobile-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    background: var(--deep);
    color: #fff;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 30;
}

    .mobile-topbar .hamburger {
        background: transparent;
        border: none;
        color: #fff;
        font-size: 22px;
        padding: 4px 10px;
        border-radius: 8px;
        line-height: 1;
    }

        .mobile-topbar .hamburger:hover {
            background: rgba(255,255,255,.12);
        }

    .mobile-topbar .mobile-topbar-title {
        font-weight: 700;
        font-size: 15px;
    }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10,20,16,.5);
    z-index: 35;
}

    .sidebar-overlay.show {
        display: block;
    }


/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width:880px) {

    .mobile-topbar {
        display: flex;
    }

    #app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 270px;
        max-width: 82vw;
        transform: translateX(100%);
        transition: transform .25s ease;
        z-index: 40;
        box-shadow: -12px 0 30px rgba(0,0,0,.3);
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .main {
        padding: 16px 14px 40px;
    }

    .topbar {
        margin-bottom: 16px;
    }

    .card {
        padding: 16px;
    }
}

@media (max-width:760px) {

    .grid2,
    .grid3 {
        grid-template-columns: 1fr;
    }
}

@media (max-width:480px) {

    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .topbar h2 {
        font-size: 19px;
    }
}


/* =========================================================
   CARDS
   ========================================================= */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

    .card h3 {
        margin: 0 0 14px;
        font-size: 17px;
        color: var(--deep);
    }

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.grid3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
}


/* =========================================================
   STATS
   ========================================================= */

.stats {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 14px;
    margin-bottom: 20px;
}

@media (max-width:900px) {

    .stats {
        grid-template-columns: repeat(2,1fr);
    }
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
}

    .stat .num {
        font-family: 'Amiri',serif;
        font-size: 32px;
        color: var(--deep);
        font-weight: 700;
    }

    .stat .lbl {
        font-size: 13px;
        color: var(--muted);
        margin-top: 2px;
    }

    .stat .ic {
        position: absolute;
        left: 14px;
        top: 14px;
        font-size: 26px;
        opacity: .18;
    }


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

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}

table.grid {
    border-collapse: collapse;
    width: 100%;
    min-width: 1400px;
    font-size: 13px;
}

    table.grid th,
    table.grid td {
        border: 1px solid var(--line);
        padding: 7px 8px;
        text-align: center;
        white-space: nowrap;
    }

    table.grid thead th {
        background: var(--deep);
        color: #fff;
        position: sticky;
        top: 0;
        z-index: 2;
        font-weight: 700;
        font-size: 12.5px;
    }

    table.grid thead tr.grp th {
        background: var(--deep-2);
        font-size: 12px;
    }

    table.grid tbody tr:nth-child(even) {
        background: #faf9f3;
    }

    table.grid tbody tr:hover {
        background: var(--emerald-l);
    }

    table.grid td.name-cell {
        text-align: right;
        font-weight: 700;
        min-width: 160px;
        position: sticky;
        right: 0;
        background: inherit;
    }

    table.grid thead th.name-cell {
        position: sticky;
        right: 0;
        z-index: 3;
    }

    table.grid input.cellnum {
        width: 52px;
        padding: 4px;
        border: 1px solid transparent;
        border-radius: 6px;
        text-align: center;
        background: transparent;
        font-size: 13px;
    }

        table.grid input.cellnum:hover {
            border-color: var(--line);
        }

        table.grid input.cellnum:focus {
            border-color: var(--emerald);
            background: #fff;
            outline: none;
            box-shadow: 0 0 0 2px var(--emerald-l);
        }

    table.grid td.calc {
        background: var(--gold-l);
        font-weight: 700;
        color: #6b4e14;
    }

    table.grid td.fail {
        background: var(--danger-l);
        color: var(--danger);
        font-weight: 700;
    }

    table.grid td.pass {
        color: var(--emerald);
        font-weight: 700;
    }

.rowActions {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.iconbtn {
    border: none;
    background: transparent;
    border-radius: 7px;
    padding: 5px 7px;
    font-size: 14px;
    color: var(--muted);
}

    .iconbtn:hover {
        background: var(--paper-2);
        color: var(--ink);
    }

    .iconbtn.del:hover {
        background: var(--danger-l);
        color: var(--danger);
    }


/* =========================================================
   SEARCH
   ========================================================= */

.searchbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

    .searchbar input,
    .searchbar select {
        padding: 9px 11px;
        border: 1px solid var(--line);
        border-radius: 9px;
        font-size: 13.5px;
        min-width: 140px;
    }

        .searchbar input:focus,
        .searchbar select:focus {
            outline: none;
            border-color: var(--emerald);
        }

.pill {
    background: var(--emerald-l);
    color: var(--deep);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
}


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

.empty {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
}

    .empty .ic {
        font-size: 40px;
        margin-bottom: 10px;
        opacity: .5;
    }


/* =========================================================
   FLASH
   ========================================================= */

.flash {
    border-radius: 10px;
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 13.5px;
    font-weight: 700;
}

.flash-ok {
    background: var(--emerald-l);
    color: var(--deep);
    border: 1px solid #cfe4d9;
}

.flash-err {
    background: var(--danger-l);
    color: var(--danger);
    border: 1px solid #f0c9c4;
}


/* =========================================================
   FIELDSET
   ========================================================= */

fieldset {
    border: 1px dashed var(--line);
    border-radius: 10px;
    margin: 0 0 16px;
    padding: 14px;
}

    fieldset legend {
        padding: 0 8px;
        font-weight: 700;
        color: var(--deep);
        font-size: 13.5px;
    }


/* =========================================================
   SEARCHABLE DROPDOWN
   ========================================================= */

.search-results {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 230px;
    overflow-y: auto;
    z-index: 20;
    display: none;
}

    .search-results.show {
        display: block;
    }

    .search-results .item {
        padding: 9px 12px;
        cursor: pointer;
        font-size: 14px;
        border-bottom: 1px solid var(--paper-2);
    }

        .search-results .item:last-child {
            border-bottom: none;
        }

        .search-results .item:hover,
        .search-results .item.active {
            background: var(--emerald-l);
        }

    .search-results .empty-msg {
        padding: 10px 12px;
        color: var(--muted);
        font-size: 13px;
    }


/* =========================================================
   SWITCH
   ========================================================= */

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
}

    .switch input {
        width: 18px;
        height: 18px;
        accent-color: var(--emerald);
    }


/* =========================================================
   CERTIFICATE - SCREEN
   ========================================================= */

.print-plain-bg {
    background: #ddd;
}

.cert-wrap {
    width: 297mm;
    max-width: 297mm;
    margin: 20px auto;
}

.certificate {
    position: relative;
    width: 297mm;
    height: 210mm;
    max-width: none;
    margin: 0 auto;
    padding: 10mm 14mm 12mm 14mm;
    background: #fffdf6;
    border: 3px double var(--gold);
    border-radius: 0;
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}


    /* =========================================================
   CERTIFICATE INNER BORDER
   ========================================================= */

    .certificate::before {
        content: "";
        position: absolute;
        top: 5mm;
        right: 5mm;
        bottom: 5mm;
        left: 5mm;
        border: 1px solid var(--emerald);
        pointer-events: none;
        z-index: 1;
    }

    .certificate > * {
        position: relative;
        z-index: 2;
    }


    /* =========================================================
   CERTIFICATE LOGO
   ========================================================= */

    .certificate .print-logo-corner {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        width: 30mm !important;
        height: 30mm !important;
        max-width: 30mm !important;
        max-height: 30mm !important;
        object-fit: contain;
        margin: 0 auto 2mm auto !important;
        flex: none;
    }


    /* =========================================================
   SCHOOL NAME
   ========================================================= */

    .certificate .cert-school {
        font-family: 'Amiri',serif;
        font-size: 29px;
        font-weight: 700;
        color: var(--deep);
        line-height: 1.2;
        margin: 0 0 2mm 0;
    }


    /* =========================================================
   CERTIFICATE TITLE
   ========================================================= */

    .certificate .cert-title {
        font-family: 'Amiri',serif;
        font-size: 40px;
        font-weight: 700;
        color: var(--deep);
        line-height: 1.15;
        margin: 1mm 0 2mm;
    }


    /* =========================================================
   QURAN YEAR
   ========================================================= */

    .certificate .cert-sub {
        font-size: 16px;
        font-weight: 700;
        color: var(--gold);
        margin: 1mm 0 5mm;
    }


    /* =========================================================
   STUDENT NAME
   ========================================================= */

    .certificate .cert-name {
        display: inline-block;
        min-width: 120mm;
        max-width: 200mm;
        padding: 3mm 12mm;
        margin: 0 0 4mm;
        font-family: 'Amiri',serif;
        font-size: 34px;
        font-weight: 700;
        color: var(--ink);
        line-height: 1.2;
        border-bottom: 3px solid var(--gold);
    }


    /* =========================================================
   STUDENT INFORMATION
   ========================================================= */

    .certificate .msg-inline {
        width: 100%;
        font-size: 16px;
        font-weight: 600;
        color: var(--muted);
        line-height: 1.6;
        margin: 1mm 0 6mm;
        white-space: nowrap;
    }


    /* =========================================================
   GRADES TABLE
   ========================================================= */

    .certificate table {
        width: 100% !important;
        max-width: 100% !important;
        margin: 2mm auto 0;
        border-collapse: collapse;
        table-layout: fixed;
        font-size: 16px;
    }

        .certificate table th,
        .certificate table td {
            border: 2px solid #555;
            padding: 4mm 3mm;
            height: 16mm;
            text-align: center;
            vertical-align: middle;
            line-height: 1.3;
            word-wrap: break-word;
            overflow-wrap: break-word;
        }

        .certificate table th {
            background: var(--emerald-l);
            color: var(--deep);
            font-size: 16px;
            font-weight: 700;
        }

        .certificate table td {
            font-size: 17px;
            font-weight: 600;
        }

            .certificate table td[colspan] {
                height: 11mm;
                padding: 3mm;
                background: var(--paper-2);
                color: var(--deep);
                font-size: 19px;
                font-weight: 700;
            }


    /* =========================================================
   TOTAL
   ========================================================= */

    .certificate .cert-total {
        display: inline-block;
        min-width: 75mm;
        padding: 4mm 12mm;
        margin-top: 6mm;
        border: 3px solid var(--gold);
        border-radius: 4px;
        font-family: 'Amiri',serif;
        font-size: 26px;
        font-weight: 700;
        color: var(--deep);
        line-height: 1.2;
        background: var(--gold-l);
    }


    /* =========================================================
   CALCULATION NOTE
   ========================================================= */

    .certificate .calc-note {
        font-size: 12px;
        margin-top: 3mm;
        color: var(--muted);
        line-height: 1.4;
    }


    /* =========================================================
   SIGNATURES
   ========================================================= */

    .certificate .cert-sign {
        position: absolute !important;
        right: 14mm !important;
        left: 14mm !important;
        bottom: 10mm !important;
        width: auto !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: flex-end;
        gap: 18mm;
        margin: 0 !important;
        font-size: 15px;
        font-weight: 600;
        color: var(--ink);
        text-align: center;
    }

        .certificate .cert-sign > div {
            flex: 1;
            min-width: 0;
            padding-top: 7mm;
            border-top: 2px solid #555;
            line-height: 1.5;
        }


/* =========================================================
   PRINT OPTIONS
   ========================================================= */

.certificate-print-options {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 15px auto;
    padding: 10px 15px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    width: max-content;
    box-shadow: var(--shadow);
}

.print-option {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

    .print-option input {
        width: 18px;
        height: 18px;
        accent-color: var(--emerald);
    }


/* =========================================================
   HINT / TAG
   ========================================================= */

.hintbox {
    background: var(--emerald-l);
    border: 1px solid #cfe4d9;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12.8px;
    color: #2c5744;
    line-height: 1.9;
}

.tag {
    display: inline-block;
    background: var(--gold-l);
    color: #6b4e14;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11.5px;
    margin: 2px;
}

.msg-inline {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}


/* =========================================================
   PRINT SHEETS
   ========================================================= */

.p-head {
    position: relative;
    text-align: center;
    margin-bottom: 14px;
}

    .p-head h2 {
        margin: 0;
        color: #000;
    }

    .p-head .meta {
        font-size: 12px;
        color: #333;
        margin-top: 4px;
    }

.print-plain-bg table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

    .print-plain-bg table th,
    .print-plain-bg table td {
        border: 1px solid #999;
        padding: 4px;
        text-align: center;
    }

.p-foot {
    display: flex;
    justify-content: space-between;
    margin-top: 26px;
    font-size: 11.5px;
}


/* =========================================================
   LOGO PRINT
   ========================================================= */

.print-logo-corner {
    object-fit: contain;
}


/* =========================================================
   SCREEN CERTIFICATE
   ========================================================= */

@media screen {

    .certificate {
        width: 297mm;
        height: 210mm;
        margin: 20px auto;
        box-shadow: 0 8px 30px rgba(0,0,0,.2);
    }
}


/* =========================================================
   PRINT - A4 LANDSCAPE FULL PAGE (single consolidated block)
   Everything the certificate needs for printing/PDF lives here.
   ========================================================= */

@media print {

    /* -------------------------------------------------------
     PAGE SIZE
     ------------------------------------------------------- */

    @page {
        size: A4 landscape;
        margin: 0 !important;
    }


    /* -------------------------------------------------------
     HTML / BODY
     ------------------------------------------------------- */

    html,
    body {
        display: block !important;
        width: 297mm !important;
        min-width: 297mm !important;
        max-width: 297mm !important;
        height: 210mm !important;
        min-height: 210mm !important;
        max-height: 210mm !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: visible !important;
        zoom: 1 !important;
        transform: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }


    /* -------------------------------------------------------
     NEUTRALIZE APP LAYOUT (sidebar/topbar/card wrappers)
     The certificate is rendered inside the app layout, so these
     rules strip the layout width/padding that was shrinking it.
     ------------------------------------------------------- */

    #app-shell,
    #app-shell > *,
    .main,
    .main > *,
    .card,
    .cert-wrap {
        width: 297mm !important;
        min-width: 297mm !important;
        max-width: 297mm !important;
        margin: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box !important;
    }

    #app-shell {
        display: block !important;
        min-height: 0 !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .main {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        overflow: visible !important;
    }

    .card {
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
        height: auto !important;
        min-height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }


    /* -------------------------------------------------------
     WRAPPER
     ------------------------------------------------------- */

    .cert-wrap {
        display: block !important;
        height: 210mm !important;
        min-height: 210mm !important;
        max-height: 210mm !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }


    /* -------------------------------------------------------
     CERTIFICATE FULL A4
     ------------------------------------------------------- */

    .certificate {
        display: flex !important;
        position: relative !important;
        width: 297mm !important;
        min-width: 297mm !important;
        max-width: 297mm !important;
        height: 210mm !important;
        min-height: 210mm !important;
        max-height: 210mm !important;
        margin: 0 !important;
        padding: 9mm 12mm 10mm 12mm !important;
        border: 3px double #b3862c !important;
        border-radius: 0 !important;
        background: #fffdf6 !important;
        box-sizing: border-box !important;
        transform: none !important;
        zoom: 1 !important;
        overflow: hidden !important;
        page-break-after: always !important;
        page-break-inside: avoid !important;
        break-after: page !important;
        break-inside: avoid !important;
    }


        /* -------------------------------------------------------
     INNER FRAME
     ------------------------------------------------------- */

        .certificate::before {
            top: 5mm !important;
            right: 5mm !important;
            bottom: 5mm !important;
            left: 5mm !important;
            border: 1px solid #1f6f52 !important;
        }


        /* -------------------------------------------------------
     LOGO
     ------------------------------------------------------- */

        .certificate .print-logo-corner {
            width: 32mm !important;
            height: 32mm !important;
            max-width: 32mm !important;
            max-height: 32mm !important;
            margin: 0 auto 1mm !important;
        }


        /* -------------------------------------------------------
     SCHOOL
     ------------------------------------------------------- */

        .certificate .cert-school {
            font-size: 31px !important;
            margin: 0 0 1mm !important;
            line-height: 1.2 !important;
        }


        /* -------------------------------------------------------
     TITLE
     ------------------------------------------------------- */

        .certificate .cert-title {
            font-size: 42px !important;
            margin: 0 0 1mm !important;
            line-height: 1.15 !important;
        }


        /* -------------------------------------------------------
     YEAR
     ------------------------------------------------------- */

        .certificate .cert-sub {
            font-size: 17px !important;
            margin: 0 0 3mm !important;
        }


        /* -------------------------------------------------------
     STUDENT NAME
     ------------------------------------------------------- */

        .certificate .cert-name {
            min-width: 140mm !important;
            max-width: 220mm !important;
            padding: 2mm 10mm !important;
            margin: 0 0 2mm !important;
            font-size: 36px !important;
            line-height: 1.2 !important;
        }


        /* -------------------------------------------------------
     STUDENT INFO
     ------------------------------------------------------- */

        .certificate .msg-inline {
            width: 100% !important;
            font-size: 17px !important;
            margin: 0 0 3mm !important;
            white-space: nowrap !important;
            line-height: 1.35 !important;
        }


        /* -------------------------------------------------------
     TABLE
     ------------------------------------------------------- */

        .certificate table {
            width: 100% !important;
            max-width: 100% !important;
            margin: 1mm 0 0 !important;
            font-size: 17px !important;
            table-layout: fixed !important;
            border-collapse: collapse !important;
            flex: 0 0 auto !important;
            page-break-inside: avoid !important;
            break-inside: avoid !important;
        }

            .certificate table th,
            .certificate table td {
                height: 15mm !important;
                padding: 3mm 2mm !important;
                border: 2px solid #555 !important;
                font-size: 17px !important;
                line-height: 1.3 !important;
            }

            .certificate table td {
                font-size: 17px !important;
                font-weight: 600 !important;
            }

                .certificate table td[colspan] {
                    height: 10mm !important;
                    padding: 2mm !important;
                    font-size: 19px !important;
                    background: #f2efe4 !important;
                }


        /* -------------------------------------------------------
     TOTAL
     ------------------------------------------------------- */

        .certificate .cert-total {
            min-width: 85mm !important;
            padding: 3mm 12mm !important;
            margin-top: 4mm !important;
            border: 3px solid #b3862c !important;
            font-size: 28px !important;
            background: #f4e8cc !important;
        }


        /* -------------------------------------------------------
     SIGNATURES
     ------------------------------------------------------- */

        .certificate .cert-sign {
            position: absolute !important;
            right: 12mm !important;
            left: 12mm !important;
            bottom: 7mm !important;
            width: auto !important;
            display: flex !important;
            justify-content: space-between !important;
            align-items: flex-end !important;
            gap: 15mm !important;
            margin: 0 !important;
            font-size: 16px !important;
        }

            .certificate .cert-sign > div {
                padding-top: 5mm !important;
                border-top: 2px solid #555 !important;
                border-top-width: 2px !important;
                line-height: 1.35 !important;
            }


        /* -------------------------------------------------------
     PREVENT BREAKING
     ------------------------------------------------------- */

        .certificate,
        .certificate table,
        .certificate tr {
            page-break-inside: avoid !important;
            break-inside: avoid !important;
        }


    /* -------------------------------------------------------
     HIDE CONTROLS
     ------------------------------------------------------- */

    .no-print,
    .toolbar,
    nav,
    header,
    footer,
    .topbar,
    .mobile-topbar,
    .sidebar,
    .sidebar-overlay,
    .certificate-print-options {
        display: none !important;
    }
}


/* =========================================================
   SCROLLBAR
   ========================================================= */

::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cfc9ae;
    border-radius: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}
