/* =====================================================================
   File: public/assets/css/app.css
   Project: OSRTC Bus Co-Maintenance Monitoring
   Purpose: Core layout shell — sidebar + topbar + content. Mobile first.
   ===================================================================== */

:root {
    --sidebar-width: 240px;
    --sidebar-bg:    #1f2937;
    --sidebar-fg:    #cbd5e1;
    --sidebar-fg-active: #ffffff;
    --topbar-h:      56px;
    --content-bg:    #f3f4f6;
}

html, body {
    height: 100%;
    background: var(--content-bg);
}

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

/* ---- Sidebar ---- */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform .25s ease;
    z-index: 1000;
}

.app-brand {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;       /* logo has a transparent / light background — give it a frame */
    min-height: 64px;
}
.app-brand i { color: #60a5fa; font-size: 1.4rem; }
.app-brand .brand-logo {
    max-height: 56px;
    width: auto;
    display: block;
    object-fit: contain;
}

.app-nav {
    padding: .75rem 0;
    flex-grow: 1;
}
.app-nav .nav-link {
    color: var(--sidebar-fg);
    padding: .65rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    border-left: 3px solid transparent;
    text-decoration: none;
    font-size: .95rem;
}
.app-nav .nav-link:hover {
    color: var(--sidebar-fg-active);
    background: rgba(255,255,255,.04);
}
.app-nav .nav-link.active {
    color: var(--sidebar-fg-active);
    background: rgba(96,165,250,.1);
    border-left-color: #60a5fa;
}
.app-nav .nav-link.disabled {
    opacity: .55;
    cursor: not-allowed;
}
.app-nav .nav-link i {
    font-size: 1.1rem;
    min-width: 1.5rem;
}

/* ---- Main column ---- */
.app-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-topbar {
    height: var(--topbar-h);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,.03);
}

.app-content {
    flex-grow: 1;
    padding: 1.5rem;
    background: var(--content-bg);
}

.app-footer {
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

/* ---- Stat cards ---- */
.stat-card .card-body {
    padding: 1rem;
}
.stat-card .stat-label {
    font-size: .8rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .25rem;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1;
}

/* ---- Login page ---- */
.login-page {
    background: linear-gradient(135deg, #e0f2fe 0%, #f1f5f9 100%);
}
.login-card {
    border: 0;
    border-radius: .75rem;
}



/* ---- Color-coded status pill (used in Session 3 dashboard) ---- */
.status-pill {
    display: inline-block;
    padding: .15rem .6rem;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #fff;
    border-radius: 999px;
    letter-spacing: .03em;
}

/* ---- Bus tile (Session 3) ---- */
.bus-tile {
    border-left: 4px solid #6c757d;
    padding: .75rem 1rem;
    background: #fff;
    border-radius: .375rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
    transition: transform .15s ease;
}
.bus-tile:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,.08);
}

/* ---- Flash animation for critical alerts ---- */
@keyframes pulse-red {
    0%   { box-shadow: 0 0 0 0 rgba(220,53,69,.55); }
    70%  { box-shadow: 0 0 0 12px rgba(220,53,69,0); }
    100% { box-shadow: 0 0 0 0 rgba(220,53,69,0); }
}
.alert-flash {
    animation: pulse-red 1.4s infinite;
}


/* === Session 5a: prominent logo + auto-collapse sidebar === */

/* Prominent logo on desktop (wide sidebar) */
.app-brand {
    padding: 0.5rem 0.5rem 0.25rem;               /* tight: just a touch of breathing room */
    min-height: 0;                                /* shrink to fit logo */
    background: var(--sidebar-bg);
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-brand .brand-logo {
    max-height: none;
    max-width: 100%;                              /* logo fills the white pill */
    width: 100%;
    height: auto;
    background: #fff;
    padding: 0;                                   /* no padding — logo touches pill edges */
    border-radius: 10px;
    box-shadow: 0 0 16px rgba(255,255,255,0.18),
                0 2px 4px rgba(0,0,0,0.25);
}

/* Pull the nav block tighter against the brand block */
.app-nav {
    padding-top: 0.25rem;
}

/* Nav label wrapper — visible by default (wide sidebar) */
.app-nav .nav-link .nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Auto-collapse to icon-strip below 992px (Bootstrap lg) ---- */
@media (max-width: 991.98px) {
    :root {
        --sidebar-width: 72px;
    }
    .app-sidebar {
        width: 72px;
        position: static;          /* override any inherited mobile-slide rules */
        transform: none;
        box-shadow: none;
    }
    .app-sidebar.open {            /* open class is now meaningless */
        transform: none;
    }

    /* Shrink the brand block; logo fits the narrow column */
    .app-brand {
        padding: 0.5rem 0.25rem;
        min-height: 64px;
    }
    .app-brand .brand-logo {
        max-width: 90%;
        max-height: 48px;
    }

    /* Hide labels and badges, keep icons centered */
    .app-nav .nav-link {
        justify-content: center;
        padding: 0.75rem 0.25rem;
        gap: 0;
        position: relative;
    }
    .app-nav .nav-link .nav-label,
    .app-nav .nav-link .badge {
        display: none;
    }
    .app-nav .nav-link i {
        min-width: 0;
        font-size: 1.3rem;          /* icons a touch larger to compensate */
    }
    .app-nav .nav-link.active {
        border-left-width: 4px;
    }

    /* Hide the mobile toggle button — collapsed sidebar is always visible */
    #sidebarToggle {
        display: none !important;
    }

    .app-content {
        padding: 1rem;
    }
}

/* Smooth resize transition on width change at the breakpoint */
.app-sidebar,
.app-brand,
.app-nav .nav-link {
    transition: width 200ms ease, padding 200ms ease, min-height 200ms ease;
}

/* === Session 5b: bus image card + clickable HO cards === */

/* HO Dashboard stat cards — make them obviously clickable */
.stat-card-link {
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}
.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
    text-decoration: none;
}
.stat-card-link:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.stat-card .stat-card-cta {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.85;
}

