.student-page {
    min-height: 100vh;
    background: var(--background, #f5f7fb);
}

.student-header {
    background: white;
    min-height: 75px;
    padding: 15px 5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border, #e8ecf3);
}

.student-header .brand {
    color: var(--text, #202b3c);
    margin: 0;
    padding: 0;
}

.student-main {
    width: min(1400px, 92%);
    margin: 32px auto;
}

.student-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 25px;
}

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

.student-title-row h1,
.form-main > h1 {
    margin: 0 0 10px;
    font-size: 27px;
}

.student-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 23px;
}

.student-stat {
    background: white;
    padding: 22px;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 14px;
}

.student-stat span,
.student-stat strong {
    display: block;
}

.student-stat span {
    color: var(--muted, #7c8799);
    font-size: 12px;
}

.student-stat strong {
    margin-top: 12px;
    font-size: 27px;
}

.student-panel,
.admission-form {
    background: white;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 14px;
    overflow: hidden;
}

.student-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border, #e8ecf3);
}

.student-toolbar input,
.student-toolbar select {
    min-height: 41px;
    padding: 10px 12px;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 8px;
    background: white;
    color: var(--text, #202b3c);
}

.student-toolbar input {
    flex: 1 1 260px;
    min-width: 0;
}

.student-toolbar select {
    flex: 0 1 150px;
}

.student-table {
    min-width: 800px;
}

.student-table td,
.student-table th {
    padding: 15px 18px;
}

.student-table tbody tr:hover {
    background: #fafbff;
}

.student-table tbody tr[hidden] {
    display: none;
}

.table-footer {
    padding: 17px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--muted, #7c8799);
    font-size: 12px;
}

.table-footer a {
    color: var(--primary, #3157d5);
    font-weight: 600;
}

.empty-state {
    padding: 35px 20px;
    text-align: center;
    color: var(--muted, #7c8799);
}

.demo-warning {
    margin: 18px 0;
    color: var(--muted, #7c8799);
    font-size: 12px;
    line-height: 1.7;
}

.form-main {
    max-width: 1000px;
}

.admission-form {
    margin-top: 25px;
    padding: 0;
}

.form-section {
    padding: 25px;
    border-bottom: 1px solid var(--border, #e8ecf3);
}

.form-section h2 {
    font-size: 17px;
    margin-bottom: 22px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.form-field {
    display: grid;
    align-content: start;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    min-height: 43px;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    font-weight: 400;
    color: var(--text, #202b3c);
    background: white;
    outline-color: var(--primary, #3157d5);
}

.form-field textarea {
    resize: vertical;
}

.full-width {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    padding: 22px 25px;
}

.form-actions a {
    display: inline-flex;
    align-items: center;
}

#formMessage {
    padding: 0 25px 20px;
    color: var(--success, #159b69);
    font-size: 13px;
}

#formMessage:empty {
    display: none;
}

@media (max-width: 700px) {
    .student-main {
        width: 94%;
        margin: 22px auto;
    }

    .student-title-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .student-title-row h1,
    .form-main > h1 {
        font-size: 23px;
    }

    .student-stats {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .student-stat {
        padding: 17px;
    }

    .student-stat strong {
        font-size: 23px;
    }

    .student-toolbar {
        padding: 14px;
    }

    .student-toolbar input,
    .student-toolbar select {
        flex: 1 1 100%;
    }

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

    .form-section {
        padding: 19px;
    }

    .form-actions {
        padding: 18px;
    }

    .form-actions button,
    .form-actions a {
        flex: 1 1 auto;
        justify-content: center;
    }
}

.field-error {
    color: #c0392b;
    font-size: 12px;
    font-weight: 400;
}

.field-error:empty {
    display: none;
}

.form-field input[aria-invalid="true"],
.form-field select[aria-invalid="true"],
.form-field textarea[aria-invalid="true"] {
    border-color: #c0392b;
}

#formMessage.error {
    color: #c0392b;
}

.required-note {
    font-size: 12px;
    color: var(--muted, #7c8799);
}

.profile-card {
    background: white;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 14px;
    overflow: hidden;
    margin-top: 22px;
}

.profile-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 18px;
    padding: 25px;
    border-bottom: 1px solid var(--border, #e8ecf3);
}

.profile-head .student-avatar {
    width: 68px;
    height: 68px;
    font-size: 22px;
}

.profile-title {
    flex: 1 1 220px;
    min-width: 0;
}

.profile-title h2 {
    margin: 0 0 6px;
    font-size: 21px;
    overflow-wrap: anywhere;
}

.profile-title p {
    margin: 0;
}

.profile-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.profile-chip {
    padding: 4px 11px;
    border-radius: 999px;
    background: var(--primary-soft, #edf1ff);
    color: var(--primary, #3157d5);
    font-size: 12px;
    font-weight: 600;
}

.profile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.detail-section {
    padding: 25px;
    border-bottom: 1px solid var(--border, #e8ecf3);
}

.detail-section:last-of-type {
    border-bottom: 0;
}

.detail-section h3 {
    margin: 0 0 18px;
    font-size: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin: 0;
}

.detail-item dt {
    color: var(--muted, #7c8799);
    font-size: 12px;
    margin-bottom: 6px;
}

.detail-item dd {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.detail-item.full-width {
    grid-column: 1 / -1;
}

.not-found {
    padding: 50px 25px;
    text-align: center;
}

.not-found h2 {
    margin: 0 0 8px;
}

@media (max-width: 700px) {
    .profile-head,
    .detail-section {
        padding: 19px;
    }

    .profile-actions {
        width: 100%;
    }

    .profile-actions .secondary-button {
        flex: 1 1 auto;
    }
}

.print-head { display: none; }

@media print {
    .print-head:not([hidden]) { display: block; margin-bottom: 14px; text-align: center; }
    .print-banner { width: 100%; display: block; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-banner[hidden], .print-text[hidden] { display: none !important; }
    .print-text strong { display: block; font-size: 20pt; text-transform: uppercase; }
    .print-text span { font-size: 9pt; color: #444; }
    .student-main > .eyebrow { display: none; }
    .student-header,
    .profile-actions,
    .demo-warning {
        display: none;
    }

    .student-page {
        background: white;
    }

    .profile-card {
        border: 0;
    }
}

.secondary-button.danger { color: #c0392b; border-color: #e3b4ae; }
.secondary-button.danger:hover { background: #fdf0ee; }

.id-batch { display: none; }
@media print {
    .printing-ids .student-page > *:not(main),
    .printing-ids main > *:not(#idBatch) { display: none !important; }
    .printing-ids .id-batch { display: grid; grid-template-columns: repeat(2, 86mm); gap: 6mm; justify-content: center; }
    .id-card { width: 86mm; height: 54mm; border: 1px solid #222; border-radius: 3mm; overflow: hidden; break-inside: avoid; display: flex; flex-direction: column; font-size: 8.5pt; }
    .id-head { background: #1e3a8a; color: #fff; text-align: center; font-weight: 700; padding: 1.5mm 2mm; display: flex; align-items: center; justify-content: center; gap: 2mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .id-logo { height: 8mm; width: 8mm; object-fit: contain; background: #fff; border-radius: 50%; }
    .id-body { display: flex; gap: 3mm; padding: 2.5mm; flex: 1; }
    .id-photo { flex: 0 0 22mm; height: 28mm; border: 1px solid #222; background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; font-size: 7pt; color: #666; }
    .id-body dl { margin: 0; display: grid; grid-template-columns: 14mm 1fr; gap: 1mm 2mm; align-content: start; }
    .id-body dt { font-weight: 400; color: #555; }
    .id-body dd { margin: 0; font-weight: 600; word-break: break-word; }
}

/* Not-found cards: keep the button clear of the text */
.not-found .primary-button { display: inline-block; margin-top: 18px; }

/* Hint text next to toolbar selects */
.student-toolbar .muted { align-self: center; }

/* ===== Shared page header (used by every page except the dashboard) ===== */
@media screen {
    .student-header {
        padding-left: calc((100% - min(1400px, 92%)) / 2);
        padding-right: calc((100% - min(1400px, 92%)) / 2);
        min-height: 72px;
        gap: 12px;
    }
    .student-header .brand { flex: 0 1 auto; min-width: 0; }
    .student-header .brand-name { font-size: 1.05rem; -webkit-line-clamp: 2; }
    /* Dashboard / back button sits on the right, next to Password and Logout */
    .student-header > .secondary-button { margin-left: auto; }
    .student-header .secondary-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 38px;
        padding: 0 16px;
        background: #fff;
        border: 1px solid var(--border, #e8ecf3);
        color: var(--text, #202b3c);
        white-space: nowrap;
        cursor: pointer;
        transition: background .15s, border-color .15s, color .15s;
    }
    .student-header .secondary-button:hover {
        background: var(--primary-soft, #edf1ff);
        border-color: #c9d5fb;
        color: var(--primary-dark, #2443b0);
    }
    .student-header .secondary-button:focus-visible {
        outline: 3px solid rgba(49, 87, 213, .35);
        outline-offset: 2px;
    }
}

@media screen and (max-width: 700px) {
    .student-header {
        padding-left: 3%;
        padding-right: 3%;
    }
}

/* Phones: school name on its own row, buttons together underneath */
@media screen and (max-width: 600px) {
    .student-header {
        flex-wrap: wrap;
        justify-content: flex-start;
        padding-top: 14px;
        padding-bottom: 14px;
    }
    .student-header .brand { flex: 1 1 100%; }
    .student-header > .secondary-button { margin-left: 0; }
    .student-header .secondary-button { padding: 0 14px; font-size: 12px; }
}

/* ===== Pagination bar under long tables ===== */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 18px;
    padding: 14px 20px;
    border-top: 1px solid var(--border, #e8ecf3);
    font-size: 13px;
    color: var(--muted, #6b7589);
}
.pager[hidden] { display: none; }
.pager-info { font-weight: 600; color: var(--text, #202b3c); }
.pager-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-nums { display: inline-flex; align-items: center; gap: 6px; }
.pager-gap { padding: 0 2px; color: var(--muted, #6b7589); }
.pager-status { display: none; padding: 0 8px; font-weight: 600; color: var(--text, #202b3c); }
.pager-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 9px;
    background: #fff;
    color: var(--text, #202b3c);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.pager-btn:hover:not(:disabled):not(.is-current) {
    background: var(--primary-soft, #edf1ff);
    border-color: #c9d5fb;
    color: var(--primary-dark, #2443b0);
}
.pager-btn.is-current {
    background: var(--primary, #3157d5);
    border-color: var(--primary, #3157d5);
    color: #fff;
    cursor: default;
}
.pager-btn:disabled { opacity: .45; cursor: not-allowed; }
.pager-btn:focus-visible { outline: 3px solid rgba(49, 87, 213, .35); outline-offset: 2px; }
.pager-size { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.pager-size select {
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border, #e8ecf3);
    border-radius: 9px;
    background: #fff;
    font: inherit;
    cursor: pointer;
}
@media (max-width: 640px) {
    .pager { flex-direction: column; align-items: stretch; text-align: center; padding: 14px; }
    .pager-nav { justify-content: center; }
    .pager-nums { display: none; }
    .pager-status { display: inline; }
    .pager-btn.pager-edge { flex: 1 1 0; height: 40px; max-width: 130px; }
    .pager-size { justify-content: center; }
}
@media print { .pager { display: none !important; } }

/* ===== Row action buttons (View / Edit / Delete / Collect ...) ===== */
.row-actions { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.table-wrapper .row-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid #d3dbf2;
    border-radius: 8px;
    background: #fff;
    color: var(--primary-dark, #2443b0);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.table-wrapper .row-btn:hover:not(:disabled) {
    background: var(--primary-soft, #edf1ff);
    border-color: #b7c5f3;
    text-decoration: none;
}
.table-wrapper .row-btn.primary {
    background: var(--primary, #3157d5);
    border-color: var(--primary, #3157d5);
    color: #fff;
}
.table-wrapper .row-btn.primary:hover:not(:disabled) { background: var(--primary-dark, #2443b0); border-color: var(--primary-dark, #2443b0); }
.table-wrapper .row-btn.danger { border-color: #f1c9c4; color: #b42318; }
.table-wrapper .row-btn.danger:hover:not(:disabled) { background: #fdecea; border-color: #e8aaa2; }
.table-wrapper .row-btn:disabled { opacity: .5; cursor: not-allowed; color: var(--muted, #6b7589); }
.table-wrapper .row-btn:focus-visible { outline: 3px solid rgba(49, 87, 213, .35); outline-offset: 2px; }

/* ===== Phones: list tables become cards ===== */
@media screen and (max-width: 700px) {
    .cards-table { min-width: 0 !important; width: 100%; }
    .cards-table thead { display: none; }
    .cards-table,
    .cards-table tbody,
    .cards-table tr,
    .cards-table td { display: block; width: 100%; box-sizing: border-box; }
    .cards-table tr { padding: 14px 16px; border-bottom: 1px solid var(--border, #e8ecf3); }
    .cards-table tbody tr:last-child { border-bottom: 0; }
    .cards-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 14px;
        padding: 5px 0;
        border: 0;
        text-align: right;
        white-space: normal;
    }
    .cards-table td::before {
        content: attr(data-label);
        flex: none;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: .5px;
        text-transform: uppercase;
        color: var(--muted, #6b7589);
        text-align: left;
    }
    .cards-table td:first-child { display: block; text-align: left; padding-bottom: 8px; }
    .cards-table td:first-child::before,
    .cards-table td:last-child::before { display: none; }
    .cards-table td:last-child { display: block; padding-top: 10px; text-align: left; }
    /* cells that hold several lines (contact details, children, capacity bar) */
    .cards-table td[data-label="Contact"],
    .cards-table td[data-label="Children"] { display: block; text-align: left; }
    .cards-table td[data-label="Contact"]::before,
    .cards-table td[data-label="Children"]::before { display: block; margin-bottom: 4px; }
    .cards-table td[data-label="Strength"] { flex-wrap: wrap; }
    .cards-table td[data-label="Strength"] .capacity-bar { flex: 0 0 100%; }
    .cards-table .row-actions { display: flex; width: 100%; }
    .cards-table .row-btn { flex: 1 1 auto; min-height: 40px; }
}

/* ===== Step 5: Add / Edit form pages ===== */
@media screen {
    /* overflow:hidden would stop the Save bar from sticking to the screen bottom */
    .admission-form { overflow: visible; }

    .form-section h2 {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 16px;
        margin-bottom: 20px;
    }
    .form-section h2::before {
        content: "";
        flex: none;
        width: 4px;
        height: 18px;
        border-radius: 3px;
        background: var(--primary, #3157d5);
    }

    /* style.css also adds margin-bottom to .form-field, which doubled the gaps */
    .form-grid { gap: 18px 20px; }
    .form-grid .form-field { margin-bottom: 0; }

    .form-field input,
    .form-field select,
    .form-field textarea {
        border-color: #dbe1ec;
        border-radius: 10px;
        transition: border-color .15s, box-shadow .15s;
    }
    .form-field input:hover,
    .form-field select:hover,
    .form-field textarea:hover { border-color: #b9c4da; }
    .form-field input:focus,
    .form-field select:focus,
    .form-field textarea:focus {
        outline: 0;
        border-color: var(--primary, #3157d5);
        box-shadow: 0 0 0 3px rgba(49, 87, 213, .15);
    }
    .form-field input[type="file"] { padding: 6px 8px; cursor: pointer; }
    .form-field input[type="file"]::file-selector-button {
        margin-right: 12px;
        padding: 7px 14px;
        border: 1px solid #d3dbf2;
        border-radius: 8px;
        background: var(--primary-soft, #edf1ff);
        color: var(--primary-dark, #2443b0);
        font: inherit;
        font-weight: 600;
        cursor: pointer;
    }

    /* Save / Cancel stay visible at the bottom of the screen while you fill a long form */
    .form-actions {
        position: sticky;
        bottom: 0;
        z-index: 20;
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--border, #e8ecf3);
        box-shadow: 0 -10px 26px rgba(23, 35, 62, .07);
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    .form-actions .primary-button,
    .form-actions .secondary-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
        padding: 0 22px;
        border-radius: 10px;
        cursor: pointer;
    }

    /* "Saved" / error message floats above the Save bar so it is seen from anywhere in the form */
    #formMessage:not(:empty) {
        position: fixed;
        left: 50%;
        bottom: calc(92px + env(safe-area-inset-bottom, 0px));
        transform: translateX(-50%);
        z-index: 60;
        width: max-content;
        max-width: min(560px, 92vw);
        padding: 12px 18px;
        border: 1px solid #bfe5d3;
        border-radius: 10px;
        background: #fff;
        box-shadow: 0 12px 30px rgba(23, 35, 62, .18);
        font-weight: 600;
        line-height: 1.4;
        text-align: center;
        pointer-events: none;
    }
    #formMessage.error:not(:empty) { border-color: #f1c9c4; }
}

@media screen and (max-width: 700px) {
    .form-actions { padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); gap: 8px; }
    .form-actions .primary-button,
    .form-actions .secondary-button { min-height: 44px; padding: 0 14px; }
    .form-actions .primary-button { flex: 2 1 0; }
    .form-actions .secondary-button { flex: 1 1 0; }
    #formMessage:not(:empty) { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}

/* ===== Footer on inner pages ===== */
@media screen {
    .student-page > .page-footer {
        width: min(1400px, 92%);
        margin: 8px auto 0;
        padding: 22px 0 30px;
        border-top: 1px solid var(--border, #e8ecf3);
    }
}
@media screen and (max-width: 700px) {
    .student-page > .page-footer {
        width: 94%;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        gap: 4px;
        padding-bottom: 24px;
    }
}
