/* ============================================================
   School Database System — modern UI
   Left sidebar layout, Inter font, soft shadows, green brand.
   ============================================================ */

:root {
    --brand-700: #1f6d2c;
    --brand-600: #2f8f3e;
    --brand-500: #3fa84f;
    --brand-400: #5cbf6c;
    --brand-50:  #eef8ef;
    --ink-900: #1c2430;
    --ink-700: #3a4553;
    --ink-500: #6b7688;
    --ink-300: #b0b9c6;
    --surface: #ffffff;
    --bg: #f3f5f8;
    --border: #e4e8ee;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 76px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    background-color: var(--bg);
    color: var(--ink-900);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: "Inter", sans-serif;
    letter-spacing: -0.01em;
}

a { text-decoration: none; }

/* ---------------------------------------------------------- */
/* App shell layout                                           */
/* ---------------------------------------------------------- */
#app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.45);
    z-index: 1030;
}
.sidebar-overlay.show { display: block; }

/* ---------------------------------------------------------- */
/* Sidebar                                                     */
/* ---------------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.18s ease, flex-basis 0.18s ease, transform 0.25s ease;
    z-index: 1040;
    scrollbar-width: thin;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: linear-gradient(160deg, var(--brand-500), var(--brand-700));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.sidebar-brand-logo {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background: #fff;
    box-shadow: var(--shadow-sm);
    padding: 2px;
}

.sidebar-brand-text {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.25;
    color: var(--ink-900);
}
.sidebar-brand-text small {
    font-weight: 500;
    color: var(--ink-500);
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sidebar-nav {
    padding: 14px 12px 24px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-link,
.sidebar-group-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-700);
    font-weight: 500;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    text-align: left;
    white-space: nowrap;
}

.sidebar-link i,
.sidebar-group-toggle i:first-child {
    font-size: 1.05rem;
    width: 22px;
    flex: 0 0 22px;
    text-align: center;
    color: var(--ink-500);
}

.sidebar-link:hover,
.sidebar-group-toggle:hover {
    background: var(--brand-50);
    color: var(--brand-700);
}
.sidebar-link:hover i,
.sidebar-group-toggle:hover i:first-child {
    color: var(--brand-600);
}

.sidebar-link.active,
.sidebar-group-toggle.active {
    background: linear-gradient(90deg, var(--brand-600), var(--brand-500));
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.sidebar-link.active i,
.sidebar-group-toggle.active i:first-child {
    color: #fff;
}

.sidebar-group-toggle span:not(.chevron) { flex: 1; }
.sidebar-group-toggle .chevron {
    font-size: 0.75rem;
    width: auto;
    flex: 0 0 auto;
    transition: transform 0.2s ease;
    color: inherit;
    opacity: 0.7;
}
.sidebar-group-toggle[aria-expanded="true"] .chevron,
.sidebar-group-toggle:not(.collapsed) .chevron {
    transform: rotate(180deg);
}

.sidebar-sublink {
    display: block;
    padding: 8px 12px 8px 46px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--ink-500);
    font-weight: 500;
}
.sidebar-sublink:hover {
    background: var(--brand-50);
    color: var(--brand-700);
}

/* Collapsed (desktop, icon-only) state */
#app-shell.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-w-collapsed);
    flex-basis: var(--sidebar-w-collapsed);
}
#app-shell.sidebar-collapsed .sidebar-brand-text,
#app-shell.sidebar-collapsed .sidebar-link span,
#app-shell.sidebar-collapsed .sidebar-group-toggle span,
#app-shell.sidebar-collapsed .sidebar-group-toggle .chevron {
    display: none;
}
#app-shell.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 20px 10px; }
#app-shell.sidebar-collapsed .sidebar-link,
#app-shell.sidebar-collapsed .sidebar-group-toggle { justify-content: center; }
#app-shell.sidebar-collapsed .collapse { display: none !important; }

/* ---------------------------------------------------------- */
/* Topbar + content                                            */
/* ---------------------------------------------------------- */
.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.sidebar-toggle-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-700);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}
.sidebar-toggle-btn:hover { background: var(--brand-50); color: var(--brand-700); }

.topbar-search {
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 14px;
    width: 260px;
    color: var(--ink-500);
}
.topbar-search input { background: transparent; font-size: 0.85rem; }
.topbar-search input:focus { box-shadow: none; }

.avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand-50);
    color: var(--brand-700);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-content {
    flex: 1 1 auto;
}

/* Mobile: sidebar becomes an off-canvas drawer */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    #app-shell.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-w);
        flex-basis: var(--sidebar-w);
    }
    #app-shell.sidebar-collapsed .sidebar-brand-text,
    #app-shell.sidebar-collapsed .sidebar-link span,
    #app-shell.sidebar-collapsed .sidebar-group-toggle span,
    #app-shell.sidebar-collapsed .sidebar-group-toggle .chevron {
        display: inline;
    }
    #app-shell.sidebar-collapsed .collapse.show { display: block !important; }
}

/* ---------------------------------------------------------- */
/* Banner + dashboard                                          */
/* ---------------------------------------------------------- */
.school-banner {
    background: linear-gradient(135deg, #ffffff 0%, var(--brand-50) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 20px;
}

.school-banner h1 {
    color: var(--brand-700);
    font-weight: 800;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
}

.dash-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-700);
    font-weight: 600;
    font-size: 0.88rem;
    text-decoration: none;
    text-align: center;
    border-radius: var(--radius-md);
    padding: 24px 10px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.dash-btn i {
    font-size: 1.6rem;
    color: var(--brand-600);
    transition: color 0.15s ease;
}

