

/* ============================================================
   المتغيرات
   ============================================================ */
:root {
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --primary-blue: #1a73e8;
    --trend-up: #137333;
    --trend-up-bg: #e6f4ea;
    --trend-down: #c5221f;
    --trend-down-bg: #fce8e6;
    --sidebar-width: 250px;
}

/* ============================================================
   إعادة الضبط
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    direction: rtl;
    line-height: 1.5;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   القائمة الجانبية
   ============================================================ */
/* ============================================================
   القائمة الجانبية (مخفية افتراضياً على كل الشاشات)
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    background-color: #ffffff;
    color: #475569;
    position: fixed;
    height: 100vh;
    right: 0;
    top: 0;
    z-index: 100;
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.04);

    /* ✅ إخفاء افتراضي على كل الشاشات */
    transform: translateX(100%);
}

/* ✅ إظهار عند إضافة class="active" */
.sidebar.active {
    transform: translateX(0);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.logo-container {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    height: 72px;
    flex-shrink: 0;
}

.logo-container .brand-logo {
    width: 140px !important;
    height: 40px !important;
    max-width: 140px !important;
    max-height: 40px !important;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.nav-menu {
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: #64748b;
    font-size: 0.88rem;
    border-radius: 6px;
    transition: all 0.15s ease;
    font-weight: 500;
}

.nav-item:hover { background-color: #f1f5f9; color: #1e293b; }
.nav-item.active { background-color: #e8f0fe; color: var(--primary-blue); font-weight: 600; }
.nav-item svg { flex-shrink: 0; stroke: currentColor; }

/* ============================================================
   المحتوى الرئيسي
   ============================================================ */
.main-content {
    margin-right: var(--sidebar-width);
    flex: 1;
    padding: 25px 30px;
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ============================================================
   شريط الرأس
   ============================================================ */
.top-header {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

/* إظهار زر الهمبرجر وجعله جاهزاً للنقر في جميع الأجهزة */
.hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary, #333);
    padding: 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.hamburger-btn:hover {
    background: rgba(0, 0, 0, 0.05); /* أو يمكنك استخدام var(--bg-surface) حسب المتغيرات المتوفرة لديك */
}

.header-logo {
    width: 140px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-word;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}


/* ============================================================
   شريط الفلتر
   ============================================================ */
.filter-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.filter-group label {
    font-weight: 500;
    white-space: nowrap;
}

.form-select {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: #fff;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease;
    min-width: 200px;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}
/* ============================================================
   شبكة KPIs (إجبار التنسيق على مربعين في الهاتف)
   ============================================================ */
.kpi-grid, #kpiGrid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important; /* مربعين في كل صف */
    gap: 10px !important;
    min-width: 0 !important;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 10px !important;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: box-shadow 0.15s ease;
}

.kpi-card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); }

.kpi-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.kpi-value-container {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 6px 0 0 0;
    flex-wrap: wrap;
}

.kpi-value {
    font-size: 1.3rem !important;
    font-weight: 600;
    color: var(--text-primary);
}

.kpi-subtext {
    display: none;
}

/* الشاشات الكبيرة (أجهزة الكمبيوتر والآيباد) */
@media (min-width: 768px) {
    .kpi-grid, #kpiGrid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 16px !important;
    }
}



/* ============================================================
   مؤشرات الاتجاه
   ============================================================ */
.trend {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.trend.positive {
    color: var(--trend-up);
    background-color: var(--trend-up-bg);
}

.trend.negative {
    color: var(--trend-down);
    background-color: var(--trend-down-bg);
}

.trend.neutral {
    color: #1a73e8;
    background-color: #e8f0fe;
}

/* ============================================================
   البطاقات
   ============================================================ */
.chart-card,
.table-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    min-width: 0;
    overflow: hidden;
}

.chart-card--wide { width: 100%; }

.card-header {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
    overflow: hidden;
}

/* ============================================================
   تبويبات الرسم
   ============================================================ */
.chart-tabs {
    display: flex;
    gap: 4px;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 6px;
}

.chart-tab {
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.15s ease;
}

.chart-tab:hover { color: var(--text-primary); }

.chart-tab.active {
    background: #ffffff;
    color: var(--primary-blue);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ============================================================
   الشبكات
   ============================================================ */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    min-width: 0;
}

/* ============================================================
   الجداول
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
    width: 100%;
    border-radius: 6px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: right;
}

.data-table thead {
    background: #f8fafc;
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 10px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    font-size: 0.82rem;
    text-align: right;
}

.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.85rem;
}

.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td strong { font-weight: 600; color: var(--text-primary); }

/* ============================================================
   Sidebar Overlay
   ============================================================ */
/* ============================================================
   Sidebar Overlay (يعمل على كل الشاشات)
   ============================================================ */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    z-index: 99;
    display: block;    /* ✅ ظاهر على كل الشاشات */
    cursor: pointer;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}
/* ============================================================
   Responsive
   ============================================================ */
 

@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    /* الـ sidebar يبقى مخفياً كما هو */
    .sidebar-overlay { display: block; }

    .main-content {
        margin-right: 0;
        width: 100%;
        padding: 15px;
        gap: 15px;
    }

    .hamburger-btn { display: block; }

    .page-title { font-size: 1.1rem; }
    .page-subtitle { font-size: 0.78rem; }

    .chart-container { height: 240px; }

    .filter-bar { padding: 10px 15px; gap: 12px; }
    .filter-group { flex: 1; min-width: 140px; }
    .form-select { width: 100%; min-width: 0; }

    .data-table { font-size: 0.8rem; }
    .data-table th, .data-table td { padding: 8px 6px; }
}

