/* =====================================================================
   app.responsive.css  —  طبقة الاستجابة الموحّدة لنظام سهل
   تُحمّل بعد site.rtl.css. الغرض: تخطيط واحد يتكيّف مع
   الموبايل (<768) / التابلت (768–991) / الحاسبة (≥992).
   لا تضع هنا ألوان الهوية أو منطق الصفحات — فقط قواعد التخطيط والاستجابة.
   ===================================================================== */

:root {
    --sb-width: 230px;          /* عرض السايدبار المفتوح */
    --sb-rail: 75px;            /* عرض السايدبار المطوي (أيقونات فقط) */
    --bottom-nav-h: 60px;       /* ارتفاع الشريط السفلي في الموبايل */
    --tap-min: 44px;            /* أصغر مساحة لمس مقبولة */
}

/* ---------------------------------------------------------------------
   1) تخطيط الإطار الرئيسي — مصدر واحد للحقيقة
   يُلغي التعارض بين قواعد @media المتعددة في site.rtl.css
   --------------------------------------------------------------------- */

/* الافتراضي (موبايل + تابلت): لا سايدبار ثابت، المحتوى بكامل العرض */
#layoutSidenav_content {
    margin-right: 0 !important;
    width: 100% !important;
    transition: margin-right .25s ease;
}

#layoutSidenav_nav {
    display: none !important;
}

/* الحاسبة: السايدبار الثابت يظهر ويُزيح المحتوى */
@media (min-width: 992px) {
    #layoutSidenav_nav {
        display: block !important;
    }

    /* المحتوى يتقلّص بمقدار عرض السايدبار عبر الهامش فقط.
       يجب إلغاء width:100% هنا وإلا صار العرض = 100% + الهامش
       ⇐ تجاوز أفقي وشريط سكرول وزحف المحتوى تحت السايدبار الثابت. */
    #layoutSidenav_content {
        width: auto !important;
        margin-right: var(--sb-width) !important;
    }

    /* حالة الطي (rail) */
    .sb-sidenav-toggled #layoutSidenav_nav {
        width: var(--sb-rail) !important;
    }

    .sb-sidenav-toggled #layoutSidenav_content {
        width: auto !important;
        margin-right: var(--sb-rail) !important;
    }
}

/* ---------------------------------------------------------------------
   2) الشريط العلوي (navbar)
   --------------------------------------------------------------------- */
.app-navbar {
    min-height: 56px;
    gap: .25rem;
    flex-wrap: nowrap;
}

/* لازم لعمل text-truncate داخل flex */
.min-width-0 {
    min-width: 0;
}

    .app-navbar .navbar-brand {
        font-size: 1rem;
        line-height: 1.15;
    }

/* عنوان الصفحة الحالي في الشريط العلوي (بديل نص العلامة الطويل) */
.app-navbar .navbar-title {
    font-size: 1.05rem;
    line-height: 1.2;
    min-width: 0;
}

/* الشريط ليس navbar-expand، لذا يجعل بوتستراب قوائمه المنسدلة static
   فتُفتح داخل الشريط وتكبّر ارتفاعه. نُعيدها absolute لتنسدل فوق المحتوى. */
.app-navbar .navbar-nav .dropdown-menu {
    position: absolute;
    z-index: 1030;
}

/* أفاتار المستخدم بدل زر الخروج الكبير */
.app-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #0d6efd;
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    line-height: 1;
    flex-shrink: 0;
}

/* على الموبايل: وفّر المساحة وأعطها للعنوان */
@media (max-width: 575.98px) {
    .app-navbar .navbar-logo {
        display: none;
    }

    .app-navbar .navbar-title {
        font-size: .98rem;
    }
}

/* زر فتح القائمة الجانبية في الموبايل/التابلت */
.app-drawer-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap-min);
    min-height: var(--tap-min);
    border: 0;
    background: transparent;
    font-size: 1.4rem;
    color: #0d2b6b;
}

@media (min-width: 992px) {
    .app-drawer-toggle {
        display: none;
    }
}

/* الموبايل: نستغني عن ☰ العلوي — عنصر "القائمة" في الشريط السفلي يفتح الدرج.
   يبقى ☰ ظاهراً على التابلت (768–991) حيث لا يوجد شريط سفلي. */
@media (max-width: 767.98px) {
    .app-drawer-toggle {
        display: none;
    }
}

/* زر طي السايدبار — للحاسبة فقط */
.app-rail-toggle {
    display: none;
}

@media (min-width: 992px) {
    .app-rail-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 40px;
        min-height: 40px;
    }
}

