/*
 * IBC Staff — design system
 *
 * Built from the Stitch design, but layered over Bootstrap rather than
 * replacing it, so every existing screen keeps working while the look changes.
 *
 * Only the six real tokens are kept. The export carried about forty, most of
 * them Material Design defaults the tool added on its own.
 *
 * No web fonts: the school's internet is unreliable and nothing here should
 * wait on a network round-trip.
 */

/*
 * Palette taken from the school crest and ipsck.edu.pk, not invented:
 *
 *   deep indigo-navy   the ring around the crest      -> sidebar, headings
 *   warm gold          the laurel wreath              -> brand accents
 *   maroon             the flag between the mountains -> reserved, unused
 *   #1a56db            the website's own theme colour -> buttons and links
 *
 * Gold is deliberately never a button: white text on it fails contrast, and a
 * gold "Post this run" would look decorative rather than deliberate.
 */
:root {
    --navy-900:  #2A1C55;   /* sidebar — sampled from the crest ring */
    --navy-800:  #342267;   /* sidebar hover */
    --navy-700:  #443090;   /* sidebar active */
    --gold:      #AA9B71;   /* the laurel — the crest's most common colour */
    --gold-soft: #F3F0E7;
    --maroon:    #551C1C;   /* the flag — held in reserve */

    --ink:       #111827;
    --ink-muted: #6B7280;
    --paper:     #F7F6F3;   /* page background, warm not grey */
    --surface:   #FFFFFF;
    --line:      #E5E7EB;

    --emerald:   #1a56db;   /* the school site's blue: actions and links */
    --emerald-dark: #1447b0;
    --emerald-soft: #EFF4FE;
    --amber:     #B45309;
    --amber-soft:#FEF6EC;
    --red:       #B91C1C;
    --red-soft:  #FEF2F2;

    --radius: 8px;
    --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 12px rgba(16,24,40,.05);
    --sidebar-w: 236px;
}

/* ---------- base ---------- */

body {
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { color: var(--navy-900); font-weight: 600; letter-spacing: -.01em; }
h1.h4 { font-size: 20px; }

a { color: var(--navy-700); text-underline-offset: 2px; }
a:hover { color: var(--navy-900); }

/* Every figure is tabular, so columns line up down the page. */
.num, td.num, th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.text-muted { color: var(--ink-muted) !important; }
.fw-semibold { font-weight: 600; }

/* ---------- shell ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--navy-900);
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 18px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(198,166,100,.35);
    text-decoration: none;
}
.sidebar-brand img {
    width: 40px; height: 40px;
    object-fit: contain;
    flex: 0 0 40px;
    background: #fff;
    border-radius: 6px;
    padding: 3px;
}
.sidebar-brand strong { display: block; font-size: 14.5px; color: #fff; line-height: 1.2; }
.sidebar-brand span   { font-size: 10.5px; color: var(--gold); letter-spacing: .04em; }

.sidebar .nav-link {
    display: block;
    color: rgba(255,255,255,.72);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13.5px;
    margin-bottom: 2px;
    text-decoration: none;
    transition: background .15s ease-out, color .15s ease-out;
}
.sidebar .nav-link:hover  { background: var(--navy-800); color: #fff; }
.sidebar .nav-link.active {
    background: var(--navy-700);
    color: #fff;
    font-weight: 500;
    box-shadow: inset 3px 0 0 var(--gold);
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.1);
    font-size: 11.5px;
    color: rgba(255,255,255,.5);
}

.main { flex: 1 1 auto; min-width: 0; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 13px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar .school { font-weight: 600; color: var(--navy-900); }

.content { padding: 22px 24px 56px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

/* ---------- cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 13.5px;
    color: var(--navy-900);
    padding: 11px 14px;
}
.card-body { padding: 14px; }
.card.border-danger  { border-color: #FCA5A5; }
.card.border-warning { border-color: #FDE68A; }
.bg-danger-subtle    { background: var(--red-soft) !important; }

/* ---------- stats ---------- */

.stat-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--ink-muted);
    font-weight: 600;
}
.stat {
    font-size: 26px;
    font-weight: 600;
    line-height: 1.15;
    color: var(--navy-900);
    font-variant-numeric: tabular-nums;
    margin-top: 3px;
}
/* No colour on figures: a coloured number reads as "this number is wrong".
   Colour belongs on the alert that explains the problem. */

