:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --ink: #17201d;
  --ink-2: #3d4744;
  --muted: #6c7571;
  --line: #e2e6e3;
  --brand: #0e6b5c;
  --brand-ink: #ffffff;
  --brand-soft: #e2f0ec;
  --ok: #1d7f47;
  --ok-soft: #e3f4ea;
  --warn: #a8660b;
  --warn-soft: #fcf0dc;
  --bad: #b8322a;
  --bad-soft: #fbe6e4;
  --info: #3a5bb8;
  --info-soft: #e7ecfa;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #171d1b;
    --surface-2: #1c2321;
    --ink: #e8eeeb;
    --ink-2: #c3ccc8;
    --muted: #8d9894;
    --line: #2a3431;
    --brand: #35b39c;
    --brand-ink: #06231d;
    --brand-soft: #173a33;
    --ok: #4cc07c;
    --ok-soft: #173424;
    --warn: #e2a64a;
    --warn-soft: #3a2c14;
    --bad: #ef6f66;
    --bad-soft: #3d1c1a;
    --info: #86a2f2;
    --info-soft: #1e2744;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171d1b; --surface-2: #1c2321; --ink: #e8eeeb; --ink-2: #c3ccc8; --muted: #8d9894;
  --line: #2a3431; --brand: #35b39c; --brand-ink: #06231d; --brand-soft: #173a33; --ok: #4cc07c; --ok-soft: #173424;
  --warn: #e2a64a; --warn-soft: #3a2c14; --bad: #ef6f66; --bad-soft: #3d1c1a; --info: #86a2f2; --info-soft: #1e2744;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Plex', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px; line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }
.hide { display: none !important; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--ink); }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }
.logo-mark svg { width: 18px; height: 18px; }
.nav { margin-inline-start: auto; display: flex; gap: 2px; }
.nav a, .nav button {
  border: 0; background: none; cursor: pointer; color: var(--ink-2);
  padding: 7px 10px; border-radius: 9px; font-size: 14px; display: flex; align-items: center; gap: 6px;
}
.nav a:hover, .nav button:hover { background: var(--surface); }
.nav a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.nav svg { width: 18px; height: 18px; }
@media (max-width: 640px) { .nav .lbl { display: none; } .nav a, .nav button { padding: 8px; } }