/* ---------------------------------------------------------------------
   3) الدرج الجانبي المنزلق (Offcanvas) — موبايل + تابلت
   يُعيد استخدام نفس هوية السايدبار الكحلية
   --------------------------------------------------------------------- */
#appSidebarDrawer {
    width: min(84vw, 320px);
    background: linear-gradient(180deg, #020f2b, #032e8a 60%, #032e8a);
    color: #fff;
}

    #appSidebarDrawer .offcanvas-header {
        background: rgba(255, 255, 255, .04);
    }

    #appSidebarDrawer .drawer-link,
    #appSidebarDrawer .accordion-button {
        color: #e2e8f0;
        background: transparent;
        box-shadow: none;
        font-size: .95rem;
        font-weight: 600;
        padding: .8rem 1rem;
        display: flex;
        align-items: center;
        gap: .6rem;
        text-decoration: none;
        width: 100%;
        border: 0;
    }

        #appSidebarDrawer .drawer-link:hover,
        #appSidebarDrawer .accordion-button:not(.collapsed) {
            background: linear-gradient(90deg, #2563eb, #3b82f6);
            color: #fff;
        }

        #appSidebarDrawer .accordion-button::after {
            filter: invert(1) grayscale(1) brightness(1.6);
            margin-right: auto;
            margin-left: 0;
        }

    #appSidebarDrawer .accordion-item {
        background: transparent;
        border: 0;
        border-bottom: 1px solid rgba(255, 255, 255, .08);
    }

    #appSidebarDrawer .accordion-body {
        padding: .25rem 0 .5rem;
    }

    #appSidebarDrawer .accordion-body a {
        color: rgba(255, 255, 255, .72);
        text-decoration: none;
        display: block;
        padding: .55rem 1rem .55rem 2.4rem;
        font-size: .9rem;
        min-height: var(--tap-min);
    }

        #appSidebarDrawer .accordion-body a:hover {
            color: #fff;
            background: rgba(255, 255, 255, .08);
        }

/* ---------------------------------------------------------------------
   4) الشريط السفلي (Bottom nav) — الموبايل فقط (<768)
   --------------------------------------------------------------------- */
.app-bottom-nav {
    display: none;
}

/* الزر العائم (FAB) — يظهر داخل @media الموبايل فقط */
.app-fab {
    display: none;
}

@media (max-width: 767.98px) {
    .app-bottom-nav {
        display: flex;
        position: fixed;
        inset: auto 0 0 0;
        height: var(--bottom-nav-h);
        background: #fff;
        border-top: 1px solid #dee2e6;
        box-shadow: 0 -2px 12px rgba(0,0,0,.06);
        z-index: 1045;
        justify-content: space-around;
        align-items: stretch;
        padding-bottom: env(safe-area-inset-bottom);
    }

        .app-bottom-nav a {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 2px;
            color: #6c757d;
            text-decoration: none;
            font-size: .72rem;
            font-weight: 600;
        }

            .app-bottom-nav a i {
                font-size: 1.35rem;
                line-height: 1;
            }

            .app-bottom-nav a.is-active {
                color: #0d6efd;
            }

    /* فراغ وسط الشريط ليجلس فيه الزر العائم دون تغطية أي عنصر */
    .app-bottom-nav .bn-gap {
        flex: .55;
    }

            .app-bottom-nav a .nav-badge {
                position: absolute;
                transform: translate(90%, -60%);
                font-size: .55rem;
                padding: .2rem .35rem;
                border-radius: 999px;
            }

    /* مساحة سفلية حتى لا يغطي الشريط المحتوى/الفوتر */
    body {
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    }

    #layoutSidenav_content > footer {
        display: none;
    }

    /* (1) إخفاء الشريط العلوي عند التمرير للأسفل */
    .app-navbar {
        transition: transform .25s ease;
        will-change: transform;
    }

        .app-navbar.app-navbar--hidden {
            transform: translateY(-100%);
        }

    /* (2) زر عائم لبدء فاتورة بيع سريعة */
    .app-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) - 20px);
        width: 58px;
        height: 58px;
        border-radius: 50%;
        background: #0d6efd;
        color: #fff;
        font-size: 1.6rem;
        line-height: 1;
        text-decoration: none;
        border: 3px solid #fff;
        box-shadow: 0 8px 20px rgba(13, 110, 253, .45);
        z-index: 1046;
    }

        .app-fab:hover,
        .app-fab:focus,
        .app-fab:active {
            color: #fff;
            background: #0b5ed7;
            transform: translateX(-50%) scale(1.05);
        }
}

