/* ==========================================================================
   منظومة الوصيد للحسابات — ملف التصميم الرئيسي
   الهوية: أسود #0A0A0A، أبيض، ذهبي #BFAE5F (+ درجاته)، رمادي للضرورة فقط،
   الأحمر #C0463B للتنبيهات فقط. الخط: Tajawal. العنصر الزخرفي: خطوط مائلة 25° بشفافية 4–7%.
   كل الألوان معرّفة كمتغيرات هنا؛ لتغيير الهوية عدّل هذا القسم فقط.
   ========================================================================== */

:root {
    --aw-black: #0A0A0A;
    --aw-black-2: #141414;
    --aw-black-3: #1d1d1d;
    --aw-white: #FFFFFF;
    --aw-cream: #F4F2EA;
    --aw-gold: #BFAE5F;
    --aw-gold-light: #D9CC8E;
    --aw-gold-dark: #8F8142;
    --aw-gray: #9A9A9A;
    --aw-alert: #C0463B;

    --aw-bg: #F7F6F1;
    --aw-surface: #FFFFFF;
    --aw-text: #0A0A0A;
    --aw-muted: #6b6b6b;
    --aw-border: #E6E2D4;
    --aw-row-hover: #FBF8EE;
    --aw-thead: #F4F2EA;

    --aw-radius: 10px;
    --aw-sidebar: 264px;
    --aw-stripes: repeating-linear-gradient(115deg, rgba(191, 174, 95, .06) 0 1px, transparent 1px 22px);

    --aw-font: 'Tajawal', 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Noto Sans Arabic', Arial, sans-serif;
    --aw-font-latin: 'Montserrat', 'Segoe UI', Tahoma, Arial, sans-serif;
    --bs-body-font-family: var(--aw-font);
    --bs-body-bg: var(--aw-bg);
    --bs-body-color: var(--aw-text);
    --bs-link-color-rgb: 143, 129, 66;
    --bs-link-hover-color-rgb: 10, 10, 10;
    --bs-border-color: var(--aw-border);
    --bs-primary-rgb: 10, 10, 10;
}

/* الوضع الليلي (اختياري): يُفعَّل من زر القمر ويُحفظ في المتصفح */
[data-bs-theme=dark] {
    --aw-bg: #0f0f0f;
    --aw-surface: #171717;
    --aw-text: #ECEAE2;
    --aw-muted: #a3a3a3;
    --aw-border: #2a2a2a;
    --aw-row-hover: #1f1d16;
    --aw-thead: #1d1c18;
    --bs-body-bg: var(--aw-bg);
    --bs-body-color: var(--aw-text);
    --bs-link-color-rgb: 217, 204, 142;
    --bs-link-hover-color-rgb: 255, 255, 255;
}

html, body { font-family: var(--aw-font); }
.skip-link { position: absolute; inset-inline-start: -999px; top: 0; z-index: 2000; background: var(--aw-gold); color: var(--aw-black); padding: .5rem 1rem; }
.skip-link:focus { inset-inline-start: 0; }
body { background: var(--aw-bg); color: var(--aw-text); font-size: .95rem; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; white-space: nowrap; }
td.n, th.n { text-align: end; }
.text-gold { color: var(--aw-gold-dark) !important; }
[data-bs-theme=dark] .text-gold { color: var(--aw-gold) !important; }
.text-alert { color: var(--aw-alert) !important; }
.text-muted, .text-secondary { color: var(--aw-muted) !important; }
.link-gold { color: var(--aw-gold-dark); text-decoration: none; font-weight: 600; }
.link-gold:hover { color: var(--aw-black); }
a { text-decoration: none; }

