/* ============================================
   SIDEBAR LAYOUT
   Modern sidebar navigation for admin areas
   ============================================ */

/* ========================================
   LAYOUT STRUCTURE
   ======================================== */

.sidebar-layout {
    display: flex;
    min-height: 100vh;
    overflow-x: visible !important; /* CRITICAL: Allow horizontal scroll for tables */
}

/* ========================================
   SIDEBAR
   ======================================== */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: linear-gradient(180deg, #2E7D32 0%, #388E3C 100%);
    /* Using your root green colors: primary-800 to primary-700 */
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
}

/* Removed collapsed state - using hidden state instead */

/* ========================================
   SIDEBAR HEADER
   ======================================== */

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: white;
    font-weight: 600;
    font-size: 1.25rem;
    transition: opacity 0.2s;
}

.sidebar-brand:hover {
    opacity: 0.9;
    color: white;
}

.sidebar-logo {
    height: 36px;
    width: 36px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}

.sidebar-brand-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.3s;
}

/* Removed collapsed state styling */

.sidebar-toggle {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: rgba(165, 214, 167, 0.3);
    /* Green accent on hover */
}

/* Toggle icon rotates when sidebar hidden */
.sidebar.hidden .sidebar-toggle i {
    transform: rotate(180deg);
}

/* ========================================
   ENVIRONMENT BADGE
   ======================================== */

.sidebar-env-badge {
    padding: 0.75rem 1rem;
}

/* Removed collapsed env badge styling */

/* ========================================
   SIDEBAR MENU
   ======================================== */

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

/* ========================================
   SUBMENU CONTROLS (Collapse/Expand All)
   ======================================== */

.sidebar-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-submenu-control {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.375rem;
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-submenu-control:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(165, 214, 167, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-submenu-control:active {
    transform: translateY(0);
}

.btn-submenu-control i {
    font-size: 0.875rem;
}

.btn-submenu-control .control-text {
    font-size: 0.7rem;
}

/* When sidebar is hidden, controls are not visible anyway */

/* Mobile: Stack buttons vertically for better touch targets */
@media (max-width: 576px) {
    .sidebar-controls {
        flex-direction: column;
        gap: 0.375rem;
    }
    
    .btn-submenu-control {
        padding: 0.625rem 0.75rem;
        min-height: 44px; /* Better touch target */
    }
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(200, 230, 201, 0.9);
    /* Light green for section titles */
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 0.375rem;
    user-select: none;
}

.sidebar-section-title:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(200, 230, 201, 1);
}

.sidebar-section-title:focus {
    outline: 2px solid rgba(165, 214, 167, 0.5);
    outline-offset: 2px;
}

.section-title-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.section-chevron {
    font-size: 0.875rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar-section-title.collapsed .section-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-links {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s ease,
                margin-bottom 0.3s ease;
    opacity: 1;
    margin-bottom: 0.5rem;
}

.sidebar-section-links.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
}

/* Removed collapsed section title styling */

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    transition: all 0.2s;
    position: relative;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    border-left: 2px solid rgba(165, 214, 167, 0.5);
    /* Subtle green accent on hover */
}

.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
    font-weight: 600;
    border-left: 3px solid #A5D6A7;
    /* Using your root green: primary-200 */
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #C8E6C9;
    /* Using your root green: primary-100 */
}

.sidebar-link i {
    font-size: 1.25rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.sidebar-link-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Removed collapsed link styling */

/* ========================================
   SIDEBAR FOOTER
   ======================================== */

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.sidebar-user-info i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.sidebar-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.875rem;
}

/* Removed collapsed user name styling */

.sidebar-logout {
    color: white;
    padding: 0.25rem 0.5rem;
    text-decoration: none;
}

.sidebar-logout:hover {
    color: rgba(255,255,255,0.8);
}

/* Removed collapsed logout styling */

/* ========================================
   MAIN WRAPPER
   ======================================== */

.main-wrapper {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden; /* Prevent horizontal scroll on mobile */
    width: 100%;
    max-width: 100%;
}

/* Removed collapsed main wrapper margin */

/* ========================================
   TOPBAR
   ======================================== */

.topbar {
    background: white;
    border-bottom: 1px solid #e9ecef;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-toggle-mobile {
    background: transparent;
    border: none;
    color: #495057;
    font-size: 1.5rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 0.375rem;
}

.sidebar-toggle-mobile:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-toggle-mobile:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #212529;
    margin: 0;
}

