:root {
    --bg: #0d0d0f;
    --surface: #18181b;
    --surface-hover: #222228;
    --border: #2d2d35;
    --text: #f4f4f5;
    --text-muted: #a1a1aa;
    --accent: #22d3ee;
    --accent-dark: #0891b2;
    --danger: #ef4444;
    --success: #34d399;
    --radius: 12px;
}

/* =========================
           RESET
        ========================= */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0 !important;
    padding: 0 !important;
}

body {
    font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button {
    cursor: pointer;
}

/* =========================
           LOGIN
        ========================= */

.login-wrap {
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background:
        radial-gradient(ellipse at 50% 0%,
            rgba(34, 211, 238, 0.08) 0%,
            transparent 50%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.login-card .sub {
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
}

.form-group input:focus,
.toolbar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

/* =========================
           BUTTONS
        ========================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--accent);
    color: #071013;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background: #06b6d4;
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text);
    background: var(--surface-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

/* =========================
           ALERTS
        ========================= */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(248, 113, 113, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.alert-success {
    background: rgba(52, 211, 153, 0.15);
    color: #6ee7b7;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

/* =========================
           APP
        ========================= */

.app {
    display: none;
    width: 100%;
    min-height: 100vh;
}

.app.active {
    display: block;
    min-height: 100vh;
}

/* =========================
           MAIN LAYOUT
        ========================= */

.layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
    align-items: stretch;
}

/* Fixed to the very top.
           This prevents the sidebar from appearing
           lower than the page. */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;

    width: 240px;
    height: 100vh;

    background: var(--surface);
    border-right: 1px solid var(--border);

    padding: 1.5rem 0;

    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 1.5rem 1.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;

    padding: 0.75rem 1.5rem;

    color: var(--text-muted);
    text-decoration: none;

    transition: all 0.15s;
    cursor: pointer;

    border: none;
    background: none;

    width: 100%;

    font-size: 1rem;
    font-family: inherit;
    text-align: left;
}

.nav-item:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(34, 211, 238, 0.1);
}

/* Main starts at the top and leaves room for fixed sidebar */
.main {
    margin-left: 240px;

    width: calc(100% - 240px);
    min-height: 100vh;

    padding: 2rem;

    overflow-x: hidden;
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    margin-bottom: 2rem;

    min-height: 40px;
}

.header h1 {
    font-size: 1.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info span {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* =========================
           DASHBOARD
        ========================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stat-card .label {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.subtabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.subtab {
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.subtab:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.subtab.active {
    color: var(--accent);
    border-color: rgba(34, 211, 238, 0.35);
    background: rgba(34, 211, 238, 0.1);
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* =========================
           DANGER ZONE
        ========================= */

.danger-box {
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.25);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.danger-title {
    font-weight: 700;
    color: #fca5a5;
    margin-bottom: 0.25rem;
}

.checklist {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.check-item {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.check-item input {
    margin-top: 0.2rem;
}

.check-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.15rem;
}

/* =========================
           TABLES
        ========================= */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.875rem 1rem;
    text-align: left;
}

th {
    background: var(--surface-hover);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

td {
    border-top: 1px solid rgba(255, 255, 255, 0.025);
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.empty {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.loading {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

/* =========================
           BADGES
        ========================= */

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    font-weight: 500;
}

.badge-pass {
    background: rgba(52, 211, 153, 0.2);
    color: #6ee7b7;
}

.badge-fail {
    background: rgba(248, 113, 113, 0.2);
    color: #fca5a5;
}

/* =========================
           SEARCH / TOOLBAR
        ========================= */

.toolbar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar input {
    padding: 0.65rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}

.toolbar input::placeholder {
    color: #71717a;
}

/* =========================
           RESULT CARD
        ========================= */

.result-card {
    position: relative;

    background:
        linear-gradient(145deg,
            rgba(34, 211, 238, 0.055),
            transparent 28%),
        var(--surface);

    border: 1px solid var(--border);
    border-radius: 18px;

    margin-top: 1.5rem;

    overflow: hidden;

    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.015);
}

.result-card::before {
    content: "";
    display: block;
    height: 4px;
    background: linear-gradient(90deg,
            var(--accent),
            #0891b2,
            var(--accent));
}

.result-card-inner {
    padding: 2rem;
}

.result-school-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;

    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.school-heading {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.school-logo {
    width: 58px;
    height: 58px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 14px;

    background: rgba(34, 211, 238, 0.1);
    border: 1px solid rgba(34, 211, 238, 0.25);

    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 800;
}

.school-name {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text);
}

.school-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.15rem;
}

.report-label {
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: right;
}

.report-title {
    font-size: 1.2rem;
    font-weight: 700;
    text-align: right;
    margin-top: 0.2rem;
}

.student-profile {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 1rem;

    margin: 1.5rem 0;
}

.student-info-box {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.9rem 1rem;
}

.student-info-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.2rem;
}

.student-info-value {
    display: block;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    word-break: break-word;
}

.result-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.summary-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
}

.summary-box .summary-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.summary-box .summary-value {
    margin-top: 0.25rem;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--accent);
}

.exam-block {
    margin-top: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

.exam-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 0.9rem 1rem;

    background: var(--surface-hover);
    border-bottom: 1px solid var(--border);
}

.exam-block-title {
    font-weight: 700;
    color: var(--text);
}

.exam-block-subtitle {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.subject-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

.subject-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;

    padding: 0.9rem 1rem;

    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.subject-row:nth-child(odd) {
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.subject-name {
    font-size: 0.9rem;
    color: var(--text);
}

.subject-right {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.subject-mark {
    min-width: 45px;
    text-align: right;
    font-weight: 700;
    color: var(--text);
}

.overall-status {
    margin-top: 1.5rem;
    padding: 1.1rem 1.25rem;

    display: flex;
    justify-content: space-between;
    align-items: center;

    border-radius: 12px;

    background: rgba(34, 211, 238, 0.06);
    border: 1px solid rgba(34, 211, 238, 0.18);
}

.overall-status-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.overall-status-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--accent);
}

.result-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;

    border-top: 1px solid var(--border);

    display: flex;
    justify-content: space-between;

    color: var(--text-muted);
    font-size: 0.75rem;
}

/* =========================
           RESULT CARD FORM
        ========================= */

.result-search-card {
    max-width: 650px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
}

.result-search-card h2 {
    font-size: 1.15rem;
    margin-bottom: 0.3rem;
}

.result-search-card p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
}

.result-search-row {
    display: flex;
    gap: 0.75rem;
}

.result-search-row input {
    flex: 1;
    min-width: 0;

    padding: 0.75rem 1rem;

    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);

    color: var(--text);
    font-size: 1rem;
}

.result-search-row .btn {
    width: auto;
}

/* =========================
           RESPONSIVE
        ========================= */

@media (max-width: 900px) {
    .sidebar {
        width: 210px;
    }

    .main {
        margin-left: 210px;
        width: calc(100% - 210px);
        padding: 1.5rem;
    }

    .student-profile {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 700px) {
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        min-height: 0;
    }

    .layout {
        display: block;
    }

    .main {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }

    .header {
        margin-bottom: 1.25rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .user-info span {
        display: none;
    }

    .sidebar {
        padding: 1rem 0;
    }

    .sidebar-brand {
        padding-bottom: 1rem;
    }

    .student-profile {
        grid-template-columns: 1fr;
    }

    .result-summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .subject-list {
        grid-template-columns: 1fr;
    }

    .subject-row:nth-child(odd) {
        border-right: none;
    }

    .result-school-header {
        flex-direction: column;
    }

    .report-label,
    .report-title {
        text-align: left;
    }

    .result-card-inner {
        padding: 1rem;
    }

    .result-search-row {
        flex-direction: column;
    }

    .result-search-row .btn {
        width: 100%;
    }

    table {
        min-width: 650px;
    }

    .table-wrap {
        overflow-x: auto;
    }
}

@media print {
    body {
        background: white;
        color: black;
    }

    .sidebar,
    .header,
    .result-search-card,
    .subtabs {
        display: none !important;
    }

    .main {
        margin: 0;
        width: 100%;
        padding: 0;
    }

    .result-card {
        box-shadow: none;
        border: 1px solid #ccc;
        color: #111;
    }

    .result-card-inner {
        padding: 20px;
    }

    .student-info-box,
    .summary-box,
    .exam-block {
        border-color: #ddd;
        background: white;
    }

    .school-name,
    .student-info-value,
    .subject-name,
    .subject-mark,
    .exam-block-title {
        color: #111;
    }

    .school-subtitle,
    .student-info-label,
    .exam-block-subtitle,
    .summary-label,
    .result-footer {
        color: #666;
    }
}

/* =========================================================
   EDIT STUDENT MODAL
========================================================= */

.student-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
}

.student-modal-overlay {
    position: fixed;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.75);
}

.student-modal-box {
    width: 100%;
    max-width: 700px;
    max-height: 90vh;

    overflow-y: auto;

    background: var(--panel, #111827);
    color: var(--text, #f9fafb);

    border: 1px solid var(--border, #374151);
    border-radius: 14px;

    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
}

.student-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 18px 22px;

    border-bottom: 1px solid var(--border, #374151);
}

.student-modal-header h2 {
    margin: 0;

    font-size: 1.25rem;
    color: var(--text, #ffffff);
}

.student-modal-close {
    width: 38px !important;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: none;
    border-radius: 8px;

    background: transparent;
    color: var(--text-muted, #9ca3af);

    font-size: 25px;
    cursor: pointer;
}

.student-modal-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

#editStudentForm {
    padding: 22px;
}

.student-form-grid {
    display: grid;

    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 18px;
}

.student-form-grid .form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.student-form-grid label {
    display: block;

    color: var(--text, #f9fafb);

    font-size: 0.9rem;
    font-weight: 600;
}

.student-form-grid input {
    width: 100%;
    box-sizing: border-box;

    padding: 11px 13px;

    border: 1px solid var(--border, #374151);
    border-radius: 8px;

    background: var(--input, #0f172a);
    color: var(--text, #ffffff);

    font-size: 0.95rem;

    outline: none;
}

.student-form-grid input:focus {
    border-color: var(--accent, #22d3ee);

    box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.15);
}

.student-form-grid input::placeholder {
    color: var(--text-muted, #9ca3af);
}

.student-modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;

    gap: 10px;

    margin-top: 22px;
    padding-top: 18px;

    border-top: 1px solid var(--border, #374151);
}

/*
   Override your global .btn width if it is currently
   making Save Changes full width.
*/
.student-modal-footer .btn {
    width: auto !important;
    min-width: 120px;
}

.student-modal-footer .btn-primary {
    width: auto !important;
}

/* Error message */
#editStudentError {
    width: 100%;
    box-sizing: border-box;
}

/* Mobile */
@media (max-width: 600px) {

    .student-modal-overlay {
        padding: 10px;
    }

    .student-modal-box {
        max-height: 95vh;
        border-radius: 10px;
    }

    .student-form-grid {
        grid-template-columns: 1fr;
    }

    #editStudentForm {
        padding: 16px;
    }

    .student-modal-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .student-modal-footer .btn {
        width: 100% !important;
    }
}