/* --- Theme tokens ---------------------------------------------------------
   Every brandable colour in this stylesheet lives here. The values below are
   the stock palette; a white-label deployment overrides any of them from a
   later `<style>:root{...}</style>` block (see app/branding.php), so nothing
   downstream should hard-code a colour again.
   -------------------------------------------------------------------------- */
:root {
    /* Accent used for the active nav pill and any brand-tinted chrome. */
    --sms-brand: #602874;

    /* App shell */
    --sms-body-bg: #f1f5f9;

    /* Sidebar */
    --sms-sidebar-bg: #1e293b;
    --sms-sidebar-fg: #cbd5e1;
    --sms-sidebar-muted: #94a3b8;
    --sms-sidebar-hover-fg: #fff;
    --sms-sidebar-hover-bg: rgba(255, 255, 255, .08);
    --sms-sidebar-active: var(--sms-brand);
    --sms-sidebar-active-fg: #fff;
    --sms-sidebar-border: rgba(255, 255, 255, .1);

    /* Geometry */
    --sms-sidebar-width: 260px;
    --sms-sidebar-rail: 76px;
}

body {
    background-color: var(--sms-body-bg);
    min-height: 100vh;
}

#app-wrapper {
    min-height: 100vh;
}

.sidebar {
    width: var(--sms-sidebar-width);
    background-color: var(--sms-sidebar-bg);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width .2s ease;
}

.sidebar .nav-link {
    color: var(--sms-sidebar-fg);
    border-radius: .5rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.sidebar .nav-link:hover {
    color: var(--sms-sidebar-hover-fg);
    background-color: var(--sms-sidebar-hover-bg);
}

.sidebar .nav-link.active {
    background-color: var(--sms-sidebar-active);
    color: var(--sms-sidebar-active-fg);
}

/* Fixed-width icon column keeps labels aligned and lets them fade out cleanly
   when the sidebar rails down to icons only. */
.sidebar .nav-icon {
    flex: 0 0 1.5rem;
    text-align: center;
    margin-right: .5rem;
}

.sidebar-toggle {
    color: var(--sms-sidebar-muted);
    border: 0;
    padding: .25rem .4rem;
    line-height: 1;
}

.sidebar-toggle:hover {
    color: var(--sms-sidebar-hover-fg);
    background-color: var(--sms-sidebar-hover-bg);
}

/* --- Accordion groups --- */

.nav-group-toggle {
    background: none;
    border: 0;
    letter-spacing: .04em;
    color: var(--sms-sidebar-muted);
}

.nav-group-toggle:hover {
    color: var(--sms-sidebar-hover-fg);
}

.nav-group-caret {
    transition: transform .2s ease;
}

.nav-group-toggle[aria-expanded="true"] .nav-group-caret {
    transform: rotate(180deg);
}

.nav-group-items {
    margin-left: .5rem;
    border-left: 1px solid var(--sms-sidebar-border);
    padding-left: .25rem;
}

.content-area {
    max-width: calc(100% - var(--sms-sidebar-width));
    transition: max-width .2s ease;
}

/* --- Collapsed rail (desktop) --- */

html.sidebar-collapsed .sidebar {
    width: var(--sms-sidebar-rail);
}

html.sidebar-collapsed .content-area {
    max-width: calc(100% - var(--sms-sidebar-rail));
}

html.sidebar-collapsed .sidebar-label {
    display: none !important;
}

html.sidebar-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

html.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding-left: .5rem;
    padding-right: .5rem;
}

html.sidebar-collapsed .sidebar .nav-icon {
    margin-right: 0;
    font-size: 1.15rem;
}

/* With the group headers hidden there is nothing left to expand, so every
   group is forced open - the rail is a flat icon list. */
html.sidebar-collapsed .nav-group-items {
    display: block !important;
    height: auto !important;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
}

html.sidebar-collapsed .nav-group + .nav-group {
    border-top: 1px solid var(--sms-sidebar-border);
    margin-top: .35rem;
    padding-top: .35rem;
}

