/* Money. Each envelope takes the colour of a South African banknote;
   its card drains as the money is spent. */
:root {
  --paper: #eef1ee;
  --card: #ffffff;
  --ink: #14201b;
  --muted: #5a6761;
  --line: #d3dad5;
  --primary: #14503b;
  --on-primary: #ffffff;
  --over: #b42318;
  --over-tint: rgba(180, 35, 24, 0.1);
  --good: #1f7a4d;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(20, 32, 27, 0.06), 0 6px 20px rgba(20, 32, 27, 0.05);

  --hue-0: #2f7d4f; --tint-0: rgba(47, 125, 79, 0.17);   /* R10 green */
  --hue-1: #2c6a9c; --tint-1: rgba(44, 106, 156, 0.16);  /* R100 blue */
  --hue-2: #c4701a; --tint-2: rgba(196, 112, 26, 0.18);  /* R200 orange */
  --hue-3: #b5445a; --tint-3: rgba(181, 68, 90, 0.16);   /* R50 red */
  --hue-4: #7a5aa6; --tint-4: rgba(122, 90, 166, 0.16);
  --hue-pool: #a07a1c; --tint-pool: rgba(160, 122, 28, 0.16);

  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", "Noto Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1513;
    --card: #18211e;
    --ink: #e8efeb;
    --muted: #9aa8a1;
    --line: #2a3631;
    --primary: #5fc79b;
    --on-primary: #0a1511;
    --over: #ff8a7a;
    --over-tint: rgba(255, 138, 122, 0.13);
    --good: #6fd3a3;
    --focus: #7aa7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --hue-0: #5fc79b; --tint-0: rgba(95, 199, 155, 0.2);
    --hue-1: #6fb0e6; --tint-1: rgba(111, 176, 230, 0.2);
    --hue-2: #f0a050; --tint-2: rgba(240, 160, 80, 0.2);
    --hue-3: #f08aa0; --tint-3: rgba(240, 138, 160, 0.2);
    --hue-4: #b79bea; --tint-4: rgba(183, 155, 234, 0.2);
    --hue-pool: #e6c262; --tint-pool: rgba(230, 194, 98, 0.18);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.boot { padding: 40vh 24px 0; text-align: center; color: var(--muted); }

.hue-0 { --hue: var(--hue-0); --tint: var(--tint-0); }
.hue-1 { --hue: var(--hue-1); --tint: var(--tint-1); }
.hue-2 { --hue: var(--hue-2); --tint: var(--tint-2); }
.hue-3 { --hue: var(--hue-3); --tint: var(--tint-3); }
.hue-4 { --hue: var(--hue-4); --tint: var(--tint-4); }
.hue-pool { --hue: var(--hue-pool); --tint: var(--tint-pool); }

/* ---------- layout ---------- */
.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font: 600 34px/1.05 var(--serif); letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
h2 { margin: 28px 0 10px; font: 600 15px/1.2 var(--sans); }

/* ---------- salary banner ---------- */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; margin-bottom: 14px;
  background: var(--primary); color: var(--on-primary); border-radius: 16px;
}
.banner strong { display: block; font-weight: 650; }
.banner span { font-size: 14px; opacity: 0.85; }
.banner .banner-text { flex: 1 1 200px; }
.banner button {
  background: var(--on-primary); color: var(--primary); border: 0; border-radius: 999px;
  padding: 10px 16px; font-weight: 650; min-height: 44px;
}

/* ---------- extra income strip ---------- */
.income-strip {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 12px 4px 14px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
}
.income-strip .label { color: var(--muted); font-size: 14px; }
.income-strip .figure { font: 600 22px/1 var(--serif); font-variant-numeric: lining-nums tabular-nums; color: var(--good); }

