/*
 * ==========================================================================
 * ENTERPRISE SIDEBAR CSS — UI/UX Redesign
 * ==========================================================================
 * Logic:
 * - Collapsed (default): width 56px, centered group/item icons, floating badge dots
 * - Expanded (hover / pinned): width 220px, icon + label + badge count + accordion
 * - Mobile: smooth drawer navigation with backdrop
 */

/* ==========================================
   1. DESIGN TOKENS & CSS VARIABLES
   ========================================== */
:root {
    --header-height: 70px;
    --sidebar-width-collapsed: 56px;
    --sidebar-width-expanded: 224px;
    --sidebar-width-mobile: min(17rem, calc(100vw - 3.5rem));
    --menu-item-height: 40px;
    --sidebar-item-x: 6px;
    --icon-size: 20px;

    /* System Yellow-Orange Brand Palette */
    --sidebar-bg: #fd7e14;
    --sidebar-gradient: linear-gradient(180deg, #ff922b 0%, #fd7e14 45%, #f76707 100%);
    --sidebar-border-right: rgba(255, 255, 255, 0.18);
    --sidebar-shadow: 4px 0 20px -2px rgba(253, 126, 20, 0.2);

    /* Interactive States */
    --sidebar-item-hover: rgba(255, 255, 255, 0.16);
    --sidebar-item-active: rgba(255, 255, 255, 0.26);
    --sidebar-item-active-border: rgba(255, 255, 255, 0.35);

    /* Animation Timing */
    --sidebar-transition: 0.25s cubic-bezier(0.2, 0, 0, 1);
    --sidebar-accordion-transition: 0.24s cubic-bezier(0.2, 0, 0, 1);
}

/* ==========================================
   2. SIDEBAR CONTAINER & BACKDROP
   ========================================== */
.sidebar-container {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width-collapsed);
    z-index: 1030;
    transition: width var(--sidebar-transition);
    overflow: hidden;
    will-change: width;
}

.sidebar-mobile-backdrop {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity var(--sidebar-transition);
    z-index: 1025;
    pointer-events: none;
}

.sidebar-mobile-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-container:hover,
.sidebar-container.pinned {
    width: var(--sidebar-width-expanded);
}

/* ==========================================
   3. SIDEBAR MAIN ELEMENT
   ========================================== */
#sidebar {
    width: var(--sidebar-width-collapsed);
    height: 100%;
    box-sizing: border-box;
    background: var(--sidebar-gradient);
    border-right: 1px solid var(--sidebar-border-right);
    box-shadow: var(--sidebar-shadow);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    transition: width var(--sidebar-transition);
    scrollbar-width: none;
    scrollbar-color: transparent transparent;
}

#sidebar::-webkit-scrollbar {
    width: 0;
    height: 0;
}

#sidebar::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 6px;
}

.sidebar-container:hover #sidebar,
#sidebar.pinned {
    width: var(--sidebar-width-expanded);
    scrollbar-width: thin;
}

.sidebar-container:hover #sidebar::-webkit-scrollbar,
#sidebar.pinned::-webkit-scrollbar {
    width: 5px;
}

.sidebar-container:hover #sidebar::-webkit-scrollbar-thumb,
#sidebar.pinned::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.28);
}

.sidebar-container:hover #sidebar::-webkit-scrollbar-thumb:hover,
#sidebar.pinned::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.45);
}

#sidebar.pinned {
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.16);
}

/* ==========================================
   4. SIDEBAR TOP BAR & PIN CONTROL
   ========================================== */
.sidebar-top {
    position: sticky;
    top: 0;
    z-index: 10;
    background: inherit;
    min-height: 44px;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end !important;
    align-items: center;
    padding: 8px 10px 4px !important;
}

.sidebar-mobile-close {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    transition: background 0.15s ease;
}

.sidebar-mobile-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

#pin-container {
    width: 32px;
    height: 32px;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.88;
    pointer-events: auto;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.sidebar-container:hover #pin-container,
#sidebar.pinned #pin-container {
    opacity: 1;
}

#pin-button {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: white;
    cursor: pointer;
    border-radius: 8px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

#pin-button:hover,
#pin-button:focus-visible {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.48);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
    transform: scale(1.04);
}

#pin-button:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

