/* Daftari v1.5.0 — Arabic RTL mobile-first styles */
:root{
  --bg:#f3f5f4; --panel:#ffffff; --ink:#10201b; --ink2:#33423d; --muted:#56645f; --line:#d6ddda; --line2:#e3e8e6;
  --brand:#0a5c44; --brand-dark:#073f2f; --brand-soft:#e4efe9;
  --owe:#b4470f; --owe-soft:#fff1e8; --owe-line:#f1cfb6; --owe-ink:#7a3410;
  --ok:#0a6b4f; --wa:#1f8a4c;
  --brand-text:#0a5c44; --owe-text:#b4470f;
  --strong:#10201b; --soft:#e7ecea; --hover:#f7f9f8; --thead:#eef3f1; --handle:#c3ccc8; --faint:#8a9692;
  --bal-line:#c6ddd2; --owe-panel:#fff4ec; --shadow:rgba(10,60,45,.3);
  color-scheme:light;
  --radius:14px;
  --font:'Cairo', Tahoma, Arial, sans-serif;
}
:root[data-theme="dark"]{
  --bg:#0e1513; --panel:#16201c; --ink:#e6eeeb; --ink2:#c3cfcb; --muted:#97a6a0; --line:#33433d; --line2:#253330;
  --brand:#0e7556; --brand-dark:#0a5c44; --brand-soft:#173a30;
  --owe:#bf5418; --owe-soft:#3a2216; --owe-line:#6a3a20; --owe-ink:#f2b48d;
  --ok:#4fcf9b; --wa:#1f8a4c;
  --brand-text:#5fd3a6; --owe-text:#f29a64;
  --strong:#2f413b; --soft:#24312d; --hover:#1c2824; --thead:#1c2824; --handle:#45554f; --faint:#7f8f89;
  --bal-line:#2a5546; --owe-panel:#2c1c13; --shadow:rgba(0,0,0,.45);
  color-scheme:dark;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{background:var(--bg);color:var(--ink);font:500 16.5px/1.5 var(--font);-webkit-tap-highlight-color:transparent}
button,input,select,textarea{font:inherit;color:inherit}
[hidden]{display:none!important}
.num{direction:ltr;unicode-bidi:isolate;font-variant-numeric:tabular-nums}
.small{font-size:14px}
.muted{color:var(--muted)}

#app{max-width:520px;margin:0 auto;min-height:100%;background:var(--bg);position:relative}
.view{min-height:100vh;min-height:100dvh;display:flex;flex-direction:column;padding-bottom:calc(96px + env(safe-area-inset-bottom,0px))}
#view-loading,#view-auth,#view-setup{padding-bottom:24px}
.center-box{margin:auto;display:flex;flex-direction:column;align-items:center;gap:12px}

/* ---------- auth ---------- */
.logo-mark{width:64px;height:64px;border-radius:18px;background:var(--brand);color:#fff;display:grid;place-items:center;font:800 37.5px var(--font);box-shadow:0 8px 24px var(--shadow)}
.auth-hero{padding:48px 24px 20px;display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px}
.auth-hero h1{margin:6px 0 0;font-size:31px;font-weight:800}
.auth-hero p{margin:0;color:var(--muted);max-width:32ch}
.auth-card{margin:0 16px;background:var(--panel);border:1px solid var(--line2);border-radius:20px;padding:18px;display:flex;flex-direction:column;gap:12px}

/* ---------- controls ---------- */
.field{display:flex;flex-direction:column;gap:6px}
.field > span{font-size:14.5px;font-weight:600;color:var(--ink2)}
.field input,.field select,.field textarea{height:48px;border:1px solid var(--line);border-radius:12px;padding:0 12px;background:var(--panel);font-size:17.5px;width:100%}
.field input:focus,.field select:focus{outline:2px solid var(--brand-text);outline-offset:0;border-color:transparent}
.btn{min-height:50px;border-radius:var(--radius);border:0;padding:0 16px;font-weight:800;font-size:17.5px;display:flex;align-items:center;justify-content:center;gap:8px;cursor:pointer;text-decoration:none;width:100%}
.btn:disabled{opacity:.5;cursor:not-allowed}
.btn.primary{background:var(--brand);color:#fff}
.btn.primary:active{background:var(--brand-dark)}
.btn.debt{background:var(--owe);color:#fff}
.btn.wa{background:var(--wa);color:#fff}
.btn.ghost{background:var(--panel);color:var(--ink);border:1px solid var(--line)}
.link{background:none;border:0;color:var(--brand-text);font-weight:700;padding:10px;cursor:pointer;min-height:44px}
.seg{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));background:var(--soft);border-radius:14px;padding:4px}
.seg button{min-height:44px;border:0;border-radius:11px;background:transparent;font-weight:700;color:var(--ink2);cursor:pointer}
.seg button.on{background:var(--strong);color:#fff}
.seg.type button.on[data-v="debt"]{background:var(--owe)}
.seg.type button.on[data-v="pay"]{background:var(--brand)}
.icon-btn{width:44px;height:44px;border-radius:22px;border:0;background:transparent;display:grid;place-items:center;cursor:pointer;color:var(--ink);flex:none;text-decoration:none}
.icon-btn.light{border:1px solid rgba(255,255,255,.4);color:#fff}
.icon-btn.outline{border:1px solid var(--line);background:var(--panel)}
button:focus-visible,a:focus-visible,input:focus-visible{outline:2px solid var(--brand-text);outline-offset:2px}

/* ---------- home ---------- */
.hero{background:var(--brand);color:#fff;padding:calc(18px + env(safe-area-inset-top,0px)) 18px 22px;display:flex;flex-direction:column;gap:16px}
.hero-top{display:flex;justify-content:space-between;align-items:center}
.hero-title{display:flex;flex-direction:column}
.hero-title .small{opacity:.85}
.hero-title .big{font-size:26.5px;font-weight:800;line-height:1.2}
.stats{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.stat{background:rgba(255,255,255,.12);border-radius:14px;padding:12px 14px;display:flex;flex-direction:column;min-width:0}
.stat .small{opacity:.9}
.stat > .num:not(.small){font-size:24px;font-weight:800;text-align:start}
.stat .small.num{text-align:start;min-height:1.5em}
.toolbar{padding:14px 16px 6px;display:flex;flex-direction:column;gap:10px}
.search{display:flex;align-items:center;gap:8px;background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:0 12px;height:48px;color:var(--muted)}
.search input{border:0;outline:0;flex:1;background:transparent;font-size:17.5px;color:var(--ink);min-width:0}
.chips{display:flex;gap:8px;overflow-x:auto;scrollbar-width:none}
.chip{height:38px;padding:0 14px;border-radius:19px;border:1px solid var(--line);background:var(--panel);font-weight:600;font-size:15px;white-space:nowrap;cursor:pointer}
.chip.on{background:var(--strong);color:#fff;border-color:var(--strong)}

.list{list-style:none;margin:0;padding:4px 16px;display:flex;flex-direction:column;gap:8px}
.row{background:var(--panel);border:1px solid var(--line2);border-radius:var(--radius);padding:12px 14px;display:flex;align-items:center;gap:12px;cursor:pointer;width:100%;text-align:start}
.row:active{background:var(--hover)}
.avatar{width:42px;height:42px;border-radius:21px;background:var(--brand-soft);color:var(--brand-text);display:grid;place-items:center;font-weight:800;font-size:17.5px;flex:none}
.row-main{flex:1;display:flex;flex-direction:column;min-width:0}
.row-main .name{font-weight:700;font-size:16.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row-main .small{color:var(--muted)}
.row-amt{display:flex;flex-direction:column;align-items:flex-end;gap:0}
.row-amt .num{font-weight:800;font-size:16.5px}
.owe{color:var(--owe-text)}
.cr{color:var(--ok)}
.zero{color:var(--muted)}
.tag{font-size:12.5px;font-weight:700}
.empty{color:var(--muted);text-align:center;padding:28px 24px;margin:0}

.fab{position:fixed;bottom:calc(22px + env(safe-area-inset-bottom,0px));inset-inline-end:max(18px, calc(50% - 242px));height:56px;padding:0 22px;border-radius:28px;border:0;background:var(--brand);color:#fff;display:flex;align-items:center;gap:8px;font-weight:800;font-size:17.5px;box-shadow:0 6px 18px var(--shadow);cursor:pointer;z-index:5}

/* ---------- customer ---------- */
.bar{background:var(--panel);border-bottom:1px solid var(--line2);padding:calc(10px + env(safe-area-inset-top,0px)) 10px 10px;display:flex;align-items:center;gap:8px;position:sticky;top:0;z-index:4}
.bar-title{flex:1;display:flex;flex-direction:column;min-width:0}
.bar-title .name{font-weight:800;font-size:18.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bar-title .small{color:var(--muted);text-align:start}
.balance{margin:14px 16px 0;border-radius:16px;padding:16px;display:flex;flex-direction:column;gap:4px;background:var(--brand-soft);border:1px solid var(--bal-line);color:var(--ink)}
.balance.owing{background:var(--owe-panel);border-color:var(--owe-line);color:var(--owe-ink)}
.bal-row{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 12px}
.bal-row .num{font-size:33px;font-weight:800}
.bal-row .num + .num{font-size:18.5px}
.balance.owing .bal-row .num{color:var(--owe-text)}
.actions2{padding:12px 16px 0;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.actions2 .btn{font-size:16px;min-height:50px}
.section-head{padding:16px 16px 6px;display:flex;justify-content:space-between;align-items:center;font-weight:800}
.entries .row{cursor:default;padding:10px 12px 10px 6px}
.sign{width:34px;height:34px;border-radius:10px;display:grid;place-items:center;font-weight:800;font-size:20px;flex:none}
.sign.debt{background:var(--owe-soft);color:var(--owe-text)}
.sign.pay{background:var(--brand-soft);color:var(--ok)}
.del{width:40px;height:40px;border:0;background:none;color:var(--faint);border-radius:20px;display:grid;place-items:center;cursor:pointer;flex:none}
.del:hover{color:var(--owe-text);background:var(--owe-soft)}
.bottom-actions{position:fixed;bottom:0;left:50%;transform:translateX(-50%);width:100%;max-width:520px;background:var(--panel);border-top:1px solid var(--line2);padding:12px 16px calc(14px + env(safe-area-inset-bottom,0px));display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;z-index:5}
.bottom-actions .btn{min-height:54px}

/* ---------- sheet ---------- */
.sheet-wrap{position:fixed;inset:0;z-index:20;display:flex;align-items:flex-end;justify-content:center}
.sheet-backdrop{position:absolute;inset:0;background:rgba(10,20,16,.45)}
.sheet{position:relative;width:100%;max-width:520px;max-height:92vh;overflow:auto;background:var(--bg);border-radius:22px 22px 0 0;padding:8px 16px calc(18px + env(safe-area-inset-bottom,0px));animation:up .2s ease-out}
@keyframes up{from{transform:translateY(30px);opacity:.5}to{transform:none;opacity:1}}
.sheet-handle{width:44px;height:5px;border-radius:3px;background:var(--handle);margin:4px auto 10px}
#sheetBody{display:flex;flex-direction:column;gap:12px}
#sheetBody h2{margin:0;font-size:21px;font-weight:800}
.amount-box{background:var(--panel);border:1px solid var(--line2);border-radius:16px;padding:14px;display:flex;flex-direction:column;align-items:center;gap:10px}
.amount-box input{border:0;outline:0;text-align:center;font:800 44px var(--font);width:100%;background:transparent;direction:ltr}
.amount-box.debt input{color:var(--owe-text)}
.amount-box.pay input{color:var(--ok)}
.cur{display:flex;gap:6px}
.cur button{height:38px;padding:0 16px;border-radius:19px;border:1px solid var(--line);background:var(--panel);font-weight:700;font-size:15px;cursor:pointer}
.cur button.on{background:var(--strong);color:#fff;border-color:var(--strong)}
.check{display:flex;align-items:center;gap:8px;font-size:15.5px;color:var(--ink2);min-height:44px}
.check input{width:20px;height:20px;accent-color:var(--brand-text);margin:0}
.grid2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}

/* pricing */
.feat{display:flex;flex-direction:column;gap:8px;padding:4px 0}
.feat div{display:flex;align-items:center;gap:10px;font-weight:600;font-size:16px}
.feat i{width:24px;height:24px;border-radius:12px;background:var(--brand-soft);color:var(--brand-text);display:grid;place-items:center;flex:none;font-style:normal}
.plan{border-radius:16px;padding:14px 16px;background:var(--panel);border:1px solid var(--line);display:flex;align-items:center;gap:12px;cursor:pointer;width:100%;text-align:start}
.plan.on{border:2px solid var(--brand-text);padding:13px 15px}
.plan .radio{width:22px;height:22px;border-radius:11px;border:2px solid var(--brand-text);display:grid;place-items:center;flex:none}
.plan.on .radio::after{content:'';width:12px;height:12px;border-radius:6px;background:var(--brand-text)}
.plan .pm{flex:1;display:flex;flex-direction:column}
.plan .pm b{font-size:17.5px}
.plan .pp{display:flex;flex-direction:column;align-items:flex-end}
.plan .pp .num{font-weight:800;font-size:20px}
.badge{font-size:12px;font-weight:700;background:var(--strong);color:#fff;border-radius:6px;padding:0 6px}
.plan-box{background:var(--panel);border:1px solid var(--line2);border-radius:14px;padding:12px 14px;display:flex;justify-content:space-between;align-items:center;gap:10px}
.pro-pill{background:var(--brand);color:#fff;border-radius:8px;padding:2px 10px;font-weight:800;font-size:14.5px}
.free-pill{background:var(--soft);color:var(--ink2);border-radius:8px;padding:2px 10px;font-weight:800;font-size:14.5px}

/* dialog + toast */
.dlg-wrap{position:fixed;inset:0;z-index:30;background:rgba(10,20,16,.5);display:grid;place-items:center;padding:20px}
.dlg{background:var(--panel);border-radius:18px;padding:20px;max-width:360px;width:100%;display:flex;flex-direction:column;gap:10px}
.dlg h3{margin:0;font-size:20px;font-weight:800}
.dlg p{margin:0;color:var(--ink2)}
.dlg-btns{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin-top:6px}
.toast{position:fixed;top:calc(16px + env(safe-area-inset-top,0px));left:50%;transform:translateX(-50%);background:var(--strong);color:#fff;padding:10px 18px;border-radius:24px;font-weight:600;font-size:15.5px;z-index:40;max-width:calc(100% - 32px);box-shadow:0 6px 18px rgba(0,0,0,.2);text-align:center}
.toast.err{background:var(--owe)}

/* ---------- print (statement) ---------- */
#printArea{display:none}
@media print{
  @page{size:A4;margin:14mm}
  body{background:#fff}
  #app,.sheet-wrap,.dlg-wrap,.toast,.fab,.bottom-actions{display:none!important}
  #printArea{display:block;font:500 12pt/1.5 var(--font);color:#000}
  #printArea h1{font-size:20pt;margin:0}
  #printArea .meta{display:flex;justify-content:space-between;margin:6px 0 14px;font-size:11pt;color:#333}
  #printArea table{width:100%;border-collapse:collapse;font-size:11pt}
  #printArea th,#printArea td{border-bottom:1px solid #bbb;padding:6px 4px;text-align:start;vertical-align:top}
  #printArea th{background:#eef3f1;font-weight:700}
  #printArea td.num,#printArea th.num{text-align:end}
  #printArea .tot{margin-top:14px;font-size:13pt;font-weight:800}
  #printArea .foot{margin-top:24px;font-size:9pt;color:#555}
}
@media (prefers-reduced-motion:reduce){.sheet{animation:none}}

/* theme toggle + smooth switch */
.theme-ico .sun{display:none}
:root[data-theme="dark"] .theme-ico .sun{display:block}
:root[data-theme="dark"] .theme-ico .moon{display:none}
body,.panel,.row,.sheet,.card,.k{transition:background-color .2s,border-color .2s,color .2s}
@media (prefers-reduced-motion:reduce){body,.row,.sheet,.card,.k{transition:none}}

/* v1.4 — language switch, dial code, LTR support */
.corner-tools{position:absolute;top:14px;inset-inline-end:14px;display:flex;gap:8px;align-items:center;z-index:2}
#view-auth,#view-setup{position:relative}
.lang-btn{min-height:44px;padding:0 14px;border-radius:22px;border:1px solid var(--line);background:var(--panel);color:var(--ink);font-weight:700;cursor:pointer;font-family:'Cairo',system-ui,sans-serif}
.lang-select{min-height:44px;padding:0 12px;border-radius:22px;border:1px solid var(--line);background:var(--panel);color:var(--ink);font-weight:700;font-size:15px;cursor:pointer;font-family:'Cairo',system-ui,sans-serif;max-width:160px}
.lang-select:focus-visible{outline:2px solid var(--brand,#0a5c44);outline-offset:2px}
.dial-wrap{display:flex;align-items:center;gap:6px;height:48px;border:1px solid var(--line);border-radius:12px;padding:0 12px;background:var(--panel)}
.dial-wrap b{color:var(--muted)}
.dial-wrap input{border:0;outline:0;background:transparent;flex:1;font-size:17.5px;min-width:0;height:100%;padding:0}
.field small{font-size:13px}
.field select{appearance:auto;padding:0 10px}
[dir="ltr"] .back-btn svg{transform:scaleX(-1)}
[dir="ltr"] body{font-family:'Cairo',system-ui,-apple-system,'Segoe UI',sans-serif}
.cur{flex-wrap:wrap;justify-content:center}
[dir="rtl"] .stat .num,[dir="rtl"] .bar-title .small.num{text-align:right}
