/* منصة المحاسبة: ورق دفتر، حبر أخضر، وختم المصادقة بلون حبر الأختام */
:root {
  --paper: #F4F5F1;
  --surface: #FFFFFF;
  --ink: #17211C;
  --ink-2: #56635C;
  --ink-3: #8A958F;
  --rule: #DCE2DD;
  --rule-strong: #B9C4BD;
  --ledger: #1E5B4A;
  --ledger-deep: #173F34;
  --ledger-soft: #E4EEE8;
  --stamp: #33409A;
  --amber: #96600F;
  --amber-soft: #FAF0DA;
  --red: #A43A2E;
  --red-soft: #F8E6E3;
  --radius: 6px;
  --font: 'IBM Plex Sans Arabic', 'IBM Plex Sans', system-ui, sans-serif;
  --font-head: 'Noto Kufi Arabic', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-num: 'IBM Plex Sans', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
html[lang="fr"] { --font: 'IBM Plex Sans', system-ui, sans-serif; --font-head: 'IBM Plex Sans', system-ui, sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--ledger); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; margin: 0; letter-spacing: 0; }
h1 { font-size: 1.6rem; line-height: 1.3; }
h2 { font-size: 1.05rem; color: var(--ink); }
h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.muted { color: var(--ink-2); }
.neg { color: var(--red); }
.ok-text { color: var(--ledger); font-weight: 500; }
.strong { font-weight: 600; }
.narrow { max-width: 62ch; }

