﻿/* ============================================
   Sidebar Modern Design
   ============================================ */

/* القائمة الجانبية الرئيسية */
#sidebarMenu {
    width: 320px;
    position: fixed;
    top: 0;
    right: -320px;
    height: 100vh;
    background: linear-gradient(180deg, #ffffff 0%, #f8f9fa 100%);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    direction: rtl;
    border-left: 1px solid #e9ecef;
}

#sidebarMenu.sidebar-open {
    right: 0;
}

/* تأثير على المحتوى الرئيسي عند فتح القائمة (Desktop فقط) */
@media (min-width: 992px) {
    .main.sidebar-open {
        margin-right: 320px;
        transition: margin-right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* عنوان القائمة */
.sidebar-header {
    padding: 20px 24px;
    border-bottom: 2px solid #e9ecef;
    background: linear-gradient(135deg, #4DA8D4 0%, #82C1E2 100%);
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-header h4 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.sidebar-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 1.25rem;
    color: #ffffff;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-close-btn:active {
    transform: rotate(90deg) scale(0.95);
}

/* القائمة الشجرية */
#menuTree {
    list-style: none;
    padding: 12px 0;
    margin: 0;
    direction: rtl;
}

#menuTree li {
    margin: 0;
}

#menuTree > li {
    border-bottom: 1px solid #f0f0f0;
}

#menuTree > li:last-child {
    border-bottom: none;
}

/* عناصر القائمة */
.menu-item {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    color: #495057;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    font-size: 0.95rem;
    font-weight: 500;
    border-right: 3px solid transparent;
}

    .menu-item:hover {
        background: linear-gradient(90deg, rgba(77, 168, 212, 0.1) 0%, rgba(77, 168, 212, 0.05) 100%);
        color: #4DA8D4;
        border-right-color: #4DA8D4;
        padding-right: 28px;
    }

    .menu-item.active {
        background: linear-gradient(90deg, rgba(77, 168, 212, 0.15) 0%, rgba(77, 168, 212, 0.1) 100%);
        color: #4DA8D4;
        font-weight: 600;
        border-right: 3px solid #4DA8D4;
        box-shadow: inset -2px 0 4px rgba(77, 168, 212, 0.1);
    }

/* أيقونات الفئات التي لديها أبناء */
.menu-item.has-children::after {
    content: '\25B6';
    margin-right: auto;
    margin-left: 12px;
    font-size: 0.75rem;
    transition: transform 0.3s ease;
    color: #6c757d;
    font-weight: normal;
}

    .menu-item.has-children.open::after {
        transform: rotate(90deg);
        color: #4DA8D4;
    }

    .menu-item.has-children:hover::after {
        color: #4DA8D4;
    }

/* القوائم الفرعية */
.menu-children {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #f8f9fa;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    border-top: 1px solid #e9ecef;
}

.menu-children.open {
    max-height: 2000px;
    padding: 4px 0;
}

.menu-children .menu-item {
    padding-right: 48px;
    font-size: 0.9rem;
    border-top: 1px solid #e9ecef;
    background-color: transparent;
}

.menu-children .menu-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.04) 100%);
}

.menu-children .menu-children .menu-item {
    padding-right: 72px;
    font-size: 0.85rem;
    background-color: #f1f3f5;
}

.menu-children .menu-children .menu-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.06) 100%);
}

.menu-children .menu-children .menu-children .menu-item {
    padding-right: 96px;
    font-size: 0.8rem;
}

/* زر إظهار/إخفاء القائمة في الهيدر */
#toggleSidebar {
    background: transparent;
    border: none;
    color: #495057;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 10px;
    transition: all 0.3s ease;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    position: relative;
}

    #toggleSidebar:hover {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
        color: #4DA8D4;
        transform: scale(1.1);
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
    }

#toggleSidebar:active {
    transform: scale(1.05);
}

    #toggleSidebar:focus {
        outline: 2px solid #4DA8D4;
        outline-offset: 2px;
    }

/* Overlay عند فتح القائمة */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Responsive - Mobile */
@media (max-width: 991px) {
    #sidebarMenu {
        width: 85%;
        max-width: 320px;
        right: -100%;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .main.sidebar-open {
        margin-right: 0;
    }

    .sidebar-header {
        padding: 18px 20px;
    }

    .sidebar-header h4 {
        font-size: 1.2rem;
    }

    .menu-item {
        padding: 12px 20px;
        font-size: 0.9rem;
    }

    .menu-children .menu-item {
        padding-right: 40px;
    }

    .menu-children .menu-children .menu-item {
        padding-right: 60px;
    }
}

/* Desktop Enhancements */
@media (min-width: 992px) {
    #sidebarMenu {
        position: fixed;
    }

    .main {
        transition: margin-right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* تأثيرات إضافية على Desktop */
    .menu-item {
        padding: 16px 24px;
    }

    .menu-item:hover {
        transform: translateX(-4px);
    }
}

/* Scrollbar Modern Styling */
#sidebarMenu::-webkit-scrollbar {
    width: 8px;
}

#sidebarMenu::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-left: 1px solid #e9ecef;
}

#sidebarMenu::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #4DA8D4 0%, #764ba2 100%);
    border-radius: 4px;
    border: 2px solid #f8f9fa;
}

#sidebarMenu::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #5568d3 0%, #6a3d8f 100%);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Firefox Scrollbar */
#sidebarMenu {
    scrollbar-width: thin;
    scrollbar-color: #4DA8D4 #f8f9fa;
}

/* Animations */
@keyframes slideInRight {
    from {
        right: -320px;
        opacity: 0;
    }
    to {
        right: 0;
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Loading State */
.menu-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

    .menu-item.loading::before {
        content: '';
        display: inline-block;
        width: 16px;
        height: 16px;
        border: 2px solid #4DA8D4;
        border-top-color: transparent;
        border-radius: 50%;
        animation: spin 0.6s linear infinite;
        margin-left: 8px;
    }

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Active Category Indicator */
.menu-item.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: linear-gradient(180deg, #4DA8D4 0%, #764ba2 100%);
    border-radius: 0 4px 4px 0;
}

/* Improved Typography */
.menu-item {
    letter-spacing: 0.01em;
    line-height: 1.6;
}

/* RTL Support */
[dir="rtl"] #sidebarMenu {
    right: auto;
    left: -320px;
    border-left: none;
    border-right: 1px solid #e9ecef;
}

[dir="rtl"] #sidebarMenu.sidebar-open {
    right: auto;
    left: 0;
}

[dir="rtl"] .menu-item {
    border-right: none;
    border-left: 3px solid transparent;
}

    [dir="rtl"] .menu-item:hover,
    [dir="rtl"] .menu-item.active {
        border-left-color: #4DA8D4;
        border-right-color: transparent;
    }

[dir="rtl"] .menu-item.active::before {
    right: auto;
    left: 0;
    border-radius: 4px 0 0 4px;
}

/* Accessibility */
.menu-item:focus {
    outline: 2px solid #4DA8D4;
    outline-offset: -2px;
    border-radius: 4px;
}

.sidebar-close-btn:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    #sidebarMenu {
        display: none;
    }

    .sidebar-overlay {
        display: none;
    }
}
