/* ===== Sidebar ===== */
/* ألوان شعار الشركة: أزرق (#003865), أحمر (#C8102E), ذهبي (#FFC72C) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 4px 0 20px rgba(var(--sidebar-shadow-rgb), 0.3);
    z-index: 1000;
    right: 0;
    top: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
    border-left: 3px solid var(--sidebar-accent);
    -webkit-overflow-scrolling: touch;
    /* إزالة will-change لمنع memory leaks - يتم إضافتها ديناميكياً عند الحاجة */
    /* will-change: transform; */
}

.sidebar.collapsed {
    width: 84px;
    min-width: 84px;
}

.sidebar.collapsed .navigation {
    align-items: center;
}

/* تحسين شكل القائمة الجانبية عند الطي: إظهار الأيقونات فقط بشكل منسق */
.sidebar.collapsed .user-profile {
    padding: 0.75rem 0.5rem;
    text-align: center;
}

.sidebar.collapsed .user-info {
    display: none !important;
}

.sidebar.collapsed .user-avatar {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    font-size: 1.25rem;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem 0.5rem;
    min-height: 44px;
}

.sidebar.collapsed .nav-item span {
    display: none !important;
}

.sidebar.collapsed .nav-item i {
    margin-left: 0;
    margin-right: 0;
}

.sidebar.collapsed .logout-btn span {
    display: none !important;
}

.sidebar.collapsed .logout-btn {
    justify-content: center;
    padding: 0.75rem 0.5rem;
}

.sidebar.collapsed .logout-btn i {
    margin-left: 0;
    margin-right: 0;
}

.sidebar.collapsed .language-switcher .language-toggle-btn > span:first-of-type {
    display: none !important;
}

.sidebar.collapsed .language-switcher {
    justify-content: center;
    padding: 0.5rem;
}

.sidebar.collapsed .language-switcher .language-toggle-btn {
    padding: 0.5rem;
    justify-content: center;
}

/* Sidebar action buttons row (collapse + sync + notifications + theme) */
.sidebar .sidebar-actions-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 1rem;
    position: relative;
    z-index: 1002;
}

.sidebar .sidebar-actions-row .sidebar-action-btn-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar .sidebar-actions-row .sidebar-action-btn {
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
}

/* ضمان قابلية النقر على زر اللغة وزر الإشعارات في القائمة الجانبية */
.sidebar .language-switcher,
.sidebar #sidebar-notifications-container,
.sidebar .language-toggle-btn,
.sidebar #notifications-btn {
    pointer-events: auto !important;
    position: relative;
    z-index: 10;
}

/* عند طي القائمة: إظهار زر الجرس ثم زر متصل تحته، وعدم إخفاء الحاوية فوق زر اللغة */
.sidebar.collapsed .sidebar-actions-row,
.sidebar.collapsed [style*="z-index: 1002"] {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0.5rem !important;
    margin: 0.5rem 0 !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.sidebar.collapsed .sidebar-actions-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    justify-items: center !important;
}

.sidebar.collapsed #sync-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

.sidebar.collapsed #sidebar-theme-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

.sidebar.collapsed #sync-btn .sync-label-text {
    display: none;
}

.sidebar-collapse-toggle {
    margin: 0.5rem 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    cursor: pointer;
    transition: background 0.3s ease;
}

.sidebar-collapse-toggle:hover,
.sidebar-collapse-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.24);
}

/* User Profile */
.user-profile {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.user-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--sidebar-avatar-bg);
    border: 3px solid var(--sidebar-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 2rem;
    box-shadow: 0 4px 15px rgba(var(--sidebar-accent-rgb), 0.3);
    transition: transform 0.3s ease;
}

.user-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(var(--sidebar-accent-rgb), 0.5);
}

.user-info {
    margin-top: 1rem;
}

.user-name {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.user-email {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.7);
}

/* Navigation */
.navigation {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: all 0.3s ease;
    border-right: 4px solid transparent;
    margin: 0.25rem 0.5rem;
    border-radius: 8px 0 0 8px;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    /* Touch-friendly minimum height */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255, 199, 44, 0.2);
    user-select: none;
    -webkit-user-select: none;
}

.nav-item::before {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 0;
    height: 100%;
    background: rgba(255, 199, 44, 0.1);
    transition: width 0.3s ease;
}

.nav-item:hover::before,
.nav-item.active::before {
    width: 100%;
}

.nav-item i {
    width: 24px;
    margin-left: 1rem;
    font-size: 1.125rem;
    transition: transform 0.3s ease, color 0.3s ease;
    color: rgba(255, 255, 255, 0.9);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border-right-color: var(--sidebar-accent);
    transform: translateX(-3px);
}

.nav-item:hover i {
    transform: scale(1.1);
    color: var(--sidebar-accent);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(var(--sidebar-accent-rgb), 0.2) 0%, rgba(var(--sidebar-accent-rgb), 0.05) 100%);
    color: white;
    border-right-color: var(--sidebar-accent);
    font-weight: 600;
    box-shadow: -2px 0 10px rgba(var(--sidebar-accent-rgb), 0.3);
}

.nav-item.active i {
    color: var(--sidebar-accent);
    transform: scale(1.1);
}

.sidebar.collapsed .logout-btn i {
    margin-left: 0;
    margin-right: 0;
}

.sidebar-app-version {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0.35rem 0.75rem 0.25rem;
    padding: 0.55rem 0.85rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 199, 44, 0.22);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.78rem;
    line-height: 1.35;
}

.sidebar-app-version i {
    color: var(--sidebar-accent, #FFC72C);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.sidebar-app-version-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-app-version-label {
    font-size: 0.68rem;
    opacity: 0.82;
    font-weight: 600;
}

.sidebar-app-version-value {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.sidebar.collapsed .sidebar-app-version {
    justify-content: center;
    padding: 0.55rem 0.35rem;
    margin-inline: 0.5rem;
}

.sidebar.collapsed .sidebar-app-version-text {
    display: none !important;
}

.mobile-app-version {
    display: block;
    font-size: 0.68rem;
    opacity: 0.78;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

/* Logout Button */
.logout-btn {
    padding: 1rem 1.5rem;
    background: rgba(200, 16, 46, 0.15);
    color: #ffffff;
    border: none;
    border-top: 2px solid rgba(255, 199, 44, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    font-family: 'Cairo', sans-serif;
    margin: 0.5rem;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.logout-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(200, 16, 46, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.logout-btn:hover::before {
    width: 300px;
    height: 300px;
}

.logout-btn i {
    margin-left: 0.75rem;
    position: relative;
    z-index: 1;
}

.logout-btn span {
    position: relative;
    z-index: 1;
}

.logout-btn:hover {
    background: rgba(200, 16, 46, 0.25);
    color: #FFC72C;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(200, 16, 46, 0.4);
}
