/* ============================================
   SIDEBAR NAVIGATION STYLES
   Modern collapsible sidebar with 3-level hierarchy
   ============================================ */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Dimensions */
    --sidebar-width-collapsed: 60px;
    --sidebar-width-expanded: 250px;
    --sidebar-transition-speed: 0.3s;

    /* Colors */
    --sidebar-bg: #192024;
    --sidebar-bg-hover: #252d32;
    --sidebar-bg-active: #2a3439;
    --sidebar-text: #c5c7c8;
    --sidebar-text-hover: #ffffff;
    --sidebar-accent: #7B833A;
    --sidebar-accent-hover: #8d9542;
    --sidebar-divider: rgba(144, 144, 144, 0.2);

    /* Mobile */
    --mobile-btn-size: 44px;
}

/* ============================================
   SIDEBAR BASE STYLES
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 10001;
    overflow: hidden;
    transition: width var(--sidebar-transition-speed) ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

/* Collapsed State (Default on Desktop) */
.sidebar.sidebar-collapsed {
    width: var(--sidebar-width-collapsed);
}

/* Expanded State */
.sidebar.sidebar-expanded {
    width: var(--sidebar-width-expanded);
}

/* Text visibility in collapsed state */
.sidebar-collapsed .sidebar-text,
.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-chevron,
.sidebar-collapsed .sidebar-user-name {
    opacity: 0;
    visibility: hidden;
    width: 0;
    overflow: hidden;
}

/* Text visibility in expanded state */
.sidebar-expanded .sidebar-text,
.sidebar-expanded .sidebar-brand-text,
.sidebar-expanded .sidebar-chevron,
.sidebar-expanded .sidebar-user-name {
    opacity: 1;
    visibility: visible;
    width: auto;
}

/* Hover expansion removed - only expand on click */

/* ============================================
   SIDEBAR TOGGLE BUTTON
   ============================================ */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    min-height: 50px;
    cursor: pointer;
    color: var(--sidebar-text);
    border-bottom: 1px solid var(--sidebar-divider);
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background-color: var(--sidebar-bg-hover);
}

.sidebar-toggle i {
    font-size: 1.25rem;
}

/* ============================================
   SIDEBAR BRAND/LOGO
   ============================================ */
.sidebar-brand {
    padding: 12px 15px;
    border-bottom: 1px solid var(--sidebar-divider);
    flex-shrink: 0;
}

.sidebar-brand a {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--sidebar-text-hover);
}

.sidebar-logo {
    width: 30px;
    height: 30px;
    min-width: 30px;
    object-fit: contain;
    border-radius: 4px;
}

.sidebar-brand-text {
    margin-left: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: opacity var(--sidebar-transition-speed), visibility var(--sidebar-transition-speed);
    letter-spacing: 0.02em;
}

/* ============================================
   NAVIGATION MENU
   ============================================ */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

/* Custom scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sidebar-divider);
    border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-accent);
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ============================================
   LEVEL 1 - MAIN MENU ITEMS
   ============================================ */
.sidebar-item {
    position: relative;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 11px 15px 11px 5px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.sidebar-link:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
    text-decoration: none;
}

.sidebar-link.active,
.sidebar-item.active > .sidebar-link {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-hover);
}

/* Icon styling */
.sidebar-link > i:first-child {
    width: 30px;
    min-width: 30px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-text {
    margin-left: 10px;
    font-size: 0.9rem;
    transition: opacity var(--sidebar-transition-speed), visibility var(--sidebar-transition-speed);
}

/* Chevron for expandable items */
.sidebar-chevron {
    margin-left: auto;
    font-size: 0.7rem;
    transition: transform 0.3s, opacity var(--sidebar-transition-speed);
    padding-right: 5px;
}

.sidebar-item.open > .sidebar-link .sidebar-chevron {
    transform: rotate(90deg);
}

/* ============================================
   LEVEL 2 - SUBMENUS
   ============================================ */
.sidebar-submenu {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
    background-color: rgba(0, 0, 0, 0.15);
}

.sidebar-item.open > .sidebar-submenu {
    display: block;
}

.sidebar-submenu > li > a {
    display: flex;
    align-items: center;
    padding: 9px 15px 9px 45px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.sidebar-submenu > li > a:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
    text-decoration: none;
}

.sidebar-submenu > li > a.active {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-hover);
}

.sidebar-submenu > li > a > i {
    margin-right: 10px;
    width: 18px;
    min-width: 18px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--sidebar-accent);
}

/* ============================================
   LEVEL 2 - CATEGORY HEADERS (Admin subcategories)
   ============================================ */
.sidebar-submenu-category {
    border-bottom: 1px solid var(--sidebar-divider);
}

.sidebar-submenu-category:last-child {
    border-bottom: none;
}

.sidebar-category-toggle {
    display: flex;
    align-items: center;
    padding: 10px 15px 10px 45px;
    color: var(--sidebar-accent);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.sidebar-category-toggle:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-accent-hover);
    text-decoration: none;
}

.sidebar-category-toggle > i:first-child {
    margin-right: 8px;
    width: 16px;
    min-width: 16px;
    text-align: center;
}

.sidebar-category-toggle .sidebar-chevron {
    margin-left: auto;
    opacity: 1;
    visibility: visible;
}

.sidebar-submenu-category.open > .sidebar-category-toggle .sidebar-chevron {
    transform: rotate(90deg);
}

/* ============================================
   LEVEL 3 - ITEMS WITHIN CATEGORIES
   ============================================ */
.sidebar-submenu-items {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
    background-color: rgba(0, 0, 0, 0.1);
}

.sidebar-submenu-category.open > .sidebar-submenu-items {
    display: block;
}