/* ---------- الهيكل ---------- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--ledger-deep); color: #E8EFEA; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--paper); color: var(--ledger-deep); display: grid; place-items: center; font: 700 20px/1 var(--font-head); flex: none; }
.brand-mark.big { width: 56px; height: 56px; font-size: 30px; border-radius: 12px; background: var(--ledger-deep); color: var(--paper); }
.brand-name { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.brand-sub { font-size: .78rem; color: #A9BDB2; }
.side nav { flex: 1; padding-top: 12px; }
.nav-group { margin-bottom: 14px; }
.nav-title { font-size: .76rem; color: #8FA79A; padding: 6px 10px; }
.side nav a { display: block; color: #E8EFEA; padding: 7px 10px; border-radius: var(--radius); font-size: .93rem; }
.side nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.side nav a.active { background: var(--paper); color: var(--ledger-deep); font-weight: 600; }
.side-foot { border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; display: grid; gap: 10px; }
.year-pick { display: grid; gap: 4px; font-size: .8rem; color: #A9BDB2; }
.year-pick select { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.2); }
.side .btn-ghost { color: #E8EFEA; border-color: rgba(255,255,255,.25); }
.main { padding: 28px 36px 64px; min-width: 0; outline: none; }

.page-head { margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.back { font-size: .85rem; display: inline-block; margin-bottom: 4px; }
.block { margin-top: 30px; }
.block h2 { margin-bottom: 10px; }

/* ---------- عناصر النماذج ---------- */
label { display: grid; gap: 4px; font-size: .82rem; color: var(--ink-2); }
input, select { font: inherit; font-size: .93rem; color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 7px 9px; min-width: 0; }
input:focus, select:focus { border-color: var(--ledger); outline: none; box-shadow: 0 0 0 3px var(--ledger-soft); }
input:disabled, select:disabled { background: transparent; border-color: transparent; color: var(--ink); padding-inline: 0; }
input.bad { border-color: var(--red); background: var(--red-soft); }
label.check { display: flex; align-items: center; gap: 6px; font-size: .85rem; align-self: end; padding-bottom: 8px; }
label.check input { width: 16px; height: 16px; }
.btn { font: inherit; font-size: .9rem; font-weight: 500; border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.btn-primary:hover { background: var(--ledger-deep); border-color: var(--ledger-deep); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn-sm { padding: 3px 9px; font-size: .8rem; }
.icon-btn { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 1rem; width: 26px; height: 26px; border-radius: 4px; }
.icon-btn:hover { background: var(--paper); color: var(--ink); }
.icon-btn.rm:hover { color: var(--red); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 12px 14px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 16px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters .batch { display: flex; gap: 6px; align-items: end; margin-inline-start: auto; padding-inline-start: 12px; border-inline-start: 1px solid var(--rule); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid .full, .actions.full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- الجداول: ورق دفتر ---------- */
.num { text-align: end; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono-num, .acc-code { font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-code { font-weight: 600; color: var(--ledger-deep); }
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); font-size: .9rem; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--rule); text-align: start; vertical-align: top; }
.grid thead th { background: var(--paper); color: var(--ink-2); font-weight: 500; font-size: .82rem; border-bottom: 1px solid var(--rule-strong); position: sticky; top: 0; z-index: 1; }
.grid thead th.num { text-align: end; }
.grid td.num, .grid th.num { border-inline-start: 1px solid var(--rule); }
.grid tfoot th, .grid tfoot td { border-top: 3px double var(--rule-strong); font-weight: 600; background: var(--paper); }
.grid tr.sub th, .grid tr.sub td { background: var(--ledger-soft); font-weight: 600; color: var(--ledger-deep); }
.grid .wrap { white-space: normal; max-width: 420px; }
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover td { background: #F9FBF9; }
.grid tr.is-draft td { color: var(--amber); }
.tb th.grp { text-align: center; border-inline-start: 1px solid var(--rule-strong); }
.accounts tr.is-group td { background: var(--paper); font-weight: 600; }
.accounts tr.lvl-1 td, .accounts tr.lvl-2 td { font-family: var(--font-head); }
.tag { font-size: .72rem; color: var(--ledger); background: var(--ledger-soft); padding: 1px 7px; border-radius: 10px; }
.tag-custom { color: var(--stamp); background: #E8EAF6; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 9px; border-radius: 10px; font-weight: 500; }
.pill-draft { background: var(--amber-soft); color: var(--amber); }
.pill-ok { background: var(--ledger-soft); color: var(--ledger); }
.pill-rev { background: #ECEDEF; color: var(--ink-2); }
.empty { padding: 40px 0; color: var(--ink-2); }

/* ---------- محرر القيد ---------- */
.entry { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px 22px; position: relative; }
.entry-top { display: flex; gap: 24px; align-items: flex-start; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.entry-head { flex: 1; display: grid; grid-template-columns: 220px 160px 170px 1fr; gap: 12px; }
.entry.is-ro .entry-head { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.lines { width: 100%; border-collapse: collapse; margin-top: 4px; }
.lines th { font-size: .8rem; color: var(--ink-2); font-weight: 500; text-align: start; padding: 10px 6px 6px; border-bottom: 1px solid var(--rule-strong); }
.lines td { padding: 5px 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.lines td.c-amt, .lines th.c-amt { width: 150px; border-inline-start: 1px solid var(--rule); }
.lines .c-acc { width: 220px; }
.lines .c-tier { width: 210px; }
.lines .c-act { width: 60px; white-space: nowrap; }
.lines input, .lines select { width: 100%; }
.lines input.amt { text-align: end; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.lines input.acc { font-family: var(--font-num); font-weight: 600; }
.ro-field { display: grid; gap: 2px; }
.ro-field span { font-size: .8rem; color: var(--ink-2); }
.ro-field strong { font-weight: 500; }
.acc-hint { font-size: .75rem; color: var(--ink-2); padding: 2px 2px 0; line-height: 1.35; }
.acc-name { color: var(--ink-2); }
.lines tfoot th, .lines tfoot td { padding: 10px 6px; font-weight: 600; border-top: 3px double var(--rule-strong); }
.lines tfoot .num { padding-inline-end: 16px; }
.lines tr.diff th, .lines tr.diff td { color: var(--red); background: var(--red-soft); border-top: 0; font-weight: 500; }
.entry-actions { display: flex; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
.entry-actions .btn-danger-ghost { margin-inline-start: auto; }
.tpl-pick { min-width: 260px; }

/* الختم: العنصر الوحيد البارز في المنصة */
.seal { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 170px; }
.seal-ring { width: 132px; height: 132px; border-radius: 50%; border: 3px solid var(--stamp); outline: 1px dashed var(--stamp); outline-offset: -10px; color: var(--stamp); display: grid; place-content: center; text-align: center; transform: rotate(-7deg); opacity: .92; mix-blend-mode: multiply; }
.seal-num { font: 600 .82rem/1.2 var(--font-num); letter-spacing: .02em; }
.seal-word { font: 700 1.15rem/1.4 var(--font-head); }
.seal-date { font: 500 .78rem/1.2 var(--font-num); }
.seal-meta { font-size: .74rem; color: var(--ink-2); text-align: center; line-height: 1.5; }
.hash { font-family: var(--font-num); font-size: .72rem; word-break: break-all; direction: ltr; }

/* ---------- الوضعية ---------- */
.sheet { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.sheet-col { padding: 18px 20px; }
.sheet-col + .sheet-col { border-inline-start: 1px solid var(--rule); }
.sheet-col h2 { font-size: .95rem; color: var(--ink-2); font-weight: 500; margin-bottom: 8px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: start; font-weight: 400; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.kv td { padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 1.05rem; }
.kv-total th, .kv-total td { border-bottom: 0; border-top: 3px double var(--rule-strong); font-weight: 600; font-size: 1.15rem; }
.months { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(12, 1fr); border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.months li { padding: 10px 8px; display: grid; gap: 2px; border-inline-start: 1px solid var(--rule); font-size: .85rem; }
.months li:first-child { border-inline-start: 0; }
.months li small { color: var(--ink-3); font-size: .74rem; }
.months li.is-closed { background: var(--ledger-soft); }
.months li.is-closed small { color: var(--ledger); }
.todo { margin: 0; padding: 0; list-style: none; }
.todo li { padding: 9px 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 6px; }
.todo li.warn { background: var(--amber-soft); border-color: #EAD6AE; color: var(--amber); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.warn-inline { color: var(--amber); font-size: .85rem; }

/* ---------- الإقفال ---------- */
.period-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.period-list li { display: grid; grid-template-columns: 160px 1fr auto; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--rule); align-items: center; }
.period-list li:last-child { border-bottom: 0; }
.period-list li.is-closed { background: var(--ledger-soft); }
.p-name { font-family: var(--font-head); font-weight: 600; }
.p-meta { color: var(--ink-2); font-size: .88rem; }
.p-state { font-size: .85rem; color: var(--ledger); }

/* ---------- تبويبات ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule-strong); margin-bottom: 14px; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ledger-deep); border-color: var(--ledger); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---------- نوافذ وإشعارات ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(23, 33, 28, .38); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; padding: 22px 24px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(23, 33, 28, .25); }
.modal-wide { width: min(820px, 100%); }
.modal p { margin: 0 0 12px; }
.toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .25s; z-index: 60; max-width: min(640px, 90vw); font-size: .92rem; }
html[dir="rtl"] .toast { transform: translate(50%, 20px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
html[dir="rtl"] .toast.show { transform: translate(50%, 0); }
.toast-err { background: var(--red); }

/* ---------- التأسيس ---------- */
.setup { max-width: 760px; margin: 60px auto; padding: 0 20px; grid-column: 1 / -1; }
.setup h1 { margin: 18px 0 6px; font-size: 1.9rem; }
.setup > p { margin: 0 0 24px; }

/* ---------- الطباعة ---------- */
.print-head { display: none; }
.certify { margin-top: 18px; padding: 14px 16px; border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); font-size: .9rem; }
.certify .sign { display: flex; justify-content: space-between; margin-top: 30px; color: var(--ink-2); font-size: .82rem; }
@media print {
  .side, .no-print, .filters, .entry-actions, .back, .tpl-pick, #addLine, .c-act { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  body { background: #fff; font-size: 11px; }
  .print-head { display: block; margin-bottom: 12px; border-bottom: 1px solid #000; padding-bottom: 8px; }
  .print-head h2 { margin-top: 8px; font-size: 14px; }
  .grid thead th { position: static; }
  .grid, .entry { border-color: #999; }
  .page-head .row { display: none; }
}

/* ---------- الشاشات الصغيرة ---------- */
@media screen and (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group { margin: 0; display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-title { display: none; }
  .main { padding: 18px 16px 48px; }
  .entry-top { flex-direction: column; }
  .entry-head { grid-template-columns: 1fr 1fr; width: 100%; }
  .seal { width: auto; flex-direction: row; }
  .sheet { grid-template-columns: 1fr; }
  .sheet-col + .sheet-col { border-inline-start: 0; border-top: 1px solid var(--rule); }
  .months { grid-template-columns: repeat(6, 1fr); }
  .grid { display: block; overflow-x: auto; }
  .lines-wrap { overflow-x: auto; }
  .lines { min-width: 860px; }
  .filters .batch { margin-inline-start: 0; border: 0; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- إضافات النسخة الثانية ---------- */
.intro { color: var(--ink-2); margin: 6px 0 0; max-width: 70ch; }
.demo-badge { margin: 12px 8px 0; padding: 4px 10px; border-radius: 10px; background: #F3D98B; color: #4A3507; font-size: .78rem; font-weight: 600; justify-self: start; width: fit-content; }
.co-pick { margin: 12px 8px 0; }
.hint-box { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 16px; margin: 0 0 20px; background: var(--surface); border: 1px dashed var(--rule-strong); border-radius: var(--radius); }
.hint-box p { margin: 0; color: var(--ink-2); max-width: 60ch; }
.setup .hint-box { margin-top: 28px; }
.chart-box { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 14px 6px; margin-top: 10px; }
.chart { width: 100%; height: auto; display: block; }
.chart .gridline { stroke: var(--rule); stroke-width: 1; }
.chart .bar-rev { fill: var(--ledger); }
.chart .bar-exp { fill: #C3CCC6; }
.chart .axis { fill: var(--ink-2); font: 12px var(--font); }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--ink-2); }
.lg::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 6px; vertical-align: -1px; }
.lg-rev::before { background: var(--ledger); }
.lg-exp::before { background: #C3CCC6; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; }
.two-col .block h2 { margin-bottom: 0; }
.two-col .row-between { margin-bottom: 10px; }
.grid.compact td { padding: 8px 10px; }
.ops { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.op { display: grid; gap: 6px; align-content: start; padding: 16px 18px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); color: var(--ink); min-height: 104px; border-inline-start: 3px solid var(--ledger); }
.op:hover { text-decoration: none; border-color: var(--ledger); background: #FBFCFA; }
.op-t { font: 600 1.02rem/1.4 var(--font-head); }
.op-d { color: var(--ink-2); font-size: .87rem; line-height: 1.5; }
.op-manual { border-inline-start-color: var(--ink-3); background: transparent; }
.tpl-note { margin: 14px 0 0; padding: 9px 12px; background: var(--ledger-soft); color: var(--ledger-deep); border-radius: var(--radius); font-size: .9rem; }
.form-grid .full { grid-column: 1 / -1; margin: 0; }
.form-grid small { font-size: .74rem; }
@media screen and (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- النسخة الثالثة: الوحدات والوثائق ---------- */
.btn-new { margin: 14px 0 4px; justify-content: center; background: #F3D98B; border-color: #F3D98B; color: #3D2C05; font-weight: 600; }
.btn-new:hover, .btn-new.active { background: #F7E4A9; border-color: #F7E4A9; }
.side nav { padding-top: 6px; }
.pill-info { background: #E8EEF8; color: #2D4B86; }
.pill-bad { background: var(--red-soft); color: var(--red); }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 16px; }
.stat-row > div { padding: 12px 16px; display: grid; gap: 2px; }
.stat-row > div + div { border-inline-start: 1px solid var(--rule); }
.stat-row span { color: var(--ink-2); font-size: .82rem; }
.stat-row strong { font: 600 1.15rem var(--font-num); font-variant-numeric: tabular-nums; }
.doc-edit { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px 22px; display: grid; gap: 14px; }
.doc-edit > .full { display: grid; }
.row.nowrap { flex-wrap: nowrap; }
.row .grow, select.grow { flex: 1; min-width: 0; }
.inv-lines .c-qty { width: 90px; }
.lines .c-rate { width: 96px; }
.lines .c-acc2 { width: 240px; }
.totals-box { justify-self: end; width: min(360px, 100%); }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.file-chip { padding: 5px 10px; border: 1px solid var(--rule-strong); border-radius: 14px; font-size: .85rem; background: var(--paper); }
.file-btn { cursor: pointer; display: inline-flex; }
.clip { font-size: .9rem; }
.small { font-size: .8rem; }
.cards-accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 14px; }
.acct { display: grid; gap: 4px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); color: var(--ink); }
.acct:hover { border-color: var(--ledger); text-decoration: none; }
.acct strong { font: 600 1.35rem var(--font-num); font-variant-numeric: tabular-nums; }
.acct-name { color: var(--ink-2); }
.month-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.month-tabs a { padding: 5px 11px; border-radius: 14px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2); font-size: .85rem; }
.month-tabs a.active { background: var(--ledger); border-color: var(--ledger); color: #fff; }
.month-tabs a:hover { text-decoration: none; border-color: var(--ledger); }
.decl { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.decl section { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; }
.decl h2 { margin-bottom: 10px; }
.decl .kv th { font-weight: 400; }
.inline-label { display: flex; gap: 6px; align-items: center; }
.fin-title { margin: 22px 0 8px; }
.grid.fin td:first-child { min-width: 320px; }
.grid tr.grp-row th { background: var(--paper); color: var(--ledger-deep); font-family: var(--font-head); }
.pay-list { max-width: 560px; margin-bottom: 16px; }

/* الوثيقة A4 (فاتورة، كشف راتب، تقرير) */
.doc-stage { background: #E9ECE8; border-radius: var(--radius); padding: 28px; overflow-x: auto; }
.a4 { background: #fff; color: #111; width: 210mm; min-height: 297mm; margin: 0 auto; padding: 16mm 14mm; box-shadow: 0 2px 14px rgba(23, 33, 28, .12); font-size: 12.5px; line-height: 1.55; }
.invoice-doc .inv-head, .payslip-doc .inv-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 14px; border-bottom: 2px solid var(--ledger-deep); }
.inv-company { font: 700 17px var(--font-head); color: var(--ledger-deep); }
.inv-company.small { font-size: 14px; color: #111; }
.ids { color: #555; font-family: var(--font-num); font-size: 11.5px; direction: ltr; text-align: end; unicode-bidi: plaintext; }
.inv-title { text-align: end; min-width: 220px; }
.inv-word { font: 700 24px var(--font-head); color: var(--ledger-deep); line-height: 1.2; }
.inv-word span { display: block; font: 600 12px var(--font-num); letter-spacing: .12em; color: #555; }
.inv-meta { margin-top: 10px; margin-inline-start: auto; border-collapse: collapse; font-size: 12px; }
.inv-meta th { font-weight: 500; color: #555; text-align: start; padding: 2px 0 2px 12px; }
.inv-meta td { padding: 2px 0; font-weight: 600; }
.inv-buyer { margin: 16px 0; padding: 12px 14px; border: 1px solid #D5DAD6; border-radius: 6px; max-width: 60%; }
.lbl { color: #666; font-size: 11px; margin-bottom: 2px; }
.inv-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.inv-table th { background: var(--ledger-deep); color: #fff; font-weight: 500; font-size: 11.5px; padding: 7px 8px; text-align: start; }
.inv-table th.num { text-align: end; }
.inv-table td { padding: 8px; border-bottom: 1px solid #E2E6E3; vertical-align: top; }
.inv-bottom { display: flex; justify-content: space-between; gap: 24px; margin-top: 16px; align-items: flex-start; }
.inv-words { flex: 1; }
.inv-words p { margin: 0 0 8px; font-weight: 500; }
.inv-totals { border-collapse: collapse; min-width: 260px; }
.inv-totals th { text-align: start; font-weight: 400; padding: 6px 10px 6px 0; color: #444; }
.inv-totals td { padding: 6px 0; font-weight: 600; }
.inv-totals tr.grand th, .inv-totals tr.grand td { border-top: 2px solid var(--ledger-deep); font-size: 14px; color: var(--ledger-deep); padding-top: 9px; }
.inv-foot { margin-top: 48px; display: flex; justify-content: flex-end; color: #666; font-size: 11.5px; }
.inv-foot > div { border-top: 1px solid #999; padding-top: 6px; min-width: 200px; text-align: center; }
.inv-foot.two { justify-content: space-between; }
.report-doc { min-height: 0; }
.report-doc .grid { font-size: 11px; }

body.print-mode { background: #fff; }
.print-main { padding: 0; }
body.print-mode .a4 { box-shadow: none; width: auto; min-height: 0; padding: 0; margin: 0; }
body.print-mode .print-head { display: block; }

@page { size: A4; margin: 14mm 12mm 16mm; @bottom-center { content: counter(page) " / " counter(pages); font-size: 9px; color: #777; } }
@media print {
  .doc-stage { background: none; padding: 0; }
  .a4 { box-shadow: none; width: auto; min-height: 0; padding: 0; }
  .grid tr.clickable:hover td { background: none; }
  .month-tabs, .tabs, .stat-row, .hint-box, .intro { display: none !important; }
  .decl { grid-template-columns: 1fr 1fr; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
}
@media screen and (max-width: 980px) {
  .stat-row { grid-template-columns: 1fr 1fr; }
  .decl { grid-template-columns: 1fr; }
  .doc-stage { padding: 10px; }
}

/* ---------- v4: الدائنون والمدينون ---------- */
.debts-sum > a { padding: 12px 16px; display: grid; gap: 2px; color: inherit; text-decoration: none; border-inline-start: 1px solid var(--rule); }
.debts-sum > a:first-child { border-inline-start: 0; }
.debts-sum > a.on { box-shadow: inset 0 -3px 0 var(--ledger); }
.debts-sum > a:hover { background: var(--paper); }
.debts-sum > div:first-of-type { border-inline-start: 1px solid var(--rule); }
.debts-sum small { font-size: .78rem; }
.stat-row small { display: block; }
.debts-bar { margin-bottom: 10px; gap: 12px; flex-wrap: wrap; align-items: center; }
.debts-bar .tabs { margin-bottom: 0; }
label.inline { display: inline-flex; gap: 8px; align-items: center; font-size: .88rem; color: var(--ink-2); }
.aging-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 6px 0 8px; }
.aging-bar span { min-width: 4px; }
.aging-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .82rem; color: var(--ink-2); margin-bottom: 14px; }
.aging-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.ab-notDue { background: var(--ledger); } .ab-d30 { background: #7FA392; } .ab-d60 { background: #E3BE57; }
.ab-d90 { background: #D9822B; } .ab-over90 { background: #B3261E; } .ab-noDoc { background: #8C8FA8; }
table.aging th, table.aging td { white-space: nowrap; }
table.aging td:first-child { white-space: normal; min-width: 180px; }
.row-act { white-space: nowrap; text-align: end; }
.row-act > * + * { margin-inline-start: 6px; }
.sub-h { font-size: 1rem; margin: 22px 0 8px; }
.st-party { display: grid; gap: 4px; padding: 12px 16px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); margin-bottom: 14px; }
.st-name { font-size: 1.15rem; }
@media screen and (max-width: 980px) { .table-scroll-x, table.aging { display: block; overflow-x: auto; } }
@media print { .aging-bar span, .aging-legend i { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
@media print { table.aging th, table.aging td { white-space: normal; font-size: 8.5pt; padding: 4px 5px; } table.aging td:first-child { min-width: 0; } }
.print-mode table.aging th, .print-mode table.aging td { white-space: normal; font-size: 8.5pt; padding: 4px 5px; }
.print-mode table.aging td:first-child { min-width: 0; }
