/* ==========================================================================
   theme.css — واجهة حديثة هادئة فوق Bootstrap 4 (RTL)
   • قائمة جانبية تنطوي + درج للموبايل
   • لوحة إحصائيات مرتبة
   • جداول بسكرول أفقي داخلي + رأس ثابت + تحكم بالأعمدة
   تُحمّل بعد كل ملفات CSS الأخرى. ما تغيّر أي منطق — الشكل فقط.
   ========================================================================== */

:root {
    /* ألوان هادئة: رمادي مزرق + أزرق مغبّر */
    --bg:            #f3f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --surface-3:     #eef2f8;
    --border:        #e4e9f2;
    --border-2:      #d3dbe8;

    --text:          #1e2a3a;
    --text-2:        #4b5a6e;
    --muted:         #7c8899;

    --brand:         #4a6fa5;   /* أزرق هادئ */
    --brand-600:     #3d5d8c;
    --brand-700:     #334d74;
    --brand-soft:    #eaf0f8;

    --teal:          #4b8b8c;
    --teal-soft:     #e7f1f1;
    --sage:          #55916f;
    --sage-soft:     #e8f2ec;
    --amber:         #b5843f;
    --amber-soft:    #f7f0e3;
    --clay:          #b3625c;
    --clay-soft:     #f8ebea;

    --sidebar-1:     #22304a;
    --sidebar-2:     #1a2539;

    --sidebar-w:      254px;
    --sidebar-mini:   76px;
    --topbar-h:       60px;

    --r-lg: 16px;
    --r:    12px;
    --r-sm: 9px;

    --sh-xs: 0 1px 2px rgba(23, 35, 55, .05);
    --sh-sm: 0 1px 3px rgba(23, 35, 55, .06), 0 1px 2px rgba(23, 35, 55, .04);
    --sh:    0 4px 14px rgba(23, 35, 55, .07);
    --sh-lg: 0 12px 32px rgba(23, 35, 55, .14);

    --ease: cubic-bezier(.4, 0, .2, 1);
    --fast: .16s;
    --mid:  .26s;

    --font: "Segoe UI", "Dubai", "Tajawal", Tahoma, "Traditional Arabic", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body, .body {
    background-color: var(--bg) !important;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    direction: rtl;
    margin: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--text); letter-spacing: -.1px; }
h4 { font-size: 1.1rem; }
h5 { font-size: .98rem; }

a { color: var(--brand); text-decoration: none; transition: color var(--fast) var(--ease); }
a:hover { color: var(--brand-700); text-decoration: none; }

::selection { background: var(--brand-soft); color: var(--brand-700); }

