/* Premium Collapsible Sidebar Styling (RTL) */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 75px;
    --navbar-height: 80px;
    --sidebar-bg-light: #ffffff;
    --sidebar-bg-dark: #0d1322;
    --sidebar-border-light: #e2e8f0;
    --sidebar-border-dark: rgba(255, 255, 255, 0.06);
    --sidebar-text-light: #334155;
    --sidebar-text-dark: #cbd5e1;
    --sidebar-hover-light: #f8fafc;
    --sidebar-hover-dark: #141d33;
    --sidebar-active-bg-light: rgba(99, 102, 241, 0.08);
    --sidebar-active-bg-dark: rgba(99, 102, 241, 0.15);
    --sidebar-active-text-light: #4f46e5;
    --sidebar-active-text-dark: #a5b4fc;
}

/* Container Structure */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.main-wrapper {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-container.has-sidebar {
    --sidebar-real-width: var(--sidebar-width);
}

.app-container.has-sidebar.sidebar-collapsed,
html.sidebar-collapsed-global .app-container.has-sidebar {
    --sidebar-real-width: var(--sidebar-collapsed-width);
}

/* Sidebar Wrapper */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-real-width);
    height: 100vh;
    z-index: 1040;
    background-color: var(--sidebar-bg-light);
    border-left: 1px solid var(--sidebar-border-light);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    overflow-x: hidden;
}

[data-bs-theme="dark"] .sidebar {
    background-color: var(--sidebar-bg-dark);
    border-left: 1px solid var(--sidebar-border-dark);
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.25);
}

/* Main content & Header adjusts */
.app-container.has-sidebar .main-wrapper {
    flex-grow: 1;
    margin-right: var(--sidebar-real-width);
    min-width: 0;
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-container.has-sidebar .navbar.fixed-top {
    right: var(--sidebar-real-width);
    left: 0;
    width: auto;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar Header / Brand */
.sidebar-header {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--sidebar-border-light);
    overflow: hidden;
    white-space: nowrap;
    transition: padding 0.3s ease;
}

[data-bs-theme="dark"] .sidebar-header {
    border-bottom: 1px solid var(--sidebar-border-dark);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--sidebar-active-text-light);
}

[data-bs-theme="dark"] .sidebar-brand {
    color: var(--sidebar-active-text-dark);
}

.sidebar-brand-name {
    font-weight: 700;
    font-size: 1.25rem;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Sidebar Profile Section */
.sidebar-profile {
    padding: 20px;
    border-bottom: 1px solid var(--sidebar-border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    white-space: nowrap;
}

[data-bs-theme="dark"] .sidebar-profile {
    border-bottom: 1px solid var(--sidebar-border-dark);
}

.sidebar-profile-avatar {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid var(--primary-color);
}

.sidebar-profile-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: opacity 0.2s ease;
}

.sidebar-profile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--sidebar-text-light);
    margin-bottom: 2px;
    text-overflow: ellipsis;
    overflow: hidden;
}

[data-bs-theme="dark"] .sidebar-profile-name {
    color: var(--sidebar-text-dark);
}

.sidebar-profile-role {
    font-size: 0.75rem;
    color: #64748b;
}

/* Sidebar Menu Section */
.sidebar-menu {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Custom Scrollbar for Sidebar Menu */
.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: rgba(100, 116, 139, 0.2);
    border-radius: 4px;
}

/* Menu Group Header */
.sidebar-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: #94a3b8;
    padding: 15px 10px 5px 10px;
    letter-spacing: 0.5px;
    transition: opacity 0.2s ease;
}

/* Sidebar Links */
.sidebar-item {
    position: relative;
    list-style: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: 10px;
    color: var(--sidebar-text-light);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 1px solid transparent;
}

[data-bs-theme="dark"] .sidebar-link {
    color: var(--sidebar-text-dark);
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover-light);
    color: var(--sidebar-active-text-light);
}

[data-bs-theme="dark"] .sidebar-link:hover {
    background-color: var(--sidebar-hover-dark);
    color: var(--sidebar-active-text-dark);
}

.sidebar-link-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-link i.link-icon {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
    transition: transform 0.2s ease;
}

.sidebar-link:hover i.link-icon {
    transform: scale(1.1);
}

