/* =========================================
   1. GLOBAL LAYOUT
   ========================================= */
body {
    font-size: .875rem;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

/* LOCK SCROLL ON MOBILE WHEN MENU OPEN */
body.sidebar-open {
    overflow: hidden !important;
}

#main-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: 56px; /* Header Height */
    transition: margin-left 0.3s ease;
    width: 100%;
}

main#main-content {
    flex: 1;
    width: 100%;
    overflow-x: hidden;
}

/* =========================================
   2. HEADER (HIGHEST LAYER)
   ========================================= */
#page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 1100 !important; /* Highest Layer */
    display: flex;
    align-items: center;
    background-color: #212529; /* Always Dark Header */
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.navbar-brand {
    padding-top: .75rem;
    padding-bottom: .75rem;
    background-color: rgba(0, 0, 0, .25);
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
    white-space: nowrap;
}

.form-control-dark {
    color: #fff;
    background-color: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
    color: #fff;
    background-color: rgba(255, 255, 255, .1);
    border-color: transparent;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}

/* =========================================
   3. SIDEBAR (THEME AWARE & PREMIUM)
   ========================================= */
.sidebar {
    position: fixed;
    top: 56px !important;
    bottom: 0;
    left: 0;
    width: 260px;
    padding-top: 20px;
    overflow-y: auto;
    /* Theme Aware Backgrounds */
    background-color: var(--bs-tertiary-bg); 
    border-right: 1px solid var(--bs-border-color);
    z-index: 1050 !important;
    
    transform: translateX(-100%);
    visibility: hidden; 
    transition: transform 0.3s ease-in-out, visibility 0.3s ease-in-out;
    box-shadow: 4px 0 15px rgba(0,0,0,0.05);
}

/* OPEN STATE */
body.sidebar-open .sidebar {
    transform: translateX(0) !important;
    visibility: visible !important;
}

/* --- PREMIUM LINKS STYLING --- */
.sidebar .nav-link {
    font-weight: 500;
    color: var(--bs-body-color);
    padding: 0.6rem 1rem;
    margin: 2px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: all 0.2s ease-in-out;
    border-left: 3px solid transparent; /* Indicator Bar placeholder */
}

/* Icons styling */
.sidebar .nav-link i.bi { 
    margin-right: 12px; 
    font-size: 1.1rem; 
    color: var(--bs-secondary-color);
    transition: color 0.2s;
}

/* Hover State */
.sidebar .nav-link:hover {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-primary);
}
.sidebar .nav-link:hover i.bi {
    color: var(--bs-primary);
}

/* Active State (The Item you are currently on) */
.sidebar .nav-link.active {
    background-color: rgba(169, 34, 68, 0.08); /* Brand color tint */
    color: #a92244; /* Brand Color */
    border-left-color: #a92244; /* Left Accent Bar */
    font-weight: 600;
}
.sidebar .nav-link.active i.bi {
    color: #a92244;
}

/* Dark Mode Active Override */
[data-bs-theme="dark"] .sidebar .nav-link.active {
    background-color: rgba(169, 34, 68, 0.2);
    color: #ff6b8b; /* Lighter pink for contrast */
    border-left-color: #ff6b8b;
}
[data-bs-theme="dark"] .sidebar .nav-link.active i.bi {
    color: #ff6b8b;
}

/* --- COLLAPSIBLE CATEGORY HEADERS --- */
.sidebar .nav-link[data-bs-toggle="collapse"] {
    justify-content: space-between;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--bs-secondary-color);
    border-left: none !important;
    margin-top: 10px;
}

/* Base Icon: Chevron Down */
.sidebar .nav-link[data-bs-toggle="collapse"] i.bi-chevron-down {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

/* Closed State: Rotate -90deg (Point Right >) */
.sidebar .nav-link[data-bs-toggle="collapse"].collapsed i.bi-chevron-down {
    transform: rotate(-90deg);
}

/* Open State: Rotate 0deg (Point Down v) */
.sidebar .nav-link[data-bs-toggle="collapse"]:not(.collapsed) i.bi-chevron-down {
    transform: rotate(0deg);
    color: var(--bs-primary);
}

/* --- SUB-MENU TREE VIEW --- */
.sidebar .collapse {
    position: relative;
    width: 100%; /* Ensure full width on expand */
}

/* The vertical line guide */
.sidebar .collapse::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 10px;
    left: 28px; /* Position of the line */
    width: 2px;
    background-color: var(--bs-border-color);
    opacity: 0.5;
}

.sidebar .collapse .nav-link {
    padding-left: 3rem; /* Indent sub items */
    font-size: 0.85rem;
    margin-top: 1px;
}

/* =========================================
   4. DESKTOP OVERRIDE (Min Width 768px)
   ========================================= */
@media (min-width: 768px) {
    .sidebar {
        transform: translateX(0) !important;
        visibility: visible !important;
        width: 250px;
        z-index: 1040 !important;
        box-shadow: none;
    }
    
    #main-content-wrapper {
        margin-left: 250px;
    }

    body.sidebar-closed .sidebar {
        transform: translateX(-100%) !important;
    }
    body.sidebar-closed #main-content-wrapper {
        margin-left: 0;
    }
    
    #mobile-overlay { display: none !important; }
}

/* =========================================
   5. MOBILE OVERLAY
   ========================================= */
#mobile-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1045;
    backdrop-filter: blur(2px);
}
body.sidebar-open #mobile-overlay {
    display: block !important;
}

/* =========================================
   6. UTILITIES & DARK MODE FIXES
   ========================================= */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.footer {
    padding: 1.5rem 0; margin-top: auto;
    background-color: var(--bs-tertiary-bg);
    border-top: 1px solid var(--bs-border-color);
}

/* Dark Mode Specifics */
[data-bs-theme="dark"] {
    --bs-body-bg: #212529;
    --bs-body-color: #dee2e6;
    --bs-tertiary-bg: #2b3035; /* Slightly lighter sidebar */
}

/* Fix Cards in Dark Mode */
[data-bs-theme="dark"] .card {
    background-color: #2c3034;
    border-color: #373b3e;
}
[data-bs-theme="dark"] .card-header {
    background-color: rgba(0, 0, 0, 0.2);
    border-color: #373b3e;
}

/* Notifications Dropdown */
.dropdown-menu.notification-menu {
    width: 380px;
    max-height: 400px;
    overflow-y: auto;
}
.notification-item {
    white-space: normal !important; 
}
[data-bs-theme="dark"] .notification-item:hover {
    background-color: #343a40;
}