/* Bus profile image card */
.bus-image-card .bus-image-frame {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 0.75rem;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bus-image-card .bus-image {
    max-height: 280px;
    width: auto;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.bus-image-card .bus-image-placeholder {
    text-align: center;
    color: #9ca3af;
}
.bus-image-card .bus-image-placeholder i {
    font-size: 2.4rem;
}
.bus-image-card .bus-image-preview {
    max-height: 200px;
    border-radius: 6px;
    border: 2px dashed #cbd5e1;
    padding: 4px;
}

/* === Session 6: consolidated TV + QR sheet === */

/* ---- Consolidated TV cells ---- */
.bus-cell-consolidated,
.bus-cell-consolidated:hover,
.bus-cell-consolidated:focus,
.bus-cell-consolidated:active,
.bus-cell-consolidated:visited {
    text-decoration: none !important;
}
.bus-cell-consolidated {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 0.6rem 0.7rem;
    border-radius: 6px;
    color: #fff;
    min-height: 80px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    transition: transform 80ms ease, box-shadow 80ms ease;
    overflow: hidden;
    cursor: pointer;
}
.bus-cell-consolidated:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.bus-cell-consolidated .cell-reg {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    line-height: 1.15;
    text-decoration: none;
}
.bus-cell-consolidated .cell-status {
    font-size: 0.78rem;
    opacity: 0.95;
    margin-top: 0.3rem;
    line-height: 1.15;
    text-decoration: none;
}

/* ---- SOS visual: red circle + red-bordered reg pill, side-by-side, white bg ---- */
.bus-cell-consolidated.has-sos {
    background: #fff !important;
    border: 2px solid #dc2626;
    flex-direction: row;          /* side-by-side */
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.7rem;
    color: #dc2626;
}
.bus-cell-consolidated.has-sos .sos-circle {
    background: #dc2626;
    color: #fff;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px #dc2626;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.95rem;
    flex-shrink: 0;
    animation: sos-pulse-anim 1s ease-in-out infinite;
    text-decoration: none;
}
.bus-cell-consolidated.has-sos .sos-pill {
    flex: 1;
    padding: 0.45rem 0.55rem;
    border: 2px solid #dc2626;
    border-radius: 10px;
    text-align: center;
    color: #dc2626;
    font-weight: 700;
    font-size: 0.92rem;
    background: #fff;
    text-decoration: none;
    line-height: 1.15;
}

@keyframes sos-pulse-anim {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Long-stuck (>=48h) blinking */
.bus-cell-consolidated.blink {
    animation: cell-blink 1.8s ease-in-out infinite;
}
@keyframes cell-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* Print: hide the topbar/sidebar entirely when printing the QR sheet */
@media print {
    .app-topbar,
    .app-sidebar,
    .app-footer,
    .d-print-none {
        display: none !important;
    }
    .app-content,
    .app-main,
    .app-shell {
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }
}

/* === Session 6.5: accident image album + repair photo + TV chooser === */

/* Accident evidence images — thumbnail grid */
.accident-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
}
.accident-image-tile {
    position: relative;
    aspect-ratio: 3 / 2;
    overflow: hidden;
    border-radius: 6px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
}
.accident-image-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
    transition: transform 120ms ease;
}
.accident-image-tile img:hover {
    transform: scale(1.05);
}
.accident-image-delete-form {
    position: absolute;
    top: 2px;
    right: 2px;
    margin: 0;
    background: rgba(255,255,255,0.85);
    border-radius: 50%;
    line-height: 1;
    padding: 0 2px;
}
.accident-image-delete-form .btn {
    font-size: 1rem;
    line-height: 1;
}

/* Repair photo card */
.bus-repair-photo-card .repair-photo-frame {
    background: #fff8e1;
    border-radius: 8px;
    padding: 0.75rem;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bus-repair-photo-card .repair-photo {
    max-height: 260px;
    width: auto;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.bus-repair-photo-card .repair-photo-placeholder {
    text-align: center;
    color: #b45309;
}
.bus-repair-photo-card .repair-photo-placeholder i {
    font-size: 2.4rem;
}

/* TV chooser modal — buttons */
.tv-choose-btn {
    padding: 1rem 1.25rem;
    transition: background-color 100ms ease, transform 100ms ease;
}
.tv-choose-btn:hover {
    transform: translateX(2px);
}

/* === Session 6.6: TV consolidated polish + bus profile photo === */

/* Fix #1: Consolidated TV footer text was invisible (text-muted on dark) */
.tv-consolidated-page footer,
.tv-consolidated-page .footer,
body.kiosk-mode footer.text-muted,
#consolidatedTvFooter {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Fix #2a: TV Dash 2 topbar — smaller and aligned */
.tv-consolidated-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.tv-consolidated-topbar .topbar-date-clock {
    font-size: 0.95rem;
    line-height: 1.15;
    color: #fafafa;
    text-align: right;
    min-width: 110px;
}
.tv-consolidated-topbar .topbar-date-clock .clock-time {
    font-weight: 600;
}
.tv-consolidated-topbar .topbar-sos-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.55rem;
    border-radius: 0.4rem;
    background: #dc2626;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1;
}
.tv-consolidated-topbar .topbar-sos-badge .sos-count {
    font-size: 1.05rem;
    font-weight: 800;
    background: #fff;
    color: #dc2626;
    border-radius: 50%;
    width: 1.55rem;
    height: 1.55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.tv-consolidated-topbar .topbar-fullscreen-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.4);
    color: #fafafa;
    border-radius: 0.4rem;
    width: 2.1rem;
    height: 2.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 100ms ease;
}
.tv-consolidated-topbar .topbar-fullscreen-btn:hover {
    background: rgba(255,255,255,0.15);
}
.tv-consolidated-topbar .topbar-fullscreen-btn .bi {
    font-size: 1.05rem;
}

/* Fix #3: Tile aspect ratio — prevents pillars on depot filter */
.bus-cell-consolidated {
    aspect-ratio: 3 / 2;
    max-height: 110px;
}
#consolidatedGrid {
    grid-auto-rows: minmax(auto, 110px);
}

/* Fix #4: Bus profile square thumbnail in header */
.bus-profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: nowrap;
}
.bus-profile-header .profile-meta {
    flex: 1;
    min-width: 0;
}
.bus-profile-header .profile-actions {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.bus-profile-thumb {
    flex-shrink: 0;
    width: 110px;
    height: 110px;
    border-radius: 8px;
    overflow: hidden;
    background: #f3f4f6;
    border: 2px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
}
.bus-profile-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 120ms ease;
}
.bus-profile-thumb:hover img {
    transform: scale(1.05);
}
.bus-profile-thumb-empty {
    color: #9ca3af;
    text-align: center;
    font-size: 0.7rem;
}
.bus-profile-thumb-empty .bi {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 2px;
}