/* شريط تمرير رفيع وهادئ */
* { scrollbar-width: thin; scrollbar-color: #c3ccdb transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #c8d1de; border-radius: 20px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #a9b5c7; background-clip: content-box; border: 3px solid transparent; }

/* ==========================================================================
   1) هيكل الصفحة
   ========================================================================== */

.app-shell { display: flex; min-height: 100vh; }

/* ---------- القائمة الجانبية ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(170deg, var(--sidebar-1) 0%, var(--sidebar-2) 100%);
    color: #c9d3e3;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: width var(--mid) var(--ease), transform var(--mid) var(--ease);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    height: var(--topbar-h);
    padding: 0 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    flex: 0 0 auto;
    overflow: hidden;
}

.sidebar-logo {
    width: 36px; height: 36px; flex: 0 0 36px;
    border-radius: 10px;
    background: linear-gradient(140deg, #6d8fc4, var(--brand));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: .88rem;
    box-shadow: 0 4px 12px rgba(74, 111, 165, .35);
}

.sidebar-title { font-weight: 700; font-size: .98rem; color: #fff; white-space: nowrap; line-height: 1.25; }
.sidebar-sub   { font-size: .7rem; color: #8695b3; white-space: nowrap; letter-spacing: .2px; }

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 12px 12px 22px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
}

.sidebar-nav li { margin-bottom: 3px; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 13px;
    border-radius: var(--r-sm);
    color: #b7c3d8;
    font-weight: 600;
    font-size: .875rem;
    white-space: nowrap;
    position: relative;
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), padding var(--fast) var(--ease);
}

.sidebar-nav a::before {
    content: "";
    position: absolute;
    right: 0; top: 50%;
    width: 3px; height: 0;
    background: #7ea3d8;
    border-radius: 3px;
    transform: translateY(-50%);
    transition: height var(--mid) var(--ease);
}

.sidebar-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; padding-right: 17px; }
.sidebar-nav a:hover::before { height: 18px; }

.sidebar-nav a.active {
    background: linear-gradient(90deg, rgba(122, 158, 214, .22), rgba(122, 158, 214, .08));
    color: #fff;
}

.sidebar-nav a.active::before { height: 60%; background: #86aae0; }

.sidebar-nav svg {
    width: 19px; height: 19px; flex: 0 0 19px;
    stroke: currentColor; fill: none;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    opacity: .9;
}

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .07); flex: 0 0 auto; }
.sidebar-foot .btn { width: 100%; background: rgba(179, 98, 92, .18); border-color: transparent; color: #e7b7b3; }
.sidebar-foot .btn:hover { background: var(--clay); color: #fff; filter: none; }

/* الوضع المصغّر */
.is-mini .sidebar { width: var(--sidebar-mini); flex-basis: var(--sidebar-mini); }
.is-mini .sidebar .sidebar-title,
.is-mini .sidebar .sidebar-sub,
.is-mini .sidebar-nav a span,
.is-mini .sidebar-foot .btn span { display: none; }
.is-mini .sidebar-nav a { justify-content: center; padding: 12px 6px; }
.is-mini .sidebar-nav a:hover { padding-right: 6px; }
.is-mini .sidebar-brand { justify-content: center; padding: 0 8px; }
.is-mini .app-main { margin-right: var(--sidebar-mini); }

/* تلميح باسم الصفحة وقت الطيّ */
.is-mini .sidebar-nav a { position: relative; }
.is-mini .sidebar-nav a::after {
    content: attr(data-title);
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) scale(.9);
    background: var(--sidebar-2);
    color: #fff;
    padding: 5px 10px;
    border-radius: var(--r-sm);
    font-size: .78rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: var(--sh);
    transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.is-mini .sidebar-nav a:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* ---------- المحتوى ---------- */
.app-main {
    flex: 1 1 auto;
    min-width: 0;
    margin-right: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    transition: margin var(--mid) var(--ease);
}

.topbar {
    height: var(--topbar-h);
    background: rgba(255, 255, 255, .88);
    backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-toggle {
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text-2);
    width: 38px; height: 38px;
    border-radius: var(--r-sm);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex: 0 0 38px; padding: 0;
    transition: all var(--fast) var(--ease);
}

.topbar-toggle:hover { background: var(--brand-soft); border-color: #b9cbe4; color: var(--brand); }
.topbar-toggle:active { transform: scale(.94); }
.topbar-toggle svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

.topbar-title { font-weight: 700; font-size: .98rem; margin: 0; color: var(--text); }
.topbar-spacer { flex: 1 1 auto; }

.user-chip {
    display: flex; align-items: center; gap: 9px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 4px 13px 4px 4px;
    font-weight: 600; font-size: .83rem; color: var(--text-2);
    white-space: nowrap;
    transition: border-color var(--fast) var(--ease);
}

.user-chip:hover { border-color: var(--border-2); }

.user-chip .avatar {
    width: 29px; height: 29px;
    border-radius: 50%;
    background: linear-gradient(140deg, #6d8fc4, var(--brand));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700;
}

.topbar-logout {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--clay-soft);
    border: 1px solid #eed7d5;
    color: var(--clay) !important;
    border-radius: 50px;
    padding: .38rem .95rem;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all var(--fast) var(--ease);
}

.topbar-logout:hover { background: var(--clay); border-color: var(--clay); color: #fff !important; }
.topbar-logout svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.content { padding: 18px; flex: 1 1 auto; min-width: 0; }

.sidebar-scrim {
    position: fixed; inset: 0;
    background: rgba(20, 30, 48, .5);
    backdrop-filter: blur(2px);
    z-index: 1040;
    opacity: 0; visibility: hidden;
    transition: opacity var(--mid) var(--ease), visibility var(--mid) var(--ease);
}

/* ==========================================================================
   2) البطاقات ولوحة الإحصائيات
   ========================================================================== */

.main_part {
    margin: 0;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm) !important;
    animation: fade-in var(--mid) var(--ease) backwards;
}

.card { border: 1px solid var(--border); border-radius: var(--r); }

.card-header {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    border-radius: var(--r) var(--r) 0 0 !important;
    font-weight: 700;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin: 0 0 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px 18px;
    box-shadow: var(--sh-xs);
    position: relative;
    overflow: hidden;
    transition: transform var(--mid) var(--ease), box-shadow var(--mid) var(--ease), border-color var(--mid) var(--ease);
    animation: rise var(--mid) var(--ease) backwards;
}

.stat-card:nth-child(1) { animation-delay: .02s; }
.stat-card:nth-child(2) { animation-delay: .07s; }
.stat-card:nth-child(3) { animation-delay: .12s; }
.stat-card:nth-child(4) { animation-delay: .17s; }
.stat-card:nth-child(5) { animation-delay: .22s; }

.stat-card:hover { transform: translateY(-3px); box-shadow: var(--sh); border-color: var(--border-2); }

/* هالة لونية خفيفة بالزاوية بدل الشريط الحاد */
.stat-card::after {
    content: "";
    position: absolute;
    top: -42px; left: -42px;
    width: 110px; height: 110px;
    border-radius: 50%;
    background: var(--brand-soft);
    opacity: .75;
    transition: transform var(--mid) var(--ease);
}

.stat-card:hover::after { transform: scale(1.25); }

.stat-card > * { position: relative; z-index: 1; }

.stat-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 7px;
    line-height: 1.35;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.4px;
    line-height: 1.2;
    word-break: break-word;
}

.stat-card.is-info::after    { background: var(--teal-soft); }
.stat-card.is-success::after { background: var(--sage-soft); }
.stat-card.is-warning::after { background: var(--amber-soft); }
.stat-card.is-danger::after  { background: var(--clay-soft); }

.stat-card.is-info .stat-value    { color: var(--teal); }
.stat-card.is-success .stat-value { color: var(--sage); }
.stat-card.is-warning .stat-value { color: var(--amber); }
.stat-card.is-danger .stat-value  { color: var(--clay); }

/* ==========================================================================
   3) الأزرار
   ========================================================================== */

.btn {
    font-weight: 600;
    font-size: .855rem;
    border-radius: var(--r-sm);
    padding: .5rem 1.05rem;
    border-width: 1px;
    box-shadow: none;
    transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease),
                color var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--sh-sm); }
.btn:active { transform: translateY(0) scale(.985); box-shadow: none; }
.btn:focus { box-shadow: 0 0 0 3px rgba(74, 111, 165, .2); }

