/* ===================================================================
   Natayej — style.css
   ===================================================================
   - Mobile-first: الـ default للجوال، @media (min-width: ...) للأكبر
   - Tokens موحّدة في :root
   - الهوية: gradient أزرق/أخضر مستخرج من شعار الوزارة
   =================================================================== */

/* --- 1. التوكنات (Design tokens) --- */
:root {
    /* الهوية الرئيسية المستخرجة من الشعار */
    --primary-blue:        #2A6EBB;
    --primary-green:       #37A98B;
    --primary-blue-dark:   #1F5694;
    --primary-green-dark:  #2B8870;

    /* الـ gradient الرسمي */
    --primary-gradient:        linear-gradient(135deg, #2A6EBB 0%, #37A98B 100%);
    --primary-gradient-hover:  linear-gradient(135deg, #1F5694 0%, #2B8870 100%);
    --primary-gradient-vertical: linear-gradient(180deg, #2A6EBB 0%, #37A98B 100%);

    /* aliases للتوافق مع الكود */
    --primary:        var(--primary-blue);
    --primary-dark:   var(--primary-blue-dark);
    --gold:           #D4AF37;

    --bg:             #F5F7FA;
    --bg-card:        #FFFFFF;
    --bg-muted:       #F9FAFB;

    --text:           #1F2937;
    --text-muted:     #6B7280;
    --text-light:     #9CA3AF;

    --border:         #E5E7EB;
    --border-dark:    #D1D5DB;

    --success:        var(--primary-green);
    --info:           var(--primary-blue);
    --warning:        #F59E0B;
    --orange:         #F97316;
    --danger:         #EF4444;

    /* المسافات (8px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* الحواف */
    --radius-sm:   8px;
    --radius-md:  12px;
    --radius-lg:  16px;
    --radius-xl:  24px;
    --radius-full: 9999px;

    /* الظلال */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 14px rgba(0,0,0,0.08);
    --shadow-lg: 0 20px 60px rgba(31, 86, 148, 0.15);

    /* Focus ring */
    --focus-ring: 0 0 0 4px rgba(42, 110, 187, 0.15);

    /* عرض الـ sidebar (للديسكتوب فقط) */
    --sidebar-width: 260px;
}

/* --- 2. Reset / Base (Mobile-first) --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Tajawal', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}
img, svg { max-width: 100%; height: auto; display: block; }
h1, h2, h3, h4 { line-height: 1.3; font-weight: 700; color: var(--text); }
h1 { font-size: 22px; }
h2 { font-size: 19px; }
h3 { font-size: 17px; }

/* --- 3. الأزرار --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px; /* touch target */
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
    text-align: center;
    line-height: 1.2;
    user-select: none;
}
.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(42, 110, 187, 0.20);
}
.btn-primary:hover {
    background: var(--primary-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(42, 110, 187, 0.28);
    text-decoration: none;
    color: white;
}
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--border-dark);
}
.btn-secondary:hover { background: var(--bg-muted); text-decoration: none; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; color: white; text-decoration: none; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn.is-loading {
    position: relative; color: transparent !important;
    pointer-events: none; opacity: 0.85;
}
.btn.is-loading::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 18px; height: 18px; margin-top: -9px; margin-left: -9px;
    border: 2.5px solid rgba(255,255,255,0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}
.btn-secondary.is-loading::after { border-top-color: var(--primary-blue); }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .btn.is-loading::after { animation: none; }
}

/* --- 4. حقول الإدخال --- */
.field { margin-bottom: var(--space-4); }
.field label {
    display: block;
    font-weight: 700;
    margin-bottom: var(--space-2);
    font-size: 14px;
    color: var(--text);
}
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 12px 16px;
    min-height: 44px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px; /* يمنع zoom على iOS */
    font-family: inherit;
    background: var(--bg-muted);
    transition: border-color 0.15s, background 0.15s;
    color: var(--text);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: var(--focus-ring);
}
.field .hint {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
}

