/* ============================================================================
   Impala Kids — Design System
   RTL Native | Mobile First | CSS Variables for dynamic theming

   Breakpoints (mobile-first — base rules target 320px–767px):
     Tablet:  >= 768px
     Laptop:  >= 1024px
     Desktop: >= 1440px
============================================================================ */

:root {
    --color-primary: #FF6B6B;
    --color-secondary: #4ECDC4;
    --color-accent: #FFE66D;
    --color-bg: #F7F9FB;
    --color-surface: #FFFFFF;
    --color-text: #26323A;
    --color-text-muted: #6B7A85;
    --color-border: #E6EAEE;
    --color-success: #2ECC71;
    --color-warning: #F5A623;
    --color-danger: #E74C3C;
    --color-info: #3498DB;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;

    --shadow-sm: 0 2px 8px rgba(38, 50, 58, 0.06);
    --shadow-md: 0 8px 24px rgba(38, 50, 58, 0.10);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 48px;

    /* المسافة الأفقية للمحتوى — أضيق على الجوال، تتسع تدريجياً */
    --page-pad: var(--space-3);

    --font-base: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    direction: rtl;
    /* شبكة أمان: يمنع أي عنصر شارد من إحداث تمرير أفقي للصفحة بالكامل.
       كل عنصر يحتاج تمريراً أفقياً (جداول، جداول الفترات، إلخ) يحصل عليه
       بشكل معزول عبر .table-wrap بدلاً من تمرير الصفحة كاملة. */
    overflow-x: hidden;
    width: 100%;
}

body {
    margin: 0;
    font-family: var(--font-base);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.65;
    font-size: 16px;
    overflow-x: hidden;
    width: 100%;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, h5 { font-weight: 800; margin: 0 0 var(--space-3); line-height: 1.3; word-wrap: break-word; }
h1 { font-size: clamp(26px, 6vw, 42px); }
h2 { font-size: clamp(20px, 5vw, 32px); }
h3 { font-size: clamp(17px, 4vw, 22px); }
p { margin: 0 0 var(--space-3); color: var(--color-text); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* الصور والوسائط لا تتجاوز عرض حاويتها أبداً */
img, svg, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

.container { max-width: 1180px; margin: 0 auto; padding: 0 var(--page-pad); width: 100%; }
.section { padding: var(--space-5) 0; }
.grid { display: grid; gap: var(--space-3); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2); }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }

