:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f5f6fa;
}

* { font-family: 'Cairo', system-ui, sans-serif; }

body {
    background: var(--bg);
    color: var(--ink);
}

.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
}
.text-primary { color: var(--brand) !important; }

/* ===== الصفحات العامة ===== */
.guest-body { background: #fff; }
.landing-nav { background: #fff; border-bottom: 1px solid var(--line); padding: .75rem 0; }
.landing-hero {
    background: linear-gradient(180deg, var(--brand-soft), #fff);
    border-bottom: 1px solid var(--line);
}
.feature-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.75rem 1.25rem;
    text-align: center;
    transition: transform .15s, box-shadow .15s;
}
.feature-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0,0,0,.07); }
.feature-icon {
    width: 60px; height: 60px; margin: 0 auto 1rem;
    display: grid; place-items: center;
    background: var(--brand-soft); color: var(--brand);
    border-radius: 16px; font-size: 1.6rem;
}
.landing-footer { background: #fafafa; border-top: 1px solid var(--line); }

/* ===== المصادقة ===== */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--brand-soft), #fff);
}
.auth-card {
    width: 100%; max-width: 420px;
    background: #fff; border: 1px solid var(--line);
    border-radius: 18px; padding: 2rem;
    box-shadow: 0 12px 40px rgba(0,0,0,.06);
}
.auth-brand { font-size: 1.25rem; font-weight: 800; text-decoration: none; color: var(--ink); }

/* ===== هيكل التطبيق (مسجّل دخول) ===== */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: 250px; flex-shrink: 0;
    background: #111827; color: #cbd5e1;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
    padding: 1.15rem 1.25rem; font-weight: 800; font-size: 1.15rem; color: #fff;
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { color: var(--brand); }
.sidebar-nav { padding: .75rem; display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; }
.sidebar-heading { color: #64748b; font-size: .72rem; font-weight: 700; padding: .75rem .75rem .25rem; text-transform: uppercase; }
.sidebar-nav a {
    color: #cbd5e1; text-decoration: none;
    padding: .6rem .75rem; border-radius: 10px;
    display: flex; align-items: center; gap: .6rem; font-size: .93rem;
    transition: background .12s, color .12s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--brand); color: #fff; }
.sidebar-nav a.disabled { opacity: .5; pointer-events: none; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
    background: #fff; border-bottom: 1px solid var(--line);
    padding: .75rem 1.25rem; display: flex; align-items: center; gap: .75rem;
    position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-weight: 700; }

/* ===== البحث العام في الهيدر ===== */
.global-search { position: relative; width: min(340px, 42vw); }
.gs-form { position: relative; }
.gs-icon { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.gs-input {
    width: 100%; padding: .45rem 2.2rem .45rem .9rem;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--bg); font-size: .9rem; transition: border-color .2s, box-shadow .2s, background .2s;
}
.gs-input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 .18rem rgba(79,70,229,.12); }
.gs-results {
    position: absolute; top: calc(100% + 8px); right: 0; left: 0;
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 16px 40px rgba(15,23,42,.15); z-index: 1060;
    max-height: 70vh; overflow-y: auto; display: none; padding: .35rem;
}
.gs-results.show { display: block; }
.gs-group-label { font-size: .72rem; font-weight: 700; color: var(--muted); padding: .5rem .75rem .25rem; text-transform: uppercase; }
.gs-item { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; border-radius: 10px; text-decoration: none; color: var(--ink); }
.gs-item:hover, .gs-item.active { background: var(--brand-soft); color: var(--brand-dark); }
.gs-item .gs-ic { color: var(--brand); font-size: 1.05rem; }
.gs-item .gs-meta { margin-right: auto; font-size: .74rem; color: var(--muted); }
.gs-empty, .gs-hint { padding: .9rem .75rem; color: var(--muted); font-size: .85rem; text-align: center; }
/* تظليل الجزء المطابق للبحث */
mark.gs-hl {
    background: linear-gradient(180deg, #fde68a, #f6d24a);
    color: #3a2c05; padding: 0 2px; border-radius: 4px; font-weight: 700;
}
.gs-item:hover mark.gs-hl { background: #fff; }
.gs-all { display: block; text-align: center; padding: .55rem; font-weight: 600; color: var(--brand); text-decoration: none; border-top: 1px solid var(--line); margin-top: .25rem; }
.gs-all:hover { background: var(--brand-soft); }

@media (max-width: 575.98px) { .global-search { width: 46vw; } .gs-input::placeholder { font-size: .8rem; } }
/* تنبيه: لا تضع animation/transform على .app-content أو على أعمدة الصفوف.
   العنصر ذو الـtransform يصبح المرجع للعناصر position:fixed وينشئ طبقة عرض مستقلة،
   فينحبس المودال داخله وتغطّيه طبقة التعتيم (modal-backdrop) فلا يستجيب للنقر. */
.app-content { padding: 1.5rem; flex: 1; }

/* حركة عصرية على البطاقات داخل النظام (hover فقط — آمنة) */
.app-main .card, .app-main .stat-card {
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.app-main .card:hover, .app-main .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(15, 23, 42, .1);
}
.app-main .stat-card:hover { border-color: var(--brand); }

/* ===== الشعار الموحّد (SVG) + حركته ===== */
.brand-logo { display: inline-flex; align-items: center; gap: .55rem; text-decoration: none; }
.brand-logo.brand-stacked { flex-direction: column; gap: .3rem; }
.brand-emblem {
    width: var(--logo-size, 44px);
    height: var(--logo-size, 44px);
    display: block;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,.25));
    animation: logoFloat 4.5s ease-in-out infinite;
    transform-origin: center;
    transition: transform .35s ease, filter .35s ease;
}
.brand-logo:hover .brand-emblem {
    transform: translateY(-2px) scale(1.06);
    filter: drop-shadow(0 6px 16px rgba(212,175,55,.45));
}

