:root {
  --bg: #f4f5f7; --surface: #fff; --text: #14181f; --muted: #647084; --line: #e3e6ec;
  --primary: #0f766e; --primary-soft: #d9f0ed;
  --ok: #15803d; --ok-bg: #16a34a; --bad: #b91c1c; --warn-bg: #fff4d6; --warn-text: #6b4a00;
  --ignore-bg: #64748b;
  --radius: 16px; --tab-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #1a1f27; --text: #eef1f5; --muted: #9aa5b6; --line: #2a313c;
    --primary: #2dd4bf; --primary-soft: #12342f; --ok: #4ade80; --bad: #f87171;
    --warn-bg: #3a2f10; --warn-text: #f5d98a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 -apple-system, "SF Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  padding-top: env(safe-area-inset-top);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
bdi.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; }
.user-chip {
  min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--primary-soft); color: var(--primary);
  font-weight: 600; display: flex; align-items: center; gap: 6px;
}
.user-chip small { font-weight: 400; opacity: .8; }

main { padding: 14px 16px calc(var(--tab-h) + 90px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 6; display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; position: relative; }
.tabs button .ico { font-size: 22px; line-height: 1; }
.tabs button[aria-current="page"] { color: var(--primary); font-weight: 700; }
.badge { position: absolute; top: 6px; inset-inline-start: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

.card-box { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.spread { justify-content: space-between; }

.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.notice b { display: block; margin-bottom: 2px; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav .name { font-weight: 700; font-size: 17px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; background: var(--surface); font-size: 20px; }

.hero .big { font-size: 34px; font-weight: 800; line-height: 1.2; }
.hero .cur { font-size: 16px; font-weight: 500; color: var(--muted); }
.progress { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 12px 0 8px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.progress.over > i { background: var(--bad); }
.stats { display: flex; justify-content: space-between; gap: 8px; }
.stats .k { font-size: 13px; color: var(--muted); }
.stats .v { font-weight: 700; }
.over-text { color: var(--bad); }

.bar-row { margin: 12px 0; }
.bar-row .bar { height: 8px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.bar-row .bar > i { display: block; height: 100%; background: var(--primary); }

.btn { white-space: nowrap; min-height: 48px; padding: 0 18px; border-radius: 12px; background: var(--primary); color: #fff; font-weight: 700; }
@media (prefers-color-scheme: dark) { .btn { color: #04201c; } }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 44px; padding: 0 14px; }

.fab {
  position: fixed; inset-inline-end: 18px; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); z-index: 5;
  width: 58px; height: 58px; border-radius: 29px; background: var(--primary); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
@media (prefers-color-scheme: dark) { .fab { color: #04201c; } }

.date-head { margin: 18px 4px 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.cat-ico { width: 42px; height: 42px; border-radius: 21px; background: var(--primary-soft); display: grid; place-items: center; font-size: 20px; flex: none; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 700; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .ico { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- بطاقات العمليات الواردة والسحب ---------- */
.swipe { position: relative; overflow: hidden; border-radius: var(--radius); margin-bottom: 12px; }
.swipe-bg { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 22px; color: #fff; font-weight: 800; font-size: 18px; opacity: 0; direction: ltr; }
.swipe-bg.approve { background: var(--ok-bg); justify-content: flex-start; }
.swipe-bg.ignore { background: var(--ignore-bg); justify-content: flex-end; }
.swipe-bg span { direction: rtl; transition: transform .12s; }
.swipe-bg span::before { content: attr(data-idle); }
.swipe[data-dir="approve"] .swipe-bg.approve, .swipe[data-dir="ignore"] .swipe-bg.ignore { opacity: calc(.35 + .65 * var(--p, 0)); }
.swipe.armed .swipe-bg span { transform: scale(1.12); }
.swipe.armed .swipe-bg span::before { content: attr(data-armed); }
.swipe .card { position: relative; background: var(--surface); padding: 14px; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab; transition: transform .18s ease; }
.swipe .card.dragging { transition: none; cursor: grabbing; }
.card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card .merchant { font-weight: 700; font-size: 17px; }
.card .amount { font-size: 22px; font-weight: 800; white-space: nowrap; }
.card .amount.missing { color: var(--bad); font-size: 15px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 10px; font-size: 13px; color: var(--muted); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-size: 13px; font-weight: 600; }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.card .actions { display: flex; gap: 10px; }
.card .actions .btn { flex: 1; }
.btn.approve { background: var(--ok-bg); color: #fff; }
.btn.ignore { background: var(--line); color: var(--text); }
.hint { text-align: center; font-size: 13px; color: var(--muted); margin: 0 0 12px; }

.handled { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.handled:last-child { border-bottom: 0; }

/* ---------- النوافذ السفلية ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 19px; }
label.field { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
label.field > span { display: block; margin-bottom: 4px; }
.sheet input, .sheet select, .sheet textarea, .inline-form input {
  width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 17px;
}
.sheet textarea { min-height: 130px; line-height: 1.6; }
.sheet input.invalid { border-color: var(--bad); }
.error { color: var(--bad); font-size: 14px; margin: 0 0 12px; font-weight: 600; }
.raw { white-space: pre-wrap; background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 13px; direction: auto; color: var(--muted); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.btn-row .btn { flex: 1; min-width: 120px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); font-size: 14px; font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 14px; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 30; max-width: 608px; margin: 0 auto;
  background: #1f2937; color: #fff; border-radius: 14px; padding: 8px 8px 8px 16px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.toast span { flex: 1; }
.toast button { min-height: 44px; padding: 0 16px; border-radius: 10px; background: rgba(255,255,255,.16); color: #fff; font-weight: 700; }

.user-opt { display: flex; align-items: center; gap: 12px; min-height: 56px; width: 100%; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); margin-bottom: 8px; text-align: start; }
.user-opt[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.inline-form { display: flex; gap: 8px; }
.inline-form .btn { flex: none; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) { .swipe .card { transition: none; } }
