/* =====================================================================
   دفتر مسارك — الأنماط المشتركة
   ===================================================================== */
:root {
  --brand: #0F5D46;
  --brand-dark: #0A4433;
  --brand-tint: #E3EFE9;
  --brand-ink: #0B4A37;
  --bg: #F4F6F3;
  --card: #FFFFFF;
  --ink: #10231C;
  --ink-2: #4A5B54;
  --ink-3: #6B7A74;
  --line: #E6EBE8;
  --line-2: #DCE3DF;
  --owe: #8A4300;
  --owe-bg: #FDF0DC;
  --paid: #14603F;
  --paid-bg: #E2F3EA;
  --bad: #9B2119;
  --bad-bg: #FBE6E4;
  --bad-line: #C8473E;
  --wait-bg: #EEF0EF;
  --wait: #3F4B46;
  --warn-line: #EBC48F;
  --radius: 14px;
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- shell */
.shell { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; position: relative; }
.page { flex: 1; padding: 0 16px calc(96px + var(--safe-b)); }
.page.no-nav { padding-bottom: calc(24px + var(--safe-b)); }

.topbar { display: flex; align-items: center; gap: 8px; padding: 14px 4px 8px; min-height: 64px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: none; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink); flex-shrink: 0;
  text-decoration: none;
}
.icon-btn:hover { background: rgba(16,35,28,0.06); }
.icon-btn svg { width: 22px; height: 22px; }
.flip { transform: scaleX(-1); }