/* Fix #4: form.php — bus photo upload field preview */
.bus-form-photo-block {
    background: #f9fafb;
    border-radius: 8px;
    padding: 1rem;
    border: 1px dashed #d1d5db;
    margin-bottom: 1rem;
}
.bus-form-photo-block .photo-preview {
    width: 140px;
    height: 90px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bus-form-photo-block .photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.bus-form-photo-block .photo-preview .placeholder-icon {
    color: #9ca3af;
    font-size: 1.4rem;
}


/* === Session 6.6.2 — final tile + SOS sizing === */
#consolidatedGrid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
    grid-auto-rows: minmax(auto, 120px) !important;
    gap: 0.55rem !important;
}
.bus-cell-consolidated {
    aspect-ratio: auto !important;
    min-height: 88px !important;
    max-height: 120px !important;
    padding: 0.45rem 0.6rem !important;
}
.bus-cell-consolidated .cell-reg {
    font-size: 0.95rem !important;
    line-height: 1.1 !important;
}
.bus-cell-consolidated .cell-status {
    font-size: 0.72rem !important;
    margin-top: 0.25rem !important;
}

/* SOS tile — smaller circle, larger pill area, reg in single line */
.bus-cell-consolidated.has-sos {
    padding: 0.4rem 0.55rem !important;
    gap: 0.5rem !important;
}
.bus-cell-consolidated.has-sos .sos-circle {
    width: 40px !important;
    height: 40px !important;
    font-size: 0.72rem !important;
    border-width: 2px !important;
    box-shadow: 0 0 0 1.5px #dc2626 !important;
}
.bus-cell-consolidated.has-sos .sos-pill {
    font-size: 0.78rem !important;
    padding: 0.3rem 0.4rem !important;
    border-width: 1.5px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    flex: 1 !important;
    min-width: 0 !important;
}

/* === Session 6.6.6 — navigation loading bar === */
#nav-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: linear-gradient(90deg, #0d6efd 0%, #0dcaf0 50%, #6610f2 100%);
    z-index: 99999;
    box-shadow: 0 1px 4px rgba(13, 110, 253, 0.4);
    pointer-events: none;
    opacity: 0;
    transition: width 200ms ease, opacity 200ms;
}
#nav-progress.active {
    width: 70%;
    opacity: 1;
    transition: width 3s cubic-bezier(0.2, 0.8, 0.4, 0.95), opacity 100ms;
}
#nav-progress.done {
    width: 100%;
    opacity: 1;
    transition: width 200ms ease-out, opacity 200ms;
}

/* =====================================================================
   S10+ — Expandable "Fleet" nav group
   Wide (>=992px): collapsible parent + indented children.
   Narrow (<992px): flattened to plain centered icons (group always open).
   ===================================================================== */

/* Parent toggle: same look as a nav-link, plus a chevron that rotates */
.app-nav .nav-group-toggle {
    width: 100%;
    background: transparent;
    border: 0;
    cursor: pointer;
}
.app-nav .nav-group-toggle .nav-chevron {
    margin-left: auto;
    font-size: .85rem;
    transition: transform .18s ease;
}
/* When the collapse is open, Bootstrap removes .collapsed from the toggle */
.app-nav .nav-group-toggle:not(.collapsed) .nav-chevron {
    transform: rotate(90deg);
}

/* Children: indent under the parent at full width */
.app-nav .nav-group-items .nav-link {
    padding-left: 2.75rem;
    font-size: .9rem;
}
.app-nav .nav-group-items .nav-link i {
    font-size: 1rem;
}

/* ---- Narrow icon-strip: flatten the group ---- */
@media (max-width: 991.98px) {
    /* Hide the parent toggle entirely */
    .app-nav .nav-group-toggle {
        display: none;
    }
    /* Force the children visible regardless of collapse state */
    .app-nav .nav-group-items {
        display: block !important;
        height: auto !important;
    }
    /* Remove the indent so children align like every other icon */
    .app-nav .nav-group-items .nav-link {
        padding-left: 0.25rem;
        justify-content: center;
    }
    .app-nav .nav-group-items .nav-link i {
        font-size: 1.3rem;
    }
}



/* =====================================================================
   S10+ — Sidebar restyle to match reference (v2: blue underline active,
   muted items, roomy spacing, flush-left Fleet group toggle).
   Appended as overrides; later rules win the cascade.
   ===================================================================== */

:root {
    --sidebar-bg:        #161e2e;
    --sidebar-fg:        #8b95a7;   /* muted gray inactive */
    --sidebar-fg-active: #ffffff;
    --sidebar-underline: #2563eb;   /* blue underline for active */
    --sidebar-hover-bg:  #1f2a3d;
    --sidebar-badge:     #2563eb;
}

.app-nav {
    padding: 0.75rem 0.5rem;
}

/* Base item: muted, rounded hover target, roomy. No left border.
   IMPORTANT: identical box model for <a> links AND the <button> toggle
   so everything aligns flush-left. */
.app-nav .nav-link {
    color: var(--sidebar-fg);
    padding: 0.7rem 0.9rem;
    margin-bottom: 0.3rem;
    border-radius: 10px;
    border-left: 0;
    font-size: 0.95rem;
    font-weight: 500;
    gap: 0.85rem;
    /* Neutralize <button> defaults so the Fleet toggle aligns like an <a> */
    width: 100%;
    text-align: left;
    background-color: transparent;
    font-family: inherit;
    line-height: 1.5;
    appearance: none;
    -webkit-appearance: none;
}
.app-nav .nav-link i {
    font-size: 1.15rem;
    min-width: 1.4rem;
    color: var(--sidebar-fg);
    transition: color .15s ease;
}

/* Hover: subtle fill + brighter text */
.app-nav .nav-link:hover {
    color: var(--sidebar-fg-active);
    background: var(--sidebar-hover-bg);
    border-left: 0;
}
.app-nav .nav-link:hover i {
    color: var(--sidebar-fg-active);
}

/* ---- ACTIVE = solid blue rounded pill, white text+icon ---- */
.app-nav .nav-link.active {
    color: #fff;
    background: var(--sidebar-underline);   /* reuse the blue token as pill fill */
    border-left: 0;
    box-shadow: 0 2px 8px rgba(37,99,235,.35);
}
.app-nav .nav-link.active:hover {
    background: var(--sidebar-underline);   /* keep pill on hover, don't fade to grey */
    color: #fff;
}
.app-nav .nav-link.active i {
    color: #fff;
}

/* Right-aligned blue badge */
.app-nav .nav-link .badge {
    margin-left: auto;
    background: var(--sidebar-badge) !important;
    color: #fff;
    font-weight: 600;
    border-radius: 999px;
    padding: .2rem .5rem;
    font-size: .72rem;
}