/* أجزاء الإمبلم المتحركة */
.em-ring { transform-origin: 60px 60px; transition: transform .8s ease; }
.brand-logo:hover .em-ring { transform: rotate(8deg); }
.em-cap { transform-origin: 60px 40px; animation: capBob 4.5s ease-in-out infinite; }
.em-tassel { transform-origin: 88px 40px; animation: tasselSwing 3.5s ease-in-out infinite; }
.em-arrow, .em-arrow-head { animation: arrowPulse 3s ease-in-out infinite; }
.brand-logo:hover .em-arrow-head { animation: arrowShoot .6s ease; }

/* رسم السهم عند التحميل */
.em-arrow { stroke-dasharray: 30; stroke-dashoffset: 30; animation: arrowDraw 1s ease forwards, arrowPulse 3s ease-in-out 1s infinite; }

.brand-word {
    font-weight: 800;
    letter-spacing: .3px;
    background: linear-gradient(135deg, #f6e27a, #d4af37);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    color: var(--word-color, #d4af37);
    line-height: 1.08;
}
.brand-stacked .brand-word {
    font-size: calc(var(--logo-size, 44px) * .26);
    text-align: center;
    max-width: calc(var(--logo-size, 44px) * 2.6);
}
.brand-inline .brand-word {
    font-size: calc(var(--logo-size, 44px) * .34);
    white-space: nowrap;
}

/* ===== أنيميشن أحرف اسم المنصة (تتساقط حرفاً حرفاً) ===== */
.brand-word.brand-anim {
    -webkit-text-fill-color: currentColor;
    display: inline-flex; align-items: center; overflow: visible;
    direction: ltr; unicode-bidi: isolate; /* اسم لاتيني: يُقرأ يسار→يمين وبالترتيب الصحيح */
}
.brand-word .bl {
    display: inline-block;
    background: linear-gradient(135deg, #f9e79f, #d4af37 55%, #b8912e);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    will-change: transform, opacity;
}
/* باقي الأحرف: طابور يخرج من بطن الـC ويمشي لمكانه (المسافة عبر --travel) */
.brand-word .bl:not(.bl-first) {
    transform-origin: left center;
    animation: letterEmerge 5.5s ease-in-out infinite both;
}
/* تتجمّع → تثبت (~ثانية ونصف مشتركة) → تتشتّت → تعيد */
@keyframes letterEmerge {
    0%   { transform: translateX(calc(var(--travel, 0px) * -1)) scale(.08); opacity: 0; }
    16%  { transform: translateX(0) scale(1); opacity: 1; }
    75%  { transform: translateX(0) scale(1); opacity: 1; }
    90%  { transform: translateX(calc(var(--travel, 0px) * -0.55)) scale(.4); opacity: 0; }
    100% { transform: translateX(calc(var(--travel, 0px) * -1)) scale(.08); opacity: 0; }
}

/* حرف C كشعار مرسوم (SVG): قوس عريض + قبعة تتنطنط + نقاط تفريغ + قاعدة */
.brand-word .bl-first {
    display: inline-block;
    width: 2.5em;
    line-height: 0;
    margin-inline-end: .1em;
    align-self: center;
    -webkit-text-fill-color: initial;
}
.brand-word .bl-first .c-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
    animation: cPulse 4.6s ease-in-out infinite;
    transform-origin: center;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,.35));
}
@keyframes cPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
/* القبعة تتنطنط فوق الـC (داخل الـSVG) */
.brand-word .bl-first .c-cap {
    transform-box: view-box;
    transform-origin: 42px 25px;
    animation: capBounce 1.3s ease-in-out infinite;
}
@keyframes capBounce {
    0%   { transform: translateY(0) rotate(-7deg); }
    24%  { transform: translateY(-9px) rotate(6deg); }
    48%  { transform: translateY(0) rotate(-5deg); }
    68%  { transform: translateY(-4px) rotate(3deg); }
    100% { transform: translateY(0) rotate(-7deg); }
}

