/* وافي للتقسيط — واجهة البرنامج */
:root {
  --bg: #f3f5f4; --panel: #fff; --ink: #18231f; --muted: #6a7a74; --line: #e2e8e5; --line-2: #d3dcd8;
  --brand: #0d6b55; --brand-2: #0a5544; --brand-soft: #e4f1ec; --brand-ink: #083d31;
  --side: #10302a; --side-2: #173d36; --side-ink: #c9dad4;
  --accent: #b7791f; --accent-soft: #fdf3e1;
  --ok: #1a7a49; --ok-bg: #e5f4ec; --warn: #95600a; --warn-bg: #fff3da; --bad: #b42318; --bad-bg: #fdecea;
  --done: #2f5bb0; --done-bg: #e8eefb; --early: #6b3fa0; --early-bg: #f1eafa;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 40, 34, .05), 0 1px 3px rgba(16, 40, 34, .06);
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
body.app { background: linear-gradient(to left, var(--side) 250px, var(--bg) 250px); display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 60px 1fr; min-height: 100vh; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 23px; margin: 0 0 4px; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 16.5px; margin: 24px 0 10px; font-weight: 700; color: var(--brand-ink); }
svg.ic { width: 19px; height: 19px; flex: none; }

/* الشريط العلوي */
.topbar { grid-column: 1 / -1; display: flex; gap: 18px; align-items: center; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 18px; position: sticky; top: 0; z-index: 40; box-shadow: var(--shadow); }
.topbar .brand { display: flex; align-items: center; gap: 10px; color: var(--brand-ink); font-weight: 700; font-size: 21px; white-space: nowrap; min-width: 200px; }
.topbar .brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; }
.login-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #149174);
  color: #fff; font-size: 21px; font-weight: 700; box-shadow: 0 2px 6px rgba(13, 107, 85, .35); }
