/* ── إدارة الدين · أساس التصميم ── */
:root {
  --font-head: 'Noto Naskh Arabic', 'Noto Sans Arabic', system-ui, serif;
  --font-body: 'Noto Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bg: #F4F6FB;
  --surface: #FFFFFF;
  --surface-2: #EEF2F8;
  --surface-3: #E4EAF3;
  --border: #DFE6F0;
  --border-strong: #C6D1E2;
  --text: #0F172A;
  --text-soft: #33415C;
  --muted: #64748B;
  --primary: #1E40AF;
  --primary-2: #3B82F6;
  --primary-soft: #E7EDFC;
  --pos: #059669;
  --pos-soft: #E3F6EF;
  --neg: #DC2626;
  --neg-soft: #FCE9E9;
  --warn: #D97706;
  --warn-soft: #FDF3E3;
  --neutral: #64748B;
  --ring: rgba(30,64,175,.28);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --shadow: 0 6px 20px rgba(15,23,42,.07);
  --shadow-lg: 0 18px 50px rgba(15,23,42,.16);
  --space: 8px;
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;
  --sidebar-w: 260px;
}
[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #121A2B;
  --surface-2: #182238;
  --surface-3: #1F2B44;
  --border: rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.18);
  --text: #F1F5F9;
  --text-soft: #D3DCEA;
  --muted: #93A1B8;
  --primary: #4F8DF7;
  --primary-2: #7CB0FF;
  --primary-soft: rgba(79,141,247,.16);
  --pos: #34D399;
  --pos-soft: rgba(52,211,153,.14);
  --neg: #F87171;
  --neg-soft: rgba(248,113,113,.14);
  --warn: #FBBF24;
  --warn-soft: rgba(251,191,36,.14);
  --ring: rgba(124,176,255,.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
}
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── الهيكل العام ── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, var(--primary), #0B7A5E);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 6px 18px rgba(30,64,175,.28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-family: var(--font-head); font-size: 20px; font-weight: 700; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav-group-title {
  font-size: 11px; font-weight: 600; color: var(--muted);
  letter-spacing: .06em; padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: 14.5px; font-weight: 500;
  cursor: pointer; min-height: 44px; border: 1px solid transparent;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 22%, transparent); font-weight: 600;
}
.nav-item .badge-count {
  margin-inline-start: auto; background: var(--neg); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px;
}
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; min-height: 66px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
}
.view { padding: 22px 20px 120px; max-width: 1400px; width: 100%; margin-inline: auto; }
.hidden { display: none !important; }
.mobile-only { display: none; }

/* ── أدوات مساعدة ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px; font-family: inherit;
  font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, opacity .14s;
  min-height: 44px; white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 6px 18px rgba(30,64,175,.26); }
.btn-pos { background: var(--pos); color: #fff; }
.btn-neg { background: var(--neg); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; min-height: 36px; border-radius: 10px; }
.btn-icon { padding: 0; width: 44px; height: 44px; border-radius: 12px; flex: none; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px;
}
.card-pad-lg { padding: 22px; }
.card-hover { transition: transform .16s ease, box-shadow .16s ease; }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title { font-family: var(--font-head); font-size: 17px; font-weight: 600; }
.card-sub { font-size: 12.5px; color: var(--muted); }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }

/* ── الشارات والحالات ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-soft); white-space: nowrap;
}
.badge-pos { background: var(--pos-soft); color: var(--pos); }
.badge-neg { background: var(--neg-soft); color: var(--neg); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-neutral { background: var(--surface-3); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--neutral); }
.dot-pos { background: var(--pos); } .dot-neg { background: var(--neg); }
.dot-warn { background: var(--warn); } .dot-neutral { background: var(--neutral); }
.t-pos { color: var(--pos); } .t-neg { color: var(--neg); }
.t-warn { color: var(--warn); } .t-muted { color: var(--muted); }
.t-primary { color: var(--primary); } .t-soft { color: var(--text-soft); }
.bold { font-weight: 700; } .mono { font-variant-numeric: tabular-nums; }

/* ── بطاقات المؤشرات ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi::after { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--neutral); }
.kpi.pos::after { background: var(--pos); } .kpi.neg::after { background: var(--neg); }
.kpi.warn::after { background: var(--warn); } .kpi.primary::after { background: var(--primary); }
.kpi-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi-icon {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); flex: none;
}
.kpi-value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value.sm { font-size: 22px; }
.kpi-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-spark { margin-top: 6px; }
.hero-kpi {
  background: linear-gradient(135deg, var(--primary), #0B7A5E);
  color: #fff; border: none;
}
.hero-kpi .kpi-top, .hero-kpi .kpi-foot { color: rgba(255,255,255,.82); }
.hero-kpi .kpi-icon { background: rgba(255,255,255,.18); color: #fff; }

/* ── الحقول والنماذج ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
label.field .hint { font-size: 11.5px; font-weight: 400; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 15px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; min-height: 44px; transition: border-color .16s, box-shadow .16s, background .16s;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); background: var(--surface); }
input[readonly] { color: var(--muted); }
input.invalid, select.invalid { border-color: var(--neg); box-shadow: 0 0 0 3px var(--neg-soft); }
.field-err { color: var(--neg); font-size: 12px; font-weight: 600; }
input[type="file"] { padding: 8px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; accent-color: var(--primary); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch-row .switch-label { font-size: 14px; font-weight: 600; }
.switch-row .switch-hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ── المبالغ ── */
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.amount-neg { color: var(--neg); } .amount-pos { color: var(--pos); }
.amount-neutral { color: var(--muted); }
.amount-xl { font-size: 30px; } .amount-lg { font-size: 22px; }

