﻿/* General Body Styling */
body {
    display: flex;
    min-height: 100vh;
    margin: 0;
    flex-direction: column;
    background-color: #fff; /* Light background color for the body */
}

/* ADDED: control the navbar/header height here */
:root {
    --header-height: 96px; /* tweak this if needed */
}

/* ===== Sidebar: independent scroll ===== */
.sidebar {
    width: 250px;
    background-color: #343a40;
    color: #fff;
    /* make it fixed under the navbar and scrollable */
    position: fixed;
    top: var(--header-height); /* navbar height */
    bottom: 0; /* stick to bottom of viewport */
    height: calc(100vh - var(--header-height));
    overflow-y: auto; /* <-- independent vertical scroll */
    overflow-x: hidden;
    padding: 15px;
    z-index: 1000;
    transition: transform 0.3s ease;
    /* ADDED earlier: fix width when used inside flex rows */
    flex: 0 0 250px;
    flex-shrink: 0;
}

/* Main content sits to the right of fixed sidebar on desktop */
.content {
    margin-left: 250px; /* same as sidebar width */
    padding: 15px;
    flex-grow: 1;
    background-color: #ffffff;
    color: #333333;
    transition: margin-left 0.3s ease;
    /* ADDED earlier: avoid overflow pushing layout */
    min-width: 0;
}

/* Mobile: sidebar becomes full-screen slide-over with its own scroll */
@media (max-width: 991.98px) {
    .sidebar {
        top: 0;
        height: 100vh;
        width: 100%;
        transform: translateX(-100%);
    }

        .sidebar.show {
            transform: translateX(0);
        }

    .content {
        margin-left: 0;
    }
}

/* Content Area Styling */
.content {
    margin-left: 250px;
    padding: 15px;
    flex-grow: 1;
    background-color: #ffffff; /* White background for the content area */
    transition: margin-left 0.3s ease;
    color: #333333; /* Dark text color for contrast */
    /* ADDED (duplicate-safe): ensure min-width set even if this block wins */
    min-width: 0;
}

/* Navigation Link Styling */
.nav-link {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    color: #ffffff; /* White text color */
    text-decoration: none;
}

    .nav-link:hover {
        background-color: #495057; /* Slightly lighter background on hover */
        color: #ffffff; /* White text on hover */
    }

    .nav-link i {
        margin-right: 10px;
    }

/* Navbar Brand Styling */
.navbar-brand .app-name {
    font-weight: bold;
    font-size: 1.25rem;
    color: #ffffff; /* Ensure the logo text is white */
}

.form-inline {
    max-width: 300px;
}

/* Dropdown Menu Styling */
.dropdown-menu {
    width: 300px;
    background-color: #ffffff; /* White background for dropdown */
    color: #333333; /* Dark text color for readability */
}

.dropdown-item {
    color: #333333; /* Dark text color */
}

    .dropdown-item:hover {
        background-color: #f8f9fa; /* Light background on hover */
        color: #333333; /* Dark text color on hover */
    }

/* Badge Styling */
.badge {
    font-size: 0.75rem;
    vertical-align: top;
}

img.rounded-circle {
    width: 40px;
    height: 40px;
    object-fit: cover;
}

/* Responsive Styling for Mobile Devices */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        z-index: 1000;
        top: 0;
        bottom: 0;
        width: 100%;
        transition: transform 0.3s ease;
    }

        .sidebar.show {
            transform: translateX(0);
        }

    .content {
        margin-left: 0;
        padding: 15px;
    }

    .header {
        z-index: 1100;
    }
}

/* Ensure Content Adjusts When Sidebar is Toggled */
@media (min-width: 992px) {
    .sidebar {
        /* keep it FIXED on desktop */
        position: fixed; /* ← was sticky */
        top: var(--header-height);
        bottom: 0;
        width: 250px;
        transform: none;
    }

    .content {
        margin-left: 250px;
    }

    /* ADDED earlier: only offset content when a sidebar exists (overrides inline style on logged-in pages) */
    .sidebar ~ .content {
        margin-left: 250px !important;
    }
}

/* Footer Styling */
footer {
    background-color: #f8f9fa; /* Light background for footer */
    color: #333333; /* Dark text color */
    padding: 10px 0;
    text-align: center;
    border-top: 1px solid #e3e6f0;
}

/* Ensure card headers have the correct background colors */
.card-header {
    background-color: inherit; /* Ensures it inherits the bg-* color */
    color: #ffffff; /* Ensure the text color is white */
}

