:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --ink: #141a26;
  --ink-2: #4a5468;
  --ink-3: #8a93a6;
  --line: #e1e5ee;
  --brand: #2c4f8f;
  --brand-ink: #ffffff;
  --brand-soft: #e3ebf8;
  --ok: #1d7a4f;
  --ok-soft: #dff3e8;
  --danger: #b4322b;
  --danger-soft: #fbe6e4;
  --shadow: 0 1px 2px rgba(20, 26, 38, .06), 0 4px 16px rgba(20, 26, 38, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b;
    --surface: #181d28;
    --surface-2: #212838;
    --ink: #eef1f7;
    --ink-2: #b2bacb;
    --ink-3: #7a8396;
    --line: #2a3243;
    --brand: #7fa3e6;
    --brand-ink: #0f131b;
    --brand-soft: #1f2b44;
    --ok: #5fd39a;
    --ok-soft: #173326;
    --danger: #f08a82;
    --danger-soft: #3a1d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", -apple-system, "SF Arabic", "Geeza Pro", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: calc(var(--safe-t) + 4px) 16px 0;
}
.appbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.appbar h1 { font-size: 15px; font-weight: 600; color: var(--ink-2); margin: 0; }
.grand { font-size: 13px; color: var(--ink-3); }
.grand b { color: var(--ink); font-weight: 600; }

.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 0 8px; margin: 0 -16px; padding-inline: 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 500; color: var(--ink-2);
  white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tab .dot { display: inline-block; min-width: 18px; padding: 0 5px; margin-inline-start: 6px; border-radius: 9px; font-size: 11px; line-height: 18px; background: var(--surface-2); color: var(--ink-2); text-align: center; }
.tab[aria-selected="true"] .dot { background: rgba(255,255,255,.22); color: inherit; }

main { padding: 0 12px calc(var(--safe-b) + 84px); max-width: 680px; margin: 0 auto; }

/* ---------- hero ---------- */
.hero {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 12px;
}
.hero .label { font-size: 13px; color: var(--ink-3); }
.hero .big { font-size: 32px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.hero .big small { font-size: 14px; font-weight: 500; color: var(--ink-3); margin-inline-start: 6px; }
.hero .meta { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.note-btn {
  margin-top: 10px; width: 100%; text-align: start; border: 1px dashed var(--line); background: transparent;
  border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--ink-2); white-space: pre-wrap;
}
.note-btn.blank { color: var(--ink-3); }

.seg { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; margin-bottom: 8px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 6px 6px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- list ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 52px 1fr auto 48px; align-items: center; gap: 8px;
  padding: 0; padding-inline-start: 12px; min-height: 44px; border-top: 1px solid var(--line);
  transition: transform .28s ease, opacity .28s ease, background .2s;
}
.row:first-child { border-top: 0; }
.row.leaving { transform: translateX(-30%); opacity: 0; }
.row .d, .recv .d { font-size: 13.5px; color: var(--ink-3); text-align: start; }
.row .c, .recv .c { font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; padding: 3px 0; font-size: 15.5px; }
.row .a { font-weight: 600; text-align: end; }
.row .hit { display: contents; }
.row button.body { all: unset; display: contents; cursor: pointer; }
.chk {
  width: 52px; height: 44px; border: 0; background: transparent; display: grid; place-items: center;
}
.chk span {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--ink-3); display: grid; place-items: center; transition: all .15s;
}
.chk:active span { transform: scale(.9); }
.chk.on span { background: var(--ok); border-color: var(--ok); }
.chk.on span::after { content: ""; width: 7px; height: 13px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.row.recv { grid-template-columns: 64px 1fr auto; padding-inline-end: 14px; }

.group-h {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 4px 4px; font-size: 13px; color: var(--ink-2); font-weight: 600;
}
.group-h .num { color: var(--ink); }

.empty {
  text-align: center; color: var(--ink-3); padding: 40px 16px; font-size: 14px;
}

/* ---------- summary ---------- */
.cards { display: grid; gap: 10px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; border: 0; text-align: start; width: 100%;
}
.card .n { font-weight: 600; }
.card .v { font-weight: 700; font-size: 20px; text-align: end; }
.card .s { font-size: 12.5px; color: var(--ink-3); }
.card .s.e { text-align: end; }
.total-card { background: var(--brand); color: var(--brand-ink); }
.total-card .s { color: inherit; opacity: .8; }
.actions { display: grid; gap: 8px; margin-top: 18px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600; font-size: 15px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); text-align: center; text-decoration: none; display: block;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn.danger { background: var(--danger-soft); color: var(--danger); box-shadow: none; }
.btn.ok { background: var(--ok-soft); color: var(--ok); box-shadow: none; }

/* ---------- bottom bar ---------- */
.bottombar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  padding: 8px 12px calc(var(--safe-b) + 8px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}
.bottombar .inner { max-width: 680px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bottombar .tot { flex: 1; min-width: 0; }
.bottombar .tot .l { font-size: 12px; color: var(--ink-3); }
.bottombar .tot .v { font-size: 20px; font-weight: 700; }
.fab {
  border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 14px; height: 50px; padding: 0 20px;
  font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 6px;
}
.fab svg { width: 20px; height: 20px; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 50; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 51;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(var(--safe-b) + 16px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  max-width: 680px; margin: 0 auto; max-height: 92dvh; overflow-y: auto;
}
.sheet.show { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 17px; margin: 0 0 12px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 12px 14px; font-size: 17px; /* >=16px stops iOS zoom */ outline: none; min-height: 50px;
}
.field input:focus, .field textarea:focus { border-color: var(--brand); background: var(--surface); }
.field input[type="date"] { -webkit-appearance: none; appearance: none; text-align: start; display: block; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; min-height: 18px; }
.amount-input { font-size: 22px !important; font-weight: 600; direction: ltr; text-align: right; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; inset-inline: 16px; top: calc(var(--safe-t) + 8px); z-index: 60;
  max-width: 560px; margin: 0 auto;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 14px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
  transform: translateY(-20px); opacity: 0; transition: all .2s; pointer-events: none;
}
.toast.show { transform: none; opacity: 1; pointer-events: auto; }
.toast .msg { flex: 1; }
.toast button { border: 0; background: transparent; color: var(--brand-soft); font-weight: 700; padding: 4px 6px; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--brand-ink); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 22px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { color: var(--ink-3); margin: 0 0 18px; font-size: 14px; }
.login .btn { width: 100%; }

.loading { text-align: center; color: var(--ink-3); padding: 60px 0; }

/* ---------- location management ---------- */
.pagehead { display: flex; align-items: center; gap: 10px; margin: 2px 0 12px; }
.pagehead h2 { font-size: 18px; margin: 0; }
.mlist .mrow { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.mlist .mrow:first-child { border-top: 0; }
.mmain { flex: 1 1 160px; min-width: 0; }
.mname { font-weight: 600; }
.msub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.mbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.ib { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; min-width: 40px; height: 38px; padding: 0 10px; font-size: 13px; color: var(--ink-2); }
.ib:disabled { opacity: .35; }
.ib.txt { font-weight: 600; }
.ib.red { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.help { font-size: 13px; color: var(--ink-3); margin: 12px 4px; line-height: 1.6; }
.choices { display: grid; gap: 8px; margin: 8px 0 4px; }
.choice { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); }
.choice input { width: 20px; height: 20px; accent-color: var(--brand); margin: 0; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

.iconbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 14px; height: 50px; padding: 0 12px;
  font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px;
}
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn[hidden] { display: none; }
