/* ============================================
   Sidebar Navigation - القائمة الجانبية
   ============================================ */

:root {
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 70px;
    --sidebar-bg: #ffffff;
    --sidebar-hover: #fef2f2;
    --sidebar-active: #8B0000;
    --sidebar-text: #374151;
    --sidebar-text-active: #8B0000;
    --sidebar-accent: #8B0000;
    --sidebar-border: #f3f4f6;
    --topbar-height: 50px;
    --transition-speed: 0.3s;
}

/* Dark Mode Variables */
body.dark-mode {
    --sidebar-bg: #1f2937;
    --sidebar-hover: #374151;
    --sidebar-text: #d1d5db;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #374151;
}

/* ============================================
   Main Layout
   ============================================ */

body.has-sidebar {
    margin: 0;
    padding: 0;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1040;
    transition: all var(--transition-speed) ease;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.08);
    border-left: 1px solid var(--sidebar-border);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .menu-header,
.sidebar.collapsed .submenu-arrow {
    display: none;
}

.sidebar.collapsed .sidebar-brand span {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .nav-link i {
    margin: 0;
    font-size: 1.2rem;
}

/* Sidebar Brand/Logo */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--sidebar-bg);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #fff;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.sidebar-brand span {
    color: #8B0000;
    font-size: 1rem;
    font-weight: 700;
    margin-right: 10px;
    font-family: 'Tajawal', 'Cairo', sans-serif;
    letter-spacing: -0.5px;
}

/* Navigation */
.sidebar-nav {
    padding: 12px 12px;
}

.sidebar-nav .nav-item {
    margin-bottom: 6px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    color: #111827 !important;
    border-radius: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-active);
}

.sidebar-nav .nav-link.active {
    background: rgba(139, 0, 0, 0.1);
    color: var(--sidebar-active);
    border-right: 3px solid var(--sidebar-active);
    font-weight: 700;
}

/* زر الرئيسية */
.sidebar-nav .nav-link.home-link {
    color: #111827 !important;
    background: transparent;
}

.sidebar-nav .nav-link.home-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-active) !important;
}

.sidebar-nav .nav-link.home-link.active {
    background: rgba(139, 0, 0, 0.1);
    color: var(--sidebar-active) !important;
}

.sidebar-nav .nav-link i {
    width: 20px;
    text-align: center;
    margin-left: 10px;
    font-size: 1rem;
    color: #6b7280;
}

.sidebar-nav .nav-link:hover i,
.sidebar-nav .nav-link.active i {
    color: var(--sidebar-active);
}

.sidebar-nav .nav-link .badge {
    margin-right: auto;
    font-size: 0.7rem;
}

/* Menu Headers */
.menu-header {
    color: #8B0000;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 16px 14px 8px;
    margin-top: 8px;
}

.menu-header:not(:first-of-type) {
    border-top: 1px solid var(--sidebar-border);
}

/* Submenu */
.has-submenu > .nav-link {
    position: relative;
}

.submenu-arrow {
    margin-right: auto;
    transition: transform 0.2s ease;
}

.has-submenu.open > .nav-link .submenu-arrow {
    transform: rotate(90deg);
}

.submenu {
    display: none;
    padding-right: 8px;
    margin-top: 6px;
    margin-bottom: 6px;
}

.has-submenu.open > .submenu {
    display: block;
}

.submenu .nav-link {
    padding: 12px 16px 12px 28px;
    font-size: 0.9rem;
    color: #111827 !important;
    font-weight: 500;
}

.submenu .nav-link:hover {
    color: var(--sidebar-active);
    background: var(--sidebar-hover);
}

.submenu .nav-link.active {
    color: var(--sidebar-active);
    font-weight: 600;
}

/* إزالة النقطة الدائرية لأن الأيقونات موجودة */

/* ============================================
   Top Bar
   ============================================ */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: var(--sidebar-width);
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1030;
    transition: right var(--transition-speed) ease;
}

.sidebar.collapsed ~ .main-wrapper .topbar {
    right: var(--sidebar-collapsed-width);
}

body.dark-mode .topbar {
    background: #1e293b;
    border-color: #334155;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Toggle Button */
.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #374151;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: rgba(139, 0, 0, 0.08);
    color: #8B0000;
}

body.dark-mode .sidebar-toggle:hover {
    background: #334155;
    color: #fff;
}

/* Search Box */
.topbar-search {
    position: relative;
}

