:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --text: #0f1b2d;
  --muted: #667085;
  --line: #e4e8ee;
  --brand: #12a150;
  --brand-ink: #0b7a3b;
  --brand-soft: #e5f6ec;
  --income: #12a150;
  --income-soft: #e5f6ec;
  --expense: #e5484d;
  --expense-soft: #fdebec;
  --transfer: #6d4aff;
  --transfer-soft: #efeaff;
  --pending: #d98100;
  --pending-soft: #fff3df;
  --irmi: #3e63dd;
  --ofek: #f08c00;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --hero: linear-gradient(135deg, #0f9d58 0%, #0b7a63 55%, #0a5f73 100%);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1119;
    --surface: #131c28;
    --surface-2: #1b2635;
    --text: #edf2f7;
    --muted: #8fa0b5;
    --line: #243246;
    --brand: #2bd46f;
    --brand-ink: #5fe39a;
    --brand-soft: #123424;
    --income: #3fd883;
    --income-soft: #123424;
    --expense: #ff6b6f;
    --expense-soft: #3a1a1e;
    --transfer: #9a82ff;
    --transfer-soft: #261f4a;
    --pending: #ffb340;
    --pending-soft: #3a2a10;
    --irmi: #7b97ff;
    --ofek: #ffb340;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
    --hero: linear-gradient(135deg, #0c7a43 0%, #095e4f 55%, #0a4a5c 100%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Arial Hebrew", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; border-radius: 10px; }

/* ---------- layout ---------- */
#app { display: grid; grid-template-columns: 1fr; min-height: 100dvh; }
.side { display: none; }
#view { padding: 16px 16px calc(112px + var(--safe-b)); max-width: 760px; width: 100%; margin: 0 auto; }
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr 74px 1fr 1fr; align-items: end;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab { display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: 12px; color: var(--muted); border-radius: 14px; }
.tab svg.i { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--brand-ink); font-weight: 700; }
.fab {
  justify-self: center; width: 58px; height: 58px; border-radius: 50%; margin-top: -26px;
  background: var(--hero); color: #fff; display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(15, 157, 88, 0.45);
}
.fab svg.i { width: 28px; height: 28px; stroke-width: 2.6; }

@media (min-width: 900px) {
  #app { grid-template-columns: 250px 1fr; }
  .tabbar { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100dvh;
    padding: 24px 16px; background: var(--surface); border-inline-end: 1px solid var(--line);
  }
  .side .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 4px 8px 18px; }
  .side .navbtn {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px;
    color: var(--muted); font-weight: 600; width: 100%; text-align: start;
  }
  .side .navbtn:hover { background: var(--surface-2); }
  .side .navbtn[aria-current="page"] { background: var(--brand-soft); color: var(--brand-ink); }
  .side .add { margin-top: 10px; }
  .side .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; color: var(--muted); font-size: 14px; }
  #view { padding: 32px 36px 48px; max-width: 1040px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}