/* ---------------------------------------------------------------------
   5) الجداول على الشاشات الصغيرة
   أ) تمرير أفقي آمن دائماً
   ب) نمط .table-stack: يحوّل الجدول إلى بطاقات <768 عبر data-label
   --------------------------------------------------------------------- */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    table.table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    table.table-stack tbody,
    table.table-stack tr,
    table.table-stack td {
        display: block;
        width: 100%;
    }

    table.table-stack tr {
        margin-bottom: .6rem;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0,0,0,.04);
        padding: .1rem .3rem;
    }

    table.table-stack td {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        column-gap: .75rem;
        row-gap: .15rem;
        text-align: start;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        padding: .5rem .7rem; /* بادينغ أقل حتى لا يبتلع عرض القيمة */
        min-height: var(--tap-min);
        overflow-wrap: anywhere; /* يكسر الأرقام/الأكواد الطويلة بدل قطعها */
        word-break: break-word;
    }

        table.table-stack td:last-child {
            border-bottom: 0;
        }

        table.table-stack td::before {
            content: attr(data-label);
            font-weight: 700;
            color: #64748b;
            font-size: .78rem;
            flex: 0 1 auto;
            max-width: 55%;
        }

        /* خلية بلا data-label (مثل أزرار الإجراءات) تأخذ العرض كاملاً */
        table.table-stack td:not([data-label]) {
            justify-content: center;
            gap: .35rem;
        }

            table.table-stack td:not([data-label])::before {
                display: none;
            }

    /* إلغاء حدود الجدول المزدوجة داخل نمط البطاقات */
    table.table-stack,
    table.table-stack.table-bordered,
    table.table-stack.table-bordered > tbody,
    table.table-stack.table-bordered > tbody > tr {
        border: 0;
    }

        table.table-stack.table-bordered > tbody > tr {
            border: 1px solid #e5e7eb;
        }

    /* قيمة الخلية: تُحاذى لجهة النهاية وتلتف عند الطول */
    table.table-stack td > * {
        text-align: start;
        min-width: 0;
        max-width: 100%;
    }

    /* صفّ المجاميع (tfoot) يظهر كبطاقة ملخّص */
    table.table-stack tfoot,
    table.table-stack tfoot tr,
    table.table-stack tfoot td {
        display: block;
        width: 100%;
    }

    table.table-stack tfoot tr {
        margin-top: -.25rem;
        margin-bottom: .75rem;
        border: 1px solid #dbeafe;
        border-radius: 12px;
        background: #f8fbff;
        font-weight: 700;
    }

    table.table-stack tfoot td {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        column-gap: .75rem;
        row-gap: .15rem;
        padding: .5rem .7rem;
        border: 0;
        border-bottom: 1px solid #eef2f7;
        overflow-wrap: anywhere;
    }

        table.table-stack tfoot td:last-child {
            border-bottom: 0;
        }

        table.table-stack tfoot td[data-label]::before {
            content: attr(data-label);
            font-weight: 700;
            color: #64748b;
            font-size: .8rem;
        }

    /* صف "لا توجد بيانات" (colspan) يبقى سطراً بسيطاً لا بطاقة */
    table.table-stack > tbody > tr:has(> td[colspan]) {
        border: 0;
        box-shadow: none;
        background: transparent;
        text-align: center;
    }
}

/* ---------------------------------------------------------------------
   6) أهداف اللمس + عناصر الإدخال على الشاشات الصغيرة
   --------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    .btn,
    .form-control,
    .form-select,
    .input-group-text,
    .page-link {
        min-height: var(--tap-min);
    }

    .btn-sm {
        min-height: 38px;
        padding-inline: .75rem;
    }

    /* منع تكبير iOS التلقائي عند التركيز على الحقول */
    .form-control,
    .form-select {
        font-size: 16px;
    }

    /* رؤوس الصفحات: تلتف بدل أن تتكدس */
    .page-header,
    .d-flex.justify-content-between.align-items-center {
        flex-wrap: wrap;
        gap: .5rem;
    }

    /* DataTables: أدوات التحكم تتوسّط وتلتف */
    .dataTables_wrapper .row > div {
        text-align: center !important;
        margin-bottom: .4rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
    }
}

/* ---------------------------------------------------------------------
   7) لمسات عامة
   --------------------------------------------------------------------- */
img {
    max-width: 100%;
    height: auto;
}

.container-fluid {
    padding-inline: clamp(.75rem, 3vw, 1.5rem);
}

/* بطاقة تسجيل الدخول لا تتجاوز عرض الشاشة */
.login-card {
    width: min(380px, 92vw) !important;
}

/* الرسوم البيانية لا تنفجر خارج البطاقة */
canvas {
    max-width: 100%;
}