.sidebar-submenu-items > li > a {
    display: block;
    padding: 8px 15px 8px 30px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.8rem;
    transition: all 0.2s;
    text-align: left;
}

.sidebar-submenu-items > li > a:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
    padding-left: 35px;
    text-decoration: none;
}

.sidebar-submenu-items > li > a.active {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-hover);
}

/* ============================================
   USER SECTION (Bottom)
   ============================================ */
.sidebar-user {
    border-top: 1px solid var(--sidebar-divider);
    padding: 12px;
    margin-top: auto;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.1);
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    color: var(--sidebar-text);
    padding: 8px 3px;
    margin-bottom: 4px;
}

.sidebar-user-info > i {
    font-size: 1.4rem;
    width: 30px;
    min-width: 30px;
    text-align: center;
    color: var(--sidebar-accent);
}

.sidebar-user-name {
    margin-left: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--sidebar-transition-speed), visibility var(--sidebar-transition-speed);
}

.sidebar-logout,
.sidebar-login {
    display: flex;
    align-items: center;
    padding: 8px 3px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
}

.sidebar-logout:hover {
    background-color: #c0392b;
    color: #ffffff;
    text-decoration: none;
}

.sidebar-login:hover {
    background-color: var(--sidebar-accent);
    color: #ffffff;
    text-decoration: none;
}

.sidebar-logout > i,
.sidebar-login > i {
    width: 30px;
    min-width: 30px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-logout .sidebar-text,
.sidebar-login .sidebar-text {
    margin-left: 10px;
}

/* Hidden logout form */
#logoutForm {
    display: none;
}

/* ============================================
   MOBILE STYLES (< 992px)
   ============================================ */
@media (max-width: 991px) {
    /* Sidebar slides in from left on mobile */
    .sidebar {
        width: var(--sidebar-width-expanded) !important;
        transform: translateX(-100%);
        transition: transform var(--sidebar-transition-speed) ease;
    }

    .sidebar.sidebar-mobile-open {
        transform: translateX(0);
    }

    /* Always show text when mobile sidebar is open */
    .sidebar.sidebar-mobile-open .sidebar-text,
    .sidebar.sidebar-mobile-open .sidebar-brand-text,
    .sidebar.sidebar-mobile-open .sidebar-chevron,
    .sidebar.sidebar-mobile-open .sidebar-user-name {
        opacity: 1;
        visibility: visible;
        width: auto;
    }

    /* Hide toggle button on mobile (use hamburger instead) */
    .sidebar-toggle {
        display: none;
    }

    /* Mobile overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 10000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Mobile hamburger button */
    .mobile-menu-btn {
        display: flex;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 9999;
        background: var(--sidebar-accent);
        border: none;
        border-radius: 6px;
        color: #ffffff;
        width: var(--mobile-btn-size);
        height: var(--mobile-btn-size);
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 1.25rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .mobile-menu-btn:active {
        transform: scale(0.95);
    }

    /* Adjust main content on mobile */
    .main-content {
        margin-left: 0 !important;
        padding-top: 60px;
    }
}

/* Hide mobile elements on desktop */
@media (min-width: 992px) {
    .mobile-menu-btn {
        display: none;
    }

    .sidebar-overlay {
        display: none;
    }
}

/* ============================================
   MAIN CONTENT AREA ADJUSTMENT
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width-collapsed);
    transition: margin-left var(--sidebar-transition-speed) ease;
    min-height: 100vh;
}

/* When sidebar is pinned/expanded */
body.sidebar-pinned .main-content {
    margin-left: var(--sidebar-width-expanded);
}

/* Non-authenticated users (no sidebar) */
.main-content.no-sidebar {
    margin-left: 0;
}

/* ============================================
   HIDE ORIGINAL HEADER AND SKEL NAV
   ============================================ */
body.has-sidebar #header {
    display: none !important;
}

body.has-sidebar #skel-layers-wrapper {
    padding-top: 0 !important;
}

/* Hide skel-layers mobile nav elements when sidebar is present */
body.has-sidebar #navButton {
    display: none !important;
}

body.has-sidebar #navPanel {
    display: none !important;
}

/* ============================================
   PAGE CONTENT ADJUSTMENTS
   ============================================ */
body.has-sidebar .container.body-content {
    padding-top: 20px;
}

body.has-sidebar .paddingFromTop {
    /*margin-top: 1em;*/
}

/* Fix card page titles for sidebar layout */
body.has-sidebar .card-page-title {
    left: var(--sidebar-width-collapsed);
    width: calc(100% - var(--sidebar-width-collapsed));
    transition: left var(--sidebar-transition-speed), width var(--sidebar-transition-speed);
}

body.has-sidebar.sidebar-pinned .card-page-title {
    left: var(--sidebar-width-expanded);
    width: calc(100% - var(--sidebar-width-expanded));
}

@media (max-width: 991px) {
    body.has-sidebar .card-page-title {
        left: 0;
        width: 100%;
        top: 54px;
    }

    body.has-sidebar .card-page-title-offset {
        padding-top: 130px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .sidebar-overlay,
    .mobile-menu-btn {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding-top: 0 !important;
    }

    body.has-sidebar .card-page-title {
        left: 0 !important;
        width: 100% !important;
        position: relative !important;
    }
}

/* ============================================
   ACCESSIBILITY - FOCUS STATES
   ============================================ */
.sidebar-link:focus,
.sidebar-submenu a:focus,
.sidebar-category-toggle:focus,
.sidebar-submenu-items a:focus,
.sidebar-logout:focus,
.sidebar-login:focus {
    outline: none;
    background-color: var(--sidebar-bg-hover);
}

.sidebar-toggle:focus,
.mobile-menu-btn:focus {
    outline: none;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