/* ---- Fleet group: toggle aligned identically to links, children flush-left ---- */
.app-nav .nav-group-toggle {
    color: var(--sidebar-fg);
    margin-bottom: 0.3rem;
    cursor: pointer;
    border: 0;                     /* kill button border */
}
.app-nav .nav-group-toggle:hover {
    color: var(--sidebar-fg-active);
    background: var(--sidebar-hover-bg);
}
.app-nav .nav-group-toggle .nav-chevron {
    margin-left: auto;
    font-size: .8rem;
    transition: transform .18s ease;
    color: var(--sidebar-fg);
}
.app-nav .nav-group-toggle:not(.collapsed) .nav-chevron {
    transform: rotate(90deg);
}
/* Children flush-left — same left padding as parents (no indent) */
.app-nav .nav-group-items .nav-link {
    padding-left: 0.9rem;
    font-size: 0.92rem;
}

/* ---- Icon-strip mode (<992px) ---- */
@media (max-width: 991.98px) {
    .app-nav {
        padding: 0.5rem 0.4rem;
    }
    .app-nav .nav-link,
    .app-nav .nav-group-items .nav-link {
        justify-content: center;
        padding: 0.7rem 0;
        margin-bottom: 0.4rem;
        border-radius: 12px;
    }
    .app-nav .nav-group-toggle { display: none; }
    .app-nav .nav-group-items { display: block !important; height: auto !important; }
}

/* ============================================================================
   S11D_MOBILE_BEGIN — Session 11d: mobile responsive layer
   ============================================================================
   Three breakpoints managed by Bootstrap + this stylesheet:

   • <576px  (phones)    : off-canvas sidebar drawer, hamburger active,
                           noisy table columns hidden, TV Dash hidden,
                           non-essential nav items hidden, larger touch targets,
                           16px form input font-size (prevents iOS auto-zoom).
   • 576-991px (tablets) : existing icon-strip sidebar pattern preserved.
   • ≥992px (desktop)    : existing full sidebar with labels preserved.

   This block is APPENDED to the existing app.css and must come AFTER the
   existing `@media (max-width: 991.98px)` block so cascade order is correct.
   ============================================================================ */

/* ---------------------------------------------------------------------------
   Phones only: off-canvas drawer for the sidebar
   --------------------------------------------------------------------------- */
@media (max-width: 575.98px) {

    /* Reactivate the hamburger button (previously hidden by the icon-strip block) */
    #sidebarToggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        font-size: 1.4rem;
        color: inherit;
    }

    /* Sidebar becomes a slide-in drawer */
    :root {
        --sidebar-width: 260px;
    }
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform 0.25s ease-out;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }

    /* Restore labels inside the drawer (icon-strip block hid them) */
    .app-sidebar .app-nav .nav-link .nav-label,
    .app-sidebar .app-nav .nav-link .badge {
        display: inline !important;
    }
    .app-sidebar .app-nav .nav-link {
        justify-content: flex-start;
        gap: 0.75rem;
        padding: 0.85rem 1rem;
    }
    .app-sidebar .app-nav .nav-link i {
        font-size: 1.2rem;
        min-width: 1.5rem;
    }

    /* Restore brand block to full width */
    .app-sidebar .app-brand {
        padding: 1rem;
        min-height: auto;
    }
    .app-sidebar .app-brand .brand-logo {
        max-width: 80%;
        max-height: 64px;
    }

    /* Backdrop — appears when sidebar.open is present.
       Uses :has() which is supported on iOS 15.4+, Chrome 105+, Safari 15.4+.
       Fallback: without backdrop, sidebar still slides in/out fine via app.js
       click-outside-to-close behavior. */
    body:has(.app-sidebar.open)::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        pointer-events: none;  /* clicks pass through to app.js outside-click handler */
    }

    /* Main content takes full width on phones (no sidebar gutter) */
    .app-main {
        margin-left: 0 !important;
        width: 100%;
    }
    .app-content {
        padding: 0.75rem;
    }
    .app-shell {
        display: block;
    }

    /* Topbar: more compact, sticky so it doesn't scroll off */
    .app-topbar {
        padding: 0.5rem 0.75rem;
        position: sticky;
        top: 0;
        z-index: 1030;
        background: var(--bs-body-bg, #fff);
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }
    /* Hide the depot/portal label on phones — saves horizontal space */
    .app-topbar .text-muted.small {
        display: none !important;
    }
    /* User dropdown shows only the icon, hides the name text */
    .app-topbar .dropdown-toggle {
        padding: 0.4rem 0.6rem;
    }
    .app-topbar .dropdown-toggle .bi-person-circle + * {
        display: none;
    }

    /* Hide TV Dash + non-essential nav items entirely on phones.
       This applies regardless of role — keeps the mobile UI lean. */
    .app-topbar a[href*="/dashboard/tv"] {
        display: none !important;
    }
    .app-sidebar .app-nav a[href$="/reports"],
    .app-sidebar .app-nav a[href$="/users"],
    .app-sidebar .app-nav a[href$="/technicians"],
    .app-sidebar .app-nav a[href$="/depots"],
    .app-sidebar .app-nav a[href$="/buses/bulk"] {
        display: none !important;
    }
    /* Also hide the TV Dashboard modal-toggle button in the sidebar */
    .app-sidebar .app-nav button[data-bs-target="#tvChooserModal"] {
        display: none !important;
    }

    /* Larger touch targets for buttons + inputs */
    .btn,
    .nav-link,
    .form-control,
    .form-select {
        min-height: 44px;
    }
    .btn-sm,
    .form-control-sm,
    .form-select-sm {
        min-height: 36px;
    }

    /* Inputs at 16px prevents iOS Safari from auto-zooming on focus */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="search"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Profile-actions row on bus detail: stack to full-width on phones */
    .bus-profile-header {
        flex-direction: column;
        align-items: stretch;
    }
    .bus-profile-header .profile-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }
    .bus-profile-header .profile-actions .btn {
        flex: 1 1 auto;
    }
    .bus-profile-header .profile-meta h4 {
        font-size: 1.4rem;
        word-break: break-word;
    }
    .bus-profile-thumb,
    .bus-profile-thumb-btn {
        align-self: center;
        margin-top: 0.5rem;
    }

    /* Card headers — slightly tighter padding on phones */
    .card-header {
        padding: 0.6rem 0.9rem;
    }
    .card-body {
        padding: 0.9rem;
    }

    /* Tables: kill the horizontal scroll bar visually but keep functionality.
       Bootstrap's .table-responsive already adds overflow-x:auto. */
    .table {
        font-size: 0.92rem;
    }

    /* Pagination — center on mobile */
    .pagination {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Status pill tabs (used in complaints/index, etc.) — wrap on mobile */
    .nav-pills {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    /* The "Change password now" alert banner takes too much room on phones */
    .alert .btn-warning {
        margin-top: 0.5rem;
        width: 100%;
    }
}

/* ---------------------------------------------------------------------------
   Tablets + phones (<992px): noise reduction on shared elements
   --------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    /* Hide non-essential bus list columns. The `d-none d-md-table-cell` Bootstrap
       utility is also used on individual <th>/<td> elements; this rule covers
       cases where the markup doesn't have the class applied yet. */

    /* Long-form action buttons get a hair more breathing room */
    .btn + .btn {
        margin-top: 0;
    }
}