.dash-btn:hover {
    color: #fff;
    background: linear-gradient(160deg, var(--brand-500), var(--brand-700));
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.dash-btn:hover i { color: #fff; }

/* ---------------------------------------------------------- */
/* Cards, tables, forms — general modernization                */
/* ---------------------------------------------------------- */
.card {
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.card-header {
    border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
    font-weight: 600;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.88rem;
}
.btn-primary,
.btn-success {
    background: linear-gradient(160deg, var(--brand-500), var(--brand-700));
    border: none;
}
.btn-primary:hover,
.btn-success:hover {
    background: linear-gradient(160deg, var(--brand-600), var(--brand-700));
}
.btn-outline-primary {
    color: var(--brand-700);
    border-color: var(--brand-500);
}
.btn-outline-primary:hover {
    background: var(--brand-600);
    border-color: var(--brand-600);
}

.table {
    --bs-table-bg: transparent;
}
.table thead th {
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    color: var(--ink-500);
    border-bottom-width: 1px;
    background: var(--bg);
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 0.2rem rgba(63, 168, 79, 0.15);
}

.badge { font-weight: 600; font-size: 0.72rem; }

/* ---------- Print support ----------
   Any page that wants a clean printout wraps its content in
   <div class="print-area"> ... </div> and adds a "no-print" class to
   buttons/forms/filters that shouldn't appear on paper. The app chrome
   (sidebar, topbar) is hidden automatically. */
@media print {
    .app-sidebar,
    .app-topbar,
    .sidebar-overlay,
    .no-print {
        display: none !important;
    }

    #app-shell, .app-main {
        display: block !important;
    }

    body {
        background: #ffffff !important;
    }

    .app-content {
        padding: 0 !important;
    }

    .print-area {
        box-shadow: none !important;
        border: none !important;
    }
}

/* ---------------------------------------------------------- */
/* Mobile fixes (phones & small tablets)                       */
/* Applies across ALL views automatically — no per-page edits  */
/* needed for these common patterns.                           */
/* ---------------------------------------------------------- */
@media (max-width: 767.98px) {

    /* Never allow the page itself to scroll sideways */
    html, body { max-width: 100%; overflow-x: hidden; }

    /* Give content some breathing room but not the desktop amount */
    .app-content { padding: 16px !important; }

    .app-topbar { padding: 0 12px; gap: 10px; }

    /* Page header rows: "Title ......... [Button]" now wrap instead
       of squeezing the button off-screen */
    .app-content > .d-flex.justify-content-between,
    .app-content > .d-flex.justify-content-between.align-items-center {
        flex-wrap: wrap;
        row-gap: 10px;
    }
    .app-content h1, .app-content h2, .app-content h3, .app-content h4 {
        font-size: 1.15rem;
    }

    /* Any element with a hard-coded desktop pixel width (search boxes,
       dropdown filters, date pickers, etc.) becomes fluid on phones */
    .form-control, .form-select {
        width: 100% !important;
        max-width: 100%;
    }

    /* Filter bars built as <form class="row g-2"><div class="col-auto">
       so each filter/input stacks full-width and is easy to tap */
    form.row .col-auto {
        width: 100%;
    }

    /* Small inline inputs that live INSIDE table cells (mark entry,
       roll no, per-row date pickers) must stay compact or the table
       becomes unusable — exempt them from the full-width rule above */
    table .form-control,
    table .form-select,
    .mark-input {
        width: 100% !important;
        min-width: 64px;
    }

    /* Button groups / action bars wrap instead of overflowing */
    .btn-group { flex-wrap: wrap; }
    .app-content .d-flex.gap-2,
    .app-content .d-flex.gap-3 {
        flex-wrap: wrap;
    }

    /* Dashboard quick-links: smaller tiles so 2 fit per row */
    .dashboard-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }
    .dash-btn { padding: 16px 8px; font-size: 0.8rem; }
    .dash-btn i { font-size: 1.3rem; }

    .school-banner { padding: 20px 14px; }
    .school-banner h1 { font-size: 1.4rem; }

    /* Cards: tighten padding a little */
    .card-body { padding: 14px; }

    /* dl.row detail pairs (Student/Staff Details pages) already stack
       via Bootstrap's col-sm-*, this just tightens the spacing */
    dl.row dt { margin-top: 6px; }

    /* Tables: slightly smaller text so more columns fit before the
       table-responsive scrollbar kicks in */
    .table { font-size: 0.82rem; }
    .table thead th { font-size: 0.68rem; }
}

@media (max-width: 420px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------------------------------------------------------- */
/* Auth pages (login, forgot/reset password)                  */
/* ---------------------------------------------------------- */
.auth-body {
    background: linear-gradient(160deg, var(--brand-700), var(--brand-500));
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-wrap {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px 28px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.auth-brand .sidebar-brand-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--brand-50);
    color: var(--brand-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.auth-brand-logo {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    padding: 2px;
}

@media (max-width: 420px) {
    .auth-body { padding: 14px; }
    .auth-card { padding: 22px 18px; }
}