/* ── الجداول وكشوف الحساب ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data th, table.data td { padding: 11px 12px; text-align: start; font-size: 13.5px; border-bottom: 1px solid var(--border); }
table.data th {
  background: var(--surface-2); color: var(--muted); font-weight: 600;
  font-size: 12px; position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.row-click { cursor: pointer; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tfoot td { background: var(--surface-2); font-weight: 700; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
.ledger td { vertical-align: top; }
.ledger .bal-row { background: var(--surface-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.chip-tx { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); }

/* ── النوافذ والتنبيهات ── */
.overlay {
  position: fixed; inset: 0; z-index: 90; background: rgba(6,10,20,.55);
  backdrop-filter: blur(5px); display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 14px; overflow-y: auto; animation: fadeIn .18s ease;
}
.overlay.out { animation: fadeOut .16s ease forwards; }
.modal {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; animation: popIn .22s cubic-bezier(.16,1,.3,1);
}
.modal-lg { max-width: 900px; } .modal-sm { max-width: 440px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-title { font-family: var(--font-head); font-size: 19px; font-weight: 700; }
.modal-head .card-sub { margin-top: 2px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.confirm-msg { font-size: 15px; line-height: 1.8; }

.toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: 92vw; }
.toast {
  display: flex; align-items: center; gap: 9px; padding: 11px 15px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600; animation: slideIn .24s cubic-bezier(.16,1,.3,1);
}
.toast.out { animation: fadeOut .24s ease forwards; }
.toast-pos { border-inline-start: 4px solid var(--pos); color: var(--pos); }
.toast-neg { border-inline-start: 4px solid var(--neg); color: var(--neg); }
.toast-warn { border-inline-start: 4px solid var(--warn); color: var(--warn); }
.toast-primary { border-inline-start: 4px solid var(--primary); color: var(--primary); }
.callout { border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13.5px; margin-top: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.callout-info { border-inline-start: 4px solid var(--primary); }
.callout-neg { border-inline-start: 4px solid var(--neg); background: var(--neg-soft); }
.callout-pos { border-inline-start: 4px solid var(--pos); background: var(--pos-soft); }
.callout-warn { border-inline-start: 4px solid var(--warn); background: var(--warn-soft); }

/* ── الحالات الفارغة والتحميل ── */
.empty { text-align: center; padding: 46px 18px; color: var(--muted); }
.empty-ic { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.empty h3 { font-family: var(--font-head); font-size: 17px; color: var(--text); margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--radius-sm); }
.sk-line { height: 14px; margin-bottom: 8px; } .sk-card { height: 104px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
}
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s ease; }
.divider { height: 1px; background: var(--border); margin: 14px 0; border: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes fadeOut { to { opacity: 0 } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(.98) } to { opacity: 1; transform: none } }
@keyframes slideIn { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px) } to { opacity: 1; transform: none } }
.fade-up { animation: fadeUp .38s cubic-bezier(.16,1,.3,1) both; }
.d1 { animation-delay: .04s } .d2 { animation-delay: .08s } .d3 { animation-delay: .12s } .d4 { animation-delay: .16s }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ── القفل والأمان ── */
.lock-screen {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--primary), #06301F); color: #fff; padding: 20px;
}
.lock-box { width: 100%; max-width: 380px; text-align: center; }
.lock-box .brand-mark { margin: 0 auto 16px; width: 62px; height: 62px; border-radius: 20px; background: rgba(255,255,255,.16); }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 22px 0; direction: ltr; }
.pin-dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); transition: all .18s; }
.pin-dot.on { background: #fff; border-color: #fff; transform: scale(1.12); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 280px; margin: 0 auto; }
.pin-key {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); color: #fff;
  border-radius: 16px; height: 60px; font-size: 22px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: background .16s, transform .12s;
}
.pin-key:hover { background: rgba(255,255,255,.22); }
.pin-key:active { transform: scale(.96); }
.pin-key.ghost { font-size: 15px; }
.lock-err { color: #FFD5D5; font-weight: 600; min-height: 22px; }

/* ── الفوتر السريع للهاتف ── */
.tabbar {
  display: none; position: fixed; bottom: 0; inset-inline: 0; z-index: 60;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar .tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 2px;
  border-radius: 10px; cursor: pointer; min-height: 48px; justify-content: center;
}
.tabbar .tab-item.active { color: var(--primary); background: var(--primary-soft); }
.fab {
  display: none; position: fixed; z-index: 70; inset-inline-start: 18px; bottom: 84px;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 14px 34px rgba(30,64,175,.4); display: grid; place-items: center;
  transition: transform .16s ease, box-shadow .16s ease;
}
.fab:hover { transform: translateY(-3px) scale(1.03); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.ic { width: 18px; height: 18px; flex: none; }
.ic-sm { width: 15px; height: 15px; } .ic-lg { width: 24px; height: 24px; }

/* ── استجابة الشاشات ── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 232px; }
  .view { padding: 18px 14px 120px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-end: 0; width: 284px; z-index: 100;
    transform: translateX(-104%); transition: transform .26s cubic-bezier(.16,1,.3,1); height: 100dvh;
  }
  [dir="rtl"] .sidebar { transform: translateX(104%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 8px 12px; min-height: 60px; gap: 8px; }
  .tabbar { display: flex; }
  .tabbar .tab-item { display: flex; }
  .fab { display: grid; bottom: 96px; }
}
@media (max-width: 520px) {
  .kpi-value { font-size: 23px; }
  .amount-xl { font-size: 25px; }
  .modal { max-width: 100%; }
  .view { padding: 14px 10px 130px; }
  .hide-sm { display: none !important; }
}