.btn-primary   { background-color: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background-color: var(--brand-600); border-color: var(--brand-600); }
.btn-success   { background-color: var(--sage);  border-color: var(--sage); }
.btn-danger    { background-color: var(--clay);  border-color: var(--clay); }
.btn-info      { background-color: var(--teal);  border-color: var(--teal); color: #fff; }
.btn-warning   { background-color: var(--amber); border-color: var(--amber); color: #fff; }
.btn-secondary { background-color: var(--surface); border-color: var(--border-2); color: var(--text-2); }
.btn-secondary:hover { background-color: var(--surface-3); border-color: #c2cddd; color: var(--text); }

/* شريط أزرار الصفحة — يبنيه ui.js حول كل مجموعة أزرار متجاورة.
   لازم نلغي قياسات col-* لأن الأزرار مكتوبة بـ col-sm-3/col-md-1 خارج .row
   فتطلع بعرض الصفحة كاملة. */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px;
}

center > .page-actions { justify-content: center; }

.page-actions > .btn {
    flex: 0 1 auto;
    width: auto !important;
    max-width: none !important;
    min-width: 0;
    margin: 0 !important;
    float: none !important;
    padding: .5rem 1.15rem;
}

/* زر رئيسي واحد لحاله يبقى بحجمه الطبيعي */
center > .btn, .card-body > .btn {
    width: auto !important;
    max-width: none !important;
    margin: 4px !important;
    display: inline-block;
    float: none !important;
}

/* ==========================================================================
   4) النماذج ولوحة البحث
   ========================================================================== */

.search_form {
    text-align: right;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px;
    margin: 0 auto 16px;
}

/* الفلاتر مكتوبة بالـ Views بأعمدة col-md-1/2/3 متفاوتة و<br> عشوائية،
   فتطلع مبعثرة. نخليها شبكة منتظمة بأعمدة متساوية. */
.search_form .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
    gap: 12px;
    margin: 0;
    align-items: end;
}

.search_form .form-row > [class*="col-"],
.search_form .form-group {
    flex: none !important;
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.search_form br { display: none; }          /* فواصل عشوائية تكسر المحاذاة */

.search_form strong,
.search_form label {
    display: block;
    font-size: .76rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* زر البحث يملأ خليّته ويحاذي أسفل الصف */
.search_form .btn { width: 100%; height: calc(1.6em + .74rem + 2px); padding: 0 1rem; }

/* مربّع "عرض الكل" يوقف بمحاذاة الحقول */
.search_form input[type=checkbox] {
    width: 20px; height: 20px;
    padding: 0;
    accent-color: var(--brand);
    vertical-align: middle;
}

.form-control {
    border: 1px solid var(--border-2);
    border-radius: var(--r-sm);
    font-size: .86rem;
    height: calc(1.6em + .74rem + 2px);
    padding: .36rem .68rem;
    color: var(--text);
    background-color: var(--surface);
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

.form-control:focus {
    border-color: #9db6d6;
    box-shadow: 0 0 0 3px rgba(74, 111, 165, .13);
}

.form-control::placeholder { color: #a9b3c1; }

input[type=checkbox].form-control { height: 22px; width: 22px; padding: 0; }

/* ==========================================================================
   5) الجداول — سكرول أفقي داخلي + رأس ثابت
   ========================================================================== */

/* الحاويات القديمة ما تقصّ القوائم بعد الآن */
.table_overflow, .zz, #showpaging { overflow: visible !important; width: 100%; }

/* الحاوية اللي يبنيها ui.js حول كل جدول */
.tbl-scroll {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: auto;
    max-height: 74vh;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    box-shadow: var(--sh-xs);
    overscroll-behavior-x: contain;
}

.tbl-scroll > .table { border: 0; border-radius: 0; margin: 0; box-shadow: none; }

/* ظل خفيف يبيّن انه بقى محتوى للجنب */
.tbl-scroll.has-overflow::after {
    content: "";
    position: sticky;
    left: 0; bottom: 0;
    display: block;
    height: 100%;
    width: 26px;
    margin-left: -26px;
    float: left;
    pointer-events: none;
    background: linear-gradient(to left, rgba(23, 35, 55, .07), transparent);
}

.table {
    width: 100% !important;
    max-width: 100%;
    margin-bottom: 0;
    background: var(--surface);
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    font-size: .83rem;
    color: var(--text-2);
    text-align: center;
}

/* الهدف: الجدول يدخل بعرض الصفحة بدون سكرول.
   النص ينكسر بدل ما يمدّد العمود، والسكرول بالحاوية يبقى كخطة بديلة
   للجداول اللي فعلاً ما تدخل. */
.table th, .table td {
    padding: 8px 7px;
    vertical-align: middle;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;   /* يكسر الكلمة الطويلة فقط، مو كل حرف */
    min-width: 76px;             /* يمنع انهيار العمود لعرض حرف واحد */
    line-height: 1.4;
}

.table thead th { min-width: 88px; }

/* أعمدة مربّع التحديد والترقيم ما تحتاج عرض */
.table th:first-child, .table td:first-child { min-width: 0; }

.table thead th, .head_table th, .head_table {
    background: var(--surface-3) !important;
    color: var(--text);
    font-size: .765rem;
    font-weight: 700;
    letter-spacing: .1px;
    border-bottom: 1px solid var(--border-2) !important;
    padding: 11px 12px;
    text-align: center;
}

/* رأس ثابت داخل حاوية السكرول */
.tbl-scroll .table thead th,
.table thead.data-sticky-header th,
.table thead.head_table th {
    position: sticky !important;   /* datatable.css تضع position:relative */
    top: 0;
    z-index: 5;
}

.table tbody tr { transition: background-color var(--fast) var(--ease); }
.table tbody tr:nth-child(even) { background-color: #fbfcfe; }
.table tbody tr:hover { background-color: var(--brand-soft) !important; }
.table tbody tr:last-child td { border-bottom: 0; }

.table td { font-weight: 500; }

/* الأرقام بمحاذاة موحدة */
.table td { font-variant-numeric: tabular-nums; }

/* كثافة مضغوطة */
.table.is-compact { font-size: .765rem; }
.table.is-compact th, .table.is-compact td { padding: 4px 4px; }
.table.is-compact thead th { font-size: .715rem; }

/* ملء الشاشة للجدول */
.tbl-scroll.is-full {
    position: fixed;
    inset: 12px;
    z-index: 1060;
    max-height: none;
    box-shadow: var(--sh-lg);
    animation: fade-in var(--fast) var(--ease) backwards;
}

/* ---------- شريط أدوات الجدول ---------- */
.tbl-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    margin: 4px 0 10px;
}

.tbl-toolbar .btn { padding: .34rem .8rem; font-size: .785rem; }
.tbl-toolbar .btn:hover { transform: none; }

/* التلميح يظهر بس اذا الجدول فعلاً أعرض من حاويته */
.tbl-hint { display: none; }

.tbl-toolbar.has-overflow .tbl-hint {
    font-size: .74rem;
    color: var(--muted);
    margin-inline-start: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.tbl-cols-menu { max-height: 330px; overflow-y: auto; padding: 7px 10px; min-width: 235px; }

.tbl-cols-menu label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-2);
    margin: 0;
    padding: 5px 7px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background-color var(--fast) var(--ease);
}

.tbl-cols-menu label:hover { background: var(--surface-3); color: var(--text); }
.tbl-cols-menu input { margin: 0; accent-color: var(--brand); width: 15px; height: 15px; }

/* ==========================================================================
   6) قوائم الإجراءات
   ========================================================================== */

/* الأزرار داخل خلايا الجدول: حبّات صغيرة مرتبة بدل كتل بعرض الخلية.
   بعض الـ Views تحط عدة أزرار بخلية وحدة، وبعضها بأعمدة منفصلة. */
.table td .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    max-width: none !important;
    margin: 2px !important;
    padding: .26rem .72rem !important;
    font-size: .765rem !important;
    font-weight: 600;
    border-radius: 50px;
    white-space: nowrap;
    box-shadow: none !important;
}

.table td .btn:hover { transform: none; filter: brightness(.94); }

/* بعض الـ Views تكتب الحالة كـ <td class="btn btn-success"> — ui.js يحوّلها
   خلية عادية + شارة، وهذي تنسيقات الشارة. */
.status-pill {
    display: inline-block;
    padding: .24rem .85rem;
    border-radius: 50px;
    font-weight: 700;
    font-size: .765rem;
    white-space: nowrap;
    background: var(--surface-3);
    color: var(--text-2);
}

.status-pill.is-success { background: var(--sage-soft);  color: var(--sage); }
.status-pill.is-danger  { background: var(--clay-soft);  color: var(--clay); }
.status-pill.is-warning { background: var(--amber-soft); color: var(--amber); }
.status-pill.is-info    { background: var(--brand-soft); color: var(--brand-700); }

/* عمود الإجراءات ما ينكسر */
.table td.is-actions, .table th.is-actions { white-space: nowrap; }

td .dropdown-toggle,
td a.nav-link.dropdown-toggle,
td button.dots {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    background: var(--surface) !important;
    color: var(--brand) !important;
    border: 1px solid var(--border-2);
    font-weight: 600;
    font-size: .78rem;
    padding: .28rem .7rem !important;
    border-radius: var(--r-sm);
    white-space: nowrap;
    transition: all var(--fast) var(--ease);
}

td .dropdown-toggle:hover,
td button.dots:hover {
    background: var(--brand) !important;
    border-color: var(--brand);
    color: #fff !important;
}

.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-lg);
    padding: 7px;
    font-size: .84rem;
    min-width: 200px;
    z-index: 2000;
    animation: menu-in var(--fast) var(--ease) both;
}

/* توحيد العناصر وإلغاء الخلفيات الصارخة المكتوبة inline */
.dropdown-menu .dropdown-item {
    background-color: transparent !important;
    color: var(--text-2) !important;
    border-radius: var(--r-sm);
    padding: .48rem .7rem !important;
    margin-bottom: 1px !important;
    text-align: right !important;
    font-weight: 600;
    border: none;
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), padding var(--fast) var(--ease);
}