#sidebar.pinned #pin-button {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.55);
}

/* ==========================================
   5. SIDEBAR MENU & ITEMS
   ========================================== */
.sidebar-menu {
    display: flex;
    flex-direction: column;
    padding: 4px 0 28px 0 !important;
    gap: 2px;
}

/* Individual Menu Item */
.menu-item {
    display: flex;
    align-items: center;
    height: var(--menu-item-height);
    box-sizing: border-box;
    margin: 1px var(--sidebar-item-x);
    padding: 0 !important;
    border-radius: 8px;
    text-decoration: none !important;
    color: rgba(255, 255, 255, 0.92) !important;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}

/* Menu Item Icon */
.menu-item .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--sidebar-width-collapsed) - (var(--sidebar-item-x) * 2));
    min-width: calc(var(--sidebar-width-collapsed) - (var(--sidebar-item-x) * 2));
    height: 100%;
    flex-shrink: 0;
    overflow: hidden;
}

.menu-item .icon i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem !important;
    line-height: 1;
    color: #ffffff !important;
    width: 1.25rem;
    height: 1.25rem;
    text-align: center;
    transition: transform 0.18s ease;
}

/* Menu Item Label (Hidden when 56px, visible when expanded) */
.menu-item .label {
    display: none;
    opacity: 0;
    font-size: 0.86rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    padding-right: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.18s cubic-bezier(0.2, 0, 0, 1);
}

.sidebar-container:hover .menu-item .label,
#sidebar.pinned .menu-item .label,
body.sidebar-mobile-open .menu-item .label {
    display: block;
    opacity: 1;
}

/* Badge on Menu Item */
.menu-item .badge {
    display: none;
    margin-left: auto;
    margin-right: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.22em 0.55em;
    line-height: 1;
    border-radius: 999px;
    flex-shrink: 0;
    z-index: 1;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: margin-right 0.15s ease;
}

.sidebar-container:hover .menu-item .badge,
#sidebar.pinned .menu-item .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Hover State */
.menu-item:hover {
    background: var(--sidebar-item-hover);
    color: #ffffff !important;
    transform: translateX(2px);
}

.menu-item:hover .icon i {
    transform: scale(1.08);
}

/* Active State */
.menu-item.active,
.menu-item[aria-current="page"] {
    background: var(--sidebar-item-active);
    box-shadow: inset 0 0 0 1px var(--sidebar-item-active-border), 0 2px 8px rgba(0, 0, 0, 0.12);
    color: #ffffff !important;
    font-weight: 600;
}

.menu-item.active::before,
.menu-item[aria-current="page"]::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3.5px;
    background: #ffffff;
    border-radius: 0 4px 4px 0;
    z-index: 1;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.75);
}

.menu-item.active::after,
.menu-item[aria-current="page"]::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    width: 6px;
    height: 6px;
    border-top: 2px solid rgba(255, 255, 255, 0.9);
    border-right: 2px solid rgba(255, 255, 255, 0.9);
    transform: translateY(-50%) rotate(45deg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.sidebar-container:hover .menu-item.active::after,
.sidebar-container:hover .menu-item[aria-current="page"]::after,
#sidebar.pinned .menu-item.active::after,
#sidebar.pinned .menu-item[aria-current="page"]::after {
    opacity: 0.85;
}

.sidebar-container:hover .menu-item.active .badge,
.sidebar-container:hover .menu-item[aria-current="page"] .badge,
#sidebar.pinned .menu-item.active .badge,
#sidebar.pinned .menu-item[aria-current="page"] .badge {
    margin-right: 20px;
}

/* ==========================================
   6. MENU GROUPS & ACCORDION
   ========================================== */
.menu-group {
    position: relative;
}

/* Divider Line */
.menu-group-divider {
    display: none;
    height: 1px;
    border: none !important;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.22) 50%, transparent 100%) !important;
    margin: 6px 12px !important;
}

.sidebar-container:hover .menu-group-divider,
#sidebar.pinned .menu-group-divider {
    display: block;
}

/*
 * Group Icon-Only Button (Shown ONLY in 56px mode when group is collapsed)
 */