/* ---------- Buttons (مناسبة للمس: ارتفاع فعلي ~44px كحد أدنى للأزرار الأساسية) ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px 22px; border-radius: var(--radius-md); border: none;
    font-family: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
    min-height: 44px; line-height: 1.2;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-secondary { background: var(--color-secondary); color: #fff; }
.btn-outline { background: transparent; color: var(--color-primary); border: 2px solid var(--color-primary); }
.btn-ghost { background: rgba(0,0,0,0.04); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 9px 14px; font-size: 13px; min-height: 38px; }
.btn-lg { padding: 16px 32px; font-size: 17px; min-height: 50px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); padding: var(--space-3); border: 1px solid var(--color-border);
    max-width: 100%;
}
.card-hover { transition: box-shadow .2s ease, transform .2s ease; }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }
.program-card { text-align: center; }
.program-card .icon { font-size: 36px; margin-bottom: var(--space-2); }

/* ---------- Forms (عمود واحد على الجوال دائماً، يتوسّع عبر .grid-2/3/4 على الشاشات الكبيرة) ---------- */
.form-group { margin-bottom: var(--space-3); max-width: 100%; }
label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 14px; }
input[type=text], input[type=password], input[type=tel], input[type=email],
input[type=date], input[type=number], input[type=time], input[type=color],
input[type=file], select, textarea {
    width: 100%; padding: 13px 14px; border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm); font-family: inherit;
    /* 16px بالضبط يمنع تكبير Safari/iOS التلقائي عند التركيز على الحقل */
    font-size: 16px;
    background: #fff; color: var(--color-text); transition: border-color .15s ease;
    min-height: 46px;
    max-width: 100%;
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--color-primary);
}
.form-hint { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.checkbox-row input { width: auto; min-height: auto; margin-top: 3px; }

/* ---------- Tables ---------- */
table { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius-md); overflow: hidden; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--color-border); font-size: 13.5px; white-space: nowrap; }
th { background: #FAFBFC; font-weight: 800; color: var(--color-text-muted); font-size: 12.5px; }
tr:hover td { background: #FCFCFD; }
/* أي جدول طويل يُغلَّف بهذه الحاوية: تمرير أفقي معزول داخل الجدول نفسه، وليس تمرير الصفحة كاملة */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    max-width: 100%;
}

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-success { background: #E9FBF0; color: #1E9E52; }
.badge-warning { background: #FFF6E5; color: #B9770E; }
.badge-danger { background: #FDECEA; color: #C0392B; }
.badge-info { background: #EAF4FC; color: #2874A6; }
.badge-muted { background: #F0F2F4; color: #6B7A85; }

/* ---------- Alerts ---------- */
.alert { padding: 14px 16px; border-radius: var(--radius-sm); margin-bottom: var(--space-3); font-size: 14px; border: 1px solid transparent; word-wrap: break-word; }
.alert-success { background: #E9FBF0; color: #1E9E52; border-color: #BEEBCF; }
.alert-danger { background: #FDECEA; color: #C0392B; border-color: #F5C2BC; }
.alert-warning { background: #FFF6E5; color: #B9770E; border-color: #F6DFAF; }
.alert-info { background: #EAF4FC; color: #2874A6; border-color: #C7E2F5; }

/* ---------- Navbar (public) ---------- */
.navbar { background: var(--color-surface); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 50; }
.navbar-inner { max-width: 1180px; margin: 0 auto; padding: 12px var(--page-pad); display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.navbar-brand { font-weight: 900; font-size: 18px; color: var(--color-text); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.navbar-brand img { max-height: 36px; width: auto; }

/* على الجوال والتابلت: القائمة تصبح Offcanvas ينزلق من الجهة (RTL: من اليمين) */
.navbar-links {
    list-style: none; margin: 0; padding: var(--space-5) var(--space-3);
    position: fixed; top: 0; bottom: 0; right: -300px; width: min(280px, 85vw);
    background: var(--color-surface); box-shadow: var(--shadow-md);
    display: flex; flex-direction: column; gap: 4px; z-index: 210;
    transition: right .25s ease; overflow-y: auto;
}
.navbar-links.open { right: 0; }
.navbar-links li { width: 100%; }
.navbar-links a {
    color: var(--color-text); font-weight: 600; font-size: 16px;
    display: block; padding: 12px 8px; border-radius: var(--radius-sm);
}
.navbar-links a:hover { background: var(--color-bg); text-decoration: none; }

.navbar-actions { display: flex; gap: 8px; flex-wrap: nowrap; }
.navbar-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; background: none; border: none; font-size: 24px;
    cursor: pointer; flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
/* حاجز خلفي يُغلق القائمة عند الضغط خارجها (الجوال/التابلت فقط) */
.nav-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(20,25,30,.45); z-index: 205;
}
.nav-backdrop.open { display: block; }

/* ---------- Hero ---------- */
.hero { background: linear-gradient(135deg, var(--color-primary), var(--color-secondary)); color: #fff; padding: var(--space-6) 0; text-align: center; border-radius: 0 0 32px 32px; }
.hero h1 { color: #fff; }
.hero p { color: rgba(255,255,255,0.92); font-size: 16px; max-width: 640px; margin: 0 auto var(--space-4); }

/* ---------- Footer ---------- */
.footer { background: #1F2A32; color: #C9D2D7; padding: var(--space-5) 0 var(--space-4); margin-top: var(--space-6); }
.footer a { color: #E4E9EC; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-4); }

/* ---------- Admin / Portal Layout ---------- */
.admin-shell { display: flex; min-height: 100vh; width: 100%; max-width: 100%; }
.sidebar {
    width: 260px; background: #1F2A32; color: #C9D2D7; flex-shrink: 0; padding: var(--space-3);
    overflow-y: auto;
}
.sidebar-brand { color: #fff; font-weight: 900; font-size: 19px; padding: var(--space-3) var(--space-2); }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-radius: var(--radius-sm);
    color: #C9D2D7; font-weight: 600; font-size: 14px; margin-bottom: 2px; min-height: 44px;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.admin-main { flex: 1; min-width: 0; max-width: 100%; }
.admin-topbar {
    background: #fff; border-bottom: 1px solid var(--color-border); padding: 12px var(--page-pad);
    display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
.admin-topbar h3 { font-size: 17px; }
.admin-content { padding: var(--space-3) var(--page-pad); max-width: 100%; overflow-x: hidden; }

/* زر همبرغر لفتح القائمة الجانبية — يُدرَج تلقائياً (عبر JS مشترك) كأول عنصر داخل
   .admin-topbar في كل صفحة، فيسلك سلوك التخطيط المرن الطبيعي بلا تراكب مع العنوان */
.sidebar-toggle {
    display: none; align-items: center; justify-content: center;
    width: 44px; height: 44px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); font-size: 20px; cursor: pointer; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(20,25,30,.45); z-index: 95;
}
.sidebar-backdrop.open { display: block; }

/* ---------- Stat Cards ---------- */
.stat-card { background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-3); border: 1px solid var(--color-border); }
.stat-card .value { font-size: 26px; font-weight: 900; word-wrap: break-word; }
.stat-card .label { color: var(--color-text-muted); font-size: 12.5px; font-weight: 700; }

/* ---------- Empty States ---------- */
.empty-state { text-align: center; padding: var(--space-5) var(--space-3); color: var(--color-text-muted); }
.empty-state .icon { font-size: 44px; margin-bottom: var(--space-2); opacity: .6; }

/* ---------- Skeletons / Loading ---------- */
.skeleton { background: linear-gradient(90deg, #EEF1F3 25%, #E4E8EB 37%, #EEF1F3 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(0,0,0,0.1); border-top-color: var(--color-primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth Pages ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--color-bg); padding: var(--space-3); }
.auth-card { width: 100%; max-width: 420px; background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-4); }

/* ---------- Modals (تُلائم الجوال دائماً، مركّزة بهامش آمن) ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,25,30,0.5); display: none; align-items: center; justify-content: center; z-index: 200; padding: var(--space-3); }
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff; border-radius: var(--radius-lg);
    max-width: 520px; width: 100%; padding: var(--space-3);
    max-height: 90vh; overflow-y: auto;
}

/* ============================================================================
   TABLET وما فوق (>= 768px)
============================================================================ */
@media (min-width: 768px) {
    :root { --page-pad: var(--space-4); }
    .section { padding: var(--space-6) 0; }
    .card { padding: var(--space-4); }
    .modal-box { padding: var(--space-4); }
    .admin-content { padding: var(--space-4) 28px; }
    .admin-topbar { padding: 14px 28px; }
    .admin-topbar h3 { font-size: 19px; }
    .stat-card { padding: var(--space-4); }
    .stat-card .value { font-size: 30px; }
    table { min-width: 0; }
    th, td { font-size: 14px; padding: 12px 14px; white-space: normal; }
    th { font-size: 13px; }
}

/* ============================================================================
   LAPTOP وما فوق (>= 1024px) — القائمة الجانبية تظهر ثابتة دائماً، الهمبرغر يختفي
============================================================================ */
@media (min-width: 1024px) {
    .navbar-toggle { display: none; }
    .navbar-links {
        position: static; width: auto; height: auto; box-shadow: none; padding: 0;
        flex-direction: row; gap: 22px; right: auto; background: transparent;
    }
    .navbar-links a { padding: 0; font-size: 15px; }
    .nav-backdrop { display: none !important; }

    .sidebar-toggle { display: none !important; }
    .sidebar-backdrop { display: none !important; }
    .sidebar { position: static !important; }
}

/* دون هذا الحد (الجوال + التابلت): القائمة الجانبية للإدارة/البوابة تتحول Offcanvas */
@media (max-width: 1023px) {
    .sidebar-toggle { display: flex; }
    .sidebar {
        position: fixed; right: -280px; top: 0; bottom: 0; z-index: 100;
        transition: right .25s ease; box-shadow: var(--shadow-md);
    }
    .sidebar.open { right: 0; }
}

/* ============================================================================
   DESKTOP كبير (>= 1440px) — مساحة أوسع واستغلال أفضل للعرض
============================================================================ */
@media (min-width: 1440px) {
    .container { max-width: 1320px; }
    .admin-content { padding: var(--space-5) 40px; }
    .navbar-inner { max-width: 1320px; }
}

/* ---------- Dark Mode Ready (data-theme="dark" on <html>) ---------- */
[data-theme="dark"] {
    --color-bg: #14191D;
    --color-surface: #1C2328;
    --color-text: #E7ECEF;
    --color-text-muted: #93A1AA;
    --color-border: #2B333A;
}
