:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e2e8e5;
  --text: #15201c;
  --muted: #64716c;
  --primary: #0f766e;
  --primary-600: #0b5f58;
  --primary-50: #e7f4f2;
  --side: #0f1f1c;
  --side-text: #c4d3ce;
  --danger: #b42318;
  --danger-50: #fdeceb;
  --warn: #a15c07;
  --warn-50: #fff4e2;
  --ok: #067647;
  --ok-50: #e6f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 3px rgba(16, 24, 20, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-bottom: 12px; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- التخطيط ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; }
.brand b { display: block; color: #fff; font-size: 18px; }
.brand small { color: var(--side-text); font-size: 12px; }
.brand.dark b { color: var(--text); }
.brand.dark small { color: var(--muted); }
.logo {
  width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section { font-size: 11px; color: #7f938d; padding: 14px 10px 4px; font-weight: 600; }
.sidebar nav a { color: var(--side-text); text-decoration: none; }
.nav-link, .nav-group-head {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px;
  color: var(--side-text); background: none; border: 0; font: inherit; cursor: pointer; text-align: right;
}
.nav-link:hover, .nav-group-head:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-ico { width: 19px; height: 19px; flex-shrink: 0; opacity: .9; }
.nav-chev { width: 16px; height: 16px; margin-inline-start: auto; transition: transform .2s; opacity: .7; }
.nav-group.open .nav-chev { transform: rotate(180deg); }
.nav-group.has-active > .nav-group-head { color: #fff; }
.nav-items { display: none; background: rgba(255, 255, 255, .045); border-radius: 8px; margin: 2px 0 6px; padding: 4px; }
.nav-group.open .nav-items { display: block; }
.nav-item { display: flex; align-items: center; border-radius: 6px; }
.nav-item > a:first-child { flex: 1; padding: 7px 8px; padding-inline-start: 36px; border-radius: 6px; font-size: 13.5px; }
.nav-item:hover > a:first-child { color: #fff; }
.nav-item.active > a:first-child { background: var(--primary); color: #fff; }
.nav-add {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 6px;
  font-size: 19px; line-height: 1; opacity: .65;
}
.nav-add:hover { opacity: 1; color: #fff !important; background: rgba(255, 255, 255, .1); }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .1); padding: 14px 6px 0; margin-top: 14px; }
.sidebar-foot .who b { display: block; color: #fff; font-weight: 500; }
.sidebar-foot .who small { color: var(--side-text); }
.link { background: none; border: 0; color: #f3a29a; padding: 6px 0 0; cursor: pointer; font: inherit; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
#view { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }
.banner { padding: 10px 28px; font-size: 13px; }
.banner.warn { background: var(--warn-50); color: var(--warn); }
.banner.danger { background: var(--danger-50); color: var(--danger); }
.banner.ok { background: var(--ok-50); color: var(--ok); }
.banner a { font-weight: 600; margin-inline-start: 6px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }

/* ---------- العناصر ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--danger-50); color: var(--danger); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
input[type=number] { direction: ltr; text-align: right; }
textarea { min-height: 70px; resize: vertical; }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border); background: var(--surface-2); }
.table .num { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--primary-50); }
.table tr.group td { font-weight: 600; background: var(--surface-2); }
.table tr.subtotal td { font-weight: 600; border-top: 1px solid var(--text); }
.table td.actions-cell { text-align: left; white-space: nowrap; }
.table.compact th, .table.compact td { padding: 6px 8px; }
.table input, .table select { padding: 6px 8px; }

/* ترويسة التقارير */
.report-head { text-align: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid var(--primary); }
.report-company { font-size: 18px; font-weight: 700; }
.report-title { font-size: 20px; font-weight: 700; color: var(--primary); margin-top: 2px; }
.report-period { color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.report-period span { margin-inline-start: 6px; }
.report-filter { margin-top: 6px; font-size: 12.5px; color: var(--warn); }
.btn-ico { width: 16px; height: 16px; }

/* كل التقارير */
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.report-card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text);
}
.report-card:hover { border-color: var(--primary); text-decoration: none; box-shadow: 0 0 0 3px var(--primary-50); }
.report-card b { font-size: 16px; }
.report-card span { color: var(--muted); font-size: 13px; }
.report-card-ico { width: 28px; height: 28px; color: var(--primary); }

/* ميزان المراجعة: لوحة التصفية */
.tb-filters { background: var(--side); color: #dfe9e6; border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; display: flex; flex-direction: column; gap: 12px; }
.tb-filters label { color: #b9cbc6; }
.tb-filters input, .tb-filters select { background: #fff; }
.tb-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.tb-row > label { min-width: 150px; flex: 1; }
.tb-row > label.switch { flex: 0 1 auto; min-width: 0; }
.switch { flex-direction: row !important; align-items: center; gap: 8px !important; cursor: pointer; color: #dfe9e6 !important; padding-bottom: 8px; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: #52625e; position: relative; flex-shrink: 0; transition: background .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: right .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { right: 19px; }
.multi { position: relative; }
.multi summary { list-style: none; cursor: pointer; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.multi summary::after { content: '▾'; float: left; color: var(--muted); }
.multi-panel {
  position: absolute; z-index: 20; inset-inline: 0; top: calc(100% + 4px); background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; max-height: 260px; overflow: auto; box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
}
.multi-panel .check { color: var(--text); padding: 4px 2px; }
.multi-search { margin-bottom: 6px; }

/* ميزان المراجعة: الجدول */
.tb-table th { text-align: center; }
.tb-table thead tr:first-child th { background: var(--side); color: #fff; border-inline: 1px solid rgba(255, 255, 255, .12); }
.tb-table thead tr:nth-child(2) th { background: var(--primary); color: #fff; font-size: 12px; }
.tb-table th.tb-acc { min-width: 260px; text-align: right; vertical-align: middle; }
.tb-table td.num { font-size: 13px; }
.tb-table .zero { color: #b8c2bf; }
.tb-header td { font-weight: 700; color: var(--primary); background: var(--surface-2); }
.tb-subtotal td { font-weight: 700; background: #f2f9f7; border-top: 1.5px solid var(--text); }
.tb-group td { font-weight: 700; }
.tb-party td { color: var(--muted); font-size: 12.5px; font-style: italic; }
.tb-table tfoot td { background: var(--side) !important; color: #fff; font-size: 14px; }
.tb-status { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-weight: 600; }
.tb-status.ok { background: var(--ok-50); color: var(--ok); }
.tb-status.bad { background: var(--danger-50); color: var(--danger); }
.tb-status.info { background: var(--warn-50); color: var(--warn); }

/* خيار التسجيل في الضريبة */
.vat-choice { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { flex-direction: row; cursor: pointer; }
.seg input { display: none; }
.seg span {
  flex: 1; text-align: center; padding: 10px; border: 1.5px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface);
}
.seg input:checked + span { border-color: var(--primary); background: var(--primary-50); color: var(--primary); font-weight: 700; }

/* الضريبة */
.vat-choice-card { padding: 28px; }
.vat-choice-card b { font-size: 19px; }
.sub-tabs { border-bottom: 0; margin-top: -8px; }
.sub-tabs a { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-inline-end: 6px; padding: 7px 14px; }
.sub-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 0; }
.sheet-tabs button {
  border: 1px solid var(--border); border-bottom: 0; background: var(--surface-2); color: var(--muted); font: inherit;
  padding: 8px 16px; border-radius: 8px 8px 0 0; cursor: pointer;
}
.sheet-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.vat-form td:first-child { max-width: 520px; }
.vat-form td.num { width: 160px; }

/* شجرة الحسابات */
.acc-tree td { vertical-align: middle; }
.tree-toggle {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--primary); font-weight: 700; cursor: pointer; margin-inline-end: 8px; line-height: 1; font-size: 15px;
}
.tree-toggle:hover { background: var(--primary-50); border-color: var(--primary); }
.tree-leaf { display: inline-block; width: 32px; }
.acc-root { font-weight: 700; font-size: 15px; }
.acc-group > td:first-child { font-weight: 600; }
tr.depth-0 td { background: var(--surface-2); }
.acc-desc { color: var(--muted); font-size: 12.5px; max-width: 340px; }

/* حقل التاريخ بالأرقام الإنجليزية */
.date-field { position: relative; display: flex; align-items: center; width: 100%; }
.date-field .date-text { padding-left: 36px; font-variant-numeric: tabular-nums; text-align: right; }
.date-field input[type=date] { position: absolute; left: 4px; bottom: 0; width: 28px; height: 100%; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.date-field .date-btn {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px;
  display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 6px;
}
.date-field .date-btn:hover:not(:disabled) { background: var(--primary-50); color: var(--primary); }
.date-field .date-btn svg { width: 17px; height: 17px; }
.date-field .date-btn:disabled { opacity: .4; cursor: default; }

/* القيد اليدوي: بحث الحساب واختيار الطرف */
input.invalid { border-color: var(--danger); background: var(--danger-50); }
.party-box { display: flex; gap: 4px; align-items: center; }
.party-input:disabled { background: var(--surface-2); }
.icon-btn.add { color: var(--primary); font-size: 20px; }
.icon-btn.add:hover { background: var(--primary-50); color: var(--primary); }

/* أزرار الخيارات بالأيقونات */
.icon-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-action {
  width: 38px; height: 34px; display: inline-grid; place-items: center; padding: 0;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-action svg { width: 18px; height: 18px; }
.icon-action:hover { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.icon-action.danger:hover { background: var(--danger-50); border-color: var(--danger); color: var(--danger); }
#print-area { display: none; }

/* نافذة الاستيراد */
.import-steps { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 6px 4px 18px; }
.import-step { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.import-step svg { width: 26px; height: 26px; color: var(--primary); flex-shrink: 0; }
.import-step a { text-decoration: underline; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 16px; cursor: pointer;
  border-block: 1.5px dashed var(--border); background: var(--surface-2); color: var(--text); text-align: center;
}
.dropzone svg { width: 54px; height: 54px; color: var(--primary); }
.dropzone b { font-size: 15px; }
.dropzone.over, .dropzone:hover { background: var(--primary-50); border-color: var(--primary); }
#importResult { margin-top: 14px; }
.import-errors { background: var(--danger-50); color: var(--danger); border-radius: 8px; padding: 12px 14px; }
.import-errors ul { margin: 6px 0; padding-inline-start: 20px; max-height: 220px; overflow: auto; }
.import-errors .unbalanced { background: #fff; border: 1px solid var(--danger); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.import-ok { background: var(--ok-50); color: var(--ok); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 60px; text-align: center; }
.signatures div { border-top: 1px solid var(--text); padding-top: 8px; color: var(--muted); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-50); color: var(--ok); }
.badge.warn { background: var(--warn-50); color: var(--warn); }
.badge.danger { background: var(--danger-50); color: var(--danger); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty.error { color: var(--danger); }
.empty p { margin: 0 0 12px; }

/* ---------- لوحة التحكم ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi b { font-size: 21px; font-variant-numeric: tabular-nums; }
.kpi small { margin-inline-start: 4px; }

.chart { display: flex; align-items: flex-end; gap: 12px; height: 190px; padding-top: 8px; }
.chart .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.chart .bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.chart .bar { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar.s { background: var(--primary); }
.chart .bar.p { background: #c9a227; }
.chart .lbl { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }

/* ---------- نموذج الفاتورة ---------- */
.lines-table td { padding: 6px 6px; }
.lines-table td:first-child { min-width: 160px; }
.lines-table .line-total { min-width: 100px; }
.totals { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals table { min-width: 300px; border-collapse: collapse; }
.totals td { padding: 6px 10px; }
.totals td:last-child { text-align: left; font-variant-numeric: tabular-nums; }
.totals tr.grand td { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text); }
.diff-bad { color: var(--danger); }
.diff-ok { color: var(--ok); }

/* ---------- الفاتورة المطبوعة ---------- */
.paper { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); margin-bottom: 18px; }
.paper-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 18px; margin-bottom: 18px; }
.paper-head .title h2 { color: var(--primary); font-size: 22px; margin-bottom: 6px; }
.paper-head .qr { width: 130px; height: 130px; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.parties > div { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.parties h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- التبويبات ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- الباقات ---------- */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.plan { border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.plan.current { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-50); }
.plan .price { font-size: 30px; font-weight: 700; }
.plan .price small { font-size: 14px; font-weight: 400; }
.plan ul { margin: 0; padding-inline-start: 18px; color: var(--muted); }
.plan { position: relative; }
.plan.popular { border-color: var(--primary); border-width: 2px; }
.plan-flag { position: absolute; top: -12px; inset-inline-start: 18px; background: var(--primary); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 999px; }
.plan .old-price { color: var(--muted); font-size: 14px; }
.cycle-switch { display: inline-flex; gap: 4px; padding: 4px; margin: 4px 0 18px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.cycle-switch button { border: 0; background: none; padding: 7px 22px; border-radius: 999px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.cycle-switch button.on { background: var(--primary); color: #fff; }
.pricing-page { min-height: 100vh; padding: 20px 16px 48px; max-width: 1100px; margin: 0 auto; }
.pricing-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 26px; }
.pricing-head .actions { display: flex; gap: 8px; }
.pricing-hero { text-align: center; margin-bottom: 26px; }
.pricing-hero h1 { margin: 0 0 8px; font-size: 30px; }
.pricing-hero p { max-width: 620px; margin: 0 auto 14px; }

/* ---------- الحوارات والتنبيهات ---------- */
dialog.dlg { border: 0; border-radius: 14px; padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog.dlg.wide { width: min(860px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgba(10, 20, 17, .45); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); }

/* ---------- صفحات الدخول ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #e7f4f2, var(--bg) 60%); }
.auth-card { background: var(--surface); width: min(420px, 100%); padding: 28px; border-radius: 16px; box-shadow: 0 10px 40px rgba(15, 31, 28, .12); }
.auth-card h2 { margin: 6px 0 18px; }

/* ---------- الجوال ---------- */
@media (max-width: 900px) {
  .grid-2, .parties { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; z-index: 50; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: -10px 0 40px rgba(0, 0, 0, .3); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 40; }
  .menu-btn { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  #view { padding: 18px 16px 40px; }
  .banner { padding: 10px 16px; }
  .paper { padding: 18px; }
  .paper-head { flex-wrap: wrap; }
}

/* ---------- الطباعة ---------- */
@media print {
  body { background: #fff; }
  /* طباعة التقارير: ألوان العناوين والمجاميع تظهر في PDF */
  body.printing-report .tb-table th, body.printing-report .tb-table tfoot td,
  body.printing-report .tb-subtotal td, body.printing-report .tb-header td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.printing-report .table-wrap { overflow: visible; }
  body.printing-report .page-head, body.printing-report .tb-status.info { display: none; }
  body.printing-report .tb-table { font-size: 10px; }
  body.printing-report .tb-table td, body.printing-report .tb-table th { padding: 4px 6px; }
  /* طباعة سند قيد واحد فقط */
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; }
  .sidebar, .topbar, #banner, .no-print, .toast { display: none !important; }
  #view { padding: 0; max-width: none; }
  .paper, .card { border: 0; box-shadow: none; padding: 0; }
  .table th { background: #f1f1f1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.nav-badge { display: inline-block; margin-inline-start: 6px; font-size: 10px; font-weight: 700; color: #b54708; background: #fffaeb; border: 1px solid #fec84b; border-radius: 6px; padding: 0 6px; vertical-align: middle; }

.inv-head { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 20px; align-items: start; }
.contact-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: var(--surface-2); }
@media (max-width: 860px) { .inv-head { grid-template-columns: 1fr; } }

.voucher-amount { display: inline-flex; gap: 14px; align-items: center; border: 2px solid var(--primary); border-radius: 10px; padding: 8px 18px; margin: 4px 0 18px; }
.voucher-amount span { color: var(--muted); }
.voucher-amount b { font-size: 22px; direction: ltr; }
.voucher-kv { font-size: 15px; gap: 10px 18px; }

.num-input { text-align: right; font-variant-numeric: tabular-nums; }

.pdf-box { width: 800px; background: #fff; direction: rtl; }
.pdf-box .paper { box-shadow: none; border: 0; }

/* الشريط العلوي على الشاشات الكبيرة + لوحة آخر النشاطات */
@media (min-width: 901px) {
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40; }
  .topbar .menu-btn { display: none; }
  .topbar-title { color: var(--text); }
}
.activity-btn { margin-inline-start: auto; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.activity-btn svg { width: 18px; height: 18px; }
.activity-btn:hover { border-color: var(--primary); color: var(--primary); }
.activity-panel { position: fixed; top: 58px; left: 16px; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 80px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 18px 50px rgba(0, 0, 0, .18); z-index: 60; }
.activity-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.activity-head b { margin-inline-end: auto; }
.activity-list { list-style: none; margin: 0; padding: 4px 0; }
.activity-list li { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; line-height: 1.7; }
.activity-list li small { display: block; color: var(--muted); font-size: 11px; }
.activity-avatar { flex: 0 0 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.activity-avatar.ok { background: var(--ok-50); color: var(--ok); }
.activity-avatar.warn { background: var(--warn-50); color: var(--warn); }
.activity-avatar.danger { background: var(--danger-50); color: var(--danger); }
