@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F; }
@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: 'Plex Arabic'; src: url('../fonts/ibm-plex-sans-arabic-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #f7f9fc; --ink: #14233a; --muted: #66768b; --line: #e3e9f1;
  --accent: #1f6fe5; --accent-ink: #ffffff; --accent-soft: #e6f0fe; --good: #0f8a5f; --bad: #c8364c; --warn-bg: #fff4dc; --warn-ink: #6b4a00;
  --hero-a: #1559c9; --hero-b: #2f8cf0; --shadow: 0 1px 2px rgba(16, 38, 74, .05), 0 6px 18px rgba(16, 38, 74, .05);
  --radius: 18px; --nav-h: 66px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1320; --surface: #142033; --surface-2: #1a283d; --ink: #e9f0fa; --muted: #9aabc2; --line: #24344c;
    --accent: #4b95ff; --accent-ink: #06152b; --accent-soft: #17304f; --good: #45d39b; --bad: #ff7d8f; --warn-bg: #3b2f17; --warn-ink: #ffdc9b;
    --hero-a: #13396f; --hero-b: #1f5bb0; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1320; --surface: #142033; --surface-2: #1a283d; --ink: #e9f0fa; --muted: #9aabc2; --line: #24344c;
  --accent: #4b95ff; --accent-ink: #06152b; --accent-soft: #17304f; --good: #45d39b; --bad: #ff7d8f; --warn-bg: #3b2f17; --warn-ink: #ffdc9b;
  --hero-a: #13396f; --hero-b: #1f5bb0; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto; max-width: 720px; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 16px/1.55 'Plex Arabic', system-ui, -apple-system, 'SF Arabic', 'Segoe UI', Tahoma, sans-serif;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 6px 0; }
a { color: var(--accent); }
.muted, small { color: var(--muted); }
small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.sym { font-size: .72em; font-weight: 500; opacity: .75; white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); }
[hidden] { display: none !important; }

/* رأس الصفحة */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.brand h1 { font-size: 21px; font-weight: 700; }
.status { font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.status.err { color: var(--bad); border-color: var(--bad); }

/* بطاقات */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.hero { background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: #fff; border: 0; padding: 20px 18px; }
.hero small, .hero .muted { color: rgba(255, 255, 255, .82); }
.hero .big { font-size: 34px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.5px; }
.hero .big .cur { font-size: 17px; font-weight: 500; opacity: .85; margin-inline-start: 6px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { display: block; width: 100%; text-align: start; margin: 0; padding: 14px; cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--ink); font: inherit; }
.stat:active { transform: scale(.98); }
.stat > small { display: flex; justify-content: space-between; align-items: center; }
.stat > small::after { content: '‹'; font-size: 18px; line-height: 1; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: 14px; padding: 12px 14px; margin: 10px 0; font-size: 14px; line-height: 1.7; }
.notice.info { background: var(--accent-soft); color: var(--ink); }
.notice.err { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--ink); border: 1px solid var(--bad); }
.notice .actions { margin-top: 8px; }

/* الاختصارات */
.shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 4px 0 6px; }
.shortcut { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; min-width: 0; }
.shortcut .ico { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.shortcut span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.row-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 2px 6px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-size: 13px; padding: 6px 4px; cursor: pointer; }

/* قوائم */
.list { margin: 0; padding: 0; list-style: none; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .ico { flex: 0 0 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 15px; }
.item .ico.in { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good); }
.item .ico.out { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--bad); }
.item .ico.tr { background: var(--accent-soft); color: var(--accent); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow-wrap: anywhere; }
.item .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .amt { font-weight: 700; white-space: nowrap; text-align: end; }
.item .amt small { display: block; font-weight: 400; font-size: 12px; }
button.item { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); font: inherit; color: inherit; text-align: start; cursor: pointer; }
.day { font-size: 12px; color: var(--muted); margin: 14px 0 0; font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 14px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 8px; }
.progress.good span { background: var(--good); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }
.tag.bad { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad); }