.sidebar-link .link-text {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Active State */
.sidebar-item.active > .sidebar-link {
    background-color: var(--sidebar-active-bg-light);
    color: var(--sidebar-active-text-light);
    border: 1px solid rgba(99, 102, 241, 0.08);
}

[data-bs-theme="dark"] .sidebar-item.active > .sidebar-link {
    background-color: var(--sidebar-active-bg-dark);
    color: var(--sidebar-active-text-dark);
    border: 1px solid rgba(99, 102, 241, 0.15);
}

/* Accordion Arrow */
.sidebar-link i.arrow-icon {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.sidebar-item.open > .sidebar-link i.arrow-icon {
    transform: rotate(-90deg); /* RTL Left Arrow rotated */
}

/* Submenu layout */
.sidebar-submenu {
    list-style: none;
    padding: 5px 35px 5px 10px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.sidebar-submenu-link {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    color: #64748b;
    text-decoration: none;
    font-size: 0.87rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border-right: 2px solid transparent;
}

[data-bs-theme="dark"] .sidebar-submenu-link {
    color: #94a3b8;
}

.sidebar-submenu-link:hover {
    color: var(--sidebar-active-text-light);
    background-color: var(--sidebar-hover-light);
    border-right-color: var(--sidebar-active-text-light);
}

[data-bs-theme="dark"] .sidebar-submenu-link:hover {
    color: var(--sidebar-active-text-dark);
    background-color: var(--sidebar-hover-dark);
    border-right-color: var(--sidebar-active-text-dark);
}

.sidebar-submenu-item.active > .sidebar-submenu-link {
    color: var(--sidebar-active-text-light);
    font-weight: 600;
    border-right-color: var(--sidebar-active-text-light);
    background-color: var(--sidebar-active-bg-light);
}

[data-bs-theme="dark"] .sidebar-submenu-item.active > .sidebar-submenu-link {
    color: var(--sidebar-active-text-dark);
    font-weight: 600;
    border-right-color: var(--sidebar-active-text-dark);
    background-color: var(--sidebar-active-bg-dark);
}

/* ==========================================
   Collapsed Mode (Mini Sidebar) Styles
   ========================================== */
.sidebar-collapsed .sidebar,
html.sidebar-collapsed-global .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-collapsed .sidebar-header,
html.sidebar-collapsed-global .sidebar-header {
    padding: 0 15px;
    justify-content: center;
}

.sidebar-collapsed .sidebar-brand-name,
.sidebar-collapsed .sidebar-profile-info,
.sidebar-collapsed .sidebar-group-title,
.sidebar-collapsed .sidebar-link .link-text,
.sidebar-collapsed .sidebar-link i.arrow-icon,
.sidebar-collapsed .sidebar-submenu,
html.sidebar-collapsed-global .sidebar-brand-name,
html.sidebar-collapsed-global .sidebar-profile-info,
html.sidebar-collapsed-global .sidebar-group-title,
html.sidebar-collapsed-global .sidebar-link .link-text,
html.sidebar-collapsed-global .sidebar-link i.arrow-icon,
html.sidebar-collapsed-global .sidebar-submenu {
    display: none !important;
}

.sidebar-collapsed .sidebar-profile,
html.sidebar-collapsed-global .sidebar-profile {
    padding: 15px;
    justify-content: center;
}

.sidebar-collapsed .sidebar-link,
html.sidebar-collapsed-global .sidebar-link {
    justify-content: center;
    padding: 12px;
}

/* CSS Tooltips on Hover in Collapsed Mode */
.sidebar-link .link-tooltip {
    display: none !important;
}

.sidebar-collapsed .sidebar-link .link-tooltip,
html.sidebar-collapsed-global .sidebar-link .link-tooltip {
    display: block !important;
    position: absolute;
    right: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
    background-color: #0f172a;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1060;
    pointer-events: none;
}

[data-bs-theme="dark"] .sidebar-collapsed .sidebar-link .link-tooltip,
[data-bs-theme="dark"] html.sidebar-collapsed-global .sidebar-link .link-tooltip {
    background-color: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-collapsed .sidebar-link:hover .link-tooltip,
html.sidebar-collapsed-global .sidebar-link:hover .link-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Collapsible Menu Toggle Hamburger button */
.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--sidebar-text-light);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

[data-bs-theme="dark"] .sidebar-toggle-btn {
    color: var(--sidebar-text-dark);
}

.sidebar-toggle-btn:hover {
    background-color: var(--sidebar-hover-light);
}

[data-bs-theme="dark"] .sidebar-toggle-btn:hover {
    background-color: var(--sidebar-hover-dark);
}

/* ==========================================
   Responsive Drawer Overlay for Mobile
   ========================================== */
@media (max-width: 991.98px) {
    /* Main wrapper full-width on mobile */
    .app-container.has-sidebar .main-wrapper {
        margin-right: 0 !important;
    }
    
    .app-container.has-sidebar .navbar.fixed-top {
        right: 0 !important;
    }
    
    /* Sidebar is drawer on mobile */
    .sidebar {
        width: var(--sidebar-width) !important;
        right: -270px;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    }
    
    .app-container.mobile-sidebar-open .sidebar {
        right: 0;
    }
    
    /* Show text labels in mobile drawer always */
    .sidebar-brand-name,
    .sidebar-profile-info,
    .sidebar-group-title,
    .sidebar-link .link-text,
    .sidebar-link i.arrow-icon {
        display: inline-block !important;
    }
    
    .sidebar-profile {
        padding: 20px;
        justify-content: flex-start;
    }
    
    .sidebar-link {
        justify-content: space-between;
    }
    
    /* Hide tooltips in mobile view */
    .sidebar-link .link-tooltip {
        display: none !important;
    }
    
    /* Mobile Overlay Backdrop */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(4px);
        z-index: 1030;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .app-container.mobile-sidebar-open .sidebar-backdrop {
        opacity: 1;
        visibility: visible;
    }
}