.dropdown-menu .dropdown-item:hover,
.dropdown-menu .dropdown-item:focus {
    background-color: var(--brand-soft) !important;
    color: var(--brand-700) !important;
    padding-right: .95rem !important;
}

/* القائمة المفتوحة تُثبّت بالنسبة للشاشة (js) حتى لا يقصّها الجدول.
   Popper يحدد مكانها بـ transform، ولازم نلغيه وإلا تطير بعيد عن الزر. */
.dropdown-menu.dd-escape {
    position: fixed !important;
    margin: 0 !important;
    transform: none !important;
    left: auto !important;
    bottom: auto !important;
}

/* ==========================================================================
   7) DataTables وعناصر متفرقة
   ========================================================================== */

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { font-size: .82rem; color: var(--muted); padding: 6px 0; }

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border-2);
    border-radius: var(--r-sm);
    padding: 3px 8px;
    margin: 0 6px;
    color: var(--text);
}

.pagination { justify-content: center; flex-wrap: wrap; margin-top: 10px; }

.page-link {
    color: var(--brand);
    border-color: var(--border);
    font-size: .84rem;
    padding: .4rem .75rem;
    transition: all var(--fast) var(--ease);
}

.page-link:hover { background: var(--brand-soft); border-color: var(--border-2); }
.page-item.active .page-link { background-color: var(--brand); border-color: var(--brand); }

