/* --- 1. المتغيرات والأساسيات --- */
:root {
    /* ألوان الوضع الفاتح (Light Mode) */
    --bg-body: #f4f7f6;
    --bg-sidebar: #1a223a; /* داكن للقائمة */
    --bg-card: #ffffff;
    --bg-topbar: #ffffff;
    --text-main: #333333;
    --text-muted: #777777;
    --text-sidebar: #b0b8c1;
    --text-on-primary: #ffffff;
    --border-color: #e0e0e0;

    /* الألوان الأساسية والثانوية */
    --primary-color: #3b82f6; /* أزرق عصري */
    --secondary-color: #8b5cf6; /* بنفسجي ثنائي */
    --accent-color: #22d3ee; /* تركواز */
    
    /* ألوان الحالات والظلال */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    
    --transition: all 0.3s ease;
    --sidebar-width: 260px;
    --topbar-height: 70px;
}

/* --- ألوان الوضع الداكن (Dark Mode) --- */
body.dark-mode {
    --bg-body: #111827;
    --bg-sidebar: #1f2937; /* أفتح قليلاً من الخلفية */
    --bg-card: #1f2937;
    --bg-topbar: #1f2937;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-sidebar: #d1d5db;
    --border-color: #374151;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: var(--transition);
    overflow-x: hidden;
}

/* --- 2. هيكل لوحة التحكم --- */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* --- 3. القائمة الجانبية (Sidebar) --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: fixed;
    height: 100vh;
    right: 0; /* لأننا RTL */
    transition: var(--transition);
    z-index: 100;
}

.sidebar .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-on-primary);
    margin-bottom: 40px;
    padding-right: 10px;
}

.sidebar .logo i {
    color: var(--accent-color);
}

.nav-menu ul {
    list-style: none;
}

.nav-menu ul li {
    margin-bottom: 5px;
}

.nav-menu ul li a {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    color: var(--text-sidebar);
    text-decoration: none;
    border-radius: 10px;
    transition: var(--transition);
    font-size: 0.95rem;
}

.nav-menu ul li a i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* تأثير Hover وتمييز العنصر النشط */
.nav-menu ul li a:hover,
.nav-menu ul li.active a {
    background-color: rgba(59, 130, 246, 0.1); /* شفاف من الأزرق الأساسي */
    color: var(--primary-color);
}

.nav-menu ul li.active a {
    background-color: var(--primary-color);
    color: var(--text-on-primary);
}

.sidebar-footer {
    margin-top: auto;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
}

.sidebar-footer p {
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.btn-help {
    background-color: var(--secondary-color);
    color: var(--text-on-primary);
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: var(--transition);
}

.btn-help:hover {
    background-color: #7c3aed;
}

/* --- 4. الشريط العلوي (Top Bar) --- */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width); /* حجز مساحة للقائمة */
    transition: var(--transition);
}

.top-bar {
    height: var(--topbar-height);
    background-color: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: var(--shadow-sm);
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 15px;
    width: 350px;
}

.search-bar i {
    color: var(--text-muted);
}

.search-bar input {
    border: none;
    background: transparent;
    color: var(--text-main);
    padding-right: 10px;
    width: 100%;
    outline: none;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.action-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.action-btn:hover {
    color: var(--primary-color);
}

.badge, .badge-blue {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: var(--danger);
    color: white;
    font-size: 0.7rem;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge-blue {
    background-color: var(--info);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 10px;
    transition: var(--transition);
}

.user-profile:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

body.dark-mode .user-profile:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: bold;
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.caret {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- 5. محتوى الصفحة الرئيسي --- */
.content-wrapper {
    padding: 30px;
}

.page-header {
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.page-header p {
    color: var(--text-muted);
}

/* العناصر العامة للبطاقات */
.card {
    background-color: var(--bg-card);
    border-radius: 15px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-header h2 {
    font-size: 1.1rem;
}

/* --- 6. شبكة الإحصائيات (Grid) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--bg-card);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* ألوان الأيقونات */
.stat-icon.income { background-color: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-icon.orders { background-color: rgba(59, 130, 246, 0.1); color: var(--primary-color); }
.stat-icon.customers { background-color: rgba(139, 92, 246, 0.1); color: var(--secondary-color); }
.stat-icon.products { background-color: rgba(34, 211, 238, 0.1); color: var(--accent-color); }

.stat-details h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: normal;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 5px 0;
}

.trend {
    font-size: 0.8rem;
    font-weight: bold;
}

.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

/* رسم بياني صغير (وهمي بالـ CSS) */
.mini-chart {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    opacity: 0.2;
}

.chart-income { background: linear-gradient(to top, var(--success), transparent); }
.chart-orders { background: linear-gradient(to top, var(--primary-color), transparent); }

/* --- 7. قسم الرسوم البيانية والجداول (شبكة مزدوجة) --- */
.charts-orders-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    margin-bottom: 30px;
}

.main-chart-placeholder {
    height: 300px;
    background-color: var(--bg-body);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 10px;
}

/* تنسيق الجدول */
.table-actions {
    display: flex;
    gap: 10px;
}

.search-sm {
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    outline: none;
}

.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead th {
    text-align: right;
    padding: 15px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background-color: rgba(0, 0, 0, 0.01);
}

body.dark-mode .data-table tbody tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* شارات الحالة */
.status {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
}

.status.delivered { background-color: rgba(16, 185, 129, 0.1); color: var(--success); }
.status.processing { background-color: rgba(245, 158, 11, 0.1); color: var(--warning); }
.status.shipped { background-color: rgba(14, 165, 233, 0.1); color: var(--info); }
.status.pending { background-color: rgba(239, 68, 68, 0.1); color: var(--danger); }

.action-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.action-icon:hover { color: var(--primary-color); }

/* أزرار صغيرة */
.btn-sm, .btn-sm-outline {
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-sm { background-color: var(--primary-color); color: white; border: none; }
.btn-sm:hover { background-color: #2563eb; }

.btn-sm-outline { background: transparent; color: var(--text-main); border: 1px solid var(--border-color); }
.btn-sm-outline:hover { background-color: rgba(0, 0, 0, 0.03); }

/* --- 8. قسم المنتجات والعملاء الجدد (شبكة أخرى) --- */
.best-products, .new-customers {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.product-item, .customer-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.product-item:last-child, .customer-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.product-img {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    object-fit: cover;
}

.product-info h4, .customer-info h4 { font-size: 0.95rem; }
.product-info p, .customer-info p { font-size: 0.85rem; color: var(--text-muted); }

.product-price {
    margin-right: auto;
    font-weight: bold;
    color: var(--success);
}

.reg-date {
    margin-right: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- 9. التجاوب (Media Queries) --- */
@media (max-width: 1200px) {
    .charts-orders-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 992px) {
    :root {
        --sidebar-width: 80px; /* تصغير القائمة الجانبية */
    }

    .sidebar .logo span, 
    .nav-menu ul li a span,
    .sidebar-footer {
        display: none;
    }

    .sidebar .logo {
        justify-content: center;
        padding: 0;
    }

    .nav-menu ul li a {
        justify-content: center;
        padding: 15px;
    }

    .nav-menu ul li a i {
        font-size: 1.3rem;
    }

    .main-content {
        margin-right: var(--sidebar-width);
    }
}

@media (max-width: 768px) {
    .top-bar {
        padding: 0 15px;
    }
    
    .search-bar {
        width: 180px;
    }

    .user-info, .caret {
        display: none;
    }

    .content-wrapper {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}