/* Specific overrides for each card header type */
.bg-primary .card-header {
    background-color: #007bff !important;
}

.bg-success .card-header {
    background-color: #28a745 !important;
}

.bg-warning .card-header {
    background-color: #ffc107 !important;
    color: #212529; /* Dark text for better contrast on yellow */
}

.bg-danger .card-header {
    background-color: #dc3545 !important;
}

/* Additional padding and margins for better layout control */
.p-2 {
    padding: 0.5rem !important;
}

.mb-2 {
    margin-bottom: 0.5rem !important;
}

@media (max-width: 768px) {
    .search-container {
        flex-direction: column;
        align-items: stretch;
    }

        .search-container form {
            width: 100%;
            justify-content: center;
        }

        .search-container input.form-control {
            width: 100%;
        }

        .search-container .btn-primary,
        .search-container .btn-success {
            width: 100%;
            text-align: center;
        }
}
/* Responsive tweaks for smaller screens */
@media (max-width: 768px) {
    .search-form {
        width: 100%; /* Full width on small screens */
        max-width: none;
    }

    .container.mt-5 {
        padding: 10px;
    }
}
/* Browser-specific fixes */
@supports (-webkit-touch-callout: none) {
    .dashboard-card {
        -webkit-appearance: none;
    }
}

/* === Sidebar height fix (kept) === */
/* Desktop & large screens: earlier approach */
@media (min-width: 992px) {
    .sidebar {
        height: auto !important; /* override calc(...) above */
        top: var(--header-height) !important;
        bottom: 0 !important;
        box-sizing: border-box;
    }
}

/* Mobile: keep slide-over full height */
@media (max-width: 991.98px) {
    .sidebar {
        top: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
    }
}

@media (min-width: 992px) {
    .sidebar {
        top: 0 !important; /* anchor to top of viewport */
        bottom: 0 !important; /* also anchor to bottom */
        height: auto !important; /* let top+bottom define height */
        padding-top: var(--header-height) !important; /* content starts below header */
        left: 0; /* ensure left anchoring */
    }
}

/* === KEEP HEADER ABOVE SIDEBAR so login/logout/alerts are visible === */
header.navbar {
    position: sticky; /* creates a new stacking context */
    top: 0;
    z-index: 1200; /* higher than .sidebar (1000) */
}

/* === BACKDROP STRIP behind sidebar to prevent any white showing === */
@media (min-width: 992px) {
    body::before {
        content: "";
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 250px; /* match sidebar width */
        background-color: #343a40; /* match sidebar bg */
        z-index: 900; /* behind .sidebar (1000) */
        pointer-events: none;
    }
}

body.login-page .sidebar {
    display: none !important;
}

body.login-page .content {
    margin-left: 0 !important;
}

/* Hide the fixed backdrop strip when on login */
@media (min-width: 992px) {
    body.login-page::before {
        display: none !important;
    }
}

/* Fix the header to the very top (override sticky above) */
header.navbar {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1200; /* above the sidebar (1000) */
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
}

/* Push page content below the fixed header */
body {
    padding-top: var(--header-height);
}

/* ============================================================
   PATCH: Tapability & stacking fixes (non-destructive overrides)
   ============================================================ */

/* Sidebar should sit above content and, on mobile slide-over, above header too */
.sidebar {
    z-index: 1300;
}

/* Keep content below sidebar */
.content {
    position: relative;
    z-index: 1;
}

/* Mobile: ensure collapse shows as a block and content doesn't offset */
@media (max-width: 991.98px) {
    #sidebar.collapse.show {
        display: block;
    }

    .content {
        margin-left: 0;
    }
}

/* Choose a single, consistent desktop offset without deleting earlier blocks */
@media (min-width: 992px) {
    .sidebar {
        position: fixed;
        top: var(--header-height);
        bottom: 0;
        width: 250px;
        transform: none;
        height: auto;
        box-sizing: border-box;
        left: 0;
    }

    .content {
        margin-left: 250px;
    }

    .sidebar ~ .content {
        margin-left: 250px !important;
    }
}


/* ===========================================================
   OFF-CANVAS MOBILE OVERRIDES (FINAL APPEND-ONLY SECTION)
   =========================================================== */

/* Keep sidebar above everything when opened */
.sidebar {
    z-index: 1300 !important;
}