.topbar .quick { flex: 1; max-width: 520px; position: relative; }
.topbar .quick input { width: 100%; border: 1px solid var(--line-2); background: #f6f8f7; border-radius: 10px; padding: 8px 38px 8px 12px; font: inherit; }
.topbar .quick input:focus { background: #fff; }
.quick-ic { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.topbar .who { margin-inline-start: auto; display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.today { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.today .clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; direction: ltr; }
.today small { color: var(--muted); font-size: 12px; }
.topbar .user { display: flex; align-items: center; gap: 8px; color: var(--ink); line-height: 1.2; }
.topbar .user:hover { text-decoration: none; }
.topbar .user b { display: block; font-size: 14px; }
.topbar .user small { color: var(--muted); font-size: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.icon-btn { background: transparent; border: 1px solid var(--line-2); color: var(--muted); border-radius: 10px; padding: 7px; }
.icon-btn:hover { background: var(--bad-bg); color: var(--bad); border-color: #f3c7c2; }

/* القائمة الجانبية */
nav.side { background: var(--side); padding: 14px 10px 24px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; }
nav.side a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--side-ink); font-size: 14.5px; }
nav.side a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
nav.side a.active { background: var(--brand); color: #fff; box-shadow: inset 3px 0 0 #5fd3b1; }
nav.side .label { flex: 1; }
nav.side kbd { font: 600 10.5px/1.6 'Segoe UI', Tahoma, sans-serif; color: #8fb0a6; border: 1px solid #2c534b; border-radius: 5px; padding: 0 5px; direction: ltr; }
nav.side a.active kbd { color: #fff; border-color: rgba(255, 255, 255, .45); }

main { padding: 24px 28px 64px; min-width: 0; }
main.bare { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
body.guest { background: radial-gradient(circle at 20% 10%, #dff0e9, transparent 45%), radial-gradient(circle at 90% 90%, #e6efe9, transparent 40%), var(--bg); }

.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 14px; max-width: 760px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel-title { margin: 0 0 12px; font-size: 16px; }
.panel-title small { font-weight: 400; font-size: 13px; }

/* الأزرار */
.btn, button { font: inherit; font-weight: 500; cursor: pointer; border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 9px; padding: 7px 15px;
  display: inline-flex; gap: 7px; align-items: center; transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover, button:hover { background: var(--brand-2); text-decoration: none; box-shadow: 0 2px 6px rgba(13, 107, 85, .25); }
.btn svg.ic { width: 17px; height: 17px; }
.btn.secondary, button.secondary { background: #fff; color: var(--brand); border-color: var(--line-2); }
.btn.secondary:hover, button.secondary:hover { background: var(--brand-soft); border-color: var(--brand); box-shadow: none; }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.accent:hover { background: #9a6519; }
.btn.small { padding: 4px 12px; font-size: 13.5px; }
.btn.danger, button.danger { background: var(--bad); border-color: var(--bad); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font-weight: 500; box-shadow: none; }
button.link:hover { text-decoration: underline; background: none; }
button[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; }
form.inline { display: inline; }

/* النماذج */
.grid { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide, .grid > .wide { grid-column: 1 / -1; }
.field.grow { flex: 1; min-width: 260px; }
.field label { font-size: 13px; color: #4b5b55; font-weight: 500; }
.field .req { color: var(--bad); font-weight: 700; }
input, select, textarea { font: inherit; border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 11px; background: #fff; color: inherit; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13, 107, 85, .15); }
input[type=file] { padding: 6px; background: #f8faf9; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); background: var(--bad-bg); }
.error { color: var(--bad); font-size: 12.5px; }
.hint { color: var(--muted); font-size: 12.5px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; accent-color: var(--brand); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px 18px; margin: 0 0 16px; background: var(--panel); box-shadow: var(--shadow); }
legend { font-weight: 700; padding: 2px 10px; background: var(--brand-soft); color: var(--brand-ink); border-radius: 99px; font-size: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; flex-wrap: wrap; }
.radios { display: flex; gap: 6px 10px; flex-wrap: wrap; padding: 2px 0; }
.radio { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; border: 1px solid var(--line-2); border-radius: 9px; padding: 6px 12px; background: #fff; }
.radio:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); font-weight: 500; }
.radio input { width: auto; accent-color: var(--brand); margin: 0; }

/* الجداول */
table { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 14px; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { background: #f5f8f7; font-weight: 700; font-size: 12.5px; color: #4b5b55; position: sticky; top: 0; white-space: nowrap; }
tbody tr:nth-child(even) td { background: #fbfcfc; }
tbody tr:hover td { background: #f1f7f4; }
tfoot td { font-weight: 700; background: #f3f6f5; border-bottom: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
td.num, th.num { text-align: left; }
.in { color: var(--ok); } .out { color: var(--bad); }
.date small { display: block; color: var(--muted); font-size: 11.5px; }

.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.done { background: var(--done-bg); color: var(--done); }
.badge.early { background: var(--early-bg); color: var(--early); }
.badge.muted { background: #eef1f0; color: #66736e; }

.flash { padding: 11px 16px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid transparent; background: var(--brand-soft); color: var(--brand-ink); }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #c6e6d3; }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: #f5c9c4; }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f3dfb1; }
.flash.early { background: var(--early-bg); color: var(--early); border-color: #ddcdf2; }

/* البطاقات */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.card::before { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); opacity: .55; }
.card.ok::before { background: var(--ok); } .card.bad::before { background: var(--bad); }
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.card .v.small { font-size: 17px; }
.card .muted { font-size: 12.5px; }
.card.bad .v { color: var(--bad); }
.card.ok .v { color: var(--ok); }

dl.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; margin: 0; }
dl.kv div { border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
dl.kv dt { color: var(--muted); font-size: 12.5px; }
dl.kv dd { margin: 0; font-weight: 500; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 160px; }
.muted { color: var(--muted); }
.words { background: var(--brand-soft); border-radius: 9px; padding: 7px 12px; color: var(--brand-ink); font-weight: 500; }
.calc { display: flex; gap: 16px; flex-wrap: wrap; padding: 11px 14px; background: #f5f8f7; border: 1px dashed var(--line-2); border-radius: 9px; margin-top: 14px; font-size: 14px; }
.calc .bad { color: var(--bad); font-weight: 700; }
.calc .good { color: var(--ok); font-weight: 700; }

.login { width: 380px; max-width: 92vw; padding: 30px 28px; }
.login h1 { text-align: center; margin: 10px 0 2px; font-size: 28px; color: var(--brand-ink); }
.login .login-mark { display: grid; margin: 0 auto; width: 56px; height: 56px; font-size: 30px; border-radius: 16px; }
.login .login-sub { text-align: center; margin: 0 0 18px; }
.login .field { margin-bottom: 12px; }
.login .form-actions button { width: 100%; justify-content: center; padding: 10px; }
.pager { display: flex; gap: 14px; justify-content: center; align-items: center; padding: 12px; font-size: 14px; }
.pager a { border: 1px solid var(--line-2); border-radius: 8px; padding: 3px 10px; background: #fff; }
tr.state-paid td { color: var(--muted); }
tr.state-late td, tr.state-partial_late td { background: var(--bad-bg) !important; }
tr.reversed td { text-decoration: line-through; color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.danger-zone { border-color: #f5c9c4; }
.receipt { max-width: 720px; margin: auto; background: #fff; border: 2px solid var(--ink); border-radius: 6px; padding: 26px; }
.receipt h1 { text-align: center; }
.receipt .row { display: flex; justify-content: space-between; border-bottom: 1px dotted #999; padding: 8px 0; }
.receipt .sign { display: flex; justify-content: space-between; margin-top: 40px; }

.quick-results { position: absolute; top: 100%; inset-inline: 0; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; box-shadow: 0 12px 30px rgba(0,0,0,.14); z-index: 50; max-height: 60vh; overflow: auto; }
.quick-results a { display: block; padding: 9px 12px; color: var(--ink); border-bottom: 1px solid var(--line); }
.quick-results a:hover { background: var(--brand-soft); text-decoration: none; }
.quick-results .none { padding: 10px 12px; color: var(--muted); }
.cheques { border-top: 1px dashed var(--line); margin-top: 16px; padding-top: 12px; }
.cheque-detail { display: grid; gap: 8px; margin-top: 8px; }
.cheque-detail > .field { max-width: 200px; }
.cheque-row { display: grid; grid-template-columns: 60px 1fr 1fr; gap: 10px; align-items: end; }
.cheque-row > span { padding-bottom: 8px; color: var(--muted); }
.guarantor-box .g-detail { margin-top: 12px; display: grid; gap: 14px; }
ol.steps { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 12px; }
ol.steps li { background: var(--panel); border: 1px solid var(--line); border-inline-start: 5px solid var(--warn); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
ol.steps li.done { border-inline-start-color: var(--ok); }
.step-head { margin-bottom: 8px; }
.step-body { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.inline-upload { display: inline-flex; gap: 8px; align-items: center; }
.inline-upload input[type=file] { width: auto; max-width: 260px; }
ul.att-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 30px; margin: 0 0 16px; box-shadow: var(--shadow); }
ul.att-list li { padding: 3px 0; }
ul.effects { margin: 0; padding-inline-start: 18px; font-size: 13px; }
.print-bar { max-width: 820px; margin: 0 auto 12px; display: flex; gap: 8px; }
body.bare-doc { display: block; background: #e9ecea; padding: 20px; }
body.bare-doc main { display: block; padding: 0; min-height: 0; }
/* التفعيل والشعار */
.brand img { max-height: 36px; border-radius: 8px; }
.login-logo { display: block; max-height: 80px; max-width: 220px; margin: 0 auto 10px; }
.doc-head img.doc-logo { max-height: 70px; max-width: 160px; display: block; margin-bottom: 4px; }
[hidden] { display: none !important; }

@media (max-width: 900px) {
  body.app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; background: var(--bg); }
  .topbar { flex-wrap: wrap; padding: 8px 12px; position: static; }
  .topbar .brand { min-width: 0; }
  .topbar .quick { order: 3; flex-basis: 100%; max-width: none; }
  .today { display: none; }
  nav.side { flex-direction: row; overflow-x: auto; height: auto; position: static; padding: 6px; }
  nav.side a { white-space: nowrap; }
  nav.side kbd { display: none; }
  main { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
}
@media print {
  body, body.app { display: block; background: #fff; }
  .topbar, nav.side, .no-print, .actions, .filters, .form-actions { display: none !important; }
  main { padding: 0; }
  .panel, .table-wrap, .card { border: 0; box-shadow: none; }
  th { position: static; }
  body.bare-doc { background: #fff; padding: 0; }
}

/* ---------- الإصدار 1.3: الجرس، الرسوم، التبليغات، الإقفال ---------- */
.icon-btn.bell { position: relative; display: inline-flex; }
.icon-btn.bell:hover { background: var(--brand-soft); color: var(--brand); border-color: var(--line-2); text-decoration: none; }
.icon-btn.bell.has { color: var(--bad); border-color: #f3c7c2; background: var(--bad-bg); }
.icon-btn.bell b { position: absolute; top: -7px; inset-inline-start: -7px; background: var(--bad); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
nav.side a .count { background: var(--accent); color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; display: inline-grid; place-items: center; padding: 0 5px; margin-inline-start: auto; }
nav.side a .count + kbd { margin-inline-start: 6px; }
.chart { margin-top: 4px; }
.chart-scroll { overflow-x: auto; }
.chart svg { display: block; margin: 0 auto; max-width: none; }
.chart .axis { stroke: var(--line-2); stroke-width: 1; }
.chart .bar.c-brand, .legend i.c-brand { fill: var(--brand); background: var(--brand); }
.chart .bar.c-muted, .legend i.c-muted { fill: #c5d2cd; background: #c5d2cd; }
.chart .bar.c-gold, .legend i.c-gold { fill: #d9a43a; background: #d9a43a; }
.chart text { font-family: inherit; text-anchor: middle; direction: rtl; unicode-bidi: plaintext; }
.two-col > * { min-width: 0; }
.chart .lbl { font-size: 11.5px; fill: var(--muted); }
.chart .val { font-size: 10.5px; fill: var(--ink); }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.msg-list { display: grid; gap: 12px; }
.msg-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.msg-body { white-space: pre-wrap; font: inherit; background: #f4f8f6; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; line-height: 1.8; overflow-wrap: anywhere; }
.msg.sent .msg-body, .msg.skipped .msg-body { background: #fafafa; color: var(--muted); }
.msg-edit { margin: 14px 0; } .msg-edit h3 { margin: 0 0 6px; font-size: 15px; }
.msg-edit textarea { width: 100%; font: inherit; line-height: 1.8; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; }
code { background: var(--brand-soft); border-radius: 5px; padding: 1px 5px; font-size: 12.5px; }
button.wa, .btn.wa { background: #1f9d57; border-color: #1f9d57; color: #fff; display: inline-flex; align-items: center; gap: 6px; }
button.wa:hover, .btn.wa:hover { background: #17824a; }
button.wa .ic { width: 16px; height: 16px; }
.print-only { display: none; }
.sign-table { width: 100%; margin: 28px 0 8px; } .sign-table td { padding: 10px 4px; }
@media print { .print-only { display: block; } table.print-only { display: table; } .doc-line { margin-bottom: 10px; font-size: 15px; } .chart-scroll { overflow: visible; } }