.menu-group-icon-btn {
    display: none; /* Default hidden */
    align-items: center;
    justify-content: center;
    position: relative;
    height: var(--menu-item-height);
    width: calc(var(--sidebar-width-collapsed) - (var(--sidebar-item-x) * 2));
    margin: 1px var(--sidebar-item-x);
    border-radius: 9px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    white-space: nowrap;
    overflow: visible;
    flex-shrink: 0;
}

.menu-group-icon-btn .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
}

.menu-group-icon-btn .icon i {
    font-size: 1.25rem !important;
    line-height: 1;
    color: rgba(255, 255, 255, 0.92) !important;
    width: 1.25rem;
    height: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: transform 0.18s ease;
}

.menu-group-icon-btn:hover {
    background: var(--sidebar-item-hover);
    transform: scale(1.04);
}

.menu-group-icon-btn:hover .icon i {
    color: #ffffff !important;
    transform: scale(1.08);
}

/* Active Highlight on Group Icon Button */
.menu-group-icon-btn.has-active {
    background: var(--sidebar-item-active);
    box-shadow: inset 0 0 0 1px var(--sidebar-item-active-border);
}

.menu-group-icon-btn.has-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 3.5px;
    background: white;
    border-radius: 0 4px 4px 0;
    z-index: 1;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.75);
}

.menu-group-icon-btn.has-active .icon i {
    color: #ffffff !important;
}

/*
 * Floating Notification Badge on Group Icon
 */
.group-icon-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px !important;
    font-size: 0.65rem !important;
    font-weight: 700 !important;
    line-height: 1;
    border-radius: 999px;
    background-color: #dc3545 !important;
    color: #ffffff !important;
    border: 2px solid var(--sidebar-bg);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
    transform: scale(1);
    transition: transform 0.15s ease;
}

.menu-group.collapsed .group-icon-badge:not(:empty) {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

/*
 * Visibility Rules for Icon Button:
 * - 56px mode: SHOW when group is collapsed
 * - Expanded mode: HIDE always
 */
.sidebar-container:not(:hover) #sidebar:not(.pinned) .menu-group.collapsed .menu-group-icon-btn,
body:not(.sidebar-pinned) .sidebar-container:not(:hover) .menu-group.collapsed .menu-group-icon-btn {
    display: flex;
}

.sidebar-container:hover .menu-group-icon-btn,
#sidebar.pinned .menu-group-icon-btn,
body.sidebar-pinned .menu-group-icon-btn {
    display: none !important;
}

/*
 * Group Header (Label row in expanded mode)
 */
.menu-group-header {
    display: none !important;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px 5px !important;
    margin: 4px var(--sidebar-item-x) 2px !important;
    font-size: 0.68rem !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.76) !important;
    cursor: pointer;
    user-select: none;
    border-radius: 7px;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar-container:hover .menu-group-header,
#sidebar.pinned .menu-group-header,
body.sidebar-pinned .menu-group-header,
body.sidebar-mobile-open .menu-group-header {
    display: flex !important;
}

.sidebar-container:hover .menu-group-header:hover,
#sidebar.pinned .menu-group-header:hover,
body.sidebar-pinned .menu-group-header:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff !important;
}

.menu-group-header:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 1px;
}

/* Meta container (Badge Total + Chevron) */
.menu-group-meta {
    display: none;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
}

.sidebar-container:hover .menu-group-meta,
#sidebar.pinned .menu-group-meta,
body.sidebar-pinned .menu-group-meta,
body.sidebar-mobile-open .menu-group-meta {
    display: flex;
}

