/* قواعد موحدة لكل نوافذ Filament وإشعارات اللوحة؛ محتاجة إثبات المتصفح قبل النشر. */
@media screen {
    body.fi-body {
        --en-toast-gap: 1rem;
        --en-toast-floor: max(var(--en-toast-gap), env(safe-area-inset-bottom, 0px));
        --en-toast-stack-height: min(12rem, 25dvh);
    }

    /* حيز مستقل للإشعار وقت فتح الحوار، حتى قبل تنفيذ ملف القياس أو لو غاب.
       JS بيستبدل الحد الأقصى بارتفاع الإشعار الحقيقي؛ من غير إشعار مفيش حجز. */
    body.fi-body:has(.fi-modal.fi-modal-open):has(.fi-no > .fi-no-notification) {
        --en-modal-toast-reserve: calc(var(--en-toast-floor) + var(--en-toast-stack-height) + var(--en-toast-gap));
    }

    /* جذر الحوار ثابت زي الخلفية والنافذة اللي جواه. التركيز التلقائي كده
       ما يعدّيش على صندوق fi-page القابل للتمرير فيحرّكه ناحية نافذة خارج حدوده.
       الحركة وفخ التركيز وشدّ النافذة بيفضلوا عند Filament. */
    .fi-modal.fi-modal-open {
        position: fixed;
        inset: 0;
        z-index: 40;
    }

    /* نفس أولوية النافذة التالية في Filament؛ يشمل نوافذ التأكيد المتداخلة. */
    .fi-modal.fi-modal-open ~ .fi-modal.fi-modal-open {
        z-index: 50;
    }

    /* تصغير مساحة العرض المتاحة للحوار، مش تحريك الإشعار فوق خاناته.
       min-height الأصلي 100% كان هيلغي تأثير bottom، فلازم يتلغى هنا.
       محتوى الحوار الطويل يفضل قابل للتمرير، والذيل خارج حيز الإشعار. */
    body.fi-body:has(.fi-no > .fi-no-notification) .fi-modal.fi-modal-open > .fi-modal-window-ctn {
        bottom: var(--en-modal-toast-reserve);
        min-height: 0;
    }

    body.fi-body:has(.fi-no > .fi-no-notification) .fi-modal.fi-modal-open > .fi-modal-window-ctn > .fi-modal-window {
        max-height: max(0px, calc(100dvh - var(--en-modal-toast-reserve) - 2rem));
        overflow-y: auto;
    }

    body.fi-body:has(.fi-no > .fi-no-notification) .fi-modal.fi-modal-open:is(.fi-modal-slide-over, .fi-width-screen) > .fi-modal-window-ctn > .fi-modal-window {
        height: max(0px, calc(100dvh - var(--en-modal-toast-reserve)));
        max-height: max(0px, calc(100dvh - var(--en-modal-toast-reserve)));
    }

    body.fi-body:has(.fi-no > .fi-no-notification) .fi-modal.fi-modal-open > .fi-modal-window-ctn > .fi-modal-window.fi-width-screen {
        bottom: var(--en-modal-toast-reserve);
        max-height: max(0px, calc(100dvh - var(--en-modal-toast-reserve)));
    }

    /* أسفل الشمال في RTL من غير تبديل مع فتح درج جانبي.
       الحاوية بعرض الإشعار بس؛ مساحة الهيدر تفضل برّه حتى مع إشعارات كتير. */
    body.fi-body .fi-no.fi-no {
        position: fixed;
        inset: auto;
        left: max(var(--en-toast-gap), env(safe-area-inset-left, 0px));
        bottom: var(--en-toast-floor);
        width: min(24rem, calc(100% - 2 * var(--en-toast-gap)));
        max-height: calc(100dvh - 4rem - 2 * var(--en-toast-gap));
        margin: 0;
        align-items: stretch;
        flex-direction: column;
        justify-content: flex-start;
        overflow-y: auto;
        overscroll-behavior: contain;
        pointer-events: none;
    }

    /* يلغي تمرير الضغط القديم على جسم الإشعار وقت فتح الدرج؛ أزراره تفضل شغالة. */
    body.fi-body .fi-no.fi-no > .fi-no-notification {
        min-width: 0;
        max-width: 100%;
        pointer-events: auto;
        overflow-wrap: anywhere;
    }

    body.fi-body .fi-no.fi-no .fi-no-notification-main {
        min-width: 0;
    }

    /* الإشعارات الكتير أو الطويلة تتمرر جوه الحيز، مش تتمدد فوق الحوار. */
    body.fi-body:has(.fi-modal.fi-modal-open) .fi-no.fi-no {
        max-height: var(--en-toast-stack-height);
    }

    body.fi-body .fi-no.fi-no > .fi-no-notification {
        flex-shrink: 0;
    }
}