/* ---------- الهيكل ---------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 1.25rem 1.5rem 2rem; flex: 1; }
.footer { display: flex; justify-content: space-between; padding: .75rem 1.5rem; color: var(--aw-muted); font-size: .8rem; border-top: 1px solid var(--aw-border); }

/* ---------- الشريط الجانبي الأسود ---------- */
.sidebar {
    width: var(--aw-sidebar); flex-shrink: 0; background: var(--aw-black); color: #cfcfcf;
    background-image: var(--aw-stripes); position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; z-index: 1040;
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.25rem; color: var(--aw-gold); border-bottom: 1px solid rgba(191, 174, 95, .18); }
.brand:hover { color: var(--aw-gold-light); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--aw-font-latin); font-weight: 800; letter-spacing: .14em; color: #fff; font-size: 1.05rem; }
.brand-company { font-size: .78rem; color: var(--aw-gold-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.symbol { display: block; flex-shrink: 0; height: auto; }

.side-nav { padding: .5rem .6rem 1rem; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: #333 transparent; }
.side-nav .nav-section { font-size: .7rem; letter-spacing: .08em; color: var(--aw-gold); opacity: .85; padding: 1rem .75rem .35rem; font-weight: 700; }
.side-nav .nav-link {
    display: flex; align-items: center; gap: .65rem; color: #cfcfcf; padding: .5rem .75rem;
    border-radius: 8px; font-size: .9rem; transition: background .15s, color .15s; position: relative;
}
.side-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; color: #8d8d8d; }
.side-nav .nav-link:hover { background: var(--aw-black-3); color: #fff; }
.side-nav .nav-link.active { background: rgba(191, 174, 95, .14); color: var(--aw-gold-light); font-weight: 600; }
.side-nav .nav-link.active i { color: var(--aw-gold); }
.side-nav .nav-link.active::before { content: ""; position: absolute; inset-inline-start: -.6rem; top: 20%; bottom: 20%; width: 3px; background: var(--aw-gold); border-radius: 3px; }
.side-foot { padding: .75rem 1.25rem; border-top: 1px solid #222; font-size: .8rem; color: #9a9a9a; }
.side-foot strong { color: var(--aw-gold); }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sidebar { position: fixed; inset-inline-start: 0; transform: translateX(100%); transition: transform .2s; }
    .sidebar.show { transform: none !important; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1030; }
    .content { padding: 1rem; }
}

/* ---------- الشريط العلوي ---------- */
.topbar {
    display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; background: var(--aw-surface);
    border-bottom: 1px solid var(--aw-border); position: sticky; top: 0; z-index: 1020; min-height: 58px;
}
.topbar-title { font-weight: 700; color: var(--aw-muted); font-size: .9rem; display: none; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .35rem; }
.btn-icon { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 50%; border: 1px solid transparent; color: var(--aw-text); background: transparent; padding: 0; }
.btn-icon:hover { background: var(--aw-cream); border-color: var(--aw-border); }
[data-bs-theme=dark] .btn-icon:hover { background: #222; }
.lang-pill { font-weight: 800; font-size: .8rem; }
.btn-user { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--aw-border); border-radius: 999px; padding: .2rem .75rem .2rem .25rem; background: var(--aw-surface); color: var(--aw-text); }
[dir=rtl] .btn-user { padding: .2rem .25rem .2rem .75rem; }
.page-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.page-top .page-head { flex: 1 1 320px; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--aw-black); color: var(--aw-gold); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }

/* ---------- رأس الصفحة ---------- */
.page-head { margin-bottom: 1rem; }
.breadcrumb { font-size: .8rem; margin-bottom: .25rem; --bs-breadcrumb-divider-color: var(--aw-gray); }
.breadcrumb a { color: var(--aw-muted); }
.breadcrumb a:hover { color: var(--aw-gold-dark); }
.page-title { font-size: 1.45rem; font-weight: 800; margin: 0; display: flex; align-items: center; gap: .5rem; }
.page-sub { color: var(--aw-muted); margin: .25rem 0 0; font-size: .9rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; padding-top: 1.35rem; }

.btn-help {
    width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--aw-gold); color: var(--aw-gold-dark); background: transparent;
    font-weight: 800; font-size: .85rem; line-height: 1; display: inline-grid; place-items: center; padding: 0; cursor: pointer; transition: all .15s;
}
.btn-help:hover { background: var(--aw-gold); color: var(--aw-black); }
.btn-help.static { cursor: default; }
.btn-help.sm { width: 20px; height: 20px; font-size: .7rem; }

/* ---------- الأزرار ---------- */
.btn { border-radius: 8px; font-weight: 500; }
.btn-dark { --bs-btn-bg: var(--aw-black); --bs-btn-border-color: var(--aw-black); --bs-btn-hover-bg: #262626; --bs-btn-hover-border-color: #262626; }
.btn-gold {
    --bs-btn-color: var(--aw-black); --bs-btn-bg: var(--aw-gold); --bs-btn-border-color: var(--aw-gold);
    --bs-btn-hover-color: var(--aw-black); --bs-btn-hover-bg: var(--aw-gold-light); --bs-btn-hover-border-color: var(--aw-gold-light);
    --bs-btn-active-bg: var(--aw-gold-dark); --bs-btn-active-border-color: var(--aw-gold-dark); --bs-btn-disabled-bg: var(--aw-gold); --bs-btn-disabled-border-color: var(--aw-gold);
    font-weight: 700;
}
.btn-outline-gold { --bs-btn-color: var(--aw-gold-dark); --bs-btn-border-color: var(--aw-gold); --bs-btn-hover-bg: var(--aw-gold); --bs-btn-hover-color: var(--aw-black); --bs-btn-hover-border-color: var(--aw-gold); }
.btn-outline-dark { --bs-btn-color: var(--aw-text); --bs-btn-border-color: var(--aw-border); --bs-btn-hover-bg: var(--aw-black); --bs-btn-hover-border-color: var(--aw-black); }
.btn-outline-alert { --bs-btn-color: var(--aw-alert); --bs-btn-border-color: rgba(192, 70, 59, .4); --bs-btn-hover-bg: var(--aw-alert); --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: var(--aw-alert); }
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after { content: ""; display: inline-block; width: .9em; height: .9em; margin-inline-start: .4rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: aw-spin .7s linear infinite; vertical-align: -2px; }
@keyframes aw-spin { to { transform: rotate(360deg); } }

/* ---------- البطاقات ---------- */
.card-a { background: var(--aw-surface); border: 1px solid var(--aw-border); border-radius: var(--aw-radius); margin-bottom: 1rem; }
.card-a > .card-h { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--aw-border); }
.card-a > .card-h h2, .card-a > .card-h h3 { font-size: 1rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: .5rem; }
.card-a > .card-h h2 i, .card-a > .card-h h3 i { color: var(--aw-gold-dark); }
.card-a > .card-b { padding: 1.1rem; }
.card-a > .card-b.p-0 { padding: 0; }
.card-a > .card-f { padding: .75rem 1.1rem; border-top: 1px solid var(--aw-border); display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* بطاقة مؤشر (KPI) */
.kpi { position: relative; overflow: hidden; background: var(--aw-surface); border: 1px solid var(--aw-border); border-radius: var(--aw-radius); padding: 1rem 1.1rem; height: 100%; }
.kpi .kpi-label { color: var(--aw-muted); font-size: .82rem; display: flex; gap: .4rem; align-items: center; }
.kpi .kpi-label i { color: var(--aw-gold-dark); }
.kpi .kpi-value { font-size: 1.45rem; font-weight: 800; margin-top: .3rem; }
.kpi .kpi-sub { font-size: .78rem; color: var(--aw-muted); }
.kpi.dark { background: var(--aw-black); background-image: var(--aw-stripes); color: #fff; border-color: var(--aw-black); }
.kpi.dark .kpi-label { color: var(--aw-gold-light); }
.kpi.dark .kpi-label i { color: var(--aw-gold); }
.kpi.dark .kpi-sub { color: #aaa; }

/* ---------- الجداول ---------- */
.table-a { --bs-table-bg: transparent; --bs-table-hover-bg: var(--aw-row-hover); margin: 0; font-size: .88rem; }
.table-a > thead th { background: var(--aw-thead); color: var(--aw-text); font-weight: 700; font-size: .8rem; border-bottom: 2px solid var(--aw-gold); white-space: nowrap; padding: .6rem .7rem; position: sticky; top: 0; z-index: 1; }
.table-a > tbody td { padding: .55rem .7rem; vertical-align: middle; border-color: var(--aw-border); }
.table-a > tfoot td, .table-a > tfoot th { font-weight: 800; background: var(--aw-thead); border-top: 2px solid var(--aw-black); padding: .6rem .7rem; }
[data-bs-theme=dark] .table-a > tfoot td, [data-bs-theme=dark] .table-a > tfoot th { border-top-color: var(--aw-gold); }
.table-a tr.row-group td { font-weight: 700; background: rgba(191, 174, 95, .06); }
.table-a tr.row-sub td { color: var(--aw-muted); }
.table-a th[data-sort] { cursor: pointer; user-select: none; }
.table-a th[data-sort]::after { content: "⇅"; opacity: .35; margin-inline-start: .3rem; font-size: .75em; }
.table-a th[data-dir=asc]::after { content: "↑"; opacity: 1; }
.table-a th[data-dir=desc]::after { content: "↓"; opacity: 1; }
.table-wrap { overflow: auto; max-height: 70vh; }
.code { font-family: var(--aw-font-latin); font-weight: 700; font-size: .82rem; direction: ltr; unicode-bidi: embed; }
.row-actions { white-space: nowrap; text-align: end; }
.row-actions .btn { padding: .15rem .45rem; font-size: .8rem; }

/* الشارات */
.badge-a { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; line-height: 1.3; white-space: nowrap; border: 1px solid transparent; }
.b-gold { background: rgba(191, 174, 95, .18); color: var(--aw-gold-dark); border-color: rgba(191, 174, 95, .5); }
.b-dark { background: var(--aw-black); color: var(--aw-gold-light); }
.b-outline { background: transparent; color: var(--aw-text); border-color: var(--aw-gray); border-style: dashed; }
.b-muted { background: #ececec; color: #666; }
.b-alert { background: rgba(192, 70, 59, .1); color: var(--aw-alert); border-color: rgba(192, 70, 59, .35); }
[data-bs-theme=dark] .b-gold { color: var(--aw-gold-light); }
[data-bs-theme=dark] .b-dark { background: #000; border-color: var(--aw-gold-dark); }
[data-bs-theme=dark] .b-muted { background: #2a2a2a; color: #aaa; }
.side { font-size: .7rem; font-weight: 700; padding: 0 .3rem; border-radius: 4px; }
.side-dr { color: var(--aw-black); background: rgba(191, 174, 95, .25); }
.side-cr { color: var(--aw-gold-dark); border: 1px solid rgba(191, 174, 95, .5); }
[data-bs-theme=dark] .side-dr { color: var(--aw-gold-light); }

/* ---------- النماذج ---------- */
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.form-control, .form-select { border-radius: 8px; border-color: var(--aw-border); background-color: var(--aw-surface); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--aw-gold); box-shadow: 0 0 0 .2rem rgba(191, 174, 95, .25); }
.form-check-input:checked { background-color: var(--aw-black); border-color: var(--aw-black); }
[data-bs-theme=dark] .form-check-input:checked { background-color: var(--aw-gold); border-color: var(--aw-gold); }
.form-text { color: var(--aw-muted); font-size: .78rem; }
.field-validation-error, .text-danger { color: var(--aw-alert) !important; font-size: .8rem; }
.input-validation-error { border-color: var(--aw-alert) !important; }
.req::after { content: " *"; color: var(--aw-alert); }
.form-section { font-weight: 700; color: var(--aw-gold-dark); border-bottom: 1px dashed var(--aw-border); padding-bottom: .35rem; margin: 1.2rem 0 .8rem; font-size: .9rem; }
.form-section:first-child { margin-top: 0; }
input[type=number].amount { text-align: end; direction: ltr; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filters .form-control, .filters .form-select { min-width: 140px; }
.filters .f-wide { min-width: 240px; }
.filters label { font-size: .75rem; color: var(--aw-muted); margin-bottom: .15rem; display: block; }

.alert-a { background: rgba(192, 70, 59, .07); border: 1px solid rgba(192, 70, 59, .3); color: var(--aw-alert); border-radius: var(--aw-radius); display: flex; gap: .6rem; }
.note { background: rgba(191, 174, 95, .1); border: 1px solid rgba(191, 174, 95, .4); border-radius: var(--aw-radius); padding: .7rem .9rem; font-size: .87rem; display: flex; gap: .6rem; align-items: flex-start; }
.note > i { color: var(--aw-gold-dark); font-size: 1.1rem; }
.note.dark { background: var(--aw-black); color: #ddd; border-color: var(--aw-black); background-image: var(--aw-stripes); }
.note.dark > i { color: var(--aw-gold); }
.note.alert-note { background: rgba(192, 70, 59, .07); border-color: rgba(192, 70, 59, .3); }
.note.alert-note > i { color: var(--aw-alert); }

/* حقول العرض في صفحات التفاصيل */
.field { display: flex; flex-direction: column; padding: .5rem 0; border-bottom: 1px dashed var(--aw-border); }
.field-label { color: var(--aw-muted); font-size: .75rem; }
.field-value { font-weight: 600; }

/* ---------- قائمة الاختيار القابلة للبحث (Combo) — بديل خفيف بدون مكتبات خارجية ---------- */
.combo { position: relative; }
.combo > select { display: none; }
.combo-input { cursor: text; }
.combo-input.form-control-sm { min-height: 31px; }
.combo-list { position: absolute; inset-inline: 0; top: calc(100% + 2px); z-index: 1065; max-height: 280px; overflow-y: auto; background: var(--aw-surface);
    border: 1px solid var(--aw-border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); padding: .25rem; display: none; min-width: 220px; }
.combo.open .combo-list { display: block; }
.combo-item { padding: .35rem .55rem; border-radius: 6px; cursor: pointer; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-item:hover, .combo-item.active { background: rgba(191, 174, 95, .18); }
.combo-item.selected { font-weight: 700; }
.combo-empty { padding: .45rem .6rem; color: var(--aw-muted); font-size: .82rem; }

/* ---------- الإشعارات ---------- */
.toast { border: 0; border-radius: var(--aw-radius); box-shadow: 0 10px 30px rgba(0, 0, 0, .2); min-width: 320px; }
.toast-ok { background: var(--aw-black); color: #fff; border-inline-start: 4px solid var(--aw-gold); }
.toast-ok i { color: var(--aw-gold); }
.toast-err { background: #fff; color: var(--aw-alert); border-inline-start: 4px solid var(--aw-alert); }
.toast-ok .btn-close { filter: invert(1); }
.modal-content { border-radius: 14px; border: 0; }

/* ---------- لوحة التحكم ---------- */
.bars { display: flex; align-items: flex-end; gap: .6rem; height: 190px; padding-top: 1rem; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .3rem; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .bar { width: 42%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar.rev { background: var(--aw-gold); }
.bars .bar.exp { background: var(--aw-black); }
[data-bs-theme=dark] .bars .bar.exp { background: #555; }
.bars .bar-label { font-size: .7rem; color: var(--aw-muted); white-space: nowrap; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--aw-muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: .35rem; vertical-align: -1px; }
.legend .l-rev::before { background: var(--aw-gold); }
.legend .l-exp::before { background: var(--aw-black); }
.progress-a { height: 6px; background: var(--aw-cream); border-radius: 4px; overflow: hidden; }
.progress-a > div { height: 100%; background: var(--aw-gold); }
[data-bs-theme=dark] .progress-a { background: #2a2a2a; }

.welcome-hero { background: var(--aw-black); background-image: var(--aw-stripes); color: #fff; border-radius: 14px; padding: 2rem; display: flex; gap: 1.5rem; align-items: center; color: var(--aw-gold); }
.welcome-hero h2 { color: #fff; font-weight: 800; }
.welcome-hero p { color: #ccc; margin: 0; }
.quick-links a { display: flex; gap: .75rem; align-items: center; padding: .9rem 1rem; border: 1px solid var(--aw-border); border-radius: var(--aw-radius); background: var(--aw-surface); color: var(--aw-text); height: 100%; }
.quick-links a:hover { border-color: var(--aw-gold); background: var(--aw-row-hover); }
.quick-links i { font-size: 1.4rem; color: var(--aw-gold-dark); }

/* ---------- شجرة الحسابات ---------- */
.tree-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .tree-layout { grid-template-columns: 1fr; } }
.tree-table td { padding-top: .35rem !important; padding-bottom: .35rem !important; }
.tree-row { cursor: pointer; }
.tree-row.selected td { background: rgba(191, 174, 95, .16) !important; }
.tree-name { display: flex; align-items: center; gap: .35rem; }
.tree-toggle { width: 20px; height: 20px; border: 0; background: transparent; color: var(--aw-muted); padding: 0; display: inline-grid; place-items: center; border-radius: 4px; flex-shrink: 0; transition: transform .15s; }
.tree-toggle:hover { background: var(--aw-cream); color: var(--aw-text); }
[dir=rtl] .tree-row.collapsed .tree-toggle { transform: rotate(90deg); }
.tree-spacer { width: 20px; flex-shrink: 0; }
.tree-row[data-level="1"] td { font-weight: 800; }
.tree-row[data-level="2"] td { font-weight: 700; }
.tree-row.inactive td { opacity: .5; }
.tree-icon { color: var(--aw-gold-dark); }
.details-panel { position: sticky; top: 74px; }
.details-panel .path { font-size: .78rem; color: var(--aw-muted); }

/* ---------- محرر القيد ---------- */
.lines-table td { padding: .3rem !important; vertical-align: top !important; }
.lines-table .line-no { color: var(--aw-muted); font-weight: 700; text-align: center; padding-top: .55rem !important; width: 34px; }
.lines-table input.form-control-sm, .lines-table select.form-select-sm { font-size: .85rem; }
.lines-table .col-acc { min-width: 260px; }
.lines-table .col-cc { min-width: 170px; }
.lines-table .col-cur { min-width: 92px; width: 92px; }
.lines-table .col-rate { min-width: 105px; width: 110px; }
.lines-table .col-amt { min-width: 120px; width: 130px; }
.lines-table .col-base { min-width: 115px; width: 120px; color: var(--aw-muted); font-size: .82rem; text-align: end; padding-top: .55rem !important; }
.lines-table .cc-required { color: var(--aw-alert); font-size: .72rem; }
.totals-bar { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; justify-content: flex-end; padding: .75rem 1.1rem; background: var(--aw-black); background-image: var(--aw-stripes); color: #fff; border-radius: 0 0 var(--aw-radius) var(--aw-radius); }
.totals-bar .t-label { color: var(--aw-gold-light); font-size: .78rem; display: block; }
.totals-bar .t-value { font-weight: 800; font-size: 1.1rem; }
.diff-ok { color: var(--aw-gold); }
.diff-bad { color: #ff8a80; }
.fx-hint { font-size: .75rem; color: var(--aw-muted); }
.entry-number { font-family: var(--aw-font-latin); font-weight: 800; letter-spacing: .03em; direction: ltr; unicode-bidi: embed; }

/* ---------- القوائم المالية ---------- */
.statement { max-width: 980px; }
.statement .st-section td { font-weight: 800; background: rgba(191, 174, 95, .08); }
.statement .st-total td { font-weight: 800; border-top: 1.5px solid var(--aw-text); }
.statement .st-grand td { font-weight: 800; font-size: 1rem; background: var(--aw-black); color: #fff; }
.statement .st-grand td.n { color: var(--aw-gold-light); }
.statement .lvl-2 td:first-child { padding-inline-start: 1.6rem; }
.statement .lvl-3 td:first-child { padding-inline-start: 2.6rem; }
.statement .lvl-4 td:first-child { padding-inline-start: 3.6rem; }
.statement .lvl-5 td:first-child { padding-inline-start: 4.6rem; }
.reports-grid a { display: block; padding: 1.1rem; border: 1px solid var(--aw-border); border-radius: var(--aw-radius); background: var(--aw-surface); color: var(--aw-text); height: 100%; }
.reports-grid a:hover { border-color: var(--aw-gold); box-shadow: 0 6px 20px rgba(191, 174, 95, .15); }
.reports-grid i { font-size: 1.6rem; color: var(--aw-gold-dark); }
.reports-grid h3 { font-size: 1rem; font-weight: 800; margin: .5rem 0 .25rem; }
.reports-grid p { font-size: .82rem; color: var(--aw-muted); margin: 0; }

/* ---------- الصلاحيات ---------- */
.perm-group { border: 1px solid var(--aw-border); border-radius: var(--aw-radius); padding: .75rem 1rem; height: 100%; background: var(--aw-surface); }
.perm-group h3 { font-size: .92rem; font-weight: 800; display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.perm-group .form-check { margin-bottom: .2rem; font-size: .87rem; }

/* ---------- المساعدة ---------- */
.help-panel { width: 460px !important; max-width: 92vw; }
.help-panel .offcanvas-header { background: var(--aw-black); color: #fff; background-image: var(--aw-stripes); }
.help-panel .offcanvas-header .btn-close { filter: invert(1); }
.help-panel .btn-help { border-color: var(--aw-gold); color: var(--aw-gold); }
.help-content { line-height: 1.85; font-size: .93rem; }
.help-content h2 { font-size: 1.1rem; font-weight: 800; margin-top: 1.6rem; padding-bottom: .3rem; border-bottom: 2px solid var(--aw-gold); display: inline-block; }
.help-content h3 { font-size: .98rem; font-weight: 800; margin-top: 1.2rem; }
.help-content table { width: 100%; font-size: .85rem; margin: .75rem 0; border-collapse: collapse; }
.help-content th, .help-content td { border: 1px solid var(--aw-border); padding: .4rem .55rem; vertical-align: top; }
.help-content th { background: var(--aw-thead); }
.help-content blockquote { border-inline-start: 4px solid var(--aw-gold); background: rgba(191, 174, 95, .08); padding: .6rem .9rem; margin: .8rem 0; border-radius: 6px; }
.help-content blockquote p:last-child { margin: 0; }
.help-content code { background: var(--aw-cream); color: var(--aw-black); padding: .05rem .35rem; border-radius: 4px; }
[data-bs-theme=dark] .help-content code { background: #2a2a2a; color: var(--aw-gold-light); }
.help-content :target { animation: aw-flash 2s ease; }
@keyframes aw-flash { from { background: rgba(191, 174, 95, .45); } to { background: transparent; } }
.help-toc a { display: flex; gap: .5rem; align-items: center; padding: .35rem .5rem; border-radius: 6px; color: var(--aw-text); font-size: .88rem; }
.help-toc a:hover, .help-toc a.active { background: rgba(191, 174, 95, .15); }
.help-toc .toc-section { font-size: .72rem; color: var(--aw-gold-dark); font-weight: 800; margin: .8rem .5rem .2rem; }
.help-search { max-width: 560px; }

/* ---------- حالة فارغة ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--aw-muted); }
.empty-state > i { font-size: 2.6rem; color: var(--aw-gold); display: block; margin-bottom: .5rem; }
.empty-state h2 { font-size: 1.2rem; font-weight: 800; color: var(--aw-text); }
.pager-info { font-size: .8rem; color: var(--aw-muted); }
.pagination { --bs-pagination-active-bg: var(--aw-black); --bs-pagination-active-border-color: var(--aw-black); --bs-pagination-color: var(--aw-text); --bs-pagination-hover-color: var(--aw-black); --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(191, 174, 95, .25); }
.nav-tabs-a { border-bottom: 1px solid var(--aw-border); gap: .25rem; }
.nav-tabs-a .nav-link { border: 0; border-bottom: 3px solid transparent; color: var(--aw-muted); font-weight: 600; border-radius: 0; }
.nav-tabs-a .nav-link.active { color: var(--aw-text); border-bottom-color: var(--aw-gold); background: transparent; }

/* ---------- صفحة الدخول ---------- */
body.auth { background: var(--aw-cream); }
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand { background: var(--aw-black); background-image: var(--aw-stripes); color: var(--aw-gold); display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 3rem; text-align: center; }
.auth-tagline { color: #bdbdbd; max-width: 420px; margin-top: 2rem; line-height: 1.9; }
.auth-form { display: flex; flex-direction: column; justify-content: center; padding: 3rem clamp(1.5rem, 6vw, 6rem); background: #fff; }
.auth-form h1 { font-weight: 800; font-size: 1.6rem; }
.auth-form .form-control { padding: .7rem .9rem; }
@media (max-width: 767.98px) { .auth-wrap { grid-template-columns: 1fr; } .auth-brand { padding: 2rem 1rem; } .auth-tagline { display: none; } }
.lockup { display: flex; flex-direction: column; align-items: center; gap: .9rem; }
.wordmark { font-family: var(--aw-font-latin); font-weight: 800; letter-spacing: .32em; color: #fff; font-size: 1.9rem; padding-inline-start: .32em; }
.wordmark-ar { color: var(--aw-gold-light); font-weight: 500; letter-spacing: .02em; }

/* ---------- مستندات وأسطر المستندات ---------- */
.doc-lines td { padding: .3rem !important; vertical-align: top !important; }
.doc-lines .line-no { color: var(--aw-muted); font-weight: 700; text-align: center; padding-top: .55rem !important; width: 34px; }
.doc-lines .col-acc { min-width: 240px; }
.doc-lines .col-cc { min-width: 160px; }
.doc-lines .col-qty { min-width: 90px; width: 100px; }
.doc-lines .col-price { min-width: 110px; width: 130px; }
.doc-lines .col-amt { min-width: 110px; width: 130px; text-align: end; padding-top: .55rem !important; font-weight: 700; }
.doc-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; padding: .85rem 1.1rem; background: var(--aw-thead);
    border-top: 1px solid var(--aw-border); border-radius: 0 0 var(--aw-radius) var(--aw-radius); }
.doc-totals .t-label { color: var(--aw-muted); font-size: .76rem; display: block; }
.doc-totals .t-value { font-weight: 800; font-size: 1.05rem; }
.doc-totals .t-net .t-value { color: var(--aw-gold-dark); }
.alloc-table input.amount { max-width: 150px; }
.kpi-row .kpi { min-height: 96px; }
.badge-soft { font-size: .72rem; padding: .15rem .45rem; border-radius: 4px; background: var(--aw-cream); color: var(--aw-text); }
.stat-line { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px dashed var(--aw-border); font-size: .9rem; }
.stat-line:last-child { border-bottom: 0; }
.stat-line strong { font-weight: 800; }
.table-a td.wrap { white-space: normal; min-width: 180px; }
.table-a .amount-neg { color: var(--aw-alert); }
.auth-alert { position: fixed; bottom: 1rem; inset-inline: 1rem; max-width: 520px; margin-inline: auto; background: #fff; color: var(--aw-alert);
    border-inline-start: 4px solid var(--aw-alert); border-radius: var(--aw-radius); padding: .75rem 1rem; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
@media (max-width: 575.98px) {
    .page-actions { padding-top: .25rem; width: 100%; }
    .page-actions .btn { flex: 1 1 auto; }
    .filters > div { flex: 1 1 100%; }
    .filters .form-control, .filters .form-select, .filters .f-wide { min-width: 0; width: 100%; }
    .toast { min-width: 0; width: calc(100vw - 2rem); }
    .doc-totals { grid-template-columns: 1fr 1fr; }
    .help-panel { width: 100vw !important; }
}

/* ---------- الطباعة (A4) ----------
   - حجم الورق والهوامش من @page في التخطيط (عمودي/أفقي حسب التقرير).
   - رأس الجدول يتكرر في كل صفحة (thead = table-header-group)، والأسطر لا تنقسم بين صفحتين.
   - لا قائمة جانبية ولا أزرار ولا فلاتر في الطباعة، والألوان مقروءة بالأبيض والأسود. */
.print-page { background: #e9e7df; }
.print-toolbar { position: sticky; top: 0; padding: .6rem; text-align: center; background: var(--aw-black); z-index: 5; display: flex; gap: .5rem; justify-content: center; }
.sheet { background: #fff; color: #0A0A0A; width: 210mm; min-height: 297mm; margin: 1rem auto; padding: 12mm 10mm 12mm; box-shadow: 0 4px 20px rgba(0, 0, 0, .12); }
.print-page.landscape .sheet { width: 297mm; min-height: 210mm; }
.print-frame { width: 100%; border-collapse: collapse; }
.print-frame > thead { display: table-header-group; }
.print-frame > tfoot { display: table-footer-group; }
.print-frame > * > tr > td { padding: 0; }
.print-head { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; border-bottom: 3px solid #0A0A0A; padding-bottom: .6rem; margin-bottom: 1rem; position: relative; }
.print-head::after { content: ""; position: absolute; inset-inline: 0; bottom: -7px; height: 2px; background: var(--aw-gold); }
.print-logo { color: var(--aw-gold); }
.print-logo img { max-height: 64px; max-width: 140px; }
.print-company .name { font-weight: 800; font-size: 1.1rem; }
.print-company .meta { font-size: .74rem; color: #444; }
.print-title { text-align: end; }
.print-title h1 { font-size: 1.2rem; font-weight: 800; margin: 0; }
.print-title div { font-size: .78rem; color: #444; }
.print-foot { margin-top: 1rem; padding-top: .5rem; border-top: 1px solid #bbb; display: flex; justify-content: space-between; font-size: .7rem; color: #555; }
.sheet .table-a { font-size: .78rem; }
.sheet .table-a > thead th { position: static; background: #f1efe6; }
.doc-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem 1rem; font-size: .82rem; margin-bottom: .8rem; }
.doc-meta div span { color: #555; display: block; font-size: .72rem; }
.doc-amount-words { border: 1px dashed #999; padding: .4rem .6rem; font-size: .82rem; margin: .6rem 0; }
.signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; margin-top: 2.5rem; text-align: center; font-size: .82rem; break-inside: avoid; }
.signatures div { border-top: 1px solid #0A0A0A; padding-top: .4rem; }
.only-print { display: none; }

@media print {
    html, body, .print-page { background: #fff !important; color: #000 !important; font-size: 11pt; }
    .no-print, .sidebar, .sidebar-backdrop, .topbar, .footer, .page-actions, .btn-help, .filters, .toast-container, .pager-info, .pagination,
    .print-toolbar, .btn, .card-h form, .skip-link, .breadcrumb, .page-head { display: none !important; }
    .only-print { display: block !important; }
    .app, .main { display: block; }
    .content { padding: 0; }
    .sheet { box-shadow: none; margin: 0; width: auto !important; min-height: auto !important; padding: 0; }
    .card-a { border: 0; margin-bottom: .6rem; break-inside: auto; }
    .card-a > .card-h { padding: .3rem 0; border-bottom: 1px solid #999; }
    .card-a > .card-b { padding: .3rem 0; }
    .table-wrap, .table-responsive { max-height: none !important; overflow: visible !important; }
    .table-a { font-size: 9pt; }
    .table-a > thead { display: table-header-group; }
    .table-a > tfoot { display: table-footer-group; }
    .table-a > thead th { position: static; background: #eee !important; color: #000; border-bottom: 1.5px solid #000; white-space: normal; }
    .table-a tr { break-inside: avoid; page-break-inside: avoid; }
    .table-a td, .table-a th { padding: .25rem .35rem !important; }
    .badge-a, .b-dark, .b-gold { background: transparent !important; color: #000 !important; border: 1px solid #555 !important; }
    .kpi, .kpi.dark, .note, .note.dark, .totals-bar, .statement .st-grand td { background: #fff !important; color: #000 !important; border: 1px solid #999 !important; background-image: none !important; }
    .statement .st-grand td.n { color: #000 !important; }
    a { color: inherit !important; text-decoration: none !important; }
    [data-bs-theme=dark] { --aw-surface: #fff; --aw-text: #000; --aw-bg: #fff; --aw-border: #999; --aw-thead: #eee; }
    h1, h2, h3 { break-after: avoid; }
}

/* ───────────── شبكة مؤشرات صفحات التفاصيل (عملاء، موردون، مشاريع، أصول) ───────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; }
.kpis .kpi-value { font-size: 1.2rem; }
.table-a tr.row-total td { font-weight: 800; background: var(--aw-thead); }
.table-a tr.row-group td { font-weight: 700; background: var(--aw-surface-2, #f6f5ef); }
.alloc-input { max-width: 150px; margin-inline-start: auto; }
@media print { .kpis { grid-template-columns: repeat(4, 1fr); } .kpis .kpi { padding: .4rem .6rem; } }
/* علامة مائية للمسودات والملغاة في طباعة المستندات */
.print-watermark { position: fixed; top: 40%; inset-inline: 0; text-align: center; font-size: 6rem; font-weight: 800; color: rgba(191, 174, 95, .18); transform: rotate(-20deg); pointer-events: none; z-index: 0; }
.print-meta th { background: #f4f2ea !important; font-weight: 700; font-size: .8rem; }
.print-meta td { font-size: .85rem; }
.bg-gold { background-color: var(--aw-gold) !important; }


/* ==========================================================================
   إصلاح القوائم المنسدلة داخل الجداول والفوتر/شريط الإجماليات
   ========================================================================== */

/* 1. إتاحة خروج القوائم المنسدلة من حدود الجدول والتصفح دون قص */
.table-responsive {
    overflow: visible !important;
}

/* 2. خفض الطبقة الخاصة بشريط الإجماليات والفوتر لعدم التغطية على القوائم */
.totals-bar,
.card-f,
.footer {
    position: relative;
    z-index: 1 !important;
}

/* 3. رفع طبقة أسطر الجدول عند التركيز/التحويم عليها حتى تظهر القوائم أعلى السطر التالي */
.lines-table td,
.doc-lines td {
    position: relative;
}

.lines-table tr:focus-within,
.doc-lines tr:focus-within,
.lines-table tr:hover,
.doc-lines tr:hover {
    position: relative;
    z-index: 10;
}

/* 4. إجبار حاويات مكتبات القوائم المنسدلة (مثل Select2 / Combo) على الظهور في أعلى طبقة */
.select2-container--open,
.combo-list {
    z-index: 9999 !important;
}