/* أزرار ونماذج */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { border: 0; border-radius: 13px; padding: 11px 16px; min-height: 44px; background: var(--surface-2); color: var(--ink); font-weight: 500; cursor: pointer; border: 1px solid var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn.danger { background: var(--bad); color: #fff; border-color: transparent; }
.btn.ghost-danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.end { justify-content: flex-end; }
label, .label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 500; }
input, select, textarea { display: block; width: 100%; min-width: 0; min-height: 46px; padding: 11px 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; font-size: 16px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .stat:focus-visible, .shortcut:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; display: inline-block; vertical-align: middle; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; color: var(--ink); font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > div > label { margin-top: 12px; }
.amount-input { font-size: 30px; font-weight: 700; text-align: center; direction: ltr; padding: 14px; min-height: 64px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 500; cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg button[aria-pressed="true"].in { color: var(--good); } .seg button[aria-pressed="true"].out { color: var(--bad); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 7px 13px; font-size: 14px; white-space: nowrap; cursor: pointer; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.err-msg { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 0; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar > * { flex: 1; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters input, .filters select { min-height: 40px; padding: 8px 10px; font-size: 15px; }

/* الشريط السفلي */
.bottom-nav { position: fixed; inset-inline: 0; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav .in { max-width: 720px; margin: auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); align-items: center; }
.nav-btn { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); cursor: pointer; padding: 6px 0; font-weight: 500; }
.nav-btn[aria-current="page"] { color: var(--accent); }
.nav-add { justify-self: center; width: 54px; height: 54px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); border: 0; display: grid; place-items: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); cursor: pointer; transform: translateY(-8px); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* شاشة */
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; }
.view-head h2 { font-size: 22px; flex: 1; }
.back { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; }
.more-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.more-grid .shortcut { flex-direction: row; justify-content: flex-start; padding: 14px; font-size: 15px; gap: 10px; }

/* الرسوم البيانية */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .gi { fill: var(--good); } .chart .ge { fill: var(--bad); opacity: .85; } .chart .axis { stroke: var(--line); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: middle; }
.bars .row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; margin: 9px 0; font-size: 14px; }
.bars .row .progress { grid-column: 1 / -1; margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; text-align: center; }
.kpis div { background: var(--surface-2); border-radius: 12px; padding: 10px 4px; }
.kpis b { display: block; font-size: 16px; margin-top: 2px; }

/* النوافذ */
dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: 100vw; max-height: 100vh; }
dialog::backdrop { background: rgba(5, 12, 24, .5); }
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 640px; }
dialog.sheet[open] { animation: up .22s ease; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-in { background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; overscroll-behavior: contain; }
.sheet-in::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.x { background: var(--surface-2); border: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; color: var(--muted); }
dialog.modal { width: min(420px, calc(100vw - 32px)); }
.modal-in { background: var(--surface); border-radius: 20px; padding: 20px; }
@media (min-width: 700px) { dialog.sheet { margin: auto; } .sheet-in { border-radius: 22px; } }

/* القفل */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.lock .box { width: 100%; max-width: 340px; }
.lock img { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 10px; }
.dots { display: flex; justify-content: center; gap: 12px; margin: 18px 0; direction: ltr; }
.dots i { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; direction: ltr; margin: 10px auto; max-width: 280px; }
.keypad button { height: 62px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 24px; cursor: pointer; }
.keypad button.fn { background: none; border: 0; font-size: 15px; color: var(--muted); }
.code { font-family: ui-monospace, Menlo, monospace; direction: ltr; font-size: 19px; letter-spacing: 1px; background: var(--surface-2); padding: 12px; border-radius: 12px; text-align: center; user-select: all; word-break: break-all; }

#toast { position: fixed; z-index: 60; inset-inline: 16px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); max-width: 440px; margin: auto; background: #12233c; color: #fff; padding: 12px 16px; border-radius: 14px; text-align: center; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--bad); }

@media (min-width: 640px) { .shortcuts { grid-template-columns: repeat(6, minmax(0, 1fr)); } .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 360px) { body { padding-inline: 12px; } .hero .big { font-size: 29px; } .stat .v { font-size: 18px; } .shortcut { font-size: 11px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
label.btn { display: inline-flex; align-items: center; font-size: 14px; }