/* ---------------------------------------------------------------------------
   Print: hide chrome
   --------------------------------------------------------------------------- */
@media print {
    .app-sidebar,
    .app-topbar,
    #sidebarToggle {
        display: none !important;
    }
    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* ============================================================================
   S11D_MOBILE_END
   ============================================================================ */

/* ============================================================================
   S11F_NAV_BEGIN — Session 11f: sidebar redesign with grouped nav + user card
   ============================================================================
   Replaces the existing sidebar look with a polished dark-navy design:
     - Fixed brand block at top
     - Scrollable nav region in the middle with group headers
     - Fixed user-info card at bottom (replaces the topbar user dropdown)

   Color palette: slate-900 base + slate-800 elevated + slate-300 nav text +
   white pill for active items (matches the reference UI exactly).

   This block must come AFTER all earlier .app-sidebar / .app-brand / .app-nav
   rules so cascade order picks our redefinitions.
   ============================================================================ */

:root {
    --sidebar-width-s11f: 260px;
    --sidebar-bg-new: #0f172a;
    --sidebar-bg-elevated: #1e293b;
    --sidebar-fg-muted: #94a3b8;
    --sidebar-fg-s11f: #cbd5e1;
    --sidebar-fg-active-s11f: #ffffff;
    --sidebar-active-bg: #ffffff;
    --sidebar-active-fg: #0f172a;
    --sidebar-border-s11f: rgba(148, 163, 184, 0.12);
    --sidebar-icon-accent: #818cf8;
}

/* ============================================================================
   Sidebar shell — flex column with fixed top/bottom, scrollable middle
   ============================================================================ */
.app-sidebar {
    /* Override existing widths so the design holds at all desktop widths */
    width: var(--sidebar-width-s11f);
    background: var(--sidebar-bg-new) !important;
    color: var(--sidebar-fg-s11f) !important;
    display: flex !important;
    flex-direction: column !important;
    /* Each region (brand / nav-scroll / userbox) decides its own height */
    height: 100vh;
    /* Sticky on desktop so the sidebar follows the viewport */
    position: sticky;
    top: 0;
}

/* ============================================================================
   Brand block — fixed top
   ============================================================================ */
.app-sidebar .app-brand {
    flex-shrink: 0;
    padding: 1rem 1rem;
    background: var(--sidebar-bg-new) !important;
    border-bottom: 1px solid var(--sidebar-border-s11f) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Override the S6 white-pill background — we now want clean dark */
    min-height: 72px;
}
.app-sidebar .app-brand a {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-sidebar .app-brand .brand-logo {
    /* Override S6's full-width white-pill treatment */
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    max-height: 48px;
    max-width: 100%;
    width: auto;
    height: auto;
}

/* ============================================================================
   Scrollable middle region — wraps the nav
   ============================================================================ */
.app-sidebar .app-nav-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0;
    /* Subtle scrollbar styling — Webkit + Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}
.app-sidebar .app-nav-scroll::-webkit-scrollbar { width: 6px; }
.app-sidebar .app-nav-scroll::-webkit-scrollbar-track { background: transparent; }
.app-sidebar .app-nav-scroll::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
}

/* The actual <nav> can still be the existing class but loses flex-grow */
.app-sidebar .app-nav {
    flex-grow: 0 !important;        /* growth lives on .app-nav-scroll now */
    padding: 0 !important;
}

/* ============================================================================
   Group headers — "MAIN", "OPERATIONS", "ADMINISTRATION", etc
   ============================================================================ */
.nav-group {
    margin-bottom: 0.5rem;
}
.nav-group-label {
    color: var(--sidebar-fg-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.75rem 1.25rem 0.5rem;
    margin: 0;
    user-select: none;
}

/* ============================================================================
   Nav links — pill-shaped active state matching the reference
   ============================================================================ */
.app-sidebar .app-nav .nav-link,
.app-sidebar .app-nav-scroll .nav-link {
    color: var(--sidebar-fg-s11f) !important;
    padding: 0.65rem 0.85rem !important;
    margin: 0.15rem 0.75rem !important;
    border-left: 0 !important;        /* override the existing border-left active style */
    border-radius: 8px !important;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}
.app-sidebar .app-nav .nav-link:hover,
.app-sidebar .app-nav-scroll .nav-link:hover {
    background: var(--sidebar-bg-elevated) !important;
    color: var(--sidebar-fg-active-s11f) !important;
}
.app-sidebar .app-nav .nav-link.active,
.app-sidebar .app-nav-scroll .nav-link.active {
    background: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-fg) !important;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
}
.app-sidebar .app-nav .nav-link i,
.app-sidebar .app-nav-scroll .nav-link i {
    font-size: 1.1rem;
    min-width: 1.25rem;
    color: inherit;
}

/* Collapsible group toggle (HO "Fleet" group) — keep the existing pattern */
.app-sidebar .nav-group-toggle .nav-chevron {
    margin-left: auto;
    font-size: 0.85rem;
    transition: transform .2s ease;
}
.app-sidebar .nav-group-toggle:not(.collapsed) .nav-chevron {
    transform: rotate(90deg);
}
.app-sidebar .nav-group-items {
    /* Indent nested items so the group is visually subordinate */
    padding-left: 0.75rem;
}
.app-sidebar .nav-group-items .nav-link {
    font-size: 0.88rem !important;
    padding: 0.5rem 0.85rem !important;
}

/* ============================================================================
   User card — fixed bottom
   ============================================================================ */
.app-sidebar .app-userbox {
    flex-shrink: 0;
    padding: 0.85rem 0.75rem;
    border-top: 1px solid var(--sidebar-border-s11f);
    background: var(--sidebar-bg-new);
}
.app-userbox .user-card {
    background: var(--sidebar-bg-elevated);
    border: 0;
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    text-align: left;
    color: var(--sidebar-fg-active-s11f);
    cursor: pointer;
    transition: background-color .15s ease;
}
.app-userbox .user-card:hover,
.app-userbox .user-card[aria-expanded="true"] {
    background: #334155; /* slate-700 */
}
.app-userbox .user-card .user-avatar {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--sidebar-icon-accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}
.app-userbox .user-card .user-meta {
    flex: 1;
    min-width: 0;        /* allow text-overflow to kick in */
}
.app-userbox .user-card .user-name {
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-userbox .user-card .user-role {
    font-size: 0.75rem;
    color: var(--sidebar-fg-muted);
    line-height: 1.2;
}
.app-userbox .user-card .user-chevron {
    color: var(--sidebar-fg-muted);
    font-size: 0.85rem;
    margin-left: auto;
    transition: transform .2s ease;
}
.app-userbox .user-card[aria-expanded="true"] .user-chevron {
    transform: rotate(180deg);
}

/* Dropdown menu attached to user card */
.app-userbox .dropdown-menu {
    /* Position above the card via dropup */
    margin-bottom: 0.5rem;
    /* Stretch to match card width when possible */
    min-width: 100%;
    border: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ============================================================================
   Topbar tweaks — user dropdown is gone, mobile user icon kept hidden by default
   ============================================================================ */
#topbarUserIcon {
    display: none;                                    /* desktop hides it */
}

/* ============================================================================
   Mobile breakpoints — preserve S11d off-canvas drawer behavior
   Tablet (576-991px): full-width sidebar restored (no more icon-strip per S11f)
   Phones (<576px): off-canvas drawer (per S11d)
   ============================================================================ */
@media (max-width: 991.98px) {
    .app-sidebar {
        /* Override the S11d/S6 icon-strip width=72px — we want full 260px */
        width: var(--sidebar-width-s11f) !important;
    }
    .app-sidebar .app-nav .nav-link .nav-label,
    .app-sidebar .app-nav .nav-link .badge,
    .app-sidebar .app-nav-scroll .nav-link .nav-label,
    .app-sidebar .app-nav-scroll .nav-link .badge {
        display: inline !important;
    }
    .app-sidebar .app-nav .nav-link i,
    .app-sidebar .app-nav-scroll .nav-link i {
        font-size: 1.1rem !important;
        min-width: 1.25rem !important;
    }
    /* Restore brand padding (the S6 icon-strip rule shrunk this to 0.5rem) */
    .app-sidebar .app-brand {
        padding: 1rem 1rem !important;
        min-height: 72px !important;
    }
    .app-sidebar .app-brand .brand-logo {
        max-height: 48px !important;
        max-width: 100% !important;
        width: auto !important;
    }
}

@media (max-width: 575.98px) {
    /* On phones, the topbar shows a user icon as a shortcut to the drawer */
    #topbarUserIcon {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--sidebar-icon-accent);
        color: white;
        text-decoration: none;
        font-size: 1.2rem;
    }
}

/* ============================================================================
   S11F_NAV_END
   ============================================================================ */

/* ============================================================================
   S11F_HOTFIX_BEGIN — Session 11f visual fixes from real-world feedback
   ============================================================================
   1. .app-nav-scroll must have min-height:0 so flex:1+overflow-y:auto actually
      scrolls inside the flex parent (well-known flexbox quirk)
   2. .app-sidebar needs overflow:hidden so the nav scroll context is contained
   3. Group label gets a subtle divider line below
   4. Profile card polished — slightly taller, full first-name only, chevron icon
   5. Tablet group label readability
   ============================================================================ */

/* 1 + 2. Make the nav scroll properly */
.app-sidebar {
    overflow: hidden !important;       /* contain the scroll context */
}
.app-sidebar .app-nav-scroll {
    flex: 1 1 0 !important;            /* 0-basis so it shrinks below content */
    min-height: 0 !important;          /* THE critical flexbox-scroll fix */
    overflow-y: auto !important;
}

/* 3. Group label divider */
.app-sidebar .nav-group {
    margin-bottom: 0.75rem;
}
.app-sidebar .nav-group-label {
    position: relative;
    padding-bottom: 0.65rem;
    margin-bottom: 0.15rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    margin-left: 1.25rem;
    margin-right: 1.25rem;
    padding-left: 0;
    padding-right: 0;
}

/* 4. Profile card polish */
.app-sidebar .app-userbox {
    padding: 1rem 0.85rem;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    background: var(--sidebar-bg-new);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2);  /* subtle elevation hint */
}
.app-userbox .user-card {
    padding: 0.75rem 0.85rem;
    border-radius: 12px;
}
.app-userbox .user-card .user-avatar {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}
.app-userbox .user-card .user-name {
    font-size: 0.95rem;
    font-weight: 600;
}
.app-userbox .user-card .user-role {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.85;
}

