/* ==========================================================================
   app-ui.css — نظام التصميم (Mobile-first) للمنصة
   يُحمَّل بعد Bootstrap 5.3 RTL ويعدّل عليه. ملف ثابت: لا يحتاج npm run build.
   المبادئ: الجوال أولاً · خصائص منطقية (inline-start/end) · هدف لمس ≥ 44px ·
   مناطق آمنة (notch) · وضع داكن · احترام prefers-reduced-motion
   ========================================================================== */

:root {
    --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", sans-serif;

    --ui-primary: #0a7d60;
    --ui-primary-hover: #086a52;
    --ui-primary-soft: #e3f4ee;
    --ui-primary-contrast: #ffffff;

    --ui-bg: #f3f5f7;
    --ui-surface: #ffffff;
    --ui-surface-2: #f8fafb;
    --ui-text: #17232c;
    --ui-muted: #5f7080;
    --ui-border: #e2e8ee;

    --ui-topbar: #0b2b24;
    --ui-topbar-text: #ffffff;
    --ui-topbar-muted: rgba(255, 255, 255, .72);

    --ui-chat-bg: #ece6dc;
    --ui-bubble-in: #ffffff;
    --ui-bubble-out: #d6f7cf;
    --ui-bubble-text: #111b21;

    --ui-radius: 14px;
    --ui-radius-sm: 10px;
    --ui-shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --ui-shadow: 0 6px 24px rgba(16, 24, 40, .10);

    --topbar-h: 56px;
    --bottomnav-h: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Bootstrap overrides */
    --bs-primary: #0a7d60;
    --bs-primary-rgb: 10, 125, 96;
    --bs-link-color: #0a7d60;
    --bs-link-color-rgb: 10, 125, 96;
    --bs-link-hover-color: #086a52;
    --bs-link-hover-color-rgb: 8, 106, 82;
    --bs-body-font-family: var(--font);
    --bs-body-bg: var(--ui-bg);
    --bs-body-color: var(--ui-text);
    --bs-border-color: var(--ui-border);
    --bs-border-radius: 10px;
    --bs-border-radius-lg: var(--ui-radius);
}

[data-bs-theme="dark"] {
    --ui-primary: #2bb892;
    --ui-primary-hover: #4cc9a8;
    --ui-primary-soft: #11332b;

    --ui-bg: #0d1418;
    --ui-surface: #151e24;
    --ui-surface-2: #1a252c;
    --ui-text: #e6edf1;
    --ui-muted: #94a6b3;
    --ui-border: #263540;

    --ui-topbar: #0a1a16;
    --ui-chat-bg: #0b141a;
    --ui-bubble-in: #202c33;
    --ui-bubble-out: #005c4b;
    --ui-bubble-text: #e9edef;

    --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --ui-shadow: 0 6px 24px rgba(0, 0, 0, .5);

    --bs-primary: #2bb892;
    --bs-primary-rgb: 43, 184, 146;
    --bs-link-color: #4cc9a8;
    --bs-link-color-rgb: 76, 201, 168;
    --bs-link-hover-color: #7ddcc2;
    --bs-body-bg: var(--ui-bg);
    --bs-body-color: var(--ui-text);
    --bs-border-color: var(--ui-border);
}

/* ───────────── أساسيات ───────────── */
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--ui-bg); color: var(--ui-text); }
h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: 0; }
h4 { font-size: 1.25rem; }
a { text-underline-offset: 3px; }
:focus-visible { outline: 3px solid rgba(10, 125, 96, .45); outline-offset: 2px; }
[data-bs-theme="dark"] :focus-visible { outline-color: rgba(43, 184, 146, .6); }
.i { width: 1.25rem; height: 1.25rem; flex: none; vertical-align: -.2em; }
.i-sm { width: 1rem; height: 1rem; }
.i-lg { width: 1.6rem; height: 1.6rem; }
.text-ltr { direction: ltr; unicode-bidi: plaintext; }
[dir="rtl"] .i-flip { transform: scaleX(-1); }