/* --- 5. التنبيهات --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    border-right: 4px solid;
    font-weight: 500;
    font-size: 14px;
    line-height: 1.6;
}
.alert-success { background: #DCFCE7; color: #065F46; border-color: var(--success); }
.alert-error   { background: #FEE2E2; color: #991B1B; border-color: var(--danger); }
.alert-warning { background: #FEF3C7; color: #92400E; border-color: var(--warning); }
.alert-info    { background: #DBEAFE; color: #1E3A8A; border-color: var(--info); }

/* --- 6. الشارات --- */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
}
.badge-green  { background: #DCFCE7; color: #065F46; }
.badge-blue   { background: #DBEAFE; color: #1E3A8A; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-gray   { background: #F3F4F6; color: #4B5563; }

/* --- 7. البطاقات --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-4);
    border: 1px solid var(--border);
}

/* --- 8. الجداول --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    background: white;
}
.data-table th {
    text-align: right;
    padding: 12px 14px;
    background: var(--bg-muted);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-muted); }

/* --- 9. لوحة التحكم: تخطيط Mobile-first --- */
.admin-layout { min-height: 100vh; display: flex; flex-direction: column; }
.sidebar {
    background: var(--primary-gradient-vertical);
    color: white;
    padding: var(--space-4) 0;
}
.sidebar-logo {
    text-align: center;
    padding: 0 var(--space-5) var(--space-4);
    border-bottom: 1px solid rgba(255,255,255,0.12);
    margin-bottom: var(--space-3);
}
.sidebar-logo .brand {
    font-size: 22px;
    font-weight: 900;
    color: white;
    letter-spacing: -0.5px;
}
.sidebar-logo .school {
    color: rgba(255,255,255,0.75);
    font-size: 13px;
    margin-top: 2px;
}
.sidebar-nav { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; padding: 0 var(--space-3); }
.sidebar-nav li { flex: 1 1 calc(50% - 4px); }
.sidebar-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 12px;
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.08);
    transition: background 0.15s;
}
.sidebar-nav a:hover {
    background: rgba(255,255,255,0.18);
    color: white;
    text-decoration: none;
}
.sidebar-nav a.active {
    background: rgba(255,255,255,0.22);
    color: white;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.sidebar-nav .icon { font-size: 18px; }
.sidebar-user {
    padding: var(--space-4) var(--space-5) 0;
    border-top: 1px solid rgba(255,255,255,0.12);
    font-size: 13px;
    color: rgba(255,255,255,0.75);
    margin-top: var(--space-3);
}
.sidebar-user .name { color: white; font-weight: 700; margin-bottom: 2px; }
.sidebar-user a { color: white; font-size: 13px; opacity: 0.85; }
.sidebar-user a:hover { opacity: 1; }

.admin-main {
    flex: 1;
    padding: var(--space-4);
    max-width: 100%;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
    gap: var(--space-3);
}
.page-header h1 { font-size: 22px; font-weight: 900; color: var(--text); }
.page-header .subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* --- 10. بطاقات الإحصائيات --- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}
.stat-card {
    background: white;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    display: flex;
    gap: var(--space-3);
    align-items: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-right: 4px solid var(--primary-blue);
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card[href]:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: inherit;
}
.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    background: #DBEAFE;
    color: var(--info);
    flex-shrink: 0;
}
.stat-card .stat-value { font-size: 26px; font-weight: 900; line-height: 1; color: var(--text); }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* --- 11. صفحات المصادقة --- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--primary-gradient);
}
.auth-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-8) var(--space-6);
    box-shadow: var(--shadow-lg);
    max-width: 460px;
    width: 100%;
}
.auth-brand { text-align: center; margin-bottom: var(--space-5); }
.auth-brand .logo {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    font-size: 34px;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-3);
    box-shadow: 0 6px 16px rgba(42, 110, 187, 0.30);
}
.auth-brand h1 {
    font-size: 22px;
    color: var(--primary);
    margin-bottom: 4px;
}
.auth-brand .subtitle { color: var(--text-muted); font-size: 14px; }

/* --- 12. Tablet (≥ 640px) --- */
@media (min-width: 640px) {
    .sidebar-nav li { flex: 1 1 calc(33.333% - 4px); }
    .admin-main { padding: var(--space-5) var(--space-6); }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .page-header h1 { font-size: 24px; }
    h1 { font-size: 24px; }
}

/* --- 13. Desktop (≥ 1024px) --- */
@media (min-width: 1024px) {
    .admin-layout { flex-direction: row-reverse; }
    .sidebar {
        width: var(--sidebar-width);
        position: sticky;
        top: 0;
        height: 100vh;
        flex-shrink: 0;
        overflow-y: auto;
        padding: var(--space-6) 0;
        display: flex;
        flex-direction: column;
    }
    .sidebar-logo {
        padding: 0 var(--space-5) var(--space-5);
        margin-bottom: var(--space-4);
    }
    .sidebar-nav {
        flex-direction: column;
        flex-wrap: nowrap;
        padding: 0;
        gap: 2px;
    }
    .sidebar-nav li { flex: none; }
    .sidebar-nav a {
        justify-content: flex-start;
        background: transparent;
        border-radius: 0;
        padding: 12px 22px;
        font-size: 15px;
    }
    .sidebar-nav a:hover { background: rgba(255,255,255,0.08); }
    .sidebar-nav a.active {
        background: rgba(255,255,255,0.12);
        box-shadow: none;
        border-right: 3px solid var(--gold);
    }
    .sidebar-user {
        margin-top: auto;
        padding: var(--space-4) var(--space-5);
    }
    .admin-main {
        padding: var(--space-6) var(--space-8);
        max-width: calc(100% - var(--sidebar-width));
    }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
    .page-header h1 { font-size: 26px; }
}