/* 5. Tablet (576-991px) group label readability — slightly tighter padding */
@media (max-width: 991.98px) {
    .app-sidebar .nav-group-label {
        font-size: 0.65rem !important;
        padding-top: 0.6rem !important;
        padding-bottom: 0.5rem !important;
        margin-left: 1rem !important;
        margin-right: 1rem !important;
    }
}

/* ============================================================================
   S11F_HOTFIX_END
   ============================================================================ */

/* ============================================================================
   S11F_LOGO_FIX_BEGIN — logo sizing/rounding/centering pass
   ============================================================================ */
.app-sidebar .app-brand {
    padding: 1rem 1rem;
    min-height: 96px;                                /* a touch taller for breathing room */
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-sidebar .app-brand a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.app-sidebar .app-brand .brand-logo {
    max-height: 72px !important;                     /* up from 48px */
    max-width: 92% !important;
    width: auto !important;
    height: auto !important;
    border-radius: 12px !important;                  /* rounded corners on the white-baked PNG */
    background: #fff !important;                     /* keep the white card look, but now rounded */
    padding: 0.5rem 0.75rem !important;              /* inner breathing room so logo doesn't touch edges */
    object-fit: contain;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;  /* subtle elevation against navy bg */
}

/* Mobile keeps the same proportion */
@media (max-width: 991.98px) {
    .app-sidebar .app-brand {
        padding: 1rem 1rem !important;
        min-height: 96px !important;
    }
    .app-sidebar .app-brand .brand-logo {
        max-height: 72px !important;
        max-width: 92% !important;
        padding: 0.5rem 0.75rem !important;
        border-radius: 12px !important;
    }
}
/* ============================================================================
   S11F_LOGO_FIX_END
   ============================================================================ */

/* ============================================================================
   S11G_TILE_POLISH_BEGIN — dashboard stat-card visual polish
   ============================================================================
   - Equal-height tiles (achieved by Bootstrap h-100 already in markup)
   - Vertical flex inside card-body so big number sits in a fixed slot
   - VIEW LIST link pinned to bottom of card via margin-top:auto
   - Subtle hover lift + shadow elevation
   - Softer border-left rendering (the 4→3 thinness was patched in markup)
   - Tighter, consistent label typography (uppercase, 2-line clamp)
   - More breathing room around the BIG NUMBER
   ============================================================================ */

.stat-card {
    border: 1px solid rgba(15, 23, 42, 0.06) !important;
    border-radius: 12px !important;
    transition: transform .15s ease, box-shadow .15s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.stat-card .card-body {
    display: flex !important;
    flex-direction: column !important;
    padding: 1.1rem 1.1rem !important;
    min-height: 150px;        /* enforces equal-ish heights even with short labels */
}

/* Label: small uppercase, two-line clamp so long labels stay tidy */
.stat-card .stat-label {
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
    color: #64748b !important;
    line-height: 1.3 !important;
    /* clamp to 2 lines, ellipsis if longer (defensive) */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.2em;        /* reserve 2 lines so 1-line and 2-line labels align */
    margin-bottom: 0.5rem;
}

/* Big number: sits in its own slot, doesn't squeeze the rest */
.stat-card .stat-value {
    font-size: 2rem !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
    margin: 0 0 0.25rem 0 !important;
}

/* VIEW LIST → cta sits pinned to the bottom of card body */
.stat-card .stat-card-cta {
    margin-top: auto !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
}

/* Hover lift + shadow for clickable tiles */
.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08) !important;
    text-decoration: none !important;
}

