:root {
  color-scheme: light;
  --bg: #f4f5f1; --card: #fff; --ink: #17231f; --dim: #5c6b65; --line: #dfe4dd;
  --brand: #0f4c43; --brand-ink: #fff; --soft: #e3eee9; --in: #14794f; --out: #b3372b; --project: #9a5b00; --warn: #fff1d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101715; --card: #18211e; --ink: #e9efec; --dim: #9aaaa3; --line: #2b3833;
    --brand: #17594e; --soft: #203a33; --in: #5fcf9d; --out: #f08a7d; --project: #e5ae5c; --warn: #43351a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "IBM Plex Sans Arabic", "Segoe UI", "Noto Sans Arabic", system-ui, Tahoma, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--in); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }

header, main, nav .in { max-width: 560px; margin-inline: auto; }
header { display: flex; align-items: center; gap: 4px; padding: calc(10px + env(safe-area-inset-top)) 16px 6px; }
header h1 { font-size: 1.3rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.icon { width: 44px; height: 44px; border: 0; background: none; border-radius: 12px; display: grid; place-items: center; flex: none; }
svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { padding: 4px 16px calc(104px + env(safe-area-inset-bottom)); display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }

nav { position: fixed; inset: auto 0 0; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 2; }
nav .in { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
nav a { display: grid; justify-items: center; padding: 9px 0; font-size: .75rem; color: var(--dim); min-height: 58px; }
nav a[aria-current] { color: var(--in); font-weight: 700; }
nav button { justify-self: center; width: 54px; height: 54px; border-radius: 18px; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; margin-top: -16px; box-shadow: 0 0 0 5px var(--bg); }

.hero { background: var(--brand); color: #fff; border-radius: 22px; padding: 18px 20px; display: grid; gap: 4px; }
.hero small { opacity: .85; }
.hero .big { font-size: 2.1rem; font-weight: 700; line-height: 1.3; }
.hero .split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; padding-top: 12px; border-top: 1px solid #ffffff38; }
.hero b { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.card h2, .sec { font-size: 1rem; }
.sec { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.sec button, .link { border: 0; background: none; color: var(--in); font-weight: 600; padding: 8px 4px; min-height: 40px; }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.row > :last-child { flex: none; text-align: end; }
.dim, small { color: var(--dim); font-size: .85rem; }
.hero small { color: #fff; }
.num { font-weight: 700; white-space: nowrap; }
.in-c { color: var(--in); } .out-c { color: var(--out); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats > div { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 11px 14px; }
.stats b { display: block; font-size: 1.1rem; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick button { border: 1px solid var(--line); background: var(--card); border-radius: 16px; min-height: 52px; font-weight: 600; }
.list { padding: 2px 16px; gap: 0; }
.list > * + * { border-top: 1px solid var(--line); }
.item { width: 100%; border: 0; background: none; text-align: start; padding: 11px 0; min-height: 56px; }
.item small { display: block; }
.day { font-size: .85rem; color: var(--dim); margin-top: 4px; }
.bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--in); border-radius: 4px; }
.bar i.p { background: var(--project); } .bar i.over { background: var(--out); }
.seg, .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { background: var(--soft); padding: 4px; border-radius: 14px; flex-wrap: nowrap; }
.seg button { flex: 1; border: 0; background: none; border-radius: 11px; min-height: 42px; padding: 0 4px; font-size: .95rem; }
.seg [aria-pressed=true] { background: var(--card); font-weight: 700; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 12px; min-height: 44px; padding: 4px 14px; overflow-wrap: anywhere; }
.chips [aria-pressed=true] { background: var(--brand); border-color: var(--brand); color: #fff; }
.month { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.note { background: var(--warn); border-radius: 14px; padding: 12px 14px; font-size: .92rem; }
.empty { text-align: center; color: var(--dim); padding: 26px 10px; }

.btn { border: 0; border-radius: 14px; min-height: 50px; padding: 8px 16px; background: var(--brand); color: #fff; font-weight: 700; width: 100%; }
.btn.alt { background: var(--soft); color: var(--ink); }
.btn.danger { background: none; color: var(--out); border: 1px solid currentColor; }
.btn:disabled { opacity: .55; }
dialog { border: 0; padding: 0; background: var(--bg); color: var(--ink); width: 100%; max-width: 560px; max-height: 94dvh; margin: auto auto 0; border-radius: 24px 24px 0 0; overflow-y: auto; overscroll-behavior: contain; }
dialog::backdrop { background: #0009; }
dialog form { padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
dialog h2 { font-size: 1.15rem; }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 4px; }
input, select { width: 100%; min-height: 48px; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; }
textarea { width: 100%; border: 1px solid var(--line); background: var(--card); color: inherit; border-radius: 12px; padding: 10px 12px; font: inherit; resize: vertical; }
.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.three small { display: block; }
.three .num { white-space: normal; }
.badge { font-size: .8rem; padding: 2px 10px; border-radius: 10px; background: var(--soft); white-space: nowrap; }
.badge.go { color: var(--in); } .badge.done { background: var(--brand); color: #fff; }
.badge.over { color: var(--out); font-weight: 700; } .badge.set { background: var(--warn); }
input.amount { font-size: 1.8rem; font-weight: 700; text-align: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err { color: var(--out); font-weight: 600; }
.err:empty { display: none; }
.actions { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 calc(4px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
#toast { position: fixed; inset: auto 16px calc(90px + env(safe-area-inset-bottom)); margin: auto; max-width: 420px; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 3; }
#toast.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
