/* Payment Masalih — mobile first, RTL/LTR via propriétés logiques */
:root {
  --bg: #f3f5f2; --surface: #ffffff; --ink: #14201b; --muted: #5d6b65; --line: #dbe2dd;
  --accent: #0f6b55; --accent-ink: #ffffff; --accent-soft: #dcefe7;
  --income: #1f7a4d; --charge: #b4462f; --danger: #b4462f;
  --chip: #eef2ef; --overlay: rgba(10, 20, 16, .45); --icmix: 100%;
  --f-display: "Alexandria", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --f-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1311; --surface: #151d1a; --ink: #e6ede9; --muted: #9aa9a2; --line: #26322d;
    --accent: #3fb48f; --accent-ink: #06231a; --accent-soft: #173329;
    --income: #5ccf92; --charge: #f08a70; --danger: #f08a70;
    --chip: #1d2723; --overlay: rgba(0, 0, 0, .6); --icmix: 45%;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 var(--f-body); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-family: var(--f-display); line-height: 1.3; text-wrap: balance; }
h2 { font-size: 1.35rem; }
p { margin: 0; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.in { color: var(--income); } .out { color: var(--charge); }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.tiny { width: 12px; height: 12px; vertical-align: -2px; }
[dir="rtl"] .icon-btn .i { transform: scaleX(-1); }
[dir="rtl"] .icon-btn.flip .i { transform: none; }
[dir="ltr"] .icon-btn.flip .i { transform: scaleX(-1); }

/* splash & auth */
.splash { min-height: 100vh; display: grid; place-items: center; }
.logo { width: 60px; height: 60px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 800 22px var(--f-display); }
.auth { min-height: 100vh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.auth-card h1 { font-size: 1.7rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.field input, .field select { border: 0; background: transparent; outline: none; padding: 2px 0; width: 100%; min-width: 0; }
.field:focus-within { border-color: var(--accent); }
.field.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.field.toggle > span { font-size: 14px; color: var(--ink); }
.field.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.btn { background: var(--accent); color: var(--accent-ink); border-radius: 14px; padding: 13px 16px; font-weight: 600; text-align: center; }
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; }
.err { color: var(--danger); font-size: 14px; }
.info { color: var(--accent); font-size: 14px; }
.lock { font-size: 13px; color: var(--muted); padding-inline-start: 18px; position: relative; }
.lock::before { content: ""; position: absolute; inset-inline-start: 0; top: 5px; width: 9px; height: 11px; border: 1.6px solid var(--accent); border-radius: 3px; }
.demo { font-size: 12.5px; color: var(--muted); background: var(--chip); border-radius: 12px; padding: 10px 12px; }
.lang-switch { display: inline-flex; background: var(--chip); border-radius: 12px; padding: 3px; align-self: flex-start; }
.lang-switch button { padding: 6px 14px; border-radius: 9px; font-size: 14px; }
.lang-switch .on { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* shell */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.month { display: flex; align-items: center; gap: 4px; }
.month b { font-family: var(--f-display); font-size: 1.05rem; min-width: 8.5em; text-align: center; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:active { background: var(--chip); }
.av { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.content { max-width: 560px; margin: 0 auto; padding: 4px max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left)); }
.nav { position: fixed; inset: auto 0 0 0; z-index: 6; display: flex; justify-content: space-around; align-items: center; background: var(--surface); border-top: 1px solid var(--line);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left)); }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 0; }
.nav button.on { color: var(--accent); font-weight: 600; }
.nav .plus span { width: 50px; height: 50px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(15,107,85,.35); }
.nav .plus .i { width: 26px; height: 26px; }

/* home */
.hello { color: var(--muted); }
.hello b { color: var(--ink); }
.hero { background: var(--accent); color: var(--accent-ink); border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 2px; }
.hero.neg { background: var(--charge); }
.hero small { opacity: .85; font-size: 13px; }
.hero .big { font-size: 2.1rem; line-height: 1.2; text-align: start; }
.hero .big small { font-size: 1rem; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; min-width: 0; }
.mini small { color: var(--muted); font-size: 12.5px; }
.mini .num { font-size: 1.15rem; }
.meter { height: 8px; background: var(--chip); border-radius: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--charge); border-radius: 8px; }
.lbl { font-family: var(--f-body); font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.empty { color: var(--muted); font-size: 14px; background: var(--surface); border: 1px dashed var(--line); border-radius: 16px; padding: 18px; text-align: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.due { border-color: var(--accent); display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; }
.due-h { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.due-h b { flex: 1; font-size: 14px; }

/* lists */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-top: 1px solid var(--line); text-align: start; width: 100%; }
.list > .row:first-child, .due .row { border-top: 0; }
.due .row { padding-inline: 0; }
button.row:active, .row.sel { background: var(--chip); }
.row .m { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .m b { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .m > span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-row { color: var(--accent); }
.add-form input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 4px 0; }
.ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: color-mix(in srgb, var(--c) var(--icmix), var(--ink)); }
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.big2 { font-size: 1.2rem; }
.tr { display: block; height: 6px; background: var(--chip); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.tr i { display: block; height: 100%; border-radius: 6px; background: var(--c); }

/* report */
.bars { display: flex; flex-direction: column; gap: 10px; }
.b { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto 3.2em; gap: 8px; align-items: center; font-size: 13px; }
.b .bn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b .tr { height: 10px; margin: 0; }
.b .pct { color: var(--muted); text-align: end; }
.months { display: flex; gap: 8px; align-items: stretch; height: 140px; }
.mo { flex: 1; display: flex; flex-direction: column; gap: 4px; align-items: center; min-width: 0; }
.mo .pair { flex: 1; width: 100%; display: flex; gap: 3px; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--line); }
.mo i { display: block; width: 40%; max-width: 16px; border-radius: 4px 4px 0 0; min-height: 1px; }
.bi { background: var(--income); } .bo { background: var(--charge); }
.mo .ml { font-size: 11px; color: var(--muted); white-space: nowrap; }
.mo.cur .ml { color: var(--ink); font-weight: 600; }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: block; }
.legend .num { margin-inline-start: auto; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; white-space: nowrap; }
.chip.sel { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chips .chip.sel[style] { background: var(--c); color: #fff; }
.chip.dashed { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }

/* sheet */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 20; animation: fade .18s ease; }
.sheet { position: fixed; inset: auto 0 0 0; z-index: 21; background: var(--bg); border-radius: 24px 24px 0 0; max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); animation: up .22s ease; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; }
.sheet-h b { font-family: var(--f-display); font-size: 1.1rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--chip); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px; border-radius: 9px; font-weight: 500; }
.seg .on { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 8px; direction: ltr; padding: 4px 0; }
.amount input { font: 500 2.4rem var(--f-num); text-align: center; width: 7em; max-width: 70%; border: 0; border-bottom: 2px solid var(--line); background: transparent; outline: none; }
.amount input:focus { border-color: var(--accent); }
.amount small { color: var(--muted); font-size: 1rem; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.dialog { position: fixed; z-index: 31; inset: 50% 16px auto 16px; transform: translateY(-50%); max-width: 360px; margin: 0 auto; background: var(--surface); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.dialog + .overlay, .overlay:has(+ .dialog) { z-index: 30; }
.toast { position: fixed; z-index: 40; inset-inline: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 14px; animation: fade .2s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
@media (min-width: 700px) { .nav { max-width: 560px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; } }