/* ───────────── Bootstrap: لمسة العلامة التجارية ───────────── */
.btn { font-weight: 500; border-radius: var(--ui-radius-sm); display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-sm { border-radius: 8px; }
.btn-primary {
    --bs-btn-bg: var(--ui-primary); --bs-btn-border-color: var(--ui-primary);
    --bs-btn-hover-bg: var(--ui-primary-hover); --bs-btn-hover-border-color: var(--ui-primary-hover);
    --bs-btn-active-bg: var(--ui-primary-hover); --bs-btn-active-border-color: var(--ui-primary-hover);
    --bs-btn-disabled-bg: var(--ui-primary); --bs-btn-disabled-border-color: var(--ui-primary);
    --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff;
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #04201a; --bs-btn-hover-color: #04201a; --bs-btn-active-color: #04201a; }
.btn-outline-primary {
    --bs-btn-color: var(--ui-primary); --bs-btn-border-color: var(--ui-primary);
    --bs-btn-hover-bg: var(--ui-primary); --bs-btn-hover-border-color: var(--ui-primary); --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--ui-primary); --bs-btn-active-border-color: var(--ui-primary); --bs-btn-active-color: #fff;
}
.form-control, .form-select { border-radius: var(--ui-radius-sm); border-color: var(--ui-border); background-color: var(--ui-surface); color: var(--ui-text); }
.form-control:focus, .form-select:focus { border-color: var(--ui-primary); box-shadow: 0 0 0 .2rem rgba(10, 125, 96, .18); background-color: var(--ui-surface); color: var(--ui-text); }
.form-control::placeholder { color: var(--ui-muted); opacity: .8; }
.card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow-sm); color: var(--ui-text); }
.alert { border-radius: var(--ui-radius-sm); }
.badge { font-weight: 500; }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link { background-color: var(--ui-primary); color: #fff; }
.list-group-item { background: var(--ui-surface); color: var(--ui-text); border-color: var(--ui-border); }
.table { --bs-table-bg: transparent; --bs-table-color: var(--ui-text); --bs-table-border-color: var(--ui-border); --bs-table-hover-bg: var(--ui-surface-2); }
.table > thead th { font-size: .8rem; font-weight: 600; color: var(--ui-muted); background: var(--ui-surface-2); white-space: nowrap; }

/* ───────────── القشرة (Shell) ───────────── */
body.app-shell {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    overflow: hidden; overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
}

.topbar {
    flex: none; display: flex; align-items: center; gap: .5rem;
    height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) max(.75rem, env(safe-area-inset-right)) 0 max(.75rem, env(safe-area-inset-left));
    background: var(--ui-topbar); color: var(--ui-topbar-text);
    z-index: 30;
}
.brand { display: flex; align-items: center; gap: .55rem; color: inherit; text-decoration: none; min-width: 0; }
.brand:hover { color: inherit; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--ui-primary); display: grid; place-items: center; flex: none; color: #fff; }
.brand-mark .i { width: 1.15rem; height: 1.15rem; }
.brand-name { font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }

.icon-btn {
    width: 44px; height: 44px; border: 0; background: transparent; color: inherit;
    border-radius: 12px; display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.icon-btn--plain { color: var(--ui-text); }
.icon-btn--plain:hover, .icon-btn--plain:active { background: var(--ui-surface-2); }

.topnav { display: flex; align-items: center; gap: .15rem; margin-inline-start: 1rem; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
    color: var(--ui-topbar-muted); text-decoration: none; padding: .45rem .8rem; border-radius: 10px;
    font-size: .92rem; white-space: nowrap; display: inline-flex; align-items: center; gap: .4rem;
}
.topnav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topnav a.active { color: #fff; background: rgba(255, 255, 255, .14); }
.topbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: .35rem; }
.user-chip { color: var(--ui-topbar-muted); font-size: .85rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn-outline-light { --bs-btn-border-color: rgba(255, 255, 255, .35); }

.app-main { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.banner { flex: none; margin: 0; border: 0; border-radius: 0; padding: .55rem 1rem; text-align: center; font-size: .85rem; }

.page { padding-top: 1rem; padding-bottom: calc(1.25rem + var(--safe-bottom)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h4 { margin: 0; }
.page-head .btn-group-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* شريط التنقل السفلي (جوال) */
.bottom-nav {
    flex: none; display: flex; background: var(--ui-surface); border-top: 1px solid var(--ui-border);
    height: calc(var(--bottomnav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); z-index: 30;
}
.bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--ui-muted); text-decoration: none; font-size: .7rem; font-weight: 500; background: none; border: 0; padding: 0; min-width: 0;
}
.bottom-nav .i { width: 1.45rem; height: 1.45rem; }
.bottom-nav a.active { color: var(--ui-primary); }
.bottom-nav a.active .tab-ico { background: var(--ui-primary-soft); }
.tab-ico { width: 52px; height: 28px; border-radius: 14px; display: grid; place-items: center; transition: background .15s; }
.tab-badge { position: absolute; top: -2px; inset-inline-end: 6px; min-width: 16px; height: 16px; border-radius: 8px; background: #dc3545; color: #fff; font-size: .62rem; display: grid; place-items: center; padding: 0 4px; }
/* داخل محادثة مفتوحة على الجوال: نخفي الشريط السفلي لنعطي الشاشة كاملة للمحادثة */
body:has(.inbox--chat-open) .bottom-nav { display: none; }
@media (min-width: 992px) { .bottom-nav { display: none; } }

/* القائمة الجانبية (Drawer) */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(8, 15, 20, .55); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; z-index: 1040; }
.drawer {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(86vw, 330px);
    background: var(--ui-surface); color: var(--ui-text); z-index: 1050; display: flex; flex-direction: column;
    padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
    transform: translateX(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
    box-shadow: var(--ui-shadow);
}
[dir="ltr"] .drawer { transform: translateX(-100%); }
.drawer-open .drawer { transform: none; }
.drawer-open .drawer-backdrop { opacity: 1; visibility: visible; }
.drawer-head { display: flex; align-items: center; gap: .6rem; padding: 1rem; border-bottom: 1px solid var(--ui-border); }
.drawer-head .who { min-width: 0; flex: 1; }
.drawer-head .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-head .who small { color: var(--ui-muted); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; font-size: 1rem; }
.drawer-nav { flex: 1; overflow-y: auto; padding: .5rem; }
.drawer-nav a {
    display: flex; align-items: center; gap: .85rem; padding: .8rem .9rem; border-radius: 12px; min-height: 48px;
    color: var(--ui-text); text-decoration: none; font-weight: 500;
}
.drawer-nav a .i { color: var(--ui-muted); }
.drawer-nav a:active, .drawer-nav a:hover { background: var(--ui-surface-2); }
.drawer-nav a.active { background: var(--ui-primary-soft); color: var(--ui-primary); }
.drawer-nav a.active .i { color: var(--ui-primary); }
.drawer-foot { padding: .75rem; border-top: 1px solid var(--ui-border); display: flex; gap: .5rem; }
.drawer-foot form { flex: 1; margin: 0; }
.drawer-foot .btn { width: 100%; }
body.drawer-open { overflow: hidden; }

/* ───────────── المحادثات (Inbox) ───────────── */
.inbox { display: flex; height: 100%; min-height: 0; background: var(--ui-surface); }
.inbox-list { width: 360px; flex: none; display: flex; flex-direction: column; min-height: 0; border-inline-end: 1px solid var(--ui-border); background: var(--ui-surface); }
.inbox-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; background: var(--ui-chat-bg); position: relative; }

.inbox-search { padding: .75rem .75rem .5rem; background: var(--ui-surface); }
.search-field { position: relative; }
.search-field .i { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: .85rem; color: var(--ui-muted); pointer-events: none; }
.search-field input { padding-inline-start: 2.5rem; height: 44px; border-radius: 22px; background: var(--ui-surface-2); border-color: transparent; font-size: 16px; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem .75rem .75rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; border-bottom: 1px solid var(--ui-border); background: var(--ui-surface); }
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none; border: 1px solid var(--ui-border); background: var(--ui-surface); color: var(--ui-muted);
    padding: .4rem .9rem; border-radius: 999px; font-size: .85rem; font-weight: 500; white-space: nowrap; min-height: 36px;
}
.chip.active { background: var(--ui-primary-soft); border-color: transparent; color: var(--ui-primary); font-weight: 600; }

.conv-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.conv {
    display: flex; align-items: center; gap: .75rem; width: 100%; text-align: start; border: 0; background: transparent;
    padding: .75rem 1rem; border-bottom: 1px solid var(--ui-border); color: inherit; min-height: 72px;
}
.conv:active { background: var(--ui-surface-2); }
.conv.is-selected { background: var(--ui-primary-soft); }
.conv .avatar { width: 48px; height: 48px; font-size: 1.1rem; }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: .72rem; color: var(--ui-muted); flex: none; }
.conv.has-unread .conv-time { color: var(--ui-primary); font-weight: 600; }
.conv-bottom { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: 2px; }
.conv-preview { color: var(--ui-muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv.has-unread .conv-preview { color: var(--ui-text); font-weight: 500; }
.unread { min-width: 22px; height: 22px; border-radius: 11px; background: var(--ui-primary); color: #fff; font-size: .74rem; font-weight: 600; display: grid; place-items: center; padding: 0 6px; flex: none; }
[data-bs-theme="dark"] .unread { color: #04201a; }
.conv-agent { font-size: .72rem; color: var(--ui-muted); }

.empty-state { display: grid; place-items: center; text-align: center; color: var(--ui-muted); padding: 2.5rem 1.5rem; gap: .5rem; }
.empty-state .i { width: 2.6rem; height: 2.6rem; opacity: .55; }
.empty-state p { margin: 0; }
.inbox-chat .empty-state { height: 100%; }

/* جوال: عرض واحد في كل مرة (قائمة ← محادثة ← رجوع)، زي واتساب */
@media (max-width: 767.98px) {
    .inbox-list { width: 100%; border-inline-end: 0; }
    .inbox-chat { display: none; }
    .inbox--chat-open .inbox-list { display: none; }
    .inbox--chat-open .inbox-chat { display: flex; }
}
/* أسماء/أرقام: (dir="auto" في الـ Blade) يمنع تبديل ترتيب الأرقام (+249 91 ...) داخل واجهة عربية */
.conv-name, .chat-head .who strong { text-align: right; }

/* رأس المحادثة */
.chat-head {
    flex: none; display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; min-height: 60px;
    background: var(--ui-surface); border-bottom: 1px solid var(--ui-border); position: relative; z-index: 5;
}
.chat-head .who { min-width: 0; flex: 1; }
.chat-head .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.25; }
.chat-head .who small { color: var(--ui-muted); display: block; }
.chat-head .avatar { width: 40px; height: 40px; }
.chat-actions { display: flex; align-items: center; gap: .5rem; }

/* قائمة منبثقة (جوال) */
.popmenu { display: none; }
.popmenu.is-open { display: flex; }
@media (max-width: 767.98px) {
    .chat-actions {
        position: absolute; top: calc(100% + 6px); inset-inline-end: .75rem; z-index: 20; display: none;
        flex-direction: column; align-items: stretch; gap: .5rem; min-width: 230px; padding: .75rem;
        background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow);
    }
    .chat-actions.is-open { display: flex; }
    .chat-actions .btn, .chat-actions .form-select { width: 100%; }
}
@media (min-width: 768px) { .chat-actions { display: flex !important; } .chat-menu-btn, .chat-back { display: none !important; } }

/* الرسائل */
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: .75rem .75rem 1rem; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.day-sep { align-self: center; margin: .6rem 0 .3rem; padding: .2rem .75rem; border-radius: 999px; background: rgba(255, 255, 255, .85); color: #54656f; font-size: .72rem; box-shadow: var(--ui-shadow-sm); }
[data-bs-theme="dark"] .day-sep { background: rgba(32, 44, 51, .95); color: #aebac1; }
.bubble { max-width: min(82%, 560px); padding: .45rem .7rem .3rem; border-radius: 14px; box-shadow: 0 1px 1px rgba(11, 20, 26, .13); color: var(--ui-bubble-text); overflow-wrap: anywhere; word-break: break-word; }
/* واجهة عربية (زي واتساب): رسائلنا على اليمين (بداية السطر) ورسائل العميل على اليسار */
.bubble--out { align-self: flex-start; background: var(--ui-bubble-out); border-start-start-radius: 4px; }
.bubble--in { align-self: flex-end; background: var(--ui-bubble-in); border-start-end-radius: 4px; }
.bubble .body { white-space: pre-wrap; line-height: 1.55; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: .3rem; font-size: .68rem; color: rgba(17, 27, 33, .55); margin-top: 1px; }
[data-bs-theme="dark"] .bubble .meta { color: rgba(233, 237, 239, .6); }
.bubble img, .bubble video { max-width: 100%; height: auto; border-radius: 10px; display: block; margin-bottom: .25rem; }
.bubble img { max-height: 300px; object-fit: cover; }
.bubble audio { width: min(260px, 100%); height: 40px; }
.bubble .tag { display: inline-block; font-size: .68rem; padding: .05rem .45rem; border-radius: 999px; background: rgba(0, 0, 0, .06); margin-bottom: .2rem; }
.ticks { letter-spacing: -3px; font-weight: 700; }
.ticks--read { color: #34b7f1; }
.ticks--fail { color: #dc3545; letter-spacing: 0; }
.bubble .file-link { display: flex; align-items: center; gap: .5rem; padding: .5rem; border-radius: 10px; background: rgba(0, 0, 0, .05); color: inherit; text-decoration: none; }

/* منطقة الكتابة */
.composer { flex: none; background: var(--ui-surface); border-top: 1px solid var(--ui-border); padding: .5rem .6rem calc(.5rem + var(--safe-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: .35rem; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 120px; min-height: 44px; border-radius: 22px; padding: .6rem 1rem; line-height: 1.45; font-size: 16px; background: var(--ui-surface-2); border-color: transparent; }
.composer textarea:focus { background: var(--ui-surface); }
.round-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; display: inline-grid; place-items: center; flex: none; cursor: pointer; background: transparent; color: var(--ui-muted); position: relative; }
.round-btn:hover, .round-btn:active { background: var(--ui-surface-2); }
.round-btn--send { background: var(--ui-primary); color: #fff; }
.round-btn--send:hover, .round-btn--send:active { background: var(--ui-primary-hover); color: #fff; }
[data-bs-theme="dark"] .round-btn--send { color: #04201a; }
.round-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.canned-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; }
.round-btn--ai { color: var(--ui-primary); }
.round-btn--ai:hover, .round-btn--ai:active { background: var(--ui-primary-soft); }
.round-btn[disabled] { opacity: .6; cursor: progress; }
.ai-meter { height: 8px; border-radius: 999px; background: var(--ui-surface-2); overflow: hidden; }
.ai-meter > span { display: block; height: 100%; background: var(--ui-primary); border-radius: inherit; transition: width .3s; }
.ai-meter.is-high > span { background: #dc3545; }
.ai-test-reply { white-space: pre-wrap; background: var(--ui-bubble-out); color: var(--ui-bubble-text); border-radius: var(--ui-radius); padding: .75rem 1rem; }
.attach-chip { display: inline-flex; align-items: center; gap: .4rem; margin: 0 .25rem .4rem; padding: .25rem .7rem; border-radius: 999px; background: var(--ui-primary-soft); color: var(--ui-primary); font-size: .8rem; max-width: 100%; }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-panel { max-height: 55dvh; overflow-y: auto; }
.composer-lock { display: flex; gap: .5rem; align-items: flex-start; background: #fff4d6; color: #6b4e00; border-radius: var(--ui-radius-sm); padding: .6rem .8rem; font-size: .85rem; margin-bottom: .6rem; }
[data-bs-theme="dark"] .composer-lock { background: #3a2f10; color: #f1d98c; }

/* ───────────── الجداول: بطاقات على الجوال ───────────── */
.table-card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); overflow: hidden; box-shadow: var(--ui-shadow-sm); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-card .table, .table-scroll .table { margin-bottom: 0; }
@media (max-width: 767.98px) {
    .table-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
    .table-stack, .table-stack tbody { display: block; width: 100%; }
    .table-stack thead { display: none; }
    .table-stack tr { display: block; background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); padding: .4rem 1rem; margin-bottom: .75rem; box-shadow: var(--ui-shadow-sm); }
    .table-stack td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem 0 !important; border: 0 !important; background: transparent !important; box-shadow: none !important; text-align: end; min-height: 40px; }
    .table-stack td + td { border-top: 1px dashed var(--ui-border) !important; }
    .table-stack td::before { content: attr(data-label); color: var(--ui-muted); font-size: .8rem; flex: none; text-align: start; }
    .table-stack td:not([data-label])::before, .table-stack td[data-label=""]::before { content: none; }
    .table-stack td[colspan] { display: block; text-align: center; }
    .table-stack td.cell-block { display: block; text-align: start; }
    .table-stack td.cell-block::before { display: block; margin-bottom: .2rem; }
    .table-stack td.cell-actions { justify-content: flex-end; flex-wrap: wrap; }
    .table-stack td.cell-actions:empty { display: none; }
    .table-stack .text-end { text-align: end !important; }
}

/* ───────────── بطاقات الإحصاء ───────────── */
.stat .text-muted { font-size: .78rem; }
.stat .fs-4 { font-weight: 600; line-height: 1.2; margin-top: .15rem; }
@media (max-width: 575.98px) { .stat .card-body { padding: .8rem .9rem; } .stat .fs-4 { font-size: 1.15rem !important; } }

/* ───────────── صفحات الدخول والتسجيل ───────────── */
.auth-wrap {
    min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
    padding: max(1rem, var(--safe-top)) 1rem max(1rem, var(--safe-bottom));
    background: radial-gradient(1200px 500px at 50% -10%, var(--ui-primary-soft), transparent 70%), var(--ui-bg);
}
.auth-card { width: 100%; max-width: 440px; border-radius: 20px; box-shadow: var(--ui-shadow); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin-bottom: 1.25rem; text-align: center; }
.auth-brand .brand-mark { width: 52px; height: 52px; border-radius: 15px; }
.auth-brand .brand-mark .i { width: 1.7rem; height: 1.7rem; }
.auth-brand h1 { font-size: 1.35rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--ui-muted); font-size: .9rem; }
.auth-card h3, .auth-card h4 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem !important; }
.auth-card .form-control { height: 48px; }

/* ───────────── لمس الجوال ───────────── */
@media (pointer: coarse), (max-width: 767.98px) {
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; padding-inline: .8rem; }
    .form-control, .form-select { min-height: 44px; font-size: 16px; }
    .form-check-input { width: 1.3em; height: 1.3em; }
    textarea.form-control { min-height: 0; }
}
@media (max-width: 767.98px) {
    .page { padding-inline: .9rem; }
    h4 { font-size: 1.15rem; }
    .page-head .btn { flex: 1 1 auto; }
    .w-100-mobile { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
@media print { .topbar, .bottom-nav, .drawer, .drawer-backdrop { display: none !important; } body.app-shell { height: auto; overflow: visible; } .app-main { overflow: visible; } }