/* Mobile: hidden by default, slide in when .collapse.show is present */
@media (max-width: 991.98px) {
    /* Full-screen slide-over panel */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        transition: transform .3s ease !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

        #sidebar.collapse.show {
            display: block !important; /* ensure it renders */
            transform: translateX(0) !important;
        }

    /* Content should never offset on mobile */
    .content {
        margin-left: 0 !important;
        position: relative !important;
        z-index: 1 !important;
    }

    /* Optional soft backdrop while menu is open; toggled by JS */
    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.25);
        z-index: 1200; /* below .sidebar (1300), above content */
        pointer-events: none;
    }
}

/* Desktop: keep your fixed, always-visible sidebar */
@media (min-width: 992px) {
    #sidebar {
        position: fixed !important;
        top: var(--header-height) !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 250px !important;
        transform: none !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    .content {
        margin-left: 250px !important;
        position: relative !important;
        z-index: 1 !important;
    }

    .sidebar ~ .content {
        margin-left: 250px !important;
    }
}
/* === REMOVE DESKTOP BACKDROP STRIP (fixes black bar) === */
@media (min-width: 992px) {
    body::before {
        display: none !important;
    }
}

/* ==============================================================
   FINAL PATCH: desktop header/sidebar alignment (no blank strip)
   ============================================================== */
@media (min-width: 992px) {
    /* Body should not carry padding on desktop */
    body {
        padding-top: 0 !important;
    }

    /* Sidebar should begin directly below header with no internal top padding */
    #sidebar.sidebar,
    .sidebar {
        top: var(--header-height) !important;
        padding-top: 0 !important;
        height: calc(100vh - var(--header-height)) !important;
        box-sizing: border-box;
    }

    /* Content sits below the fixed header */
    .content {
        padding-top: var(--header-height) !important;
    }
}
/* ===== Ensure header & its dropdown sit above the sidebar ===== */
header.navbar {
    /* header is already fixed; just ensure it's above the sidebar */
    z-index: 1600 !important; /* > 1300 */
}

    header.navbar .dropdown-menu {
        /* dropdown should be above both header and sidebar */
        z-index: 1700 !important;
    }

        /* Optional: cleaner right alignment without negative margins */
        header.navbar .dropdown-menu.dropdown-menu-end {
            right: 0 !important;
            margin-right: -57px !important;
        }
/* === MOBILE: push sidebar content below the fixed header, keep it scrollable === */
@media (max-width: 991.98px) {
    #sidebar {
        /* Keep full-screen slide-over, but offset content from the fixed header */
        padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px)) !important;
        /* Preserve your side paddings from the base rule; only override top */
        box-sizing: border-box !important;
        /* Make sure the total height is usable and scrolls fully */
        height: calc(100vh - env(safe-area-inset-bottom, 0px)) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* Optional: prevent the page behind from scrolling while the sidebar is open */
@media (max-width: 991.98px) {
    body.sidebar-open {
        overflow: hidden;
        touch-action: none;
    }
}

/* ===== Z-Index Ladder (append-only) =================================== */
:root {
    --z-sidebar: 1300;
    --z-header: 1600;
    --z-dropdown: 1700;
    --z-backdrop: 4990; /* much higher than header/sidebar */
    --z-modal: 5000;
    --z-modal-pop: 5001; /* popups inside modal */
}

/* Keep your existing values but formalize them */
.sidebar {
    z-index: var(--z-sidebar) !important;
}

header.navbar {
    z-index: var(--z-header) !important;
}

    header.navbar .dropdown-menu {
        z-index: var(--z-dropdown) !important;
    }

/* Modal should beat everything else */
.modal {
    position: fixed;
    z-index: var(--z-modal) !important;
}

.modal-backdrop {
    position: fixed;
    z-index: var(--z-backdrop) !important;
}

/* While modal is open, force other layers below backdrop */
body.modal-open header.navbar,
body.modal-open header.navbar .dropdown-menu,
body.modal-open #sidebar {
    z-index: calc(var(--z-backdrop) - 1) !important;
}

/* ===== Popups inside modals (datepickers, popovers, select2, etc.) ===== */
.bootstrap-datetimepicker-widget,
.datepicker,
.ui-datepicker,
.flatpickr-calendar,
.dropdown-menu.show, /* BS dropdowns opened inside modal */
.bs-popover-auto, .popover,
.bs-tooltip-auto, .tooltip,
.pac-container, /* Google Places autocomplete */
.select2-container--open,
.tt-menu { /* typeahead */
    z-index: var(--z-modal-pop) !important;
}

/* Neutralize accidental stacking-context creators while modal is open */
body.modal-open .content,
body.modal-open .layout-wrapper,
body.modal-open .content-wrapper {
    transform: none !important;
    filter: none !important;
    perspective: none !important;
}
