/* خط القاهرة (Cairo — رخصة SIL OFL) مضمّن مع البرنامج فيعمل بدون إنترنت وعلى أي جهاز */
@font-face { font-family: "Cairo"; src: url("fonts/Cairo-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cairo"; src: url("fonts/Cairo-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Cairo"; src: url("fonts/Cairo-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
    --font: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
    --bg: #eef1f5;
    --panel: #ffffff;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #d6dbe3;
    --accent: #1d5f8a;
    --accent-soft: #e3eef6;
    --ok: #1f7a4d;
    --err: #b42318;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
}
/* عناصر الإدخال لا ترث الخط افتراضياً في كل المتصفحات */
input, select, textarea, button { font-family: var(--font); }

/* ---------------------------------------------------------- الشريط الجانبي */
:root { --side-w: 250px; --side-bg: #17324a; --side-ink: #c9d9e6; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; }

.sidenav {
    width: var(--side-w); flex: 0 0 var(--side-w); position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; background: var(--side-bg); color: #fff; z-index: 200;
}
.sidenav a { color: var(--side-ink); text-decoration: none; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidenav .brand, .mini-bar .brand { color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
.side-head .brand { flex: 1; }
.side-close, .side-open { cursor: pointer; user-select: none; border-radius: 4px; padding: 2px 8px; line-height: 1.6; }
.side-close { color: var(--side-ink); font-size: 13px; }
.side-close:hover { background: rgba(255,255,255,.12); color: #fff; }

.side-menus { flex: 1; overflow-y: auto; padding: 8px 8px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.side-menus > a.side-home { display: block; padding: 7px 10px; border-radius: 4px; margin-bottom: 4px; }
.side-menu { margin-bottom: 2px; }
.side-menu summary {
    list-style: none; cursor: pointer; padding: 8px 10px; border-radius: 4px; color: #fff; font-weight: 600;
    display: flex; align-items: center; gap: 8px;
}
.side-menu summary::-webkit-details-marker { display: none; }
.side-menu summary::after { content: "‹"; margin-inline-start: auto; transition: transform .15s; color: var(--side-ink); }
.side-menu[open] summary::after { transform: rotate(-90deg); }
.side-menu summary:hover { background: rgba(255,255,255,.08); }
.side-menu.current summary { background: rgba(255,255,255,.06); }
.side-icon { width: 20px; text-align: center; }
.side-group-title { font-size: 11px; font-weight: 700; color: #7f9db6; padding: 8px 10px 3px; margin-inline-start: 28px; }
.side-menu a {
    display: block; padding: 5px 10px; margin-inline-start: 28px; border-radius: 4px; font-size: 13.5px;
    border-inline-start: 2px solid transparent;
}
.sidenav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.sidenav a.active { color: #fff; background: rgba(255,255,255,.16); border-inline-start-color: #6fb1e3; }

.side-foot { border-top: 1px solid rgba(255,255,255,.1); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.side-user { display: flex; align-items: center; gap: 8px; }
.side-foot .nav-user { color: var(--side-ink); font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .nav-logout { margin: 0; }
.side-foot .nav-logout button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); padding: 3px 12px; }
.side-foot .nav-logout button:hover { background: rgba(255,255,255,.12); }
.side-foot .nav-branch { margin: 0; }
.side-foot .nav-branch select {
    width: 100%; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); padding: 4px 6px; font-size: 13px; border-radius: 4px;
}
.side-foot .nav-branch select option { color: var(--ink); }
.side-foot .nav-branch-name { color: var(--side-ink); font-size: 13px; }

/* شريط صغير يظهر عند إخفاء القائمة (وعلى الجوال دائماً) */
.mini-bar { display: none; align-items: center; gap: 10px; height: 44px; padding: 0 12px; background: var(--side-bg); position: sticky; top: 0; z-index: 150; }
.side-open { color: #fff; font-size: 18px; }
.side-open:hover { background: rgba(255,255,255,.12); }
.side-backdrop { display: none; }

.nav-toggle:checked ~ .app-shell .sidenav { display: none; }
.nav-toggle:checked ~ .app-shell .mini-bar { display: flex; }
.nav-toggle:focus-visible ~ .app-shell .side-open, .nav-toggle:focus-visible ~ .app-shell .side-close { outline: 2px solid #6fb1e3; }

@media (max-width: 900px) {
    .sidenav {
        position: fixed; inset-block: 0; inset-inline-start: 0; height: auto; width: min(85vw, 290px);
        transform: translateX(100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.3);
    }
    .mini-bar { display: flex; }
    .nav-toggle:checked ~ .app-shell .sidenav { display: flex; transform: none; }
    .nav-toggle:checked ~ .app-shell .side-backdrop { display: block; position: fixed; inset: 0; z-index: 190; background: rgba(15,30,50,.4); }
}
@media print { .sidenav, .mini-bar, .side-backdrop { display: none !important; } }

/* ---------------------------------------------------------- تسجيل الدخول */
.login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 16px;
    background: linear-gradient(160deg, #17324a 0%, #1d5f8a 100%);
}
.login-card {
    width: 100%; max-width: 380px; background: var(--panel); border-radius: 10px;
    padding: 28px 28px 24px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
    display: flex; flex-direction: column; gap: 8px;
}
.login-brand { color: var(--accent); font-weight: 700; letter-spacing: .5px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.login-card label { color: var(--muted); margin-top: 6px; }
.login-card input { padding: 9px 10px; }
.login-card button { margin-top: 14px; padding: 10px; font-size: 15px; }
.login-card .msg { margin: 0; }

/* ---------------------------------------------------------- الصفحة الرئيسية */
.home { max-width: 640px; margin: 48px auto; padding: 0 16px; }
.home h1 { font-size: 22px; }
.home .home-group { font-size: 14px; color: var(--muted); margin: 22px 0 8px; }
.tile {
    display: block; padding: 16px 20px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 8px; color: var(--ink); text-decoration: none;
}
.tile { margin-bottom: 10px; }
.tile:hover { border-color: var(--accent); }
.tile small { display: block; color: var(--muted); margin-top: 4px; }

/* ---------------------------------------------------------- شاشة الحسابات */
.screen {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 12px;
    padding: 12px;
    height: calc(100vh - 44px);
}

.tree-panel, .card-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 0;
}

.tree-panel { display: flex; flex-direction: column; }
.panel-head {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.panel-head small { color: var(--muted); font-weight: 400; }
.search { margin: 8px; }
.tree { overflow: auto; padding: 0 6px 8px; flex: 1; }
.muted { color: var(--muted); padding: 8px; }

.node {
    display: flex; align-items: center; gap: 4px;
    padding: 3px 4px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.node:hover { background: var(--accent-soft); }
.node.selected { background: var(--accent); color: #fff; }
.node.selected .num { color: #cfe3f1; }
.node .toggle { width: 14px; text-align: center; color: var(--muted); }
.node .num { color: var(--accent); font-variant-numeric: tabular-nums; margin-inline-end: 4px; }
/* زر "إضافة حساب فرعي" ظاهر دائماً بجانب كل حساب رئيسي (كان يظهر عند المرور فقط) */
.node .add-child { margin-inline-start: auto; }
.node.selected .add-child { background: #fff; }

/* أزرار السطر: بديل القائمة اليمنى (ContextMenuStrip) في البرنامج الأصلي — ظاهرة دائماً وبنص واضح */
.row-btn {
    font: inherit; font-size: 12px; line-height: 1.5; padding: 1px 9px; border-radius: 4px; cursor: pointer;
    border: 1px solid var(--line); background: #fff; color: var(--ink); white-space: nowrap;
}
.row-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.row-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.row-btn.danger { color: var(--err); }
.row-btn.danger:hover:not(:disabled) { border-color: var(--err); color: var(--err); }
.row-btn.warn { color: #8a5a00; }
.row-btn:disabled { opacity: .45; cursor: default; }
a.row-btn { text-decoration: none; display: inline-block; }
.row-actions { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; }
/* عمود أزرار السطر مثبّت على طرف الجدول فيبقى ظاهراً حتى لو كان الجدول أعرض من الشاشة */
.lines td:has(> .row-actions) {
    position: sticky; inset-inline-end: 0; z-index: 1; background: var(--panel);
    box-shadow: 6px 0 8px -8px rgba(0,0,0,.25) inset;
}
.lines:has(.row-actions) thead th:last-child { position: sticky; inset-inline-end: 0; z-index: 2; }
.lines tr.selected-row td:has(> .row-actions) { background: var(--accent-soft); }
.lines tr.locked-row td:has(> .row-actions) { background: #f6f7f9; }
.children { padding-inline-start: 16px; border-inline-start: 1px dotted var(--line); margin-inline-start: 7px; }

.card-panel { padding: 14px 18px; overflow: auto; }
.title-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.title-bar h1 { font-size: 18px; margin: 0; color: var(--accent); }
.mode { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.mode.new { background: #e7f6ee; color: var(--ok); }

fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 12px; padding: 12px 14px; }
legend { padding: 0 6px; color: var(--muted); }

.grid {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr) 120px minmax(0, 1fr);
    gap: 8px 12px;
    align-items: center;
}
.grid > label { color: var(--muted); }

input, select {
    width: 100%; padding: 6px 8px; font: inherit; color: inherit;
    border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly], select:disabled { background: #f4f6f8; color: var(--muted); }
input[type=checkbox] { width: auto; }

.with-btn { display: flex; gap: 4px; }
.checks { display: flex; gap: 20px; grid-column: span 3; }
.checks label { display: flex; align-items: center; gap: 6px; }
.tafkit { margin-top: 8px; color: var(--accent); min-height: 1.4em; }

.balance { display: flex; align-items: center; gap: 16px; }
.balance > div { flex: 1; background: #f7f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.balance small { display: block; color: var(--muted); }
.balance b { font-size: 16px; font-variant-numeric: tabular-nums; }
.balance .neg b { color: var(--err); }

.buttons { display: flex; gap: 8px; }
button {
    font: inherit; padding: 7px 16px; border-radius: 4px; cursor: pointer;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .45; cursor: default; }
button.small { padding: 4px 10px; }
kbd { font-size: 11px; opacity: .7; margin-inline-start: 4px; }

.msg { padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; cursor: pointer; }
.msg.ok { background: #e7f6ee; color: var(--ok); }
.msg.error { background: #fdecea; color: var(--err); }

/* ---------------------------------------------------------- سند القيد */
.journal {
    margin: 12px; padding: 14px 18px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 8px;
}
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h1 { font-size: 18px; margin: 0; color: var(--accent); }
.toolbar .spacer { flex: 1; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.toolbar .goto { width: 90px; text-align: center; }
.badge { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.new { background: #e7f6ee; color: var(--ok); }
.badge.locked { background: #fdecea; color: var(--err); }
button.danger:not(:disabled) { color: var(--err); }
button.danger:hover:not(:disabled) { border-color: var(--err); }

fieldset.head { margin-bottom: 8px; }
.head-grid {
    display: grid;
    grid-template-columns: 110px minmax(0,1fr) 90px minmax(0,1fr) 90px minmax(0,1fr) 100px minmax(0,1fr);
    gap: 8px 12px; align-items: center;
}
.head-grid > label { color: var(--muted); }
.head-grid .wide { grid-column: span 5; }
.head-grid .check { display: flex; gap: 6px; align-items: center; color: var(--ink); }

.columns-bar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 6px 0 8px; color: var(--muted); font-size: 13px; }
.columns-bar label { display: flex; gap: 4px; align-items: center; color: var(--ink); }
.columns-bar .hint { margin-inline-start: auto; font-size: 12px; }

.lines-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table.lines { width: 100%; border-collapse: collapse; }
table.lines th {
    background: #f3f6f9; color: var(--muted); font-weight: 600; text-align: start;
    padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
table.lines td { padding: 2px 3px; border-bottom: 1px solid #edf0f4; }
table.lines td input, table.lines td select { border-color: transparent; background: transparent; padding: 5px 6px; }
table.lines td input:focus, table.lines td select:focus { background: #fff; border-color: var(--accent); }
table.lines tr:hover td { background: #fafbfd; }
table.lines tr.invalid td { background: #fdecea; }
table.lines tr.ro td { background: #f6f7f9; }
table.lines input.bad { color: var(--err); border-color: var(--err); }
table.lines .idx { width: 32px; text-align: center; color: var(--muted); }
table.lines th.acc { min-width: 220px; }
table.lines td select { min-width: 90px; }
table.lines .num { text-align: end; font-variant-numeric: tabular-nums; min-width: 100px; }
/* الأرقام السالبة: بدون هذا تظهر علامة الناقص يمين الرقم داخل الصفحة العربية */
table.lines td.num { direction: ltr; text-align: left; }
.balance b, .totals b { direction: ltr; unicode-bidi: isolate; }
table.lines td.calc { color: var(--muted); padding-inline-end: 9px; }
table.lines .act { width: 64px; white-space: nowrap; }
button.icon { padding: 2px 7px; border-color: transparent; background: transparent; color: var(--muted); }
button.icon:hover:not(:disabled) { color: var(--accent); }
.add-row { margin: 6px; border-style: dashed; color: var(--accent); }

.totals { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.totals > div { flex: 1; background: #f7f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.totals small { display: block; color: var(--muted); }
.totals b { font-size: 17px; font-variant-numeric: tabular-nums; }
.totals em { font-style: normal; font-size: 12px; margin-inline-start: 8px; }
.totals .balanced { border-color: #b7e0c8; background: #eef9f2; color: var(--ok); }
.totals .unbalanced { border-color: #f3c1bc; background: #fdf1f0; color: var(--err); }

/* ---------------------------------------------------------- إيصال قبض / دفع */
.cash-grid {
    display: grid; grid-template-columns: 100px minmax(0,1fr) 90px minmax(0,1fr) 70px minmax(0,1fr) 90px minmax(0,1fr);
    gap: 8px 12px; align-items: center;
}
.cash-grid.two { grid-template-columns: 110px minmax(0,1fr); }
.cash-grid > label { color: var(--muted); }
.cash-grid > label.strong { color: var(--ink); font-weight: 600; }
.cash-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 12px; }
.cash-main fieldset { margin: 0; }
.cash-side { display: flex; flex-direction: column; gap: 12px; }
.amount-row { display: flex; gap: 8px; align-items: center; }
.amount-row .amount { font-size: 18px; font-weight: 700; direction: ltr; text-align: left; max-width: 220px; }
.amount-row select { max-width: 140px; }
.amount-row .eq { color: var(--muted); white-space: nowrap; }
.amount-row .eq b { color: var(--ink); direction: ltr; unicode-bidi: isolate; }
a.button-link.small { padding: 4px 10px; white-space: nowrap; }
.party-balance { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.party-balance > div { background: #f7f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.party-balance small { display: block; color: var(--muted); }
.party-balance b { font-size: 16px; direction: ltr; unicode-bidi: isolate; }
.party-balance b.dr { color: var(--err); }
.party-balance b.cr { color: #1d4ed8; }
.party-balance em { font-style: normal; font-size: 12px; color: var(--muted); margin-inline-start: 6px; }
.cash fieldset[disabled] input, .cash fieldset[disabled] select { background: #f7f9fb; color: var(--ink); }
.attachments { display: flex; flex-direction: column; gap: 4px; }
.attachments .muted { padding: 2px 0; font-size: 13px; }
.att-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px dashed #edf0f4; }
.att-row a { color: var(--accent); text-decoration: none; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-row small { color: var(--muted); white-space: nowrap; direction: ltr; }
label.upload {
    position: relative; margin-top: 6px; padding: 7px 12px; border: 1px dashed var(--accent); border-radius: 4px;
    color: var(--accent); text-align: center; cursor: pointer;
}
label.upload:hover { background: var(--accent-soft); }
label.upload.busy { opacity: .6; cursor: progress; }
label.upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

@media (max-width: 1100px) {
    .cash-grid { grid-template-columns: 100px minmax(0,1fr) 90px minmax(0,1fr); }
    .cash-main { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------- ميزان المراجعة */
.tb-table th.grp { text-align: center; border-inline-start: 1px solid var(--line); }
.tb-table thead tr:first-child th { top: 0; }
.tb-table thead tr:nth-child(2) th { top: 31px; }
.tb-table td.strong { font-weight: 600; color: #b42318; }
.tb-table td.strong.cr { color: #1d4ed8; }
.tb-table tr.agg td { background: #f3f6f9; font-weight: 600; }
.tb-table tfoot td { position: sticky; bottom: 0; background: #e3eef6; font-weight: 700; padding: 7px 6px; border-top: 2px solid var(--accent); }
.tb-table a { color: var(--accent); text-decoration: none; }
.tb-check { font-weight: 600; padding: 2px 10px; border-radius: 99px; }
.tb-check.ok { background: #e7f6ee; color: var(--ok); }
.tb-check.bad { background: #fdecea; color: var(--err); }

/* ---------------------------------------------------------- الميزانية العمومية */
.msg.warn { background: #fff7e0; color: #8a5a00; cursor: default; }

/* ---------------------------------------------------------- بطاقة العميل (Form6) */
.customer .tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.customer .tabs button {
    border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; background: transparent;
    color: var(--muted); padding: 7px 14px; margin-bottom: -1px;
}
.customer .tabs button.active { background: var(--panel); border-color: var(--line); color: var(--accent); font-weight: 600; }
.cust-grid {
    display: grid; grid-template-columns: 130px minmax(0,1fr) 130px minmax(0,1fr);
    gap: 8px 14px; align-items: center;
}
.cust-grid > label { color: var(--muted); }
.cust-grid .span3 { grid-column: span 3; }
.cust-grid .span4 { grid-column: 1 / -1; margin: 0; }

/* ---------------------------------------------------------- إعدادات الفرع */
.branch-settings .branch-pick { width: 240px; }
.branch-settings .cust-grid { grid-template-columns: 220px minmax(0,1fr) 220px minmax(0,1fr); }
.branch-settings .field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.branch-settings .field small { font-size: 11px; }
.branch-settings .cust-grid input.req { border-inline-start: 3px solid #d08a00; }
.branch-settings .tabs button.has-warn::after { content: " •"; color: #d08a00; }
.branch-settings .toolbar .check { display: flex; gap: 6px; align-items: center; }
.small-note { font-size: 12px; margin-top: 16px; }
.muted { color: var(--muted); }
@media (max-width: 860px) { .branch-settings .cust-grid { grid-template-columns: 150px minmax(0,1fr); } }

/* ---------------------------------------------------------- شاشات الاستعراض والحسابات التجميعية */
.browse .radios { display: flex; gap: 14px; align-items: center; }
.browse .radios label { display: flex; gap: 5px; align-items: center; white-space: nowrap; }
.browse .radios input { width: auto; margin: 0; }
.browse .lines td.wrap { white-space: normal; min-width: 160px; }
.browse .lines td.actions { display: flex; gap: 4px; align-items: center; }
.browse .lines tr.locked-row td { background: #f6f7f9; color: var(--muted); }
.browse .lines tr.subtotal td { background: #e3eef6; font-weight: 600; }
.browse .lines tbody tr:hover td { background: #f2f7fb; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: #eef1f5; }
.pill.rec, .pill.t3 { background: #e7f6ee; color: var(--ok); }
.pill.pay, .pill.t4 { background: #fdecea; color: var(--err); }
.pill.t2, .pill.t0 { background: var(--accent-soft); color: var(--accent); }
button.icon { padding: 1px 6px; border: 0; background: transparent; font-size: 14px; }
button.icon:hover:not(:disabled) { background: var(--accent-soft); }
button.icon.danger { color: var(--err); }
.totals-row { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.totals-row > div { flex: 1; min-width: 180px; background: #f7f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
.totals-row small { display: block; color: var(--muted); }
.totals-row b { font-size: 16px; font-variant-numeric: tabular-nums; }
.totals-row .dr b { color: var(--err); }
.totals-row .cr b { color: var(--accent); }

.customers-list .load-modes { display: flex; gap: 10px 24px; flex-wrap: wrap; align-items: center; }
.customers-list .load-mode { display: flex; gap: 6px; align-items: center; }
.customers-list .load-mode span { color: var(--muted); white-space: nowrap; }
.customers-list .load-mode .date-input input { width: 120px; }
.customers-list input.tiny { width: 62px; }
.customers-list .columns-bar label { display: flex; gap: 4px; align-items: center; color: var(--ink); }
.customers-list .columns-bar input[type=checkbox] { width: auto; }
.customers-list .lines tr.black-row td { background: #fff1f0; }
.customers-list .lines td.over { color: var(--err); font-weight: 600; }
.customers-list .more { text-align: center; margin-top: 8px; }

.groups-layout { display: grid; grid-template-columns: 320px minmax(0,1fr); gap: 14px; align-items: start; }
.groups .panel { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.groups .panel .panel-head { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.groups .panel .panel-head .spacer { flex: 1; }
.groups .group-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.groups .group-list li { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.groups .group-list li:hover { background: #f2f7fb; }
.groups .group-list li.selected { background: var(--accent-soft); }
.groups .group-list .g-name { flex: 1; }
.groups .group-list .g-actions { display: flex; gap: 2px; }
.groups .empty { padding: 20px; text-align: center; color: var(--muted); }
@media (max-width: 860px) { .groups-layout { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------- CRM */
.lines tr.selected-row td { background: var(--accent-soft) !important; }
.lines tr.top-rated td { background: #fff1f0; }          /* الأصل: MistyRose للتقييم 5 */
.lines td.expired, .expired { color: var(--err); font-weight: 600; }
.lines tbody tr { cursor: default; }
.crm-projects tbody tr { cursor: pointer; }
.stars { color: #e3a008; letter-spacing: 1px; }
.stars .off { color: #d6dbe3; }
.stars-edit { display: inline-flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.stars-edit .star { border: 0; background: transparent; font-size: 20px; color: #d6dbe3; padding: 0 2px; cursor: pointer; }
.stars-edit .star.on { color: #e3a008; }
.crm-detail { margin: 12px 0; }
.crm-detail .panel { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.crm-detail .panel-head { display: flex; gap: 10px; align-items: baseline; font-weight: 600; font-size: 15px; }
.contact-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.contact-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; min-width: 200px; display: flex; flex-direction: column; gap: 4px; }
.contact-card small { color: var(--muted); }
.contact-card .row-btn { align-self: flex-start; }
.phone-line { display: flex; gap: 6px; align-items: center; }
.phone-line a[href^="tel"] { color: var(--ink); text-decoration: none; }
.row-btn.wa { color: #128c4a; border-color: #b7e3c8; }
.crm-figures { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.crm-figures > div { flex: 1; min-width: 170px; background: #f7f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.crm-figures small { display: block; color: var(--muted); }
.crm-figures em { font-style: normal; margin-inline-start: 6px; }
.crm-notes p { margin: 2px 0; }
.crm-notes small { color: var(--muted); }
.tasks-head { display: flex; gap: 10px; align-items: center; margin: 14px 0 6px; font-weight: 600; }
.tasks-head .spacer { flex: 1; }
.crm .columns-bar label, .crm-form .columns-bar label { display: flex; gap: 4px; align-items: center; color: var(--ink); }
.crm .columns-bar input[type=checkbox] { width: auto; }
.crm-form .sec-title { font-size: 15px; margin: 18px 0 8px; color: var(--accent); }
.crm-form .crm-two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.crm-form .crm-two .with-btn { margin-bottom: 8px; }
.lines.simple { width: 100%; }
.lines.simple td { padding: 5px 8px; border-bottom: 1px solid var(--line); }
.crm-form .lines-wrap { margin-top: 8px; }
@media (max-width: 860px) { .crm-form .crm-two { grid-template-columns: 1fr; } }

/* نافذة التأكيد داخل الصفحة (somar.confirm) */
.somar-confirm-back {
    position: fixed; inset: 0; z-index: 1000; background: rgba(15, 30, 50, .35);
    display: grid; place-items: center; padding: 16px;
}
.somar-confirm {
    background: var(--panel); border-radius: 10px; box-shadow: 0 18px 50px rgba(0,0,0,.25);
    padding: 20px 22px 16px; width: min(420px, 100%); direction: rtl;
}
.somar-confirm-msg { font-size: 15px; line-height: 1.7; margin-bottom: 16px; white-space: pre-line; }
.somar-confirm-btns { display: flex; gap: 8px; justify-content: flex-start; }
.somar-confirm-btns button { min-width: 84px; }

.cust-grid textarea { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; }
.cust-grid .radios { display: flex; gap: 6px 14px; flex-wrap: wrap; min-width: 0; }
.cust-grid .radios label { white-space: nowrap; }
.cust-grid .radios input { margin: 0; width: auto; }   /* القاعدة العامة input {width:100%} كانت تمطّ أزرار الراديو */
.cust-grid .radios label, .cust-grid .check { display: flex; gap: 6px; align-items: center; color: var(--ink); }
.cust-grid input.bad { border-color: var(--err); background: #fdecea; }
.cust-grid input.req { border-inline-start: 3px solid var(--err); }
.cust-search { position: relative; width: 300px; }
.cust-hits {
    position: absolute; top: 100%; inset-inline: 0; z-index: 20; background: var(--panel);
    border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 20px rgba(0,0,0,.12); max-height: 340px; overflow: auto;
}
.cust-hits button { display: block; width: 100%; text-align: start; border: 0; border-radius: 0; padding: 7px 10px; }
.cust-hits button:hover { background: var(--accent-soft); }
.cust-hits small { color: var(--muted); }
.pics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.pic { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.pic img { width: 100%; height: 170px; object-fit: contain; background: #f4f6f8; border-radius: 4px; }
.pic-empty { height: 170px; display: grid; place-items: center; background: #f4f6f8; color: var(--muted); border-radius: 4px; }
.pic-actions { display: flex; gap: 6px; justify-content: center; }
.button-like {
    padding: 4px 10px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; background: #fff;
}
.button-like:hover { border-color: var(--accent); }
@media (max-width: 860px) {
    .cust-grid { grid-template-columns: 110px minmax(0,1fr); }
    .cust-grid .span3 { grid-column: span 1; }
    .pics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cust-search { width: 100%; }
}
.bs-summary { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 10px; margin: 8px 0 10px; }
.bs-summary > div { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: #f7f9fb; }
.bs-summary small { display: block; color: var(--muted); }
.bs-summary b { font-size: 17px; direction: ltr; unicode-bidi: isolate; }
.bs-summary em { display: block; font-style: normal; font-size: 12px; color: var(--muted); }
.bs-summary .profit { border-color: #b7e0c8; background: #eef9f2; color: var(--ok); }
.bs-summary .loss { border-color: #f3c1bc; background: #fdf1f0; color: var(--err); }
.bs-summary .balanced { border-color: #b7e0c8; background: #eef9f2; color: var(--ok); }
.bs-summary .unbalanced { border-color: #f3c1bc; background: #fdf1f0; color: var(--err); }
.bs-summary .breakdown { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: 13px; color: var(--muted); }
.bs-summary .breakdown b { font-size: 13px; color: var(--ink); }
.bs-table tr.agg.d1 td { background: #dce8f2; font-weight: 700; }
.bs-table tr.agg.d2 td { background: #eaf1f7; font-weight: 600; }
.bs-table tr.special td { background: #fff7e0; }
.bs-table .tag { font-size: 11px; color: #8a5a00; background: #ffefc2; border-radius: 99px; padding: 1px 8px; margin-inline-start: 6px; }
.bs-table td.num { color: #b42318; }
.bs-table td.num.cr { color: #1d4ed8; }
@media (max-width: 900px) { .bs-summary { grid-template-columns: 1fr; } }
.is-cards { display: grid; grid-template-columns: repeat(4, 1fr) 1.4fr; gap: 10px; margin: 8px 0 10px; }
.is-cards > div { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: #f7f9fb; }
.is-cards small { display: block; color: var(--muted); }
.is-cards b { font-size: 16px; direction: ltr; unicode-bidi: isolate; }
.is-cards em { display: block; font-style: normal; font-size: 12px; color: var(--muted); }
.is-cards .profit { border-color: #b7e0c8; background: #eef9f2; color: var(--ok); }
.is-cards .loss { border-color: #f3c1bc; background: #fdf1f0; color: var(--err); }
.bs-table tfoot tr.pl-row td { background: #eef9f2; color: var(--ok); border-top: 1px solid #b7e0c8; }
@media (max-width: 1100px) { .is-cards { grid-template-columns: 1fr 1fr; } }

/* ---------------------------------------------------------- دفتر الأستاذ */
.lg-grid { display: grid; grid-template-columns: 70px 150px 40px 150px 60px minmax(180px,1.5fr) 100px minmax(180px,1.5fr); gap: 8px 10px; align-items: center; }
.lg-grid > label { color: var(--muted); }
details.types, details.cols { position: relative; }
details.types > summary, details.cols > summary { cursor: pointer; padding: 4px 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; list-style: none; }
details.types[open] .types-list, details.cols[open] .types-list {
    position: absolute; z-index: 20; top: 32px; inset-inline-start: 0; width: 520px; max-height: 340px; overflow: auto;
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 10px; background: #fff;
    border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
details.cols[open] .types-list { width: 320px; inset-inline-start: auto; inset-inline-end: 0; }
.types-list label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.types-list button { grid-column: span 1; }
.lg-table td { padding: 4px 6px; }
.lg-table td.nowrap { white-space: nowrap; }
.lg-table td.muted-cell { color: var(--muted); }
.lg-table td.bal { font-weight: 600; color: #b42318; }
.lg-table td.bal.cr { color: #1d4ed8; }
.lg-table td.empty { text-align: center; color: var(--muted); padding: 24px; }
.lg-table tr.opening td { background: #fff7e0; font-weight: 600; }
.lg-table tr.unposted td { background: #fbf7ff; }
.lg-table a { color: var(--accent); text-decoration: none; }
.lg-table .tag { font-size: 11px; color: #6b21a8; background: #f3e8ff; border-radius: 99px; padding: 1px 6px; margin-inline-start: 4px; }
.lg-table tfoot td { position: sticky; bottom: 0; background: #e3eef6; font-weight: 700; padding: 7px 6px; border-top: 2px solid var(--accent); }
details.lg-sum { margin-top: 10px; }
details.lg-sum > summary { cursor: pointer; color: var(--accent); }
@media (max-width: 1100px) { .lg-grid { grid-template-columns: 70px minmax(0,1fr) 70px minmax(0,1fr); } }

/* ---------------------------------------------------------- كشف الحساب */
.st-grid {
    display: grid; grid-template-columns: 60px minmax(220px, 2fr) 30px 150px 30px 150px auto;
    gap: 8px 10px; align-items: center;
}
.st-grid > label { color: var(--muted); }
.st-grid .quick { display: flex; gap: 4px; }
.st-options { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.st-options label { display: flex; gap: 6px; align-items: center; }
.st-options .spacer { flex: 1; }
.columns-bar .small-select { width: auto; min-width: 170px; padding: 4px 6px; }
.columns-bar .filter { width: 210px; padding: 4px 8px; }
.columns-bar .filter.num { width: 120px; }
.st-table { max-height: calc(100vh - 380px); overflow: auto; }
.st-table td { padding: 5px 6px; }
.st-table td.nowrap { white-space: nowrap; }
.st-table td.muted-cell { color: var(--muted); }
.st-table td.bal { font-weight: 600; color: #b42318; }
.st-table td.bal.cr { color: #1d4ed8; }
.st-table td.empty { text-align: center; color: var(--muted); padding: 24px; }
.st-table tr.opening td { background: #fff7e0; font-weight: 600; }
.st-table a { color: var(--accent); text-decoration: none; white-space: nowrap; }
.totals .debit { border-color: #f3c1bc; background: #fdf1f0; color: var(--err); }
.totals .credit { border-color: #bfd3f5; background: #eef4fe; color: #1d4ed8; }
.totals .eq { display: inline; margin-inline-start: 10px; color: var(--muted); }
table.by-currency { width: auto; min-width: 480px; margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; }
table.by-currency td { padding: 5px 10px; }
a.button-link {
    display: inline-flex; align-items: center; padding: 7px 16px; border-radius: 4px;
    border: 1px solid var(--line); color: var(--accent); text-decoration: none; background: #fff;
}
a.button-link:hover { border-color: var(--accent); }
/* استعراض فواتير الشراء: من/إلى، المورد/المستودع، الدفع + الاختصارات */
.purchase-list .st-grid { grid-template-columns: 70px minmax(0, 1fr) 70px minmax(0, 1fr); }
.purchase-list .st-grid .quick { grid-column: 3 / -1; }
@media (max-width: 640px) {
    .purchase-list .st-grid { grid-template-columns: 70px minmax(0, 1fr); }
    .purchase-list .st-grid .quick { grid-column: 1 / -1; }
}

@media (max-width: 1100px) {
    .st-grid { grid-template-columns: 60px minmax(0, 1fr) 30px minmax(0, 1fr); }
    .st-grid .quick { grid-column: 1 / -1; }
    .head-grid { grid-template-columns: 110px minmax(0,1fr) 100px minmax(0,1fr); }
    .head-grid .wide { grid-column: span 3; }
}

@media (max-width: 900px) {
    .screen { grid-template-columns: 1fr; height: auto; }
    .tree-panel { height: 45vh; }
    .grid { grid-template-columns: 110px minmax(0, 1fr); }
    .checks { grid-column: auto; }
}

/* واجهة الخطأ الافتراضية في Blazor */
#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; left: .75rem; top: .5rem; }

/* ===================================================== حقل التاريخ يوم/شهر/سنة (DateInput) */
.date-input { position: relative; display: inline-flex; align-items: stretch; gap: 0; min-width: 0; max-width: 100%; }
.date-input > input[type=text] { width: 9.2em; min-width: 0; flex: 1 1 auto; text-align: center; letter-spacing: .5px;
    border-start-end-radius: 0; border-end-end-radius: 0; }
.date-input > .date-pick { padding: 0 8px; min-width: 0; border-start-start-radius: 0; border-end-start-radius: 0;
    margin-inline-start: -1px; font-size: 14px; line-height: 1; cursor: pointer; }
.date-input > .date-native { position: absolute; inset-inline-end: 0; bottom: 0; width: 1px; height: 1px; opacity: 0;
    pointer-events: none; border: 0; padding: 0; }

/* ===================================================== بطاقة المادة (Form30) */
.item-card .sec-title { display: flex; align-items: center; gap: 10px; }
.item-card .item-units input, .item-card .item-units select { min-width: 0; width: 100%; }
.item-card .item-units td { padding: 3px 4px; }
.item-card .item-units th:nth-child(2), .item-card .item-units td:nth-child(2) { min-width: 105px; }
.item-card .item-units th:nth-child(4), .item-card .item-units td:nth-child(4) { min-width: 150px; }
.item-card .item-units td:nth-child(3), .item-card .item-units td:nth-child(5) { min-width: 80px; }
.item-card .item-units td:nth-child(n+6):nth-child(-n+10) { min-width: 78px; }
.item-card .item-units tr.primary-unit td:first-child { font-weight: 700; color: var(--accent); }
.item-card .item-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px 24px; margin-top: 6px; }
.item-card .item-boxes .wide { grid-column: 1 / -1; }
.item-card .cust-grid.two { grid-template-columns: 130px minmax(0, 1fr); }
.item-card table.profit { margin-top: 8px; max-width: 620px; }
.item-card table.profit input { width: 100%; min-width: 70px; }
.item-card .item-desc { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }
.item-card .item-pic img { max-width: 100%; max-height: 240px; display: block; border: 1px solid var(--line); border-radius: 4px; }
@media (max-width: 860px) { .item-card .item-desc { grid-template-columns: 1fr; } }
/* أعمدة الأسعار أهم من الأزرار هنا: عمود الأزرار لا يُثبَّت فوقها، ويظهر بالتمرير */
.item-card .item-units td:has(> .row-actions), .item-card .item-units:has(.row-actions) thead th:last-child { position: static; box-shadow: none; }

/* ===================================================== استعراض المواد (Form11_2) */
.item-list fieldset.head .radios { display: flex; gap: 8px 18px; align-items: center; flex-wrap: wrap; }
.item-list fieldset.head .radios label { display: flex; gap: 6px; align-items: center; }
.item-list fieldset.head .radios input { width: auto; margin: 0; }
.item-list tr.sub-unit td:nth-child(-n+3) { color: var(--muted); }
.item-list td input.num { width: 100px; }
.item-list .pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 10px 0; }
.item-defs .lines.simple td { padding: 4px 6px; }

/* ===================================================== فاتورة الشراء (Form41) */
.purchase fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0 0 10px; }
.purchase fieldset[disabled] { opacity: .85; }
.purchase .tiny-num { width: 90px; }
.purchase .badge.locked { background: #fdecea; color: var(--err); }
.purchase .pu-entry { background: var(--panel); }
.purchase .pu-entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 12px; align-items: end; }
.purchase .pu-entry-grid label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.purchase .pu-entry-grid .pu-search { grid-column: span 3; position: relative; }
.purchase .pu-entry-grid .pu-picked { grid-column: span 3; display: flex; flex-direction: column; justify-content: end; }
.purchase .pu-entry-grid .wide { grid-column: span 3; }
.purchase .pu-entry-actions { display: flex; gap: 6px; }
.purchase .pu-search .cust-hits { position: absolute; inset-inline: 0; top: 100%; z-index: 20; }
.purchase .pu-bottom { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 10px; }
.purchase .pu-totals input.strong { font-weight: 700; }
.purchase .pu-accounts-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.purchase .pu-accounts-head .check { display: flex; gap: 6px; align-items: center; }
.purchase .pu-accounts-head input { width: auto; }
.purchase .lines tfoot td { background: var(--panel); }
@media (max-width: 860px) { .purchase .pu-bottom { grid-template-columns: 1fr; } .purchase .pu-entry-grid .pu-search, .purchase .pu-entry-grid .pu-picked, .purchase .pu-entry-grid .wide { grid-column: 1 / -1; } }