.alert { border-radius: var(--r); border: 1px solid var(--border); font-size: .88rem; }

#myBtnTop, #scrollButtonUp, #scrollButtonDown {
    background-color: var(--brand) !important;
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 10px 18px;
    font-size: .8rem;
    font-weight: 600;
    box-shadow: var(--sh);
    z-index: 1010;
    transition: all var(--fast) var(--ease);
}

#myBtnTop:hover, #scrollButtonUp:hover, #scrollButtonDown:hover {
    background-color: var(--brand-600) !important;
    transform: translateY(-2px);
}

/* ==========================================================================
   7.3) كارت المنتج بشاشات البيع (يتكرر بكل الفواتير)
   ========================================================================== */

.producr_card1 {
    width: 310px;
    max-width: 100%;
    margin: 0 !important;
    text-align: right;
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: var(--r) !important;
    box-shadow: var(--sh-xs);
    overflow: hidden;
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.producr_card1:hover { transform: translateY(-3px); box-shadow: var(--sh); border-color: #c9d6ea; }

/* رأس الكارت: اسم المنتج + مربّع التحديد */
.producr_card1 > .card-header:first-child {
    background: var(--surface-2) !important;
    border-bottom: 1px solid var(--border) !important;
    border-radius: 0 !important;
    padding: 11px 13px !important;
    gap: 8px;
}

.producr_card1 > .card-header:first-child h6 {
    margin: 0 !important;
    font-size: .88rem;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}

.producr_card1 .item-selector { accent-color: var(--brand); flex: 0 0 auto; cursor: pointer; }

/* جسم الكارت — كان cornflowerblue بـ inline style */
.producr_card1 .card-body {
    background: var(--surface) !important;
    padding: 4px 13px !important;
}

/* كل سطر معلومة يصير صفّ (العنوان يمين والقيمة يسار) — ui.js يقسمها */
.producr_card1 .card-text {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 !important;
    padding: 7px 0 !important;
    border-bottom: 1px dashed var(--border);
    font-size: .8rem;
    color: var(--muted);
    background: transparent !important;
    line-height: 1.4;
}

.producr_card1 .card-text:last-of-type { border-bottom: 0; }

.producr_card1 .pc-k { font-weight: 600; color: var(--muted); }

.producr_card1 .pc-v {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    text-align: left;
    white-space: nowrap;
}

/* أسطر التسعير كانت خلفية سوداء/حمراء inline */
.producr_card1 .card-text[style*="black"],
.producr_card1 .card-text.pc-hi {
    background: var(--brand-soft) !important;
    color: var(--brand-700) !important;
    border-radius: var(--r-sm);
    padding: 7px 10px !important;
    margin: 3px 0 !important;
    border-bottom: 0;
}

.producr_card1 .card-text[style*="black"] .pc-k,
.producr_card1 .card-text.pc-hi .pc-k { color: var(--brand-600); }
.producr_card1 .card-text[style*="black"] .pc-v,
.producr_card1 .card-text.pc-hi .pc-v { color: var(--brand-700); }

.producr_card1 .card-text[style*="red"],
.producr_card1 .card-text.pc-warn {
    background: var(--clay-soft) !important;
    color: var(--clay) !important;
    border-radius: var(--r-sm);
    padding: 7px 10px !important;
    margin: 3px 0 !important;
    border-bottom: 0;
}

.producr_card1 .card-text[style*="red"] .pc-k,
.producr_card1 .card-text.pc-warn .pc-k,
.producr_card1 .card-text[style*="red"] .pc-v,
.producr_card1 .card-text.pc-warn .pc-v { color: var(--clay); }

/* بقية الـ card-header داخل الكارت مستخدمة كصفوف إدخال */
.producr_card1 > .card-header:not(:first-child) {
    background: transparent !important;
    border: 0 !important;
    border-top: 1px solid var(--border) !important;
    border-radius: 0 !important;
    padding: 9px 13px !important;
}

.producr_card1 > .card-header label {
    margin: 0 !important;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-2);
}

.producr_card1 .form-control { font-size: .84rem; }
.producr_card1 > .form-control { width: calc(100% - 26px); margin: 0 13px 10px; }

.producr_card1 input[type=checkbox].form-control {
    width: 20px; height: 20px;
    flex: 0 0 20px;
    accent-color: var(--brand);
}

/* زر الاضافة للسلة */
.producr_card1 > .btn {
    display: block;
    width: calc(100% - 26px);
    margin: 4px 13px 13px !important;
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    font-weight: 600;
}

.producr_card1 > .btn:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.producr_card1 > .btn:disabled { background: var(--surface-3); border-color: var(--border-2); color: var(--muted); }

/* شبكة الكروت: نلغي الهوامش العشوائية على الفورمات الحاوية */
.producr_card1-grid { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.producr_card1-grid > form { margin: 0 !important; }

/* ==========================================================================
   7.35) ملخّص السلة / الفاتورة
   ========================================================================== */

/* لوحة مجاميع الفاتورة — ui.js يلمّ الأسطر المتناثرة داخلها */
.sum-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
    gap: 9px;
    margin: 0 0 18px;
}

.sum-panel > .sum-row {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: auto !important;
    max-width: none !important;
    flex: none !important;
    padding: 10px 13px !important;
    margin: 0 !important;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: .83rem;
    font-weight: 600 !important;
    color: var(--text-2) !important;
}

.sum-panel .pc-k { font-weight: 600; color: var(--muted); }

.sum-panel .pc-v {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sum-row.is-danger  { background: var(--clay-soft);  border-color: #eed7d5; }
.sum-row.is-danger .pc-v  { color: var(--clay); }
.sum-row.is-info    { background: var(--brand-soft); border-color: #d8e3f3; }
.sum-row.is-info .pc-v    { color: var(--brand-700); }
.sum-row.is-success { background: var(--sage-soft);  border-color: #cfe4d8; }
.sum-row.is-success .pc-v { color: var(--sage); }

/* حقل مفرد ملقى بالفورم: عنوان + حقل بعرض الصفحة كاملة */
.stack-field { max-width: 430px; margin: 0 0 14px; flex: 1 1 260px; }

/* حقول متجاورة بصفّ واحد */
.field-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin: 0 0 16px;
    align-items: flex-end;
}

.field-row > .stack-field { margin: 0; }

.stack-field > strong {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 5px;
}

.stack-field > .form-control { width: 100%; }

/* حقول الحساب الملوّنة inline */
.search_form .form-control[style*="color: red"],
.search_form .form-control[style*="color:red"] { color: var(--clay) !important; }
.search_form .form-control[style*="color: blue"],
.search_form .form-control[style*="color:blue"] { color: var(--brand) !important; }
.search_form .form-control[style*="color: green"],
.search_form .form-control[style*="color:green"] { color: var(--sage) !important; }

/* داخل خلية الفلتر: مسافة بين كل زوج (عنوان + حقل) */
.search_form .form-group .form-control + strong { margin-top: 11px; }
.search_form .form-group .form-control + .form-control { margin-top: 8px; }

/* ==========================================================================
   7.4) لوحة التحكم
   ========================================================================== */

.dash-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.dash-title { font-size: 1.35rem; font-weight: 700; margin: 0 0 3px; }
.dash-sub { color: var(--muted); font-size: .86rem; margin: 0; }

.dash-date {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: .35rem .95rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.dash-section {
    font-size: 1rem;
    font-weight: 700;
    margin: 26px 0 13px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.dash-section::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--border);
}

/* ---------- الاختصارات ---------- */
.shortcut-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: 12px;
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 13px 14px;
    color: var(--text) !important;
    box-shadow: var(--sh-xs);
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.shortcut:hover {
    transform: translateY(-3px);
    box-shadow: var(--sh);
    border-color: #c9d6ea;
    text-decoration: none;
}

.shortcut-ico {
    width: 42px; height: 42px;
    flex: 0 0 42px;
    border-radius: 11px;
    background: var(--brand-soft);
    display: flex; align-items: center; justify-content: center;
    transition: transform var(--fast) var(--ease);
}

.shortcut:hover .shortcut-ico { transform: scale(1.07); }

.shortcut-ico svg {
    width: 21px; height: 21px;
    stroke: var(--brand); fill: none;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.shortcut-ico.is-sage  { background: var(--sage-soft); }
.shortcut-ico.is-sage svg  { stroke: var(--sage); }
.shortcut-ico.is-teal  { background: var(--teal-soft); }
.shortcut-ico.is-teal svg  { stroke: var(--teal); }
.shortcut-ico.is-amber { background: var(--amber-soft); }
.shortcut-ico.is-amber svg { stroke: var(--amber); }
.shortcut-ico.is-clay  { background: var(--clay-soft); }
.shortcut-ico.is-clay svg  { stroke: var(--clay); }

.shortcut-badge {
    margin-inline-start: auto;
    background: var(--clay);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    border-radius: 50px;
    padding: .12rem .5rem;
    min-width: 22px;
    text-align: center;
    flex: 0 0 auto;
}

.shortcut-txt { display: flex; flex-direction: column; min-width: 0; }
.shortcut-txt b { font-size: .89rem; font-weight: 700; line-height: 1.3; }
.shortcut-txt small { font-size: .74rem; color: var(--muted); }

/* ---------- ألواح القوائم ---------- */
.dash-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 14px;
    margin-top: 26px;
}

.dash-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-xs);
    overflow: hidden;
}

.dash-panel > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.dash-panel > header h4 { font-size: .9rem; font-weight: 700; margin: 0; }
.dash-panel > header a { font-size: .78rem; font-weight: 600; }

.dash-list { list-style: none; margin: 0; padding: 6px; }

.dash-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 11px;
    border-radius: var(--r-sm);
    transition: background-color var(--fast) var(--ease);
}

.dash-list li:hover { background: var(--surface-2); }

.dash-rank {
    width: 24px; height: 24px;
    flex: 0 0 24px;
    border-radius: 7px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: .74rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

.dash-list li:first-child .dash-rank { background: var(--amber-soft); color: var(--amber); }

.dash-list-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.dash-list-main b { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-list-main small { font-size: .73rem; color: var(--muted); }

.dash-list-val {
    font-weight: 700;
    font-size: .88rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    background: var(--surface-3);
    border-radius: 50px;
    padding: .2rem .7rem;
}

.dash-list-val.is-clay  { background: var(--clay-soft);  color: var(--clay); }
.dash-list-val.is-amber { background: var(--amber-soft); color: var(--amber); }
.dash-list-val.is-sage  { background: var(--sage-soft);  color: var(--sage); }

.dash-empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: .84rem; margin: 0; }

/* ---------- زر التحديث ---------- */
.dash-head-side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.dash-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: 50px;
    padding: .34rem .9rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-2) !important;
    transition: all var(--fast) var(--ease);
}