html.sidebar-collapsed .sidebar .dropdown-toggle::after {
    display: none;
}

/* 76px leaves no room for the logo and the toggle side by side. */
html.sidebar-collapsed .sidebar-brand-row {
    flex-direction: column;
    gap: .5rem;
}

html.sidebar-collapsed .sidebar-brand-row > a {
    justify-content: center;
    flex-grow: 0 !important;
}

/* --- Mobile drawer --- */

.topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 1030;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1040;
}

.card {
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.stat-card .icon-box {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .75rem;
    font-size: 1.4rem;
}

.table > :not(caption) > * > * {
    vertical-align: middle;
}

/* --- Branding -------------------------------------------------------------
   Hooks for the white-label logo. No existing markup carries these classes,
   so they are inert until the logo is wired into a template. */

/* Uploaded logos vary wildly in aspect ratio, so cap the height and let the
   width follow: a wide wordmark and a square crest then share one row. */
.brand-logo {
    max-height: 40px;
    max-width: 100%;
    width: auto;
    object-fit: contain;
}

html.sidebar-collapsed .brand-logo {
    max-height: 32px;
}

.text-brand {
    color: var(--sms-brand) !important;
}

.bg-brand {
    background-color: var(--sms-brand) !important;
    color: #fff;
}

@media (max-width: 991.98px) {
    #app-wrapper {
        flex-direction: column;
    }
    .topbar {
        display: flex;
    }
    /* Off-canvas: the rail state is a desktop concept, so override it here. */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: var(--sms-sidebar-width) !important;
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 1045;
    }
    html.sidebar-open .sidebar {
        transform: none;
    }
    html.sidebar-open .sidebar-backdrop {
        display: block;
    }
    .content-area,
    html.sidebar-collapsed .content-area {
        max-width: 100%;
    }
    /* Labels and groups always show in the drawer, even if railed on desktop. */
    html.sidebar-collapsed .sidebar-label {
        display: revert !important;
    }
    html.sidebar-collapsed .sidebar .nav-link {
        justify-content: flex-start;
    }
    html.sidebar-collapsed .sidebar .nav-icon {
        margin-right: .5rem;
    }
    html.sidebar-collapsed .nav-group-items {
        display: none !important;
    }
    html.sidebar-collapsed .nav-group-items.show {
        display: block !important;
    }
    html.sidebar-collapsed .nav-group + .nav-group {
        border-top: 0;
        margin-top: 0;
        padding-top: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .content-area,
    .nav-group-caret {
        transition: none;
    }
}

/* --- Parent portal --------------------------------------------------------
   The guardians' shell shares the brand colour but none of the app chrome:
   no sidebar, one bar across the top, and a pill row for families with more
   than one child at the school.
   -------------------------------------------------------------------------- */
.portal-bar {
    background-color: var(--sms-sidebar-bg);
}

.portal-bar .navbar-brand,
.portal-bar .portal-user {
    color: #fff;
}

.portal-bar .nav-link {
    color: var(--sms-sidebar-fg);
    border-radius: .375rem;
    padding-inline: .65rem;
}

.portal-bar .nav-link:hover,
.portal-bar .nav-link:focus {
    color: var(--sms-sidebar-hover-fg);
    background-color: var(--sms-sidebar-hover-bg);
}

.portal-bar .nav-link.active {
    color: var(--sms-sidebar-active-fg);
    background-color: var(--sms-sidebar-active);
}

.portal-bar .navbar-toggler {
    border-color: var(--sms-sidebar-border);
}

.child-switch .nav-link {
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, .08);
    color: inherit;
}

.child-switch .nav-link.active {
    background-color: var(--sms-brand);
    border-color: var(--sms-brand);
    color: #fff;
}

/* Bootstrap has no min-width utility; flex children need one to truncate. */
.min-w-0 {
    min-width: 0;
}