@media (max-width: 600px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .main-content { padding: 10px; }
    .page-title { font-size: 1rem; }
    .kpi-value { font-size: 1.4rem; }
    .chart-container { height: 200px; }
    .chart-tabs { width: 100%; justify-content: space-between; }

    .data-table th, .data-table td {
        padding: 6px 4px;
        font-size: 0.75rem;
    }
}

/* تنسيق المحتوى الرئيسي في وضع سطح المكتب */
/* ============================================================
   تنسيقات شريط المؤشرات التراكمية التاريخية (All-Time)
   ============================================================ */

.alltime-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    background-color: var(--card-bg, #ffffff);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e2e8f0);
}

.alltime-item {
    flex: 1 1 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px 12px;
    border-right: 1px solid var(--border-color, #f1f5f9);
}

/* إلغاء الحد الأيمن للبطاقة الأولى في الاتجاه العربي RTL */
.alltime-item:first-child {
    border-right: none;
}

.alltime-label {
    font-size: 0.8rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 6px;
    font-weight: 500;
    white-space: nowrap;
}

.alltime-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main, #0f172a);
    direction: ltr; /* لضمان عرض الأرقام بشكل صحيح */
}

/* تحسين التجاوب مع مختلف الشاشات والهواتف */
@media (max-width: 768px) {
    .alltime-bar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 12px;
    }

    .alltime-item {
        border-right: none !important;
        background: var(--bg-hover, #f8fafc);
        border-radius: 8px;
        padding: 10px 8px;
    }
}


/* ============================================================
   شريط التنقل الأفقي
   ============================================================ */
.top-nav {
    display: flex;
    gap: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.top-nav::-webkit-scrollbar {
    display: none;
}

.top-nav__link {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
    text-decoration: none;
}

.top-nav__link:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

.top-nav__link.active {
    background: var(--primary-blue);
    color: #ffffff;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .top-nav {
        padding: 4px;
    }

    .top-nav__link {
        padding: 6px 12px;
        font-size: 0.78rem;
    }
}

/* هذه القواعد ستعمل الآن على سطح المكتب وكل الأجهزة بشكل صحيح وثابت */
.main-content {
    margin-right: 0;
    width: 100%;
    padding: 24px;
    box-sizing: border-box;
}