/* ---------- tables ---------- */

.table { color: var(--ink); margin-bottom: 0; }
.table > :not(caption) > * > * { border-bottom-color: var(--line); }
.table thead th, .table-light th, .table-light td {
    background: #FAFAF8;
    color: var(--ink-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--line);
}
.table-sheet th, .table-sheet td { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
.table-hover tbody tr:hover > *          { background: #FAFAF8; }
.table-striped tbody tr:nth-of-type(odd) > * { background: #FCFCFB; }
tfoot td { background: #FAFAF8; }

/* ---------- buttons ---------- */

.btn { border-radius: 6px; font-size: 13.5px; font-weight: 500; transition: all .15s ease-out; }
.btn-sm { font-size: 12.5px; padding: .32rem .65rem; }

/* One emerald action per screen: the primary one. */
.btn-dark, .btn-primary {
    background: var(--emerald); border-color: var(--emerald); color: #fff;
}
.btn-dark:hover, .btn-primary:hover {
    background: var(--emerald-dark); border-color: var(--emerald-dark); color: #fff;
}
.btn-outline-dark {
    border-color: var(--line); color: var(--navy-900); background: var(--surface);
}
.btn-outline-dark:hover { background: #F3F4F6; border-color: #D1D5DB; color: var(--navy-900); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-outline-danger { border-color: #FCA5A5; color: var(--red); background: var(--surface); }
.btn-outline-danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn-outline-light { border-color: rgba(255,255,255,.25); color: rgba(255,255,255,.9); }
.btn-outline-light:hover { background: rgba(255,255,255,.1); color: #fff; }
.btn-link { color: var(--navy-700); font-weight: 400; }

/* ---------- chips ---------- */

.badge {
    font-weight: 500;
    font-size: 11px;
    padding: .3em .65em;
    border-radius: 100px;
    border: 1px solid var(--line);
    background: var(--surface) !important;
    color: var(--ink-muted) !important;
}
.badge::before {
    content: "";
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    margin-right: 5px;
    background: currentColor;
    vertical-align: middle;
}
.badge.bg-success   { color: var(--emerald) !important;  border-color: #A7F3D0; }
.badge.bg-warning   { color: var(--amber) !important;    border-color: #FDE68A; }
.badge.bg-danger    { color: var(--red) !important;      border-color: #FECACA; }
.badge.bg-secondary { color: var(--ink-muted) !important; }

/* ---------- alerts ---------- */

.alert {
    border-radius: var(--radius);
    border: 1px solid var(--line);
    border-left-width: 3px;
    font-size: 13.5px;
    padding: 12px 14px;
}
.alert-warning { background: var(--amber-soft);   border-left-color: var(--amber);   color: #78350F; }
.alert-danger  { background: var(--red-soft);     border-left-color: var(--red);     color: #7F1D1D; }
.alert-success { background: var(--emerald-soft); border-left-color: var(--emerald); color: #064E3B; }
.alert-info    { background: #F1F5F9;             border-left-color: var(--navy-700); color: var(--navy-900); }
.alert a { color: inherit; font-weight: 600; }

/* ---------- forms ---------- */

.form-label { font-size: 12.5px; font-weight: 500; margin-bottom: 4px; }
.form-control, .form-select { border-color: var(--line); border-radius: 6px; font-size: 13.5px; }
.form-control:focus, .form-select:focus {
    border-color: var(--navy-700);
    box-shadow: 0 0 0 3px rgba(29,48,84,.12);
}
.form-text { font-size: 11.5px; color: var(--ink-muted); }
.form-control-sm, .form-select-sm { font-size: 12.5px; }

/* ---------- print ---------- */
/* The sheet and payslips are printed and signed. */

@media print {
    .sidebar, .topbar, .btn, .alert, form { display: none !important; }
    .layout { display: block; }
    .content { padding: 0; }
    body { background: #fff; font-size: 11px; }
    .card { border: none; box-shadow: none; }
    .table thead { display: table-header-group; }
    a { text-decoration: none; color: #000; }
}

/* ---------- phone ---------- */
/*
 * The admin works on a desktop, but the app gets opened on a phone to check a
 * figure. Below 900px the sidebar becomes a drawer behind a button, tables
 * scroll inside their card instead of pushing the page sideways, and every
 * tappable thing is at least 44px.
 */

.mobile-bar { display: none; }
#navToggle { display: none; }   /* hidden at every width; only the label is visible */

@media (max-width: 900px) {
    .layout { display: block; }

    /* Top bar with the crest and a menu toggle. */
    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        background: var(--navy-900);
        padding: 10px 14px;
        position: sticky;
        top: 0;
        z-index: 40;
    }
    .mobile-bar img { width: 30px; height: 30px; object-fit: contain;
        background: #fff; border-radius: 5px; padding: 2px; }
    .mobile-bar .name { color: #fff; font-weight: 600; font-size: 14px; }
    .mobile-bar label {
        margin-left: auto;
        color: #fff;
        border: 1px solid rgba(255,255,255,.3);
        border-radius: 6px;
        padding: 7px 12px;
        font-size: 13px;
        min-height: 40px;
        display: flex;
        align-items: center;
        cursor: pointer;
    }

    /* Drawer, opened by a checkbox so it needs no JavaScript. */
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        padding: 8px 12px 14px;
        display: none;
    }
    #navToggle:checked ~ .sidebar { display: block; }
    .sidebar-brand { display: none; }
    .sidebar .nav-link { padding: 12px 12px; font-size: 15px; min-height: 44px; }
    .sidebar-foot { margin-top: 10px; }

    .topbar { padding: 10px 16px; font-size: 13px; }
    .content { padding: 14px; }

    .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
    .page-head .btn, .page-head .d-flex { width: 100%; }
    .page-head .d-flex .btn { flex: 1 1 0; }

    /* Tables scroll inside the card, with a hint that they do. */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        background:
            linear-gradient(90deg, var(--surface) 30%, rgba(255,255,255,0)),
            linear-gradient(90deg, rgba(255,255,255,0), var(--surface) 70%) 100% 0,
            radial-gradient(farthest-side at 0 50%, rgba(17,24,39,.12), transparent),
            radial-gradient(farthest-side at 100% 50%, rgba(17,24,39,.12), transparent) 100% 0;
        background-repeat: no-repeat;
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-attachment: local, local, scroll, scroll;
    }
    .table-sheet th, .table-sheet td { font-size: 13px; padding: 10px 10px; }

    /* Two stats per row reads better than four squashed ones. */
    .stat { font-size: 22px; }

    /* Tap targets. */
    .btn { min-height: 40px; padding: .5rem .8rem; }
    .btn-sm { min-height: 38px; }
    .form-control, .form-select { min-height: 42px; font-size: 16px; } /* 16px stops iOS zooming on focus */
    .form-control-sm, .form-select-sm { min-height: 38px; font-size: 15px; }

    /* Inline row forms (recording payments) stack instead of squeezing. */
    .table-sheet form.d-flex { flex-wrap: wrap; gap: 6px !important; }
    .table-sheet form.d-flex .form-control { width: 100% !important; }

    .next-step { flex-direction: column; align-items: stretch; }
    .next-step .spacer { display: none; }
    .next-step .btn { width: 100%; }

    .steps { font-size: 11px; }
    .steps .sep { display: none; }
}

@media (max-width: 480px) {
    .content { padding: 12px 10px; }
    .card-body { padding: 12px; }
    .stat { font-size: 20px; }
}