/* ---------- primitives ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.stack { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.h-title { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.sec-title { font-size: 17px; font-weight: 800; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sec-title small { font-weight: 600; color: var(--muted); font-size: 13px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head .sub { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 14px; font-weight: 700; background: var(--surface-2); color: var(--text); transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--hero); color: #fff; box-shadow: 0 6px 16px rgba(15, 157, 88, 0.3); }
.btn.danger { background: var(--expense-soft); color: var(--expense); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; font-size: 16px;
}
.avatar.irmi { background: var(--irmi); }
.avatar.ofek { background: var(--ofek); }
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 600; border: 1.5px solid transparent; white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.on { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.pending { background: var(--pending-soft); color: var(--pending); }
.badge.repeat { background: var(--transfer-soft); color: var(--transfer); }
.badge.ok { background: var(--income-soft); color: var(--income); }

input[type="text"], input[type="tel"], input[type="number"], input[type="date"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { padding: 12px 14px; min-height: 90px; resize: vertical; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; color: var(--muted); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--hero); }
.login .panel { width: min(420px, 100%); background: var(--surface); border-radius: 28px; padding: 28px 22px; display: grid; gap: 18px; box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3); text-align: center; }
.login .logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 22px; background: var(--hero); display: grid; place-items: center; color: #fff; }
.login .logo svg.i { width: 40px; height: 40px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.who button { display: grid; justify-items: center; gap: 8px; padding: 16px 8px; border-radius: 18px; border: 2px solid var(--line); font-weight: 800; }
.who button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.err { color: var(--expense); font-weight: 700; min-height: 1.4em; }

/* ---------- hero + home ---------- */
.hero { background: var(--hero); color: #fff; border-radius: 26px; padding: 22px 20px; box-shadow: 0 16px 36px rgba(11, 122, 99, 0.35); position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); inset-inline-start: -70px; top: -90px; }
.hero .label { opacity: 0.85; font-weight: 600; }
.hero .big { font-size: clamp(40px, 11vw, 56px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0 10px; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { background: rgba(255, 255, 255, 0.18); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }

.settle { display: grid; gap: 14px; }
.settle .flow { display: flex; align-items: center; justify-content: center; gap: 14px; }
.settle .flow svg.i { width: 30px; height: 30px; color: var(--muted); transform: scaleX(-1); }
.settle .amount { font-size: 38px; font-weight: 800; text-align: center; }
.settle .sentence { text-align: center; font-weight: 700; font-size: 17px; }
.settle.ok { text-align: center; justify-items: center; }
.settle .why { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; }

.people { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.person-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.person-card .big { font-size: 24px; font-weight: 800; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; position: relative; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.meter > b { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--text); opacity: 0.55; border-radius: 2px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.kv b { color: var(--text); }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 2px; }
.kpi .v { font-size: 22px; font-weight: 800; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi.pending { background: var(--pending-soft); border-color: transparent; }
.kpi.pending .v { color: var(--pending); }

/* ---------- entries ---------- */
.list { display: grid; }
.entry { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; width: 100%; text-align: start; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.kind-ic { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; }
.kind-ic.income { background: var(--income-soft); color: var(--income); }
.kind-ic.expense { background: var(--expense-soft); color: var(--expense); }
.kind-ic.transfer { background: var(--transfer-soft); color: var(--transfer); }
.kind-ic.pending { background: var(--pending-soft); color: var(--pending); }
.entry .t { font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.entry .s { font-size: 13px; color: var(--muted); }
.entry .a { font-weight: 800; text-align: end; }
.entry .a.income { color: var(--income); }
.entry .a.expense { color: var(--expense); }
.entry .a.transfer { color: var(--transfer); }
.entry .a.pending { color: var(--pending); }
.month-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 4px 6px; font-weight: 800; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.month-head small { color: var(--muted); font-weight: 700; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }

/* ---------- charts + bars ---------- */
.chart { width: 100%; overflow-x: auto; direction: ltr; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .val { fill: var(--text); font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; }
.hbar { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hbar:last-child { border-bottom: 0; }
.hbar .top { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.hbar .sub { font-size: 13px; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: start; color: var(--muted); font-weight: 700; font-size: 12px; padding: 6px 4px; }
table.t td { padding: 10px 4px; border-top: 1px solid var(--line); font-weight: 600; }
table.t td.n, table.t th.n { text-align: end; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fact { background: var(--surface-2); border-radius: 14px; padding: 12px; display: grid; gap: 2px; }
.fact .l { font-size: 12px; color: var(--muted); font-weight: 700; }
.fact .v { font-weight: 800; font-size: 17px; }

/* ---------- overlay / wizard ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; display: none; }
#overlay.open { display: block; }
.scrim { position: absolute; inset: 0; background: rgba(8, 14, 24, 0.55); animation: fade 0.2s ease; }
.sheet {
  position: absolute; inset-inline: 0; bottom: 0; margin: 0 auto; width: min(560px, 100%); max-height: 94dvh; overflow: auto;
  background: var(--bg); border-radius: 28px 28px 0 0; padding: 14px 18px calc(22px + var(--safe-b)); animation: rise 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@media (min-width: 700px) { .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 28px; animation: pop 0.2s ease; } }
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.w-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.dots { display: flex; gap: 5px; flex: 1; justify-content: center; }
.dots i { height: 6px; border-radius: 9px; background: var(--line); flex: 1; max-width: 26px; }
.dots i.done { background: var(--brand); }
.dots i.now { background: var(--brand); opacity: 0.55; }
.q { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; margin: 6px 0 4px; line-height: 1.2; }
.hint { color: var(--muted); font-size: 14px; margin-bottom: 14px; min-height: 1.3em; }
.answer { display: grid; gap: 14px; margin: 14px 0 20px; }
.bigin { font-size: 34px; font-weight: 800; text-align: center; min-height: 72px; border-radius: 18px; }
.money-wrap { position: relative; }
.money-wrap .cur { position: absolute; inset-inline-start: 18px; top: 50%; transform: translateY(-50%); font-size: 28px; font-weight: 800; color: var(--muted); pointer-events: none; }
.bigin.has-cur { padding-inline-start: 46px; }
.picks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pick {
  display: grid; justify-items: center; gap: 8px; padding: 18px 10px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; text-align: center;
}
.pick[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.pick small { font-weight: 600; color: var(--muted); }
.pick.cat { padding: 14px 8px; }
.picks.three { grid-template-columns: repeat(3, 1fr); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 18px; }
.stepper .icon-btn { width: 60px; height: 60px; border-radius: 20px; font-size: 28px; font-weight: 800; color: var(--text); }
.stepper .val { font-size: 52px; font-weight: 800; min-width: 90px; text-align: center; }
.w-actions { display: flex; gap: 10px; }
.w-actions .btn { flex: 1; }
.note-box { background: var(--pending-soft); color: var(--pending); padding: 10px 14px; border-radius: 14px; font-weight: 600; font-size: 14px; }
.note-box.good { background: var(--income-soft); color: var(--income); }
.review { display: grid; }
.review button { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); width: 100%; text-align: start; }
.review button:last-child { border-bottom: 0; }
.review .k { color: var(--muted); font-size: 14px; font-weight: 600; }
.review .v { font-weight: 800; display: flex; align-items: center; gap: 8px; }

/* ---------- toast ---------- */
#toasts { position: fixed; inset-inline: 0; bottom: calc(96px + var(--safe-b)); z-index: 80; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
@media (min-width: 900px) { #toasts { bottom: 28px; } }
.toast { pointer-events: auto; background: #0f1b2d; color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 700; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35); display: flex; align-items: center; gap: 14px; animation: rise 0.25s ease; max-width: 480px; }
.toast button { color: #7ee2a8; font-weight: 800; }
.toast.err { background: #b42318; }

.install { background: var(--brand-soft); border-radius: 16px; padding: 14px; display: grid; gap: 10px; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.sync.off .dot { background: var(--pending); }
.spin { animation: spin 0.9s linear infinite; }
.import-preview { max-height: 38dvh; overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 4px 12px; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(28px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-46%) scale(0.97); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- login shell ---------- */
#app.is-login .side, #app.is-login .tabbar { display: none; }
#app.is-login { grid-template-columns: 1fr; }
#app.is-login #view { max-width: none; padding: 0; }

/* keep the main action reachable on long review sheets */
.sticky-actions { position: sticky; bottom: calc(-22px - var(--safe-b)); margin: 0 -18px -22px; padding: 14px 18px calc(22px + var(--safe-b)); background: linear-gradient(to bottom, transparent, var(--bg) 28%); }

/* view-only partner: 4 tabs, no add button */
.tabbar.viewer { grid-template-columns: repeat(4, 1fr); }
.review .rv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.review .rv:last-child { border-bottom: 0; }
