/* ============================================================================
   حركة الواجهة — ادفع أونلاين   (السكربت المرافق: static/js/motion.js)

   قواعد هذا الملف:
   - الحركة على opacity و transform فقط، وكل مفاتيحها «from» بلا «to»: العنصر ينتهي دائماً
     عند شكله الأصلي ولا يبقى عليه أي أثر بعد انتهاء الحركة.
   - قواعد الظهور داخل ‎:where()‎ (أولوية صفر): أي حركة تعرّفها صفحة لعنصرها تبقى هي الغالبة.
   - الظهور مشروط بالصنف mo-enter على <html>، يضيفه سطر في رأس القالب ويزيله بعد التحميل؛
     بلا جافاسكربت أو مع «تقليل الحركة» في الجهاز تظهر الصفحة كما هي بلا حركة.
   - اتركّب 2026-11-25 (المسودة من 2026-10-13 + «الصفحة بتحمّل» بعد الضغط على رابط).
   ========================================================================== */

:root {
    --mo-ease: cubic-bezier(.22, 1, .36, 1);
}

/* ── شريط التقدم أعلى الصفحة عند الانتقال أو إرسال نموذج ── */
#moBar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 100000;
    pointer-events: none;
    opacity: 0;
}

#moBar i {
    display: block;
    height: 100%;
    background: linear-gradient(270deg, #ffffff, #ffe082);
    box-shadow: 0 0 10px rgba(255, 255, 255, .85), 0 1px 3px rgba(0, 0, 0, .25);
    transform: scaleX(0);
    transform-origin: 100% 50%;
}

#moBar.mo-on {
    opacity: 1;
}

#moBar.mo-on i {
    animation: moBar 14s cubic-bezier(.05, .8, .2, 1) forwards;
}

#moBar.mo-out {
    opacity: 0;
    transition: opacity .3s ease;
}

@keyframes moBar {
    to { transform: scaleX(.93); }
}

/* ── «الصفحة بتحمّل»: بعد الضغط على رابط بـ ‎350ms‎ لو لسه ما اتنقلناش، المحتوى يبهت وخط لامع يعدّي عليه
      (بدل ما الصفحة تبان واقفة). بيتشال لوحده مع الصفحة الجديدة، أو بالرجوع، أو لو الرابط طلع تنزيل ── */
html.mo-leaving main {
    opacity: .55;
    transition: opacity .25s ease;
}

html.mo-leaving main::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(100deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, .45) 50%, rgba(255, 255, 255, 0) 70%);
    background-size: 220% 100%;
    animation: moShimmer 1.1s linear infinite;
}

@keyframes moShimmer {
    from { background-position: 160% 0; }
    to { background-position: -60% 0; }
}

/* ── أثر الضغط: طبقة فوق الصفحة بمقاس العنصر المضغوط (لا تُضاف داخل العنصر نفسه) ── */
.mo-ink-box {
    position: fixed;
    z-index: 100001;
    overflow: hidden;
    pointer-events: none;
}

.mo-ink {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: moInk .55s ease-out forwards;
}

@keyframes moInk {
    to { transform: scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    #moBar.mo-on i {
        animation: none;
        transform: scaleX(.7);
    }
    html.mo-leaving main::after {
        animation: none;
        background: none;
    }
}