/* ---------- envelope cards: the fill is the money left ---------- */
.envs { display: grid; gap: 10px; margin-top: 14px; }
.env {
  position: relative; overflow: hidden; width: 100%; text-align: left;
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 2px 12px;
  padding: 14px 16px 14px 20px; min-height: 92px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow);
}
.env::before { /* the coloured edge, like the flap of an envelope */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--hue);
}
.env .fill {
  position: absolute; left: 0; top: 0; bottom: 0; background: var(--tint);
  transition: width 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.env > *:not(.fill) { position: relative; }
.env-name { font-weight: 650; font-size: 16px; }
.env-of { color: var(--muted); font-size: 13px; grid-column: 1; }
.env-amount {
  grid-row: 1 / span 2; grid-column: 2; text-align: right;
  font: 600 28px/1 var(--serif); letter-spacing: -0.02em; font-variant-numeric: lining-nums tabular-nums;
}
.env-spent { grid-column: 2; text-align: right; color: var(--muted); font-size: 13px; }
.env.over { background: var(--over-tint); }
.env.over .env-amount { color: var(--over); }
.env.over::before { background: var(--over); }
.env.pool { border-style: dashed; }
.env.archived { opacity: 0.6; }

/* ---------- lists ---------- */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 6px; }
.list-head h2 { margin: 0; }
.link { background: none; border: 0; padding: 8px 0; color: var(--primary); font-weight: 600; }
.day { margin: 18px 0 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; width: 100%;
  padding: 12px 14px; background: none; border: 0; text-align: left; min-height: 60px;
}
.row + .row { border-top: 1px solid var(--line); }
.row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--hue, var(--muted)); }
.row-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.row-sub { display: block; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.row-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.pill { padding: 1px 8px; border-radius: 999px; background: var(--tint, var(--line)); color: var(--ink); }
.row-amt { font: 600 17px/1 var(--serif); font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; }
.row-amt.income { color: var(--good); }
.row-amt.transfer { color: var(--muted); }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 16px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 9px 14px; border-radius: 999px; min-height: 44px;
  border: 1px solid var(--line); background: var(--card);
}
.chip[aria-checked="true"], .chip[aria-pressed="true"] {
  background: var(--hue, var(--primary)); color: #fff; border-color: transparent; font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .chip[aria-checked="true"], .chip[aria-pressed="true"] { color: #0a1511; }
}
.select {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}

/* ---------- settings ---------- */
.setting { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; width: 100%; padding: 14px; background: none; border: 0; text-align: left; min-height: 56px; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting small { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.setting .val { color: var(--muted); font-variant-numeric: tabular-nums; }
.setting.strong { font-weight: 650; color: var(--primary); }

/* ---------- navigation ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: var(--nav-h); }
.nav button { background: none; border: 0; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 12px; }
.nav button[aria-current="page"] { color: var(--primary); font-weight: 650; }
.icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
.fab {
  position: fixed; z-index: 21; right: max(16px, calc((100vw - 560px) / 2 + 16px));
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 22px 0 18px;
  background: var(--primary); color: var(--on-primary); border: 0; border-radius: 999px;
  font-weight: 650; box-shadow: 0 8px 24px rgba(20, 80, 59, 0.35);
}

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(8, 14, 11, 0.5); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.18s ease-out; }
.sheet {
  width: 100%; max-width: 560px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  animation: rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font: 600 22px/1.2 var(--serif); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 0; background: var(--card); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: 14px; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 13px; }
input[type="text"], input[type="password"], input[type="date"], input[type="number"] {
  width: 100%; min-height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
.amount-wrap { position: relative; }
.amount-wrap span { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font: 600 26px/1 var(--serif); color: var(--muted); }
.amount-wrap input { padding-left: 42px; min-height: 64px; font: 600 30px/1 var(--serif); letter-spacing: -0.02em; font-variant-numeric: lining-nums tabular-nums; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--line); border-radius: 14px; }
.seg button { border: 0; background: none; min-height: 44px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { display: grid; text-align: left; gap: 0; padding: 8px 14px; }
.chips .chip small { font-size: 12px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.radio { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.radio input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--primary); }
.radio:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.radio strong { display: block; }
.radio span { color: var(--muted); font-size: 14px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.note { padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.error { color: var(--over); font-weight: 600; font-size: 14px; min-height: 0; }
.btn {
  min-height: 52px; border-radius: 14px; border: 0; padding: 0 18px; font-weight: 650;
  background: var(--primary); color: var(--on-primary);
}
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--over-tint); color: var(--over); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- sign in ---------- */
.login { max-width: 400px; margin: 0 auto; padding: calc(14vh + env(safe-area-inset-top)) 22px 40px; }
.login h1 { margin: 0 0 4px; font: 600 44px/1 var(--serif); letter-spacing: -0.03em; }
.login p { margin: 0 0 28px; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-weight: 600; font-size: 14px; box-shadow: var(--shadow);
  animation: rise 0.2s ease-out;
}
.toast.bad { background: var(--over); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