/* --- Operator console ------------------------------------------------------
   Visibly not a school. The bar is near-black rather than the brand colour,
   because branding here is white-labelled per school and the control plane
   belongs to the vendor - it should look like a different building.
   -------------------------------------------------------------------------- */
.platform-bar {
    background-color: #0f172a;
}

.platform-bar .navbar-brand,
.platform-bar .platform-user {
    color: #fff;
}

.platform-bar .nav-link {
    color: #cbd5e1;
    border-radius: .375rem;
    padding-inline: .65rem;
}

.platform-bar .nav-link:hover,
.platform-bar .nav-link:focus {
    color: #fff;
    background-color: rgba(255, 255, 255, .08);
}

.platform-bar .nav-link.active {
    color: #fff;
    background-color: rgba(255, 255, 255, .16);
}

.platform-bar .navbar-toggler {
    border-color: rgba(255, 255, 255, .2);
}

.platform-login {
    min-height: 100vh;
    background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
}

/* Reports and other printable pages: drop the app chrome, keep the content */
@media print {
    .sidebar,
    .topbar,
    .sidebar-backdrop,
    .no-print {
        display: none !important;
    }
    .content-area,
    html.sidebar-collapsed .content-area {
        max-width: 100%;
        padding: 0 !important;
    }
    .content-area > .p-4 {
        padding: 0 !important;
    }
    .card {
        border: 1px solid #dee2e6 !important;
        box-shadow: none !important;
        break-inside: avoid;
    }
    a[href]::after {
        content: none !important;
    }
}

/* ---------------------------------------------------------------------------
   DV Soft accent.

   Bootstrap ships its own blue, and setting --sms-brand alone does not reach it:
   in Bootstrap 5.3 each component reads its own --bs-btn-* variables, so the
   primary button, links, pagination and focus rings all stayed blue. These
   overrides bring them onto the brand colour from dvsoft.in.

   A school's own branding still wins - app/branding.php emits a later :root
   block, and --sms-brand is what the sidebar and nav pill follow.
   -------------------------------------------------------------------------- */
:root {
    --bs-primary: #602874;
    --bs-primary-rgb: 96, 40, 116;
    --bs-link-color: #602874;
    --bs-link-color-rgb: 96, 40, 116;
    --bs-link-hover-color: #4a1d58;
    --bs-link-hover-color-rgb: 74, 29, 88;
}

.btn-primary {
    --bs-btn-bg: #602874;
    --bs-btn-border-color: #602874;
    --bs-btn-hover-bg: #4a1d58;
    --bs-btn-hover-border-color: #4a1d58;
    --bs-btn-active-bg: #4a1d58;
    --bs-btn-active-border-color: #4a1d58;
    --bs-btn-disabled-bg: #602874;
    --bs-btn-disabled-border-color: #602874;
}

.btn-outline-primary {
    --bs-btn-color: #602874;
    --bs-btn-border-color: #602874;
    --bs-btn-hover-bg: #602874;
    --bs-btn-hover-border-color: #602874;
    --bs-btn-active-bg: #602874;
    --bs-btn-active-border-color: #602874;
}

.text-primary { color: #602874 !important; }
.bg-primary { background-color: #602874 !important; }
.text-bg-primary { background-color: #602874 !important; color: #fff !important; }
.badge.bg-primary { background-color: #602874 !important; }
.bg-primary-subtle { background-color: #f3ecf7 !important; }
.text-primary-emphasis { color: #4a1d58 !important; }
.border-primary { border-color: #602874 !important; }

.page-link { color: #602874; }
.page-item.active .page-link { background-color: #602874; border-color: #602874; }

.form-control:focus,
.form-select:focus {
    border-color: #b58cce;
    box-shadow: 0 0 0 .25rem rgba(96, 40, 116, .18);
}
.form-check-input:checked { background-color: #602874; border-color: #602874; }
.form-check-input:focus { border-color: #b58cce; box-shadow: 0 0 0 .25rem rgba(96, 40, 116, .18); }