/* Badge Total on Group Header */
.group-badge-total {
    font-size: 0.65rem !important;
    font-weight: 700 !important;
    padding: 0.2em 0.5em !important;
    line-height: 1;
    border-radius: 999px;
    display: none !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.menu-group.collapsed .group-badge-total:not(:empty) {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

/* Chevron Arrow Indicator */
.menu-group-chevron {
    font-size: 0.7rem !important;
    color: rgba(255, 255, 255, 0.65);
    transition: transform var(--sidebar-accordion-transition);
    display: inline-flex;
    align-items: center;
}

.menu-group.collapsed .menu-group-chevron {
    transform: rotate(180deg);
}

/* Collapsible Items Container */
.menu-group-items {
    overflow: hidden;
    max-height: 2000px;
    transition: max-height var(--sidebar-accordion-transition), opacity var(--sidebar-accordion-transition);
    opacity: 1;
}

.menu-group.collapsed .menu-group-items {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ==========================================
   7. SUPERUSER SECTION
   ========================================== */
.superuser-section {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 9px;
    margin: 8px 4px;
    padding: 6px 0;
}

.superuser-section .menu-section-title {
    color: rgba(255, 255, 255, 0.88) !important;
}

.superuser-section .menu-item {
    margin: 0 2px;
}

.superuser-section .menu-item:hover {
    background: rgba(220, 53, 69, 0.3);
}

/* ==========================================
   8. CONTENT AREA & FOOTER ALIGNMENT
   ========================================== */
.content-area {
    margin-left: var(--sidebar-width-collapsed);
    width: calc(100% - var(--sidebar-width-collapsed));
    min-height: calc(100vh - var(--header-height));
    transition: margin-left var(--sidebar-transition), width var(--sidebar-transition);
}

body.layout-without-sidebar .content-area {
    margin-left: 0;
    width: 100%;
}

body.sidebar-pinned .content-area {
    margin-left: var(--sidebar-width-expanded);
    width: calc(100% - var(--sidebar-width-expanded));
}

#footer {
    margin-left: var(--sidebar-width-collapsed);
    width: calc(100% - var(--sidebar-width-collapsed));
    transition: margin-left var(--sidebar-transition), width var(--sidebar-transition);
}

body.layout-without-sidebar #footer {
    margin-left: 0;
    width: 100%;
}

body.layout-without-sidebar .sidebar-container,
body.layout-without-sidebar .sidebar-mobile-backdrop,
body.layout-without-sidebar #sidebar-toggle {
    display: none !important;
}

body.sidebar-pinned #footer {
    margin-left: var(--sidebar-width-expanded);
    width: calc(100% - var(--sidebar-width-expanded));
}

/* Page Navigation Exit Transition (Disabled forced layout shifting to prevent jank/stutter) */
.sidebar-container.is-navigating,
.sidebar-container.is-navigating #sidebar {
    /* Retain natural sidebar state during PJAX navigation without forced width snaps */
}

body.sidebar-navigating .content-area,
body.sidebar-navigating #footer {
    /* Keep content area margins stable during page transition to prevent layout thrashing */
}

/* ==========================================
   9. RESPONSIVE MOBILE DRAWER
   ========================================== */
@media (max-width: 991.98px) {
    .sidebar-container {
        width: var(--sidebar-width-mobile);
        pointer-events: none;
        transform: translateX(calc(-1 * var(--sidebar-width-mobile)));
        transition: transform var(--sidebar-transition);
        overflow: visible;
    }

    .sidebar-container:hover,
    .sidebar-container.pinned {
        width: var(--sidebar-width-mobile);
    }

    #sidebar {
        position: relative;
        top: auto;
        left: auto;
        bottom: auto;
        width: 100%;
        max-width: none;
        height: 100%;
        transform: none;
        transition: none;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.28);
    }

    body.sidebar-mobile-open .sidebar-container {
        pointer-events: auto;
        transform: translateX(0);
    }

    .sidebar-container:hover #sidebar,
    #sidebar.pinned {
        width: 100%;
    }

    #pin-container {
        display: none;
    }

    .menu-item .label {
        display: block !important;
        opacity: 1 !important;
    }

    .menu-section-title,
    .menu-group-divider,
    #sidebar hr {
        display: block;
    }

    .menu-group-header {
        display: flex !important;
    }

    .menu-group-meta {
        display: flex !important;
    }

    .menu-group-icon-btn {
        display: none !important;
    }

    .menu-item .badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .menu-item.active::after,
    .menu-item[aria-current="page"]::after {
        opacity: 0.85;
    }

    .menu-item.active .badge,
    .menu-item[aria-current="page"] .badge {
        margin-right: 22px;
    }

    .menu-item .icon {
        width: 44px;
        min-width: 44px;
    }

    .sidebar-top {
        min-height: 42px;
        justify-content: flex-start !important;
        padding: 6px 8px !important;
    }

    .content-area,
    #footer,
    body.sidebar-pinned .content-area,
    body.sidebar-pinned #footer {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