@media (prefers-reduced-motion: no-preference) {

    @keyframes moRise {
        from { opacity: 0; transform: translate3d(0, 16px, 0); }
    }

    @keyframes moFade {
        from { opacity: 0; }
    }

    @keyframes moDrop {
        from { opacity: 0; transform: translate3d(0, -10px, 0); }
    }

    /* ── انتقال ناعم بين الصفحات (المتصفحات التي تدعمه؛ غيرها يتجاهل القاعدة) ── */
    @view-transition {
        navigation: auto;
    }

    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: .2s;
    }

    /* ── ظهور الصفحة ── */
    :where(html.mo-enter) :where(main) {
        animation: moFade .3s ease-out backwards;
    }

    :where(html.mo-enter main) :where(.dash-hero, .svc-list-header, .pay-header) {
        animation: moFade .5s ease-out backwards;
    }

    :where(html.mo-enter main) > :where(.alert) {
        animation: moDrop .45s var(--mo-ease) backwards;
    }

    /* الرئيسية وقوائم الخدمات: العناصر تصعد واحداً بعد الآخر
       التأخير = بداية المجموعة (‎--mo-b‎) + ترتيب العنصر بين إخوته (‎--mo-i‎) × الفاصل (‎--mo-s‎) */
    :where(html.mo-enter main) :where(.dash-balance-card, .dash-quick-btn, .dash-search-wrapper, .dash-section-title, .dash-card, .dash-stat, .svc-search-wrap, .svc-card) {
        animation: moRise .5s var(--mo-ease) backwards;
        animation-delay: calc(var(--mo-b, 0ms) + var(--mo-i, 0) * var(--mo-s, 30ms));
    }

    :where(.dash-balance-card) { --mo-b: 60ms; --mo-s: 50ms; }
    :where(.dash-quick-btn) { --mo-b: 140ms; --mo-s: 45ms; }
    :where(.dash-search-wrapper, .svc-search-wrap) { --mo-b: 200ms; }
    :where(.dash-section-title) { --mo-b: 240ms; }
    :where(.dash-card, .svc-card) { --mo-b: 220ms; --mo-s: 28ms; }
    :where(.dash-stat) { --mo-b: 300ms; --mo-s: 45ms; }

    /* أول 12 صفاً في الجداول تظهر متتابعة */
    :where(html.mo-enter main) :where(.table > tbody > tr:nth-child(-n+12)) {
        animation: moFade .45s ease-out backwards;
        animation-delay: calc(140ms + var(--mo-i, 0) * 24ms);
    }

    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr) { --mo-i: 0; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(2)) { --mo-i: 1; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(3)) { --mo-i: 2; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(4)) { --mo-i: 3; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(5)) { --mo-i: 4; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(6)) { --mo-i: 5; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(7)) { --mo-i: 6; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(8)) { --mo-i: 7; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(9)) { --mo-i: 8; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(10)) { --mo-i: 9; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(11)) { --mo-i: 10; }
    :where(.dash-balance-card, .dash-quick-btn, .dash-card, .dash-stat, .svc-card, .table > tbody > tr):where(:nth-child(n+12)) { --mo-i: 11; }

    /* بقية الصفحات: البطاقات تصعد، متتابعة حسب عمودها في الصف (‎--mo-c‎) وترتيبها بين إخوتها (‎--mo-n‎) */
    :where(html.mo-enter main) :where(.card, .stats-card, .list-group, .table-responsive):where(:not(.card *, .modal *, .offcanvas *, .dropdown-menu *, .toast *)) {
        animation: moRise .5s var(--mo-ease) backwards;
        animation-delay: calc(50ms + var(--mo-c, 0ms) + var(--mo-n, 0ms));
    }

    :where(main .row) > :where(*) { --mo-c: 0ms; }
    :where(main .row) > :where(:nth-child(2)) { --mo-c: 55ms; }
    :where(main .row) > :where(:nth-child(3)) { --mo-c: 110ms; }
    :where(main .row) > :where(:nth-child(4)) { --mo-c: 165ms; }
    :where(main .row) > :where(:nth-child(n+5)) { --mo-c: 220ms; }

    :where(main) :where(.card, .stats-card, .list-group, .table-responsive) { --mo-n: 0ms; }
    :where(main) :where(.card, .stats-card, .list-group, .table-responsive):where(:nth-child(2)) { --mo-n: 55ms; }
    :where(main) :where(.card, .stats-card, .list-group, .table-responsive):where(:nth-child(3)) { --mo-n: 110ms; }
    :where(main) :where(.card, .stats-card, .list-group, .table-responsive):where(:nth-child(4)) { --mo-n: 165ms; }
    :where(main) :where(.card, .stats-card, .list-group, .table-responsive):where(:nth-child(n+5)) { --mo-n: 220ms; }

    /* القوائم المنسدلة: ظهور بالشفافية فقط (موضعها يُحسب بـ transform فلا يُمَس) */
    :where(.dropdown-menu.show) {
        animation: moFade .16s ease-out;
    }

    /* ضغطة الزر: خاصية scale المستقلة حتى لا تُلغي transform يستخدمه الزر لموضعه */
    .btn:active:not(:disabled):not(.disabled) {
        scale: .97;
    }

    /* ── ظهور البلاطات مع التمرير (motion.js يضيف mo-wait لما هو أسفل الشاشة ثم mo-in عند وصوله) ── */
    .mo-wait {
        opacity: 0 !important;
        transform: translate3d(0, 18px, 0) scale(.97) !important;
        animation: none !important;
        transition: none !important;
    }

    .mo-wait.mo-in {
        opacity: 1 !important;
        transform: none !important;
        transition: opacity .45s var(--mo-ease) var(--mo-w, 0ms), transform .45s var(--mo-ease) var(--mo-w, 0ms) !important;
    }

    /* الأرقام أثناء العدّ: خانات ثابتة العرض حتى لا يهتز السطر */
    .mo-count {
        font-variant-numeric: tabular-nums;
    }
}

@media print {
    .mo-wait {
        opacity: 1 !important;
        transform: none !important;
    }

    #moBar,
    .mo-ink-box {
        display: none !important;
    }

    html.mo-leaving main {
        opacity: 1 !important;
    }

    html.mo-leaving main::after {
        display: none !important;
    }
}