@media (prefers-reduced-motion: reduce) {
    .brand-word .bl, .brand-word .bl-first,
    .brand-word .bl-first::before, .brand-word .bl-first::after {
        animation: none !important; opacity: 1 !important; transform: none !important;
    }
}

@keyframes logoFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes capBob { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-1.5px) rotate(-2deg); } }
@keyframes tasselSwing { 0%,100% { transform: rotate(6deg); } 50% { transform: rotate(-6deg); } }
@keyframes arrowDraw { to { stroke-dashoffset: 0; } }
@keyframes arrowPulse { 0%,100% { opacity: 1; } 50% { opacity: .82; } }
@keyframes arrowShoot { 0% { transform: translate(0,0); } 50% { transform: translate(4px,-4px); } 100% { transform: translate(0,0); } }

@media (prefers-reduced-motion: reduce) {
    .brand-emblem, .em-cap, .em-tassel, .em-arrow, .em-arrow-head { animation: none !important; }
    .em-arrow { stroke-dashoffset: 0; }
}

/* ===== مشغّل الفيديو + العلامة المائية ===== */
.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-watermark {
    position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2;
}
.video-watermark span {
    position: absolute; top: 12%; left: 8%;
    color: rgba(255, 255, 255, .32); font-size: .8rem; font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .5); white-space: nowrap;
    animation: wmMove 19s linear infinite;
}
@keyframes wmMove {
    0%   { top: 12%; left: 8%; }
    25%  { top: 78%; left: 70%; }
    50%  { top: 45%; left: 20%; }
    75%  { top: 20%; left: 60%; }
    100% { top: 12%; left: 8%; }
}

/* بطاقة كورس */
.course-card { overflow: hidden; display: flex; flex-direction: column; }
.course-thumb {
    position: relative;
    height: 150px; min-height: 150px; max-height: 150px;
    flex: 0 0 150px;           /* ارتفاع ثابت لا يكبر ولا يصغر مهما كان حجم الصورة */
    background: var(--brand-soft);
    display: grid; place-items: center; color: #c7d2fe; font-size: 2.5rem;
    overflow: hidden;
}
.course-thumb img {
    width: 100%; height: 100%;
    object-fit: cover; object-position: center;
    display: block;
}
.course-badge { position: absolute; top: 8px; left: 8px; }
/* التذييل (أزرار التحكم) يبقى دائماً أسفل البطاقة وظاهراً */
.course-card .card-body { flex: 1 1 auto; }
.course-card .card-footer { margin-top: auto; }