.page { max-width: 1040px; margin: 0 auto; padding: 18px 16px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; line-height: 1.3; }
.page-head .sub { color: var(--muted); font-size: 14px; }
.crumb { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; margin-bottom: 4px; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.section-title { font-size: 15px; font-weight: 600; margin: 22px 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 11px; cursor: pointer; font-weight: 500; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.icon { padding: 7px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.paid { background: var(--ok-soft); color: var(--ok); }
.chip.due { background: var(--bad-soft); color: var(--bad); }
.chip.next { background: var(--warn-soft); color: var(--warn); }
.chip.upcoming { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip.info { background: var(--info-soft); color: var(--info); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }

/* ---------- الرئيسية ---------- */
.ob-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ob-card { display: block; color: inherit; padding: 18px; transition: border-color .15s, transform .15s; }
.ob-card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.ob-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ob-card h3 { margin: 0; font-size: 17px; }
.ob-card .kind { font-size: 12.5px; color: var(--muted); }
.ob-card .big { font-size: 28px; font-weight: 700; margin: 14px 0 2px; line-height: 1.2; }
.ob-card .big small { font-size: 15px; font-weight: 500; color: var(--muted); }
.ob-card .foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--ink-2); flex-wrap: wrap; }
.add-card { display: grid; place-items: center; min-height: 190px; border: 1.5px dashed var(--line); border-radius: var(--radius); color: var(--muted); cursor: pointer; background: none; width: 100%; }
.add-card:hover { border-color: var(--brand); color: var(--brand); }

.segbar { display: flex; gap: 3px; margin-top: 10px; }
.segbar i { flex: 1; height: 8px; border-radius: 3px; background: var(--line); }
.segbar i.paid { background: var(--ok); }
.segbar i.due { background: var(--bad); }
.segbar i.next { background: var(--warn); }

/* ---------- صفحة الالتزام ---------- */
.hero { padding: 20px; display: grid; gap: 16px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.hero h1 { margin: 0; font-size: 24px; line-height: 1.3; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.progress-big { display: grid; gap: 8px; }
.progress-big .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.progress-big .row b { font-size: 26px; }

.alert { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; font-size: 14px; flex-wrap: wrap; }
.alert .txt { flex: 1; min-width: 200px; }
.alert.bad { background: var(--bad-soft); color: color-mix(in srgb, var(--bad) 80%, var(--ink)); }
.alert.warn { background: var(--warn-soft); color: color-mix(in srgb, var(--warn) 75%, var(--ink)); }
.alert.ok { background: var(--ok-soft); color: color-mix(in srgb, var(--ok) 75%, var(--ink)); }
.alert.info { background: var(--info-soft); color: color-mix(in srgb, var(--info) 75%, var(--ink)); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { padding: 13px 14px; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; line-height: 1.35; }
.stat .h { font-size: 12px; color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--line); margin: 22px 0 12px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .count { font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 0 7px; margin-inline-start: 4px; }

/* الجدول */
.sched { width: 100%; border-collapse: collapse; font-size: 14px; }
.sched th { text-align: start; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.sched td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.sched tr:last-child td { border-bottom: 0; }
.sched tbody tr { cursor: pointer; }
.sched tbody tr:hover td { background: var(--surface-2); }
.sched tr.is-next td { background: color-mix(in srgb, var(--warn-soft) 55%, transparent); }
.sched tr.is-due td { background: color-mix(in srgb, var(--bad-soft) 55%, transparent); }
.sched .idx { color: var(--muted); width: 36px; }
.sched .c-amt, .sched .c-due, .sched .c-paid, .sched .c-status { white-space: nowrap; }
.sched .note-dot { color: var(--info); font-size: 12.5px; display: inline-flex; align-items: center; gap: 4px; }
.sched .note-dot svg { width: 14px; height: 14px; }
.table-wrap { overflow: hidden; }
@media (max-width: 720px) {
  .sched thead { display: none; }
  .sched, .sched tbody, .sched tr, .sched td { display: block; width: 100%; }
  .sched tr { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
  .sched td { padding: 0; border: 0; }
  .sched .idx { grid-row: span 2; align-self: center; width: auto; }
  .sched .c-month { font-weight: 600; }
  .sched .c-status { grid-column: 3; grid-row: 1; justify-self: end; }
  .sched .c-due { grid-column: 2; font-size: 13px; color: var(--muted); }
  .sched .c-paid { grid-column: 3; justify-self: end; font-size: 13px; color: var(--muted); }
  .sched .c-note { grid-column: 2 / 4; font-size: 13px; }
  .sched .c-note:empty { display: none; }
  .sched .c-amt { display: none; }
  .sched tr.is-next { background: color-mix(in srgb, var(--warn-soft) 55%, transparent); }
  .sched tr.is-due { background: color-mix(in srgb, var(--bad-soft) 55%, transparent); }
  .sched tr td, .sched tbody tr:hover td { background: none !important; }
}

/* التحويلات */
.pay-list { display: grid; gap: 12px; }
.pay { padding: 16px; display: grid; gap: 10px; }
.pay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.pay-head .amt { font-size: 22px; font-weight: 700; line-height: 1.2; }
.pay-head .when { font-size: 13px; color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 16px; font-size: 13.5px; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { word-break: break-word; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; direction: ltr; unicode-bidi: isolate; }
.months { display: flex; gap: 5px; flex-wrap: wrap; }
.months span { background: var(--brand-soft); color: var(--brand); padding: 1px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.ded-line { display: flex; gap: 8px; align-items: center; font-size: 13.5px; background: var(--warn-soft); color: color-mix(in srgb, var(--warn) 75%, var(--ink)); padding: 6px 10px; border-radius: 9px; }
.diff-line { font-size: 13px; background: var(--info-soft); color: var(--info); padding: 6px 10px; border-radius: 9px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { width: 74px; height: 96px; border-radius: 9px; border: 1px solid var(--line); overflow: hidden; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; position: relative; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.thumb .badge { position: absolute; bottom: 4px; inset-inline-start: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 10px; padding: 0 5px; border-radius: 5px; }
.pay-foot { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }

.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 13px; color: var(--muted); word-break: break-word; }

/* ---------- النوافذ ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 16, 14, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@media (min-width: 640px) { .modal-back { align-items: center; padding: 20px; } }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: up .2s;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

.field { display: grid; gap: 5px; }
.field > label, .field > .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  outline: none; transition: border-color .15s, box-shadow .15s; font-size: 16px; min-height: 44px;
}
textarea.input { min-height: 76px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--surface); }
.input.ltr { direction: ltr; text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.pick { display: flex; flex-wrap: wrap; gap: 7px; }
.pick label { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13.5px; background: var(--surface-2); user-select: none; }
.pick label small { color: var(--muted); font-size: 11.5px; }
.pick input { accent-color: var(--brand); width: 16px; height: 16px; margin: 0; }
.pick label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.pick label.is-due { border-style: dashed; border-color: var(--bad); }

.calc { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: grid; gap: 4px; font-size: 14px; }
.calc .r { display: flex; justify-content: space-between; }
.calc .r.total { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 2px; font-weight: 700; }

.drop { border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; font-size: 14px; }
.drop:hover { border-color: var(--brand); color: var(--brand); }
.files-sel { display: grid; gap: 4px; font-size: 13px; }

.viewer img, .viewer iframe { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.viewer iframe { height: 70vh; }

/* ---------- تنبيه ---------- */
#toast-root { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); inset-inline: 0; display: grid; justify-items: center; gap: 8px; z-index: 80; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: up .2s; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; display: grid; gap: 16px; }
.login .logo { justify-content: center; font-size: 20px; }
.login p { margin: 0; text-align: center; color: var(--muted); font-size: 14px; }
.err { color: var(--bad); font-size: 13.5px; text-align: center; min-height: 20px; }

/* ---------- معاينة التقرير والصورة ---------- */
.doc-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.doc-toolbar .sp { flex: 1; }
.doc-toolbar label.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }
.doc-stage { display: grid; justify-items: center; gap: 16px; }
.doc-scale { transform-origin: top right; }
.doc-scale-wrap { overflow: hidden; }
#render-root { position: fixed; top: 0; left: -99999px; pointer-events: none; }

/* ---------- الطباعة ---------- */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; padding: 0; }
  .topbar, .doc-toolbar, .page-head, #toast-root, #modal-root { display: none !important; }
  .page { padding: 0; max-width: none; }
  .doc-stage { display: block; gap: 0; }
  .doc-scale-wrap { width: auto !important; height: auto !important; overflow: visible; }
  .doc-scale { transform: none !important; }
  .a4 { box-shadow: none !important; margin: 0 !important; page-break-after: always; break-after: page; }
}

/* طلبات مؤجّلة وفرق المبلغ */
.chip.deferred { background: var(--info-soft); color: var(--info); }
.segbar i.deferred { background: var(--info); }
.sched tr.is-deferred td { background: color-mix(in srgb, var(--info-soft) 55%, transparent); }
@media (max-width: 720px) { .sched tr.is-deferred { background: color-mix(in srgb, var(--info-soft) 55%, transparent); } }
.adj { display: grid; gap: 9px; padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.adj.more { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.adj-t { font-size: 14px; }
.adj .pick label { background: var(--surface); }
.req-box { display: grid; gap: 6px; padding: 12px 14px; border-radius: 12px; background: var(--info-soft); color: color-mix(in srgb, var(--info) 75%, var(--ink)); font-size: 14px; }