.hero {
  background: var(--brand); color: #fff; margin: 0 -16px; padding: 18px 20px 72px;
  display: flex; justify-content: space-between; align-items: center;
}
.hero .brand { font-size: 22px; font-weight: 700; }
.hero .sub { font-size: 13px; color: #D5E8DF; }
.hero .icon-btn { color: #fff; background: rgba(255,255,255,0.14); position: relative; }
.badge-dot { position: absolute; top: 8px; inset-inline-end: 9px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #F5B041; color: #10231C; font-size: 11px; font-weight: 700; line-height: 18px; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--card); border-radius: 18px; padding: 16px 18px; box-shadow: 0 1px 2px rgba(16,35,28,0.06); }
.card + .card { margin-top: 12px; }
.stats { margin-top: -56px; position: relative; }
.stat-big { font-size: 34px; font-weight: 700; line-height: 1.15; }
.stat-big .cur { font-size: 16px; font-weight: 600; color: var(--ink-2); }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.stat-grid b { display: block; font-size: 16px; }
.stat-grid span { font-size: 12px; color: var(--ink-2); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 4px 8px; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 600; }

/* ---------------------------------------------------------------- lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; text-decoration: none; color: var(--ink); min-height: 64px; border: 1px solid transparent;
}
a.row:hover { border-color: var(--line-2); color: var(--ink); }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--brand-tint); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row .main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .main .s { font-size: 12px; color: var(--ink-2); }
.row .end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
[dir="rtl"] .row .end { align-items: flex-start; }
.amount { font-weight: 700; font-size: 16px; }
.owe { color: var(--owe); }
.paid { color: var(--paid); }

.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.chip.ok { background: var(--paid-bg); color: var(--paid); }
.chip.wait { background: var(--wait-bg); color: var(--wait); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.late { background: var(--owe-bg); color: var(--owe); }
.chip.sync { background: #E8EEF8; color: #1F4E79; }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 8px; scrollbar-width: none; }
.filters button { border: 1px solid var(--line-2); background: var(--card); border-radius: 18px; height: 36px; padding: 0 14px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.filters button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

.empty { text-align: center; padding: 32px 16px; color: var(--ink-2); }
.empty svg { width: 48px; height: 48px; color: var(--line-2); }

/* ---------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label, .label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 48px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--card);
  padding: 0 14px; font-size: 16px; outline: none;
}
textarea.input { height: auto; min-height: 88px; padding: 12px 14px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,93,70,0.15); }
.input-group { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: 12px; background: var(--card); overflow: hidden; }
.input-group:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,93,70,0.15); }
.input-group .input { border: none; box-shadow: none; }
.input-group .addon { padding: 0 12px; color: var(--ink-2); font-weight: 600; border-inline-end: 1px solid var(--line); height: 48px; display: flex; align-items: center; direction: ltr; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line-2); border-radius: 12px; padding: 0 14px; height: 46px; }
.search input { border: none; outline: none; flex: 1; background: transparent; font-size: 15px; min-width: 0; }
.search svg { width: 18px; height: 18px; color: var(--ink-2); flex-shrink: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px; background: var(--card); border-radius: 12px; border: 1px solid var(--line-2); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex-shrink: 0; }
.hint { font-size: 12px; color: var(--ink-2); }
.error-text { color: var(--bad); font-size: 13px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  height: 48px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--card); padding: 0 18px;
  font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); color: #fff; }
.btn.danger { border-color: var(--bad-line); color: var(--bad); background: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.lg { height: 56px; font-size: 16px; border-radius: 16px; }
.btn.sm { height: 36px; font-size: 13px; padding: 0 12px; border-radius: 10px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }
.btn-row.col { flex-direction: column; }
.btn-row.col > * { flex: none; width: 100%; }

.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; background: #E6EBE8; border-radius: 14px; padding: 4px; }
.segmented button { height: 44px; border: none; border-radius: 11px; background: transparent; font-size: 16px; cursor: pointer; color: var(--wait); }
.segmented button[aria-pressed="true"] { background: #fff; font-weight: 700; box-shadow: 0 1px 2px rgba(16,35,28,0.12); color: var(--ink); }
.segmented button.credit[aria-pressed="true"] { color: var(--owe); }
.segmented button.payment[aria-pressed="true"] { color: var(--paid); }

.quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.quick-actions > * {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 10px 4px;
  border: none; border-radius: 14px; background: var(--card); font-size: 12px; font-weight: 600; color: var(--ink);
  min-height: 68px; cursor: pointer; text-decoration: none;
}
.quick-actions svg { width: 22px; height: 22px; color: var(--brand); }

/* ---------------------------------------------------------------- fab + nav */
.fab-wrap { position: fixed; inset-inline: 0; bottom: calc(68px + var(--safe-b)); padding: 12px 16px 8px; background: linear-gradient(rgba(244,246,243,0), var(--bg) 35%); z-index: 5; max-width: 520px; margin: 0 auto; }
.bottom-nav {
  position: fixed; bottom: 0; inset-inline: 0; max-width: 520px; margin: 0 auto; z-index: 6;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: #fff; border-top: 1px solid var(--line);
  padding: 6px 8px calc(10px + var(--safe-b));
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; text-decoration: none; color: var(--ink-2); font-size: 11px; }
.bottom-nav a[aria-current="page"] { color: var(--brand); font-weight: 600; }
.bottom-nav svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- banners */
.banner { display: flex; gap: 10px; align-items: flex-start; border-radius: 14px; padding: 12px 14px; font-size: 13px; margin-top: 12px; line-height: 1.6; }
.banner svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.banner.info { background: var(--brand-tint); color: var(--brand-ink); }
.banner.warn { background: var(--owe-bg); color: #6A3600; }
.banner.bad { background: var(--bad-bg); color: #7A1B14; }
.banner .grow { flex: 1; }
.banner a { color: inherit; font-weight: 700; }

/* ---------------------------------------------------------------- amount entry */
.amount-display { text-align: center; padding: 18px 0 8px; }
.amount-display .v { font-size: 52px; font-weight: 700; line-height: 1.05; direction: ltr; display: inline-block; }
.amount-display .cur { font-size: 18px; color: var(--ink-2); font-weight: 600; margin-inline-start: 6px; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0 12px; direction: ltr; }
.keypad button { height: 56px; border: none; border-radius: 12px; background: var(--card); font-size: 24px; font-weight: 600; cursor: pointer; }
.keypad button:active { background: var(--brand-tint); }
.picker { max-height: 260px; overflow: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.picker button { text-align: start; }
.selected-cust { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line-2); border-radius: 14px; padding: 10px 14px; min-height: 60px; width: 100%; cursor: pointer; }

/* ---------------------------------------------------------------- entries */
.entry { background: var(--card); border-radius: 14px; padding: 12px 14px; border: 1px solid transparent; }
.entry.disputed { border-color: #F1C4BF; }
.entry .top { display: flex; align-items: center; gap: 10px; }
.entry .sign { width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; flex-shrink: 0; }
.entry .sign.plus { background: var(--owe-bg); color: var(--owe); }
.entry .sign.minus { background: var(--paid-bg); color: var(--paid); }
.entry.reversed .t, .entry.reversed .amount { text-decoration: line-through; color: var(--ink-3); }
.dispute-box { margin-top: 10px; background: #FDF3F2; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: #7A1B14; }

.limit-bar { height: 8px; border-radius: 4px; background: var(--wait-bg); overflow: hidden; margin-top: 10px; }
.limit-bar div { height: 8px; border-radius: 4px; background: #E08A1E; }
.limit-bar div.over { background: var(--bad-line); }

/* ---------------------------------------------------------------- dialog & toast */
.overlay { position: fixed; inset: 0; background: rgba(16,35,28,0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 20px 18px calc(18px + var(--safe-b)); max-height: 90dvh; overflow: auto; animation: up .18s ease-out; }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { margin: 0 0 8px; font-size: 18px; }
.sheet p { margin: 0 0 14px; color: var(--ink-2); }
.sheet .btn-row { margin-top: 12px; }
.toast { position: fixed; bottom: calc(150px + var(--safe-b)); inset-inline: 16px; margin: 0 auto; max-width: 420px; background: #10231C; color: #fff; padding: 12px 16px; border-radius: 12px; z-index: 60; font-size: 14px; text-align: center; animation: up .18s ease-out; }
.toast.error { background: var(--bad); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.loading { display: flex; justify-content: center; padding: 48px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- scan */
.scan-row { background: var(--card); border-radius: 14px; padding: 10px 12px; border: 1px solid transparent; display: flex; flex-direction: column; gap: 6px; }
.scan-row.low { border-color: var(--warn-line); }
.scan-row .cols { display: grid; grid-template-columns: minmax(0, 1fr) 104px 36px; gap: 8px; align-items: end; }
.scan-row .input { height: 40px; font-size: 15px; }
.scan-row .note { font-size: 12px; color: var(--owe); }
.scan-drop { border: 2px dashed var(--line-2); border-radius: 18px; padding: 28px 16px; text-align: center; background: var(--card); cursor: pointer; display: block; }
.scan-drop svg { width: 40px; height: 40px; color: var(--brand); }

/* ---------------------------------------------------------------- statement / print */
.statement table { width: 100%; border-collapse: collapse; font-size: 13px; }
.statement th, .statement td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: start; }
.statement td.n, .statement th.n { text-align: end; font-variant-numeric: tabular-nums; }
@media print {
  body { background: #fff; }
  .no-print, .bottom-nav, .fab-wrap, .topbar .icon-btn { display: none !important; }
  .page { padding: 0 !important; }
  .card { box-shadow: none; padding: 0; }
}

/* ---------------------------------------------------------------- auth */
.auth { max-width: 420px; margin: 0 auto; padding: 48px 20px 24px; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: var(--brand); display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.logo svg { width: 36px; height: 36px; color: #fff; }
.auth h1 { margin: 0 0 6px; font-size: 28px; }
.otp-input { letter-spacing: 12px; text-align: center; font-size: 26px; font-weight: 700; direction: ltr; }

/* ---------------------------------------------------------------- الصفحات القانونية */
.legal { max-width: 760px; margin: 0 auto; padding: 0 20px 56px; background: #fff; }
.legal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--line); margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.legal-head .b { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.legal-head .b img { width: 32px; height: 32px; border-radius: 9px; }
.legal h1 { font-size: 28px; margin: 24px 0 4px; }
.legal h2 { font-size: 18px; margin: 28px 0 8px; }
.legal p, .legal li { line-height: 1.85; color: #24352E; }
.legal ul, .legal ol { padding-inline-start: 22px; }
.legal .meta { color: var(--ink-2); font-size: 13px; }
.legal .box { background: var(--brand-tint); color: var(--brand-ink); border-radius: 14px; padding: 14px 16px; margin: 16px 0; }
.legal table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.legal th, .legal td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: start; vertical-align: top; }
.legal .toc { background: var(--bg); border-radius: 14px; padding: 12px 16px; font-size: 14px; }
.legal .toc a { text-decoration: none; }
.legal section[lang="en"] { direction: ltr; text-align: left; border-top: 2px solid var(--line); margin-top: 40px; }
body.legal-body { background: #fff; }