.topbar-item {
    display: flex;
    align-items: center;
}

.topbar-btn {
    background: transparent;
    border: none;
    color: #495057;
    padding: 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s;
    position: relative;
}

.topbar-btn:hover {
    background: #f8f9fa;
    color: #0d6efd;
}

.notification-badge {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content-sidebar {
    flex: 1;
    padding: 2rem 1.5rem;
    background: #f8f9fa;
    overflow-x: visible; /* Allow horizontal scroll for wide tables */
}

/* ========================================
   FOOTER
   ======================================== */

.footer-sidebar {
    background: white;
    border-top: 1px solid #e9ecef;
    padding: 1rem 1.5rem;
    text-align: center;
    color: #6c757d;
    font-size: 0.875rem;
}

.footer-sidebar p {
    margin: 0;
}

/* ========================================
   SIDEBAR OVERLAY (Mobile)
   ======================================== */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1039;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* ========================================
   SIDEBAR HIDDEN STATE (All Screen Sizes)
   ======================================== */

/* Hidden state for desktop */
@media (min-width: 992px) {
    .sidebar.hidden {
        transform: translateX(-100%);
    }

    .sidebar.hidden ~ .main-wrapper {
        margin-left: 0 !important;
    }
}

/* ========================================
   RESPONSIVE - MOBILE
   ======================================== */

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.2);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .main-wrapper {
        margin-left: 0 !important;
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }
    
    .sidebar-toggle {
        display: none;
    }
    
    .topbar-title {
        font-size: 1rem;
    }
    
    /* Better touch targets on mobile */
    .sidebar-link {
        padding: 1rem 1rem;
        min-height: 48px;
    }
    
    .sidebar-section-title {
        padding: 0.75rem 1rem;
    }
    
    .sidebar-header {
        padding: 1.25rem 1rem;
    }
}

@media (min-width: 992px) {
    /* Keep hamburger button visible on desktop too! */
    .sidebar-toggle-mobile {
        display: flex !important;
    }
    
    /* Ensure sidebar icon rotation works */
    .sidebar.hidden .sidebar-toggle i {
        transform: rotate(180deg);
    }
}

@media (max-width: 576px) {
    .topbar {
        padding: 0.5rem 0.75rem;
    }
    
    .topbar-title {
        display: none;
    }
    
    .main-content-sidebar {
        padding: 0.75rem;
    }
    
    .sidebar {
        width: 280px;
    }
    
    /* Compact language switcher */
    .language-switcher-modern {
        gap: 0.25rem;
    }
    
    .btn-language-modern {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Smaller icons */
    .topbar-btn {
        padding: 0.25rem;
        font-size: 1.1rem;
    }
}

/* ========================================
   RTL SUPPORT
   ======================================== */

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

[dir="rtl"] .main-wrapper {
    margin-left: 0;
    margin-right: 260px;
}

/* RTL hidden state for desktop only */
@media (min-width: 992px) {
    [dir="rtl"] .sidebar.hidden {
        transform: translateX(100%);
    }

    [dir="rtl"] .sidebar.hidden ~ .main-wrapper {
        margin-left: 0;
        margin-right: 0 !important;
    }
    
    [dir="rtl"] .sidebar.hidden .sidebar-toggle i {
        transform: rotate(180deg) scaleX(-1);
    }
}

/* Fix RTL mobile - no margin on mobile screens */
@media (max-width: 991px) {
    [dir="rtl"] .main-wrapper {
        margin-right: 0 !important;
    }
}

[dir="rtl"] .sidebar-link.active::before {
    left: auto;
    right: 0;
}

/* Moved RTL hidden toggle to desktop media query above */

[dir="rtl"] .notification-badge {
    right: auto;
    left: 0.25rem;
}

/* RTL: Section chevron positioning */
[dir="rtl"] .section-chevron {
    margin-right: auto;
    margin-left: 0;
}

[dir="rtl"] .sidebar-section-title.collapsed .section-chevron {
    transform: rotate(90deg); /* Rotate opposite direction in RTL */
}

@media (max-width: 991px) {
    [dir="rtl"] .sidebar {
        transform: translateX(100%);
        left: auto;
        right: 0;
    }
    
    [dir="rtl"] .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    [dir="rtl"] .sidebar-link.active,
    [dir="rtl"] .sidebar-link:hover {
        border-left: none;
        border-right: 3px solid #A5D6A7;
    }
}