.dash-refresh:hover { background: var(--brand-soft); border-color: #b9cbe4; color: var(--brand-700) !important; }
.dash-refresh svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- هيكل التحميل ---------- */
.dash-panel.is-loading { padding: 16px; }

.dash-skel {
    height: 34px;
    border-radius: var(--r-sm);
    margin-bottom: 10px;
    background: linear-gradient(90deg, var(--surface-3) 25%, #f6f8fc 37%, var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: skel 1.3s ease infinite;
}

.dash-skel:last-child { margin-bottom: 0; width: 70%; }

@keyframes skel {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@media (max-width: 576px) {
    .dash-title { font-size: 1.12rem; }
    .shortcut-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .shortcut { flex-direction: column; text-align: center; gap: 8px; padding: 13px 9px; }
    .shortcut-txt { align-items: center; }
    .shortcut-txt small { display: none; }
    .dash-panels { grid-template-columns: 1fr; }
}

/* ==========================================================================
   7.5) صفحة تسجيل الدخول
   ========================================================================== */

body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background:
        radial-gradient(1100px 620px at 88% -12%, #e3ebf7 0%, transparent 60%),
        radial-gradient(900px 520px at 6% 108%, #e6eef0 0%, transparent 58%),
        var(--bg) !important;
}

.login-card {
    display: grid;
    grid-template-columns: 268px 1fr;
    width: 100%;
    max-width: 760px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    overflow: hidden;
    animation: rise var(--mid) var(--ease) backwards;
}

.login-brand {
    background: linear-gradient(170deg, var(--sidebar-1) 0%, var(--sidebar-2) 100%);
    color: #fff;
    padding: 38px 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
}

.login-brand::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(320px 200px at 50% 0%, rgba(134, 170, 224, .22), transparent 70%);
    pointer-events: none;
}

.login-logo {
    width: 62px; height: 62px;
    border-radius: 18px;
    background: linear-gradient(140deg, #6d8fc4, var(--brand));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; font-weight: 800; color: #fff;
    box-shadow: 0 10px 26px rgba(74, 111, 165, .4);
    margin-bottom: 16px;
}

.login-brand h1 { color: #fff; font-size: 1.45rem; font-weight: 700; margin: 0 0 4px; }
.login-brand p  { color: #9db0d0; font-size: .84rem; margin: 0; }

.login-brand-foot {
    position: absolute;
    bottom: 20px;
    font-size: .74rem;
    color: #7c8dad;
}

.login-body { padding: 42px 40px; }

.login-body h2 { font-size: 1.3rem; font-weight: 700; margin: 0 0 5px; }
.login-sub { color: var(--muted); font-size: .85rem; margin: 0 0 26px; }

.login-field { margin-bottom: 17px; }

.login-field > label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

.login-input { position: relative; display: flex; align-items: center; }

.login-input > svg {
    position: absolute;
    right: 13px;
    width: 18px; height: 18px;
    stroke: var(--muted); fill: none;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
    pointer-events: none;
    transition: stroke var(--fast) var(--ease);
}

.login-input .form-control {
    height: 46px;
    padding-right: 42px;
    padding-left: 42px;
    font-size: .92rem;
    background: var(--surface-2);
}

.login-input .form-control:focus { background: var(--surface); }
.login-input:focus-within > svg { stroke: var(--brand); }

.login-eye {
    position: absolute;
    left: 8px;
    width: 30px; height: 30px;
    border: 0; padding: 0;
    background: transparent;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background var(--fast) var(--ease);
}

.login-eye svg { width: 17px; height: 17px; stroke: var(--muted); fill: none; stroke-width: 1.7; }
.login-eye:hover { background: var(--surface-3); }
.login-eye.is-on svg { stroke: var(--brand); }

.login-error { display: block; color: var(--clay); font-size: .78rem; font-weight: 600; margin-top: 5px; }

.login-submit {
    width: 100%;
    height: 46px;
    margin-top: 8px;
    font-size: .95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-submit svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 640px) {
    .login-card { grid-template-columns: 1fr; max-width: 420px; }
    .login-brand { padding: 26px 20px 22px; }
    .login-logo { width: 52px; height: 52px; border-radius: 15px; margin-bottom: 11px; }
    .login-brand h1 { font-size: 1.2rem; }
    .login-brand-foot { display: none; }
    .login-body { padding: 26px 22px 30px; }
}

/* ==========================================================================
   7.6) توحيد الصفحات اللي عندها تنسيق خاص (المصاريف / انواع الدفع)
   ========================================================================== */

.p-wrap, .cardx {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--r-lg) !important;
    box-shadow: var(--sh-xs) !important;
}

.p-head { border-bottom: 1px solid var(--border) !important; }
.p-title { color: var(--text) !important; font-weight: 700 !important; }
.cardx-h { background: var(--surface-2) !important; border-bottom: 1px solid var(--border) !important; }
.hint { color: var(--muted) !important; }

.btnx {
    background: var(--surface) !important;
    border: 1px solid var(--border-2) !important;
    color: var(--text-2) !important;
    border-radius: var(--r-sm) !important;
    padding: .5rem 1.05rem !important;
    font-weight: 600 !important;
    font-size: .855rem !important;
    box-shadow: none !important;
    transition: all var(--fast) var(--ease);
}

.btnx:hover { background: var(--surface-3) !important; color: var(--text) !important; transform: translateY(-1px); }
.btnx.primary { background: var(--brand) !important; border-color: var(--brand) !important; color: #fff !important; }
.btnx.primary:hover { background: var(--brand-600) !important; }
.btnx.danger { background: var(--clay) !important; border-color: var(--clay) !important; color: #fff !important; }
.btnx.gray { background: var(--surface-3) !important; color: var(--text-2) !important; }

.btn-search {
    background: var(--brand) !important;
    border: 1px solid var(--brand) !important;
    color: #fff !important;
    border-radius: var(--r-sm) !important;
    font-weight: 600 !important;
    padding: .45rem 1.05rem !important;
}

.btn-search:hover { background: var(--brand-600) !important; }

.btn-clear {
    background: var(--surface) !important;
    border: 1px solid var(--border-2) !important;
    color: var(--text-2) !important;
    border-radius: var(--r-sm) !important;
    font-weight: 600 !important;
    padding: .45rem 1.05rem !important;
}

.badge-soft {
    background: var(--brand-soft) !important;
    color: var(--brand-700) !important;
    border: 1px solid #d8e3f3 !important;
    border-radius: 50px !important;
    font-weight: 600 !important;
    font-size: .8rem !important;
    padding: .32rem .85rem !important;
}

.toast-ok {
    background: var(--sage-soft) !important;
    color: #2f6b4c !important;
    border: 1px solid #cfe4d8 !important;
    border-radius: var(--r) !important;
    font-weight: 600 !important;
}

.searchbox {
    background: var(--surface-2) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--r) !important;
}

.table-scroll { border-radius: var(--r) !important; border-color: var(--border) !important; }

/* ---------- تهدئة الألوان الصارخة المكتوبة inline داخل الجداول ---------- */
.table td[style*="background-color:red"],
.table td[style*="background-color: red"] {
    background-color: var(--clay-soft) !important;
    color: var(--clay) !important;
    font-weight: 700;
}

.table td[style*="cornflowerblue"] {
    background-color: var(--brand-soft) !important;
    color: var(--brand-700) !important;
    font-weight: 700;
}

.table tr[style*="cornflowerblue"] { background-color: var(--brand-soft) !important; }
.table tr[style*="cornflowerblue"] td { color: var(--brand-700) !important; }

/* ==========================================================================
   8) الحركات
   ========================================================================== */

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes menu-in {
    from { opacity: 0; transform: translateY(-6px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-menu.dd-escape { animation: none; }   /* موقعها محسوب بـ js */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* ==========================================================================
   9) الشاشات الصغيرة
   ========================================================================== */

@media (max-width: 991px) {
    /* الدرج المغلق يقف خارج الشاشة، فنمنع السكرول الأفقي الناتج عنه */
    html { overflow-x: hidden; }

    .sidebar { transform: translateX(100%); width: 276px; flex-basis: 276px; }
    .app-main { margin-right: 0 !important; }
    .is-open .sidebar { transform: translateX(0); }
    .is-open .sidebar-scrim { opacity: 1; visibility: visible; }
    body.is-open { overflow: hidden; }

    /* الوضع المصغّر ما يشتغل بالموبايل */
    .is-mini .sidebar { width: 276px; flex-basis: 276px; }
    .is-mini .sidebar .sidebar-title,
    .is-mini .sidebar .sidebar-sub,
    .is-mini .sidebar-nav a span,
    .is-mini .sidebar-foot .btn span { display: inline; }
    .is-mini .sidebar-nav a { justify-content: flex-start; padding: 10px 13px; }
    .is-mini .sidebar-nav a::after { display: none; }
    .is-mini .sidebar-brand { justify-content: flex-start; padding: 0 18px; }

    .content { padding: 12px; }
    .main_part { padding: 14px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat-value { font-size: 1.22rem; }
    .tbl-scroll { max-height: 68vh; }

    /* بالشاشات الصغيرة ما ينفع نحشر الأعمدة — النص يبقى بسطر واحد
       والسكرول الأفقي داخل حاوية الجدول يتكفّل بالباقي. */
    .table { width: auto !important; min-width: 100%; }
    .table th, .table td { white-space: nowrap; overflow-wrap: normal; min-width: 0; }
    .table thead th { min-width: 0; }
    .form-row > [class*="col-"] { margin-bottom: 8px; }
}

@media (max-width: 576px) {
    .content { padding: 9px; }
    .main_part { padding: 12px; border-radius: var(--r); }
    .topbar { padding: 0 11px; gap: 9px; }
    .topbar-title { font-size: .88rem; }
    .user-chip { padding: 3px 10px 3px 3px; font-size: .76rem; }
    .user-chip .avatar { width: 25px; height: 25px; font-size: .72rem; }
    /* بالموبايل نخلي زر الخروج أيقونة فقط حتى ما يزحم الهدر */
    .topbar-logout span { display: none; }
    .topbar-logout { padding: .38rem .55rem; }

    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px 13px; }
    .stat-label { font-size: .71rem; margin-bottom: 4px; }
    .stat-value { font-size: 1.05rem; }

    .table { font-size: .78rem; }
    .table th, .table td { padding: 7px 9px; }
    .tbl-scroll { max-height: 62vh; }

    /* حقول البحث عمود كامل */
    .search_form .form-group[class*="col-"] { flex: 0 0 100%; max-width: 100%; }
    /* أزرار الصفحة بعرض كامل حتى تنضغط بسهولة */
    center > .btn, .card-body > .btn { display: block; width: 100%; margin: 5px 0 !important; }
    .tbl-toolbar .btn { flex: 1 1 auto; }
}

/* ==========================================================================
   10) الطباعة
   ========================================================================== */

@media print {
    body, .body { background: #fff !important; -webkit-print-color-adjust: exact; }
    .sidebar, .sidebar-scrim, .topbar, .search_form, .tbl-toolbar,
    #myBtnTop, #scrollButtonUp, #scrollButtonDown, .btn { display: none !important; }
    .app-main { margin: 0 !important; }
    .content { padding: 0; }
    .main_part { box-shadow: none !important; border: 0; margin: 0; padding: 0; animation: none; }
    .tbl-scroll { overflow: visible !important; max-height: none !important; border: 0; box-shadow: none; }
    .table { font-size: .7rem; }
    .table th, .table td { white-space: normal; }
    .table thead th { position: static !important; }
}