/* Slightly softer outer wrapper around the row */
.stat-card-link {
    cursor: pointer;
}

/* Tighter row gap on the grid (Bootstrap g-3 = 1rem; bump to g-4 = 1.5rem feel) */
.row.g-3 + .row,
.row.g-3 {
    --bs-gutter-y: 1rem;
}

/* ============================================================================
   S11G_TILE_POLISH_END
   ============================================================================ */

/* ============================================================================
   S11G_TILE_POLISH_BEGIN — dashboard stat-card visual polish
   ============================================================================
   - Equal-height tiles (achieved by Bootstrap h-100 already in markup)
   - Vertical flex inside card-body so big number sits in a fixed slot
   - VIEW LIST link pinned to bottom of card via margin-top:auto
   - Subtle hover lift + shadow elevation
   - Softer border-left rendering (the 4→3 thinness was patched in markup)
   - Tighter, consistent label typography (uppercase, 2-line clamp)
   - More breathing room around the BIG NUMBER
   ============================================================================ */

.stat-card {
    border: 1px solid rgba(15, 23, 42, 0.06) !important;
    border-radius: 12px !important;
    transition: transform .15s ease, box-shadow .15s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.stat-card .card-body {
    display: flex !important;
    flex-direction: column !important;
    padding: 1.1rem 1.1rem !important;
    min-height: 150px;        /* enforces equal-ish heights even with short labels */
}

/* Label: small uppercase, two-line clamp so long labels stay tidy */
.stat-card .stat-label {
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
    color: #64748b !important;
    line-height: 1.3 !important;
    /* clamp to 2 lines, ellipsis if longer (defensive) */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.2em;        /* reserve 2 lines so 1-line and 2-line labels align */
    margin-bottom: 0.5rem;
}

/* Big number: sits in its own slot, doesn't squeeze the rest */
.stat-card .stat-value {
    font-size: 2rem !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
    margin: 0 0 0.25rem 0 !important;
}

/* VIEW LIST → cta sits pinned to the bottom of card body */
.stat-card .stat-card-cta {
    margin-top: auto !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
}

/* Hover lift + shadow for clickable tiles */
.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08) !important;
    text-decoration: none !important;
}

/* Slightly softer outer wrapper around the row */
.stat-card-link {
    cursor: pointer;
}

/* Tighter row gap on the grid (Bootstrap g-3 = 1rem; bump to g-4 = 1.5rem feel) */
.row.g-3 + .row,
.row.g-3 {
    --bs-gutter-y: 1rem;
}

/* ============================================================================
   S11G_TILE_POLISH_END
   ============================================================================ */

/* S11F_LOGO_BIGGER — bump logo size */
.app-sidebar .app-brand {
    min-height: 120px !important;
    padding: 1.25rem 1rem !important;
}
.app-sidebar .app-brand .brand-logo {
    max-height: 96px !important;
    max-width: 100% !important;
    padding: 0.6rem 0.85rem !important;
}
@media (max-width: 991.98px) {
    .app-sidebar .app-brand {
        min-height: 120px !important;
    }
    .app-sidebar .app-brand .brand-logo {
        max-height: 96px !important;
    }
}

/* ============================================================================
   S11F_MOBILE_FLOW_FIX_BEGIN — restore mobile layout
   ============================================================================
   Root cause: .app-shell { display: flex } reserves 260px for the sidebar
   even when the sidebar is position:fixed + translateX(-100%). On phones the
   viewport (390px) minus that reservation left only ~130px for content,
   creating a huge empty white block above the topbar.

   Fix: at <576px, switch .app-shell to display:block so the sidebar (which is
   position:fixed at that breakpoint) doesn't reserve flex space.
   Also re-scope the unconditional overflow:hidden on .app-sidebar so it only
   applies on desktop (where the scrollable nav region needs containment).
   ============================================================================ */
@media (max-width: 575.98px) {
    .app-shell {
        display: block !important;
    }
    .app-main {
        width: 100% !important;
        min-height: 100vh;
    }
    /* Re-confirm sidebar is fully off-canvas and not consuming space */
    .app-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        transform: translateX(-100%);
        overflow: hidden !important;  /* keep this on mobile too, sidebar is fixed-size */
    }
    .app-sidebar.open {
        transform: translateX(0) !important;
    }
}

/* Limit the unconditional overflow:hidden from S11f_HOTFIX to non-phone widths */
@media (min-width: 576px) {
    .app-sidebar {
        overflow: hidden !important;
    }
}
/* ============================================================================
   S11F_MOBILE_FLOW_FIX_END
   ============================================================================ */

/* ============================================================
   S17_STICKY_TABLES — scrollable list bodies with a fixed header.
   Applies to every .table-responsive in the app. The max-height is
   viewport-relative so short lists never scroll and long ones do.
   ============================================================ */
.table-responsive {
    max-height: calc(100vh - 320px);
    min-height: 180px;
    overflow-y: auto;
}
.table-responsive > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--bs-table-bg, #f8f9fa);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .12);
}
/* Keep the header opaque when the row underneath scrolls behind it */
.table-responsive > table > thead.table-light > tr > th {
    background-color: #f8f9fa;
}
@media (max-width: 767.98px) {
    .table-responsive { max-height: calc(100vh - 240px); }
}
@media print {
    .table-responsive { max-height: none; overflow: visible; }
    .table-responsive > table > thead > tr > th { position: static; }
}

/* ============================================================
   S19_TABLE_SKIN — list table styling across every .table-responsive.
   Pairs with S17_STICKY_TABLES above (which owns the scroll + sticky
   thead); this block is presentation only.
   ============================================================ */