/* صورة المدرّس */
.instructor-avatar {
    width: 84px; height: 84px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand);
    display: grid; place-items: center; overflow: hidden;
    font-size: 2rem; border: 2px solid var(--line);
}
.instructor-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* بطاقات المؤشرات */
.stat-card {
    background: #fff; border: 1px solid var(--line); border-top-width: 3px;
    border-radius: 14px; padding: 1.25rem;
}
.stat-icon { font-size: 1.8rem; margin-bottom: .5rem; }

/* ===== شبكة أقسام لوحة التحكم (بطاقات أيقونات) ===== */
.dash-section-title {
    display: flex; align-items: center; gap: .5rem;
    font-size: .82rem; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .4px;
    margin: 1.5rem 0 .75rem;
}
.dash-section-title::after {
    content: ""; flex: 1; height: 1px;
    background: linear-gradient(90deg, var(--line), transparent);
}

.nav-tile {
    position: relative; display: flex; flex-direction: column;
    align-items: center; text-align: center; gap: .55rem;
    background: #fff; border: 1px solid var(--line); border-radius: 18px;
    padding: 1.25rem .75rem; height: 100%;
    text-decoration: none; color: var(--ink); overflow: hidden;
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.nav-tile::before {
    content: ""; position: absolute; inset: 0; opacity: 0;
    background: radial-gradient(120% 90% at 50% -10%, var(--tile, var(--brand-soft)), transparent 70%);
    transition: opacity .25s ease;
}
.nav-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 34px rgba(15, 23, 42, .12);
    border-color: var(--tile-strong, var(--brand));
    color: var(--ink);
}
.nav-tile:hover::before { opacity: .5; }

.nav-tile-ic {
    position: relative; z-index: 1;
    width: 58px; height: 58px; border-radius: 16px;
    display: grid; place-items: center; font-size: 1.55rem;
    color: var(--tile-strong, var(--brand));
    background: var(--tile, var(--brand-soft));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
    transition: transform .22s ease;
}
.nav-tile:hover .nav-tile-ic { transform: scale(1.08) rotate(-4deg); }
.nav-tile-label { position: relative; z-index: 1; font-weight: 700; font-size: .92rem; }
.nav-tile-sub { position: relative; z-index: 1; font-size: .74rem; color: var(--muted); }

.nav-tile-badge {
    position: absolute; top: 10px; inset-inline-start: 10px; z-index: 2;
    min-width: 20px; height: 20px; padding: 0 6px;
    display: grid; place-items: center;
    background: #ef4444; color: #fff; font-size: .72rem; font-weight: 700;
    border-radius: 999px; box-shadow: 0 2px 8px rgba(239,68,68,.5);
}

/* استجابة للجوال */
@media (max-width: 767.98px) {
    .app-sidebar {
        position: fixed; right: 0; z-index: 1050; transform: translateX(100%);
        transition: transform .2s;
    }
    .app-sidebar.open { transform: translateX(0); }
}

/* ===== ردع لقطات الشاشة (deterrent فقط) ===== */
#screenGuard {
    position: fixed; inset: 0; z-index: 2147483647;
    display: none; align-items: center; justify-content: center;
    flex-direction: column; gap: .75rem; text-align: center; padding: 2rem;
    background: #0b1020; color: #fff;
    -webkit-user-select: none; user-select: none;
}
#screenGuard.show { display: flex; }
#screenGuard .sg-ic { font-size: 3rem; color: #f6e27a; }
#screenGuard .sg-title { font-size: 1.15rem; font-weight: 800; }
#screenGuard .sg-sub { font-size: .9rem; opacity: .8; max-width: 420px; }
/* وميض التحذير عند الضغط على PrintScreen */
#screenGuard.flash { display: flex; animation: sgFlash 1s ease forwards; }
@keyframes sgFlash {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; display: none; }
}