.topbar-search input {
    width: 300px;
    padding: 8px 15px 8px 40px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.topbar-search input:focus {
    outline: none;
    border-color: var(--sidebar-active);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.topbar-search i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

body.dark-mode .topbar-search input {
    background: #334155;
    border-color: #475569;
    color: #fff;
}

/* Topbar Icons */
.topbar-icon {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #374151 !important;
    cursor: pointer;
    transition: all 0.2s ease;
}

.topbar-icon:hover {
    background: rgba(139, 0, 0, 0.1) !important;
    color: #8B0000 !important;
}

.topbar-icon a {
    color: inherit !important;
}

body.dark-mode .topbar-icon:hover {
    background: #334155;
    color: #fff;
}

.topbar-icon .badge {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 0.65rem;
    padding: 2px 5px;
}

/* User Dropdown */
.user-dropdown {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-dropdown:hover {
    background: #f1f5f9;
}

body.dark-mode .user-dropdown:hover {
    background: #334155;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--sidebar-active);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-info {
    text-align: right;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}

.user-role {
    font-size: 0.75rem;
    color: #64748b;
}

body.dark-mode .user-name {
    color: #fff;
}

/* ============================================
   Main Content
   ============================================ */

.main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-width);
    transition: margin-right var(--transition-speed) ease;
}

.sidebar.collapsed ~ .main-wrapper {
    margin-right: var(--sidebar-collapsed-width);
}

.main-content {
    padding: calc(var(--topbar-height) + 15px) 15px 15px;
    min-height: 100vh;
    background: #f8fafc;
}

body.dark-mode .main-content {
    background: #0f172a;
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(100%);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .main-wrapper {
        margin-right: 0;
    }
    
    .topbar {
        right: 0;
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1035;
    }
    
    .sidebar.mobile-open ~ .sidebar-overlay {
        display: block;
    }
    
    .topbar-search input {
        width: 200px;
    }
}

@media (max-width: 576px) {
    .topbar-search {
        display: none;
    }
    
    .user-info {
        display: none;
    }
}

/* ============================================
   Scrollbar Styling
   ============================================ */

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

body.dark-mode .sidebar::-webkit-scrollbar-thumb {
    background: #4b5563;
}

body.dark-mode .sidebar::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.submenu {
    animation: fadeIn 0.2s ease;
}

/* ============================================
   LTR Support (English)
   ============================================ */

[dir="ltr"] .sidebar {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid var(--sidebar-border);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.08);
}

[dir="ltr"] .main-wrapper {
    margin-right: 0;
    margin-left: var(--sidebar-width);
}

[dir="ltr"] .sidebar.collapsed ~ .main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

[dir="ltr"] .topbar {
    right: 0;
    left: var(--sidebar-width);
}

[dir="ltr"] .sidebar.collapsed ~ .main-wrapper .topbar {
    left: var(--sidebar-collapsed-width);
}

[dir="ltr"] .sidebar-nav .nav-link i {
    margin-left: 0;
    margin-right: 10px;
}

[dir="ltr"] .submenu {
    padding-right: 0;
    padding-left: 12px;
}

[dir="ltr"] .submenu .nav-link {
    padding: 12px 28px 12px 16px;
}

[dir="ltr"] .submenu-arrow {
    margin-right: 0;
    margin-left: auto;
    transform: rotate(180deg);
}

[dir="ltr"] .has-submenu.open > .nav-link .submenu-arrow {
    transform: rotate(90deg);
}

[dir="ltr"] .sidebar-nav .nav-link.active {
    border-right: none;
    border-left: 3px solid var(--sidebar-active);
}

[dir="ltr"] .sidebar-brand span {
    margin-right: 0;
    margin-left: 12px;
}

@media (max-width: 991px) {
    [dir="ltr"] .sidebar {
        transform: translateX(-100%);
    }
    
    [dir="ltr"] .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    [dir="ltr"] .main-wrapper {
        margin-left: 0;
    }
    
    [dir="ltr"] .topbar {
        left: 0;
    }
}

/* ============================================
   LTR Support - Additional Elements
   ============================================ */

/* Search box icon position */
[dir="ltr"] .topbar-search i {
    right: auto;
    left: 15px;
}

[dir="ltr"] .topbar-search input {
    padding: 8px 40px 8px 15px;
}

/* Tables */
[dir="ltr"] table {
    text-align: left;
}

[dir="ltr"] .table th,
[dir="ltr"] .table td {
    text-align: left;
}

/* Forms */
[dir="ltr"] .form-label {
    text-align: left;
}

[dir="ltr"] .form-control,
[dir="ltr"] .form-select {
    text-align: left;
}

/* Cards */
[dir="ltr"] .card-header {
    text-align: left;
}

/* Dropdowns */
[dir="ltr"] .dropdown-menu {
    text-align: left;
}

[dir="ltr"] .dropdown-item i {
    margin-right: 8px;
    margin-left: 0;
}

/* Badges */
[dir="ltr"] .topbar-icon .badge {
    left: auto;
    right: 5px;
}

/* User dropdown */
[dir="ltr"] .user-info {
    text-align: left;
    margin-left: 0;
    margin-right: 10px;
}

/* Page headers */
[dir="ltr"] .page-header h2,
[dir="ltr"] .page-title {
    text-align: left;
}

/* Alerts and messages */
[dir="ltr"] .alert {
    text-align: left;
}

/* Buttons with icons */
[dir="ltr"] .btn i {
    margin-right: 5px;
    margin-left: 0;
}

/* Modal */
[dir="ltr"] .modal-header,
[dir="ltr"] .modal-body,
[dir="ltr"] .modal-footer {
    text-align: left;
}

/* Breadcrumb */
[dir="ltr"] .breadcrumb {
    direction: ltr;
}

/* Pagination */
[dir="ltr"] .pagination {
    direction: ltr;
}