.table-responsive > table.table > thead > tr > th {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #566787;
    padding: 12px 15px;
    white-space: nowrap;
}
.table-responsive > table.table > tbody > tr > td {
    padding: 12px 15px;
    vertical-align: middle;
    border-color: #e9e9e9;
}
.table-responsive > table.table > tbody > tr:hover {
    background-color: #f5f7fa;
}

/* Action buttons: borderless coloured icons, closer to the reference */
.table-responsive > table.table td .btn-outline-secondary,
.table-responsive > table.table td .btn-outline-danger,
.table-responsive > table.table td .btn-outline-warning,
.table-responsive > table.table td .btn-outline-primary {
    border-color: transparent;
    background: transparent;
    padding: 2px 6px;
}
.table-responsive > table.table td .btn-outline-secondary { color: #566787; }
.table-responsive > table.table td .btn-outline-secondary:hover { color: #2196f3; background: transparent; }
.table-responsive > table.table td .btn-outline-primary   { color: #2196f3; }
.table-responsive > table.table td .btn-outline-warning   { color: #ffc107; }
.table-responsive > table.table td .btn-outline-danger    { color: #f44336; }
.table-responsive > table.table td .btn-outline-danger:hover { color: #c62828; background: transparent; }
.table-responsive > table.table td .btn i { font-size: 1.05rem; }

/* Pagination below the scroll box */
.pagination .page-link {
    border: none;
    min-width: 32px;
    text-align: center;
    color: #999;
    border-radius: 2px;
    margin: 0 2px;
}
.pagination .page-link:hover { color: #566787; background: #eef1f5; }
.pagination .page-item.active .page-link { background: #03a9f4; color: #fff; }

/* ============================================================
   S19B_TABLE_TYPE — tighter, lighter list table typography.
   Overrides the padding set in S19_TABLE_SKIN above.
   ============================================================ */
.table-responsive > table.table {
    font-size: .82rem;
}
.table-responsive > table.table > thead > tr > th {
    font-size: .7rem;
    letter-spacing: .5px;
    padding: 9px 12px;
}
.table-responsive > table.table > tbody > tr > td {
    padding: 8px 12px;
    line-height: 1.35;
}
/* Secondary text inside cells — sub-labels, muted notes */
.table-responsive > table.table > tbody > tr > td small,
.table-responsive > table.table > tbody > tr > td .small {
    font-size: .72rem;
}
/* Badges and status pills scale with the smaller rows */
.table-responsive > table.table > tbody > tr > td .badge {
    font-size: .68rem;
    font-weight: 500;
    padding: .28em .55em;
}
.table-responsive > table.table > tbody > tr > td .status-pill {
    font-size: .68rem;
    padding: .25em .7em;
}
.table-responsive > table.table td .btn {
    padding: 1px 5px;
}
.table-responsive > table.table td .btn i {
    font-size: .95rem;
}

/* ============================================================
   S27_LIST_LOADER — dim the table and show a spinner while a
   pagination click navigates. Purely feedback: the page still
   reloads, this just makes the wait legible.
   ============================================================ */
.table-responsive.is-loading {
    position: relative;
    pointer-events: none;
}
.table-responsive.is-loading > table {
    opacity: .35;
    transition: opacity 120ms ease;
}
.table-responsive.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
    border: 3px solid rgba(13, 110, 253, .25);
    border-top-color: #0d6efd;
    border-radius: 50%;
    animation: s27spin .6s linear infinite;
    z-index: 5;
}
@keyframes s27spin { to { transform: rotate(360deg); } }

/* ============================================================
   S28_TOPBAR_GRADIENT — blue gradient topbar, pinned on desktop.
   Mobile already had position:sticky (see the media query above);
   this extends the same behaviour to wider screens and restyles
   the contents for a dark background.
   ============================================================ */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: linear-gradient(120deg, #1f7ae0 0%, #1668d6 45%, #0d47a1 100%);
    border-bottom: none;
    box-shadow: 0 2px 6px rgba(13, 71, 161, .25);
}

/* Contents need to read against the blue */
.app-topbar,
.app-topbar .text-muted,
.app-topbar .text-muted.small,
.app-topbar a,
.app-topbar .dropdown-toggle {
    color: #fff;
}
.app-topbar .text-muted,
.app-topbar .text-muted.small {
    color: rgba(255, 255, 255, .8) !important;
}
.app-topbar a:hover {
    color: #fff;
}

/* Outline buttons: translucent white instead of grey */
.app-topbar .btn-outline-secondary {
    color: #fff;
    border-color: rgba(255, 255, 255, .55);
    background: rgba(255, 255, 255, .08);
}
.app-topbar .btn-outline-secondary:hover,
.app-topbar .btn-outline-secondary:focus {
    color: #0d47a1;
    background: #fff;
    border-color: #fff;
}

/* Mobile hamburger sits on the gradient too */
.app-topbar #sidebarToggle,
.app-topbar .btn-link {
    color: #fff;
}

/* The S17 sticky table header must clear the pinned topbar */
.table-responsive > table > thead > tr > th {
    top: 0;
}

/* ============================================================
   S29_USERBOX_DARK — the user dropdown as a dark panel matching
   the sidebar, rather than a white card floating over it.
   Extends the .app-userbox .dropdown-menu rule further up.
   ============================================================ */
.app-userbox .dropdown-menu {
    background: var(--sidebar-bg-elevated, #273449);
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 10px;
    padding: .35rem;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
}
.app-userbox .dropdown-menu .dropdown-item {
    color: var(--sidebar-fg, #cbd5e1);
    border-radius: 7px;
    padding: .5rem .7rem;
    font-size: .875rem;
    transition: background-color .12s ease, color .12s ease;
}
.app-userbox .dropdown-menu .dropdown-item i {
    opacity: .75;
}
.app-userbox .dropdown-menu .dropdown-item:hover,
.app-userbox .dropdown-menu .dropdown-item:focus {
    background: #334155;               /* same hover as the card below it */
    color: var(--sidebar-fg-active, #fff);
}
.app-userbox .dropdown-menu .dropdown-item:hover i {
    opacity: 1;
}
.app-userbox .dropdown-menu .dropdown-divider {
    border-top: 1px solid rgba(255, 255, 255, .10);
    margin: .3rem .2rem;
}
/* Logout: lighter red so it reads on the dark panel */
.app-userbox .dropdown-menu .dropdown-item.text-danger {
    color: #f87171 !important;
}
.app-userbox .dropdown-menu .dropdown-item.text-danger:hover,
.app-userbox .dropdown-menu .dropdown-item.text-danger:focus {
    background: rgba(248, 113, 113, .16);
    color: #fca5a5 !important;
}
