:root {
  /* "Marigold" – warm, flat, high-contrast */
  --primary: #d9480f;        /* burnt orange: buttons, active states */
  --primary-600: #b83a0b;
  --primary-50: #fff1e6;
  --primary-100: #ffdcc2;
  --sun: #ffc233;            /* marigold yellow: summary card */
  --sun-ink: #2b2118;        /* text on yellow */
  --income: #2e7d32;
  --income-soft: #e3f1e4;
  --expense: #c62828;
  --expense-soft: #fde7e7;
  --saving: #1565c0;
  --saving-soft: #e3eefb;
  --danger: #c62828;
  --bg: #fbf7f0;
  --card: #ffffff;
  --text: #2b2118;
  --text-2: #5c4e40;
  --muted: #8c7e70;
  --line: #ece3d5;
  --track: #f3ece1;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 3px 10px rgba(60, 40, 20, .05);
  --shadow-lg: 0 6px 20px rgba(60, 40, 20, .12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

/* Bundled Sinhala font so text looks the same on Android, iPhone and PC.
   Only used for Sinhala letters (unicode-range); scaled down a little to sit well next to Latin digits. */
@font-face {
  font-family: "App Sinhala";
  src: url("/fonts/noto-sans-sinhala.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0D80-0DFF, U+200C-200D, U+25CC;
  size-adjust: 90%;
}

/* manipulation = no double-tap zoom (fast keypad taps), pinch zoom still allowed */
* { box-sizing: border-box; touch-action: manipulation; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "App Sinhala", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Sinhala", "Sinhala Sangam MN", "Iskoola Pota", "Nirmala UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
html:lang(si) body { line-height: 1.5; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 18px; /* >=16px stops iOS from zooming in */
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-100); }
:focus-visible { outline: 3px solid #ffa94d; outline-offset: 2px; }
input::placeholder { color: #b3a594; }
/* iPhone Safari draws date inputs with its own fixed width/centering; make them behave like other inputs. */
input[type="date"] {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%; text-align: left; line-height: 1.3;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .6; }

h1, h2, h3 { margin: 0; line-height: 1.3; letter-spacing: -.01em; }
svg { flex: none; }

/* ---------- layout ---------- */
#app, .auth { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
#app { padding-bottom: calc(112px + var(--safe-b)); }
main { padding: 4px 16px 24px; transition: opacity .2s; }
main.loading { opacity: .55; }
main.slide-next { animation: slideNext .28s ease; }
main.slide-prev { animation: slidePrev .28s ease; }
@keyframes slideNext { from { opacity: .3; transform: translateX(28px); } }
@keyframes slidePrev { from { opacity: .3; transform: translateX(-28px); } }

.topbar, .auth-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + var(--safe-t)) 16px 6px;
}
.greet { display: flex; align-items: center; gap: 12px; min-width: 0; }
.greet .avatar { width: 44px; height: 44px; font-size: 19px; }
.greet-text { display: flex; flex-direction: column; min-width: 0; }
.greet-app { font-size: 13px; color: var(--muted); font-weight: 600; }
.greet-name { font-size: 19px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 19px; }
.brand img { border-radius: 10px; }

.lang-btn {
  flex: none; border: 0; background: #fff; color: var(--primary);
  border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 15px; min-height: 40px;
  box-shadow: var(--shadow);
}

.offline-banner {
  position: sticky; top: 0; z-index: 30;
  background: #fef3c7; color: #78350f; text-align: center;
  padding: calc(8px + var(--safe-t)) 16px 8px; font-size: 15px; font-weight: 600;
}

/* me / household switch */
.scope-bar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 10px 16px 0; padding: 4px; background: var(--track); border-radius: 16px;
}
.scope-bar button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: transparent; border-radius: 12px; min-height: 44px; padding: 6px 10px;
  font-weight: 650; color: var(--text-2); overflow: hidden; transition: background .15s, color .15s;
}
.scope-bar button span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scope-bar button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(60, 40, 20, .12); }
.scope-emoji { font-size: 18px; }

/* month switcher */
.month-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px 4px; }
.month-center { text-align: center; flex: 1; }
.month-label {
  border: 0; background: none; padding: 2px 8px; border-radius: 10px;
  font-size: 20px; font-weight: 750; color: var(--text); line-height: 1.3;
}
.month-label:active { background: var(--track); }
.round-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; background: #fff; box-shadow: var(--shadow);
  font-size: 26px; line-height: 1; color: var(--text); display: grid; place-items: center; padding-bottom: 3px;
}
.round-btn:disabled { opacity: .35; cursor: default; box-shadow: none; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 650; padding: 4px; text-decoration: none; font-size: 15px; }
.link-btn.center { display: block; margin: 16px auto 0; }

/* floating bottom navigation */
.bottom-nav {
  position: fixed; z-index: 20;
  left: 0; right: 0; bottom: calc(10px + var(--safe-b));
  width: calc(100% - 24px); max-width: 496px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: #fff; border-radius: 22px; padding: 6px; border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: 4px 2px; border-radius: 18px; color: var(--muted); text-decoration: none;
  font-size: 12px; font-weight: 650; text-align: center; line-height: 1.25; transition: color .15s, background .15s;
}
.nav-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.active { color: var(--primary); background: var(--primary-50); }
.fab {
  justify-self: center; display: grid; place-items: center;
  margin-top: -30px; padding: 0; border: 0; background: none;
}
.fab-circle {
  width: 60px; height: 60px; border-radius: 50%; border: 5px solid var(--bg);
  background: var(--primary); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(217, 72, 15, .35); transition: transform .1s;
}
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.fab:active .fab-circle { transform: scale(.94); }

/* ---------- common pieces ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 2px 8px; }
.section-head h3 { font-size: 18px; font-weight: 750; }
.hint { color: var(--muted); font-size: 14px; margin: -4px 2px 12px; }
.hint.tight { margin: 8px 0 0; }
.muted { color: var(--muted); font-weight: 500; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 30px 12px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty-rich { padding: 26px 18px; }
.empty-rich .empty-ico { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.empty-rich p { margin: 0 0 14px; color: var(--text-2); font-weight: 600; }
.empty-rich .btn { min-width: 60%; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.saving { color: var(--saving); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 10px 20px; border-radius: 14px; border: 1.5px solid transparent;
  font-weight: 650; font-size: 16px; text-align: center; transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-600); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-outline { background: #fff; border-color: #fecdd3; color: var(--danger); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 12px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--track);
  display: grid; place-items: center; font-size: 16px; color: var(--text-2); flex: none;
}
.icon-btn.sm { width: 32px; height: 32px; font-size: 13px; }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%; font-weight: 700; color: #fff;
  background: var(--c, #d9480f);
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 27px; }
.pc0 { --c: #d9480f; } .pc1 { --c: #1565c0; } .pc2 { --c: #2e7d32; }
.pc3 { --c: #8e24aa; } .pc4 { --c: #c2185b; } .pc5 { --c: #6d4c41; }
.chip {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 9px; border-radius: 999px; margin-right: 6px;
  color: var(--c); background: #f4ede2; background: color-mix(in srgb, var(--c) 12%, white);
}

.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-weight: 650; font-size: 14px; margin-bottom: 6px; color: var(--text-2); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 140px; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-weight: 600; font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(112px + var(--safe-b)); z-index: 100;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: #2b2118; color: #fff; padding: 12px 20px; border-radius: 14px;
  max-width: calc(100% - 32px); text-align: center; transition: .25s; font-weight: 600; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Undo bar */
.snack {
  position: fixed; left: 50%; bottom: calc(112px + var(--safe-b)); z-index: 101;
  display: flex; align-items: center; gap: 16px; width: calc(100% - 32px); max-width: 480px;
  padding: 10px 10px 10px 18px; border-radius: 16px; background: var(--sun-ink); color: #fff; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 16px); opacity: 0; transition: .25s; font-weight: 650;
}
.snack.show { transform: translate(-50%, 0); opacity: 1; }
.snack span { flex: 1; }
.snack button { min-height: 44px; padding: 8px 18px; border: 0; border-radius: 12px; background: var(--sun); color: var(--sun-ink); font-weight: 800; font-size: 16px; }

/* Saved! tick */
.done-fx { position: fixed; inset: 0; z-index: 102; display: grid; place-items: center; pointer-events: none; }
.done-fx svg { width: 96px; height: 96px; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.done-fx circle { fill: var(--income); stroke: none; }
.done-fx path { stroke: #fff; stroke-width: 4.5; stroke-dasharray: 40; stroke-dashoffset: 40; }
.done-fx.play svg { animation: popIn .9s ease forwards; }
.done-fx.play path { animation: drawTick .35s .15s ease forwards; }
@keyframes popIn { 0% { transform: scale(.5); opacity: 0; } 20% { transform: scale(1.08); opacity: 1; } 35% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(.96); } }
@keyframes drawTick { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .done-fx path { stroke-dashoffset: 0; } }

/* Pull to refresh */
.ptr {
  position: fixed; top: calc(-40px + var(--safe-t)); left: 50%; z-index: 40; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 50%; background: #fff; box-shadow: var(--shadow-lg);
  color: var(--muted); opacity: 0; transform: translate(-50%, 0); transition: opacity .15s;
}
.ptr.show { opacity: 1; }
.ptr.ready { color: var(--primary); }
.ptr svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ptr.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading placeholders */
.sk { display: block; border-radius: 12px; background: linear-gradient(90deg, #efe7da 25%, #f7f1e7 50%, #efe7da 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-hero { height: 150px; border-radius: 22px; margin-top: 10px; }
.sk-stat { height: 86px; border-radius: 18px; }
.sk-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.sk-ico { width: 44px; height: 44px; flex: none; }
.sk-line { height: 14px; margin: 6px 0; }
.sk-line.short { width: 50%; }

/* Category list on Home ("where the money went") */
.cat-list { padding: 4px 14px; }
.cat-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 0; border: 0; background: none;
  text-align: left; color: inherit;
}
.cat-row + .cat-row { border-top: 1px solid #f4ede2; }
.cat-row:active { background: #fbf6ee; }
.cat-row .grow { display: flex; flex-direction: column; gap: 6px; }
.cat-row .cat-ico { margin: 0; }
.cat-row-top { display: flex; justify-content: space-between; gap: 8px; font-size: 16px; }
.cat-row-name { font-weight: 650; }
.cat-row-top b { white-space: nowrap; }
.cat-row .bd-bar { margin: 0; display: block; }
.cat-row.over .bd-bar span { background: var(--danger); }
.cat-row .cat-limit { font-size: 13px; }
.cat-row.over .cat-limit { color: var(--danger); font-weight: 650; }
.hero-cta {
  margin-top: 4px; min-height: 48px; padding: 10px 18px; border: 0; border-radius: 14px;
  background: var(--sun-ink); color: #fff; font-weight: 750; font-size: 16px;
}

/* Category page */
.cat-head { display: flex; align-items: center; gap: 14px; }
.cat-ico.lg { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; margin: 0; }
.cat-head-name { font-weight: 700; color: var(--text-2); }
.cat-head-total { font-size: 28px; font-weight: 800; line-height: 1.2; }
.cat-head .bd-bar { margin-top: 8px; }
.cat-head .cat-limit.over { color: var(--danger); font-weight: 650; }
.add-in-cat { margin: 0 0 6px; }

/* Family: who paid what share */
.split-card { padding: 16px; }
.split-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--track); margin-bottom: 8px; }
.split-bar span { display: block; height: 100%; background: var(--c); }
.split-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 16px; }
.split-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.split-pct { width: 44px; text-align: right; color: var(--muted); font-weight: 700; font-size: 14px; }
#auth:not([hidden]) ~ .toast { bottom: calc(20px + var(--safe-b)); }
.snack.show ~ .toast { bottom: calc(184px + var(--safe-b)); }

/* ---------- sign-in ---------- */
.auth { background: var(--bg); }
.auth-top .brand { color: var(--primary); }
.auth-body { padding: 16px 20px calc(24px + var(--safe-b)); }
.auth-center { text-align: center; display: flex; flex-direction: column; align-items: center; }
.auth-title { font-size: 25px; font-weight: 750; margin: 14px 0 6px; text-align: center; }
.auth-help { color: var(--text-2); text-align: center; margin: 0 0 18px; font-size: 16px; }
.auth-msg { color: var(--text-2); margin: 4px 0 16px; min-height: 1.5em; }
.auth-msg.error { color: var(--danger); font-weight: 650; }
.big-emoji { font-size: 56px; margin-top: 40px; }
.form { padding: 20px; }

.people-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-top: 26px; }
.person-btn {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 24px 12px; border-radius: 24px; border: 2px solid transparent; background: #fff; box-shadow: var(--shadow);
  font-size: 19px; font-weight: 700; transition: border-color .15s, transform .1s;
}
.person-btn:active { border-color: var(--primary); transform: scale(.98); }

.pin-dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 24px; }
.pin-dots span { width: 15px; height: 15px; border-radius: 50%; background: #d7dbe6; transition: background .12s, transform .12s; }
.pin-dots span.on { background: var(--primary); transform: scale(1.15); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 22px; justify-content: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: #fff; box-shadow: var(--shadow);
  font-size: 29px; font-weight: 600;
}
.keypad button:active { background: var(--primary-50); color: var(--primary); }
.keypad .key-text { font-size: 24px; background: transparent; box-shadow: none; }
.auth-links { display: flex; gap: 24px; justify-content: center; margin-top: 22px; }

/* ---------- home ---------- */
.hero {
  background: var(--sun); color: var(--sun-ink);
  border-radius: 22px; padding: 18px 20px 20px; margin-top: 10px;
}
.hero.neg { background: var(--expense); color: #fff; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-label { font-size: 16px; font-weight: 700; }
.hero-badge { flex: none; background: rgba(43, 33, 24, .1); border-radius: 999px; padding: 3px 11px; font-size: 13px; font-weight: 750; }
.hero.neg .hero-badge { background: rgba(255, 255, 255, .2); }
.hero-amount { font-size: 42px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 14px; line-height: 1.1; word-break: break-word; }
.hero-amount .cur { font-size: 18px; font-weight: 700; opacity: .75; margin-right: 6px; letter-spacing: 0; }
.hero-amount .dec { font-size: 24px; opacity: .7; }
.meter { height: 10px; background: rgba(43, 33, 24, .14); border-radius: 999px; overflow: hidden; }
.hero.neg .meter { background: rgba(255, 255, 255, .25); }
.meter-fill { height: 100%; width: 0; background: var(--sun-ink); border-radius: 999px; transition: width .5s ease; }
.meter-fill.warn { background: var(--primary); }
.meter-fill.over { background: #fff; }
.hero-note { font-size: 15px; margin-top: 10px; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: #fff; border-radius: 18px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 4px; font-size: 17px; }
.stat-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-val { font-size: 16px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.income .stat-ico { background: var(--income-soft); color: var(--income); }
.stat.spent .stat-ico { background: var(--expense-soft); color: var(--expense); }
.stat.saved .stat-ico { background: var(--saving-soft); color: var(--saving); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.quick-btn {
  display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 10px 14px;
  border: 0; border-radius: 18px; background: #fff; box-shadow: var(--shadow);
  font-size: 16px; font-weight: 700; text-align: left; line-height: 1.25; transition: transform .1s;
}
.quick-btn:active { transform: scale(.98); }
.quick.single { grid-template-columns: 1fr; }
.people-stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-top: 0; }
.people-stats .avatar { margin-bottom: 4px; }
.cat-tile.family-tile { border-color: var(--primary-100); background: var(--primary-50); }
.family-chip { --c: #b83a0b; }
.bar.solo { width: 46%; max-width: 22px; }
.quick-ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.quick-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.expense-btn .quick-ico { background: var(--expense); color: #fff; }
.income-btn .quick-ico { background: var(--income); color: #fff; }

.install-card { margin-top: 14px; background: var(--primary-50); box-shadow: none; border: 1.5px solid var(--primary-100); }

/* debts */
.debt-card {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 12px; text-align: left;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow);
}
.debt-card.has { border-color: #f5c99b; background: #fff8ef; }
.debt-card-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; background: var(--primary-50); flex: none; }
.debt-card-title { display: block; font-weight: 750; font-size: 16px; }
.debt-card-sub { display: block; font-size: 13px; color: var(--muted); }
.debt-card-total { font-size: 17px; color: var(--primary-600); white-space: nowrap; }
.chev { font-size: 24px; color: var(--muted); line-height: 1; }
.back-link { display: inline-block; margin: 8px 0 4px; font-size: 16px; }
.debt-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--sun); color: var(--sun-ink); border-radius: 22px; padding: 16px 18px; margin: 6px 0 12px;
}
.debt-summary-label { font-weight: 700; font-size: 15px; }
.debt-summary-total { font-size: 32px; font-weight: 800; line-height: 1.15; }
.debt-summary-total .cur { font-size: 16px; margin-right: 5px; opacity: .75; }
.debt-summary-total .dec { font-size: 20px; opacity: .7; }
.debt-summary .btn { background: var(--sun-ink); }
.debt-item { padding: 14px; }
.debt-top { display: flex; align-items: center; gap: 12px; }
.debt-top .grow { display: flex; flex-direction: column; min-width: 0; }
.debt-name { font-size: 16px; }
.debt-left { font-size: 17px; color: var(--primary-600); white-space: nowrap; }
.debt-note { margin: 8px 0 0; color: var(--text-2); font-size: 14px; }
.debt-item .bd-bar { margin-top: 12px; }
.debt-item .bd-bar span { background: var(--income); }
.debt-meta { font-size: 13px; color: var(--muted); margin-top: 6px; }
.debt-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.debt-chip { --c: #b83a0b; }
.paid-ok { color: var(--income); font-weight: 700; }

.check-row {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; margin-bottom: 14px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fffaf2; cursor: pointer;
}
.check-row input { width: 22px; height: 22px; min-height: 0; margin: 2px 0 0; padding: 0; accent-color: var(--primary); flex: none; }
.check-text { display: flex; flex-direction: column; }
.check-text b { font-size: 16px; }
.check-text small { font-size: 13px; color: var(--muted); }
.check-row:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.install-card p { margin: 6px 0 0; color: #7c2d12; font-size: 15px; }
.install-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #7c2d12; }

.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.cat-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
  padding: 12px; min-height: 118px; border-radius: 18px; border: 1.5px solid transparent;
  background: #fff; box-shadow: var(--shadow); transition: transform .1s, border-color .15s;
}
.cat-tile:active { transform: scale(.97); border-color: var(--c); }
.cat-tile.over { border-color: #f5b5b5; background: #fff6f5; }
/* A lone last tile spans the full row instead of leaving gaps. */
.cat-grid > .cat-tile:last-child:nth-child(3n + 1) { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 64px; gap: 12px; }
.cat-grid > .cat-tile:last-child:nth-child(3n + 1) .cat-ico { margin-bottom: 0; }
.cat-grid > .cat-tile:last-child:nth-child(3n + 1) .cat-amt { margin: 0 0 0 auto; }
.cat-ico {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 21px; margin-bottom: 6px; flex: none;
  background: #f4ede2; background: color-mix(in srgb, var(--c, #64748b) 15%, white);
}
.cat-ico.sm { width: 34px; height: 34px; font-size: 18px; border-radius: 11px; margin: 0; }
.cat-name { font-size: 13.5px; font-weight: 650; color: var(--text-2); line-height: 1.3; overflow-wrap: anywhere; }
.cat-amt { font-size: 16px; font-weight: 750; margin-top: auto; color: #cbbfae; white-space: nowrap; }
.cat-tile.has .cat-amt { color: var(--text); }
.mini-meter { width: 100%; height: 5px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 4px; }
.mini-meter span { display: block; height: 100%; background: var(--c); border-radius: 999px; }
.cat-tile.over .mini-meter span { background: var(--danger); }
.cat-limit { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.cat-tile.over .cat-limit { color: var(--danger); font-weight: 650; }

/* entries */
.tx-list { padding: 4px 0; }
.tx-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 14px; border: 0; background: none; min-height: 66px;
}
.tx-row + .tx-row { border-top: 1px solid #f4ede2; }
.tx-row:active { background: #fbf6ee; }
.tx-icon {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; font-size: 21px;
  background: #f4ede2; background: color-mix(in srgb, var(--c, #64748b) 14%, white);
}
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-cat { font-weight: 650; font-size: 16px; line-height: 1.35; }
.tx-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { text-align: right; display: flex; flex-direction: column; flex: none; }
.tx-amt { font-weight: 750; }
.tx-amt.income { color: var(--income); }
.tx-amt.expense { color: var(--text); }
.tx-amt.saving { color: var(--saving); }
.tx-date { color: var(--muted); font-size: 13px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: none; border: 0; background: #fff; border-radius: 999px; box-shadow: var(--shadow);
  padding: 8px 16px; font-weight: 650; font-size: 15px; min-height: 40px; color: var(--text-2);
}
.chip-btn.active { background: var(--text); color: #fff; }
.summary-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 15px; margin: 12px 2px 4px; }
.day-head { font-weight: 700; color: var(--text-2); margin: 18px 4px 8px; font-size: 14px; }

/* reports */
.chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; height: 180px; align-items: end; }
.chart-col { display: flex; flex-direction: column; align-items: center; height: 100%; padding: 4px 0 0; border: 0; border-radius: 12px; background: transparent; }
.chart-col:active { background: var(--primary-50); }
.chart-col.current { background: #fff6ea; }
.chart-hint { text-align: center; margin: 10px 0 0; }
.bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bar { width: 26%; max-width: 12px; border-radius: 6px 6px 2px 2px; height: 0; transition: height .5s ease; }
.bar.inc { background: #2e7d32; }
.bar.exp { background: #e53935; }
.bar.sav { background: #1e88e5; }
.chart-label { font-size: 12px; color: var(--muted); margin-top: 8px; white-space: nowrap; font-weight: 600; }
.chart-col.current .chart-label { color: var(--primary); font-weight: 800; }
.legend { display: flex; gap: 16px; justify-content: center; margin-top: 14px; font-size: 13px; color: var(--text-2); flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.dot.inc { background: #2e7d32; }
.dot.exp { background: #e53935; }
.dot.sav { background: #1e88e5; }

.table-card { padding: 4px 4px; overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table caption { text-align: left; color: var(--muted); font-size: 12px; padding: 10px 8px 0; }
.report-table th { text-align: right; color: var(--muted); font-weight: 650; font-size: 12px; padding: 10px 6px; }
.report-table td { text-align: right; padding: 10px 6px; border-top: 1px solid #f4ede2; white-space: nowrap; font-variant-numeric: tabular-nums; }
.report-table th:first-child, .report-table td:first-child { text-align: left; padding-left: 10px; }
.report-table th:last-child, .report-table td:last-child { padding-right: 10px; }
.report-table tr.current td { background: var(--primary-50); }

.breakdown-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 0; border: 0; background: none; text-align: left; color: inherit; }
.breakdown-row:active { background: #fbf6ee; }
.breakdown-row .grow { display: block; }
.breakdown-row .bd-top, .breakdown-row .bd-bar { display: flex; }
.breakdown-row .bd-bar { display: block; }
.breakdown-row + .breakdown-row { border-top: 1px solid #f4ede2; }
.bd-top { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.bd-top b { white-space: nowrap; }
.bd-bar { height: 7px; border-radius: 999px; background: var(--track); margin-top: 6px; overflow: hidden; }
.bd-bar span { display: block; height: 100%; background: var(--c); border-radius: 999px; }
.bd-pct { width: 42px; text-align: right; font-weight: 750; color: var(--muted); font-size: 14px; }

.person-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.person-row + .person-row { border-top: 1px solid #f4ede2; }
.pr-vals { display: flex; flex-direction: column; text-align: right; font-weight: 650; font-size: 15px; }

/* settings */
.profile { display: flex; align-items: center; gap: 14px; }
.profile-name { font-size: 20px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; flex-wrap: wrap; font-weight: 600; }
.setting-row.first { margin-top: 0; }
.day-row { margin: 0; padding: 8px 0; flex-wrap: nowrap; }
.day-row + .day-row { border-top: 1px solid #f4ede2; }
.day-row span { flex: 1; min-width: 0; }
.day-select { width: 96px; min-height: 46px; font-weight: 700; text-align: center; }
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--track); padding: 4px; border-radius: 14px; gap: 4px; }
.seg button { border: 0; background: transparent; border-radius: 10px; padding: 8px 14px; font-weight: 650; min-height: 40px; color: var(--text-2); }
.seg button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(60, 40, 20, .12); }
.wide-seg { display: grid; margin-bottom: 10px; width: 100%; }
.budget-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; font-weight: 600; font-size: 15px; }
.budget-row + .budget-row { border-top: 1px solid #f4ede2; }
.budget-row input { width: 136px; flex: none; min-height: 46px; padding: 10px 12px; text-align: right; font-size: 17px; text-overflow: ellipsis; }
/* The "No limit" hint is smaller than typed amounts so it fits; typed text stays >=16px (no iOS zoom). */
.budget-row input::placeholder { font-size: 14px; }
.about { text-align: center; color: var(--muted); font-size: 13px; margin: 18px 0 0; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; color: var(--text); background: #fff; }
dialog::backdrop { background: rgba(43, 33, 24, .45); }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh;
  margin: auto auto 0; border-radius: 28px 28px 0 0; overflow-y: auto;
}
.sheet form { padding: 10px 18px calc(18px + var(--safe-b)); }
.sheet form::before { content: ""; display: block; width: 42px; height: 5px; border-radius: 3px; background: #e0d6c6; margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 21px; font-weight: 750; }
/* Footer buttons: Cancel | Save side by side, any extra action (Delete, Reset…) full width below. */
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.sheet-actions .btn { width: 100%; min-width: 0; }
.sheet-actions .alt-btn { grid-column: 1 / -1; }

/* Pop-up mode shows ✕ and Cancel; page mode shows ← back instead. */
.sheet .back-btn { display: none; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- full-page forms (add/edit entry, add/edit debt) ---------- */
dialog.page {
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0;
  border-radius: 0; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
}
dialog.page::backdrop { background: var(--bg); }
.page form { min-height: 100%; display: flex; flex-direction: column; }
.page .sheet-head {
  position: sticky; top: 0; z-index: 3; gap: 10px; margin: 0;
  padding: calc(10px + var(--safe-t)) max(12px, calc((100% - 520px) / 2 + 12px)) 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.page .sheet-head h2 { flex: 1; min-width: 0; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page .back-btn, .page .danger-icon { width: 44px; height: 44px; background: #fff; box-shadow: var(--shadow); }
.page .back-btn { color: var(--text); }
.danger-icon { color: var(--danger); }
.page .close-x, .page .cancel-btn { display: none; }
.page .form-body { flex: 1; width: 100%; max-width: 520px; margin: 0 auto; padding: 16px 16px 8px; }
.page .sheet-actions {
  position: sticky; bottom: 0; z-index: 3; grid-template-columns: 1fr; margin: 0;
  padding: 12px max(16px, calc((100% - 520px) / 2 + 16px)) calc(12px + var(--safe-b));
  background: rgba(251, 247, 240, .97); border-top: 1px solid var(--line);
}
.page .sheet-actions .btn.primary { min-height: 56px; font-size: 18px; }
/* While a number pad is open it replaces the footer buttons (its ✓ key is the action). */
.sheet-actions.pad-open > .btn { display: none; }
.sheet-actions .numpad { grid-column: 1 / -1; }

/* Sub-screen header (debts, one category): big back button + title */
.sub-head {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-t)) 16px 10px; background: var(--bg);
}
.sub-head h2 { flex: 1; min-width: 0; font-size: 21px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-head .back-btn { width: 48px; height: 48px; background: #fff; box-shadow: var(--shadow); color: var(--text); }
.sub-head .back-btn svg { width: 24px; height: 24px; }

/* Settings: account buttons */
.profile-actions { display: grid; gap: 10px; margin-top: 16px; }
.profile-actions .btn { margin: 0; justify-content: flex-start; padding-left: 16px; }
.btn-ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.signout-btn { background: #fff4f2; border-color: #f5c2bb; color: var(--danger); }
.signout-btn:active { background: #fde4e0; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--track); padding: 4px; border-radius: 16px; margin-bottom: 16px; }
.type-toggle button { border: 0; background: transparent; border-radius: 12px; min-height: 44px; font-weight: 700; color: var(--text-2); }
.type-toggle button.active[data-type="expense"] { background: var(--expense); color: #fff; }
.type-toggle button.active[data-type="income"] { background: var(--income); color: #fff; }

.share-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: -6px 0 16px; }
.share-toggle button {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 6px 10px;
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff; font-weight: 650; font-size: 15px; color: var(--text-2);
}
.share-toggle button.active { border-color: var(--sun-ink); background: var(--sun-ink); color: #fff; }
.share-toggle button:disabled:not(.active) { opacity: .4; }

.amount-wrap {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; width: 100%; min-height: 72px; padding: 12px 16px;
  border: 1.5px solid var(--line); border-radius: 16px; background: #fff; text-align: left; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.amount-wrap.editing { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-100); }
.amount-cur { font-size: 20px; font-weight: 700; color: var(--muted); }
.amount-text { font-size: 32px; font-weight: 800; line-height: 1.15; word-break: break-all; font-variant-numeric: tabular-nums; }
.amount-text.placeholder { color: #cbbfae; }
.amount-wrap.editing .amount-text::after {
  content: ""; display: inline-block; width: 2px; height: .9em; margin-left: 2px; vertical-align: -0.1em;
  background: var(--primary); animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.amount-sum { flex-basis: 100%; font-size: 16px; font-weight: 700; color: var(--primary-600); }
.amount-sum:empty { display: none; }
.quick-amounts { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.quick-amounts button {
  flex: none; min-height: 40px; padding: 6px 16px; border: 1.5px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--text-2); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.quick-amounts button.active { background: var(--sun); border-color: var(--sun); color: var(--sun-ink); }

/* Number pad (sits above Save at the bottom of the add page) */
.numpad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.numpad button {
  min-height: 52px; border: 0; border-radius: 14px; background: #fff; box-shadow: var(--shadow);
  font-size: 24px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums;
}
.numpad button:active { background: var(--primary-50); transform: scale(.97); }
.numpad .pad-fn { background: var(--track); box-shadow: none; color: var(--text-2); font-size: 22px; }
.numpad .pad-ok {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--sun); color: var(--sun-ink); box-shadow: none; line-height: 1;
}
.numpad .pad-ok.save { background: var(--primary); color: #fff; }
.pad-ok-ico { font-size: 24px; }
.pad-ok-label { font-size: 12px; font-weight: 750; }
/* Draw attention to the categories when ✓ is pressed before choosing one. */
.cat-picker.attention { animation: nudge .6s ease; border-radius: 16px; }
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 4px var(--primary-100); } }

.cat-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; min-height: 80px;
  border: 1.5px solid var(--line); background: #fff; border-radius: 16px; font-size: 13px; font-weight: 650; text-align: center; line-height: 1.25;
  color: var(--text-2);
}
.cat-chip span:first-child { font-size: 24px; }
.cat-chip.active { border-color: var(--c); color: var(--text); background: color-mix(in srgb, var(--c) 10%, white); box-shadow: 0 0 0 2px var(--c) inset; }

.confirm { width: calc(100% - 40px); max-width: 400px; border-radius: 22px; }
.confirm form { padding: 22px; }
.confirm p { margin: 0 0 14px; font-size: 18px; font-weight: 600; }

/* ---------- date field + calendar ---------- */
.date-field { display: flex; flex-direction: column; gap: 8px; }
.date-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fff; color: var(--text);
  font-size: 17px; font-weight: 650; text-align: left;
}
.date-btn:active, .date-btn:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-100); outline: none; }
.date-btn .date-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date-ico { font-size: 20px; line-height: 1; }
.date-quick { display: flex; gap: 8px; }
.date-quick button {
  min-height: 38px; padding: 6px 16px; border: 1.5px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--text-2); font-weight: 650; font-size: 15px;
}
.date-quick button.active { background: var(--sun); border-color: var(--sun); color: var(--sun-ink); }

/* Calendar: docked at the bottom with square keys, matching the number pad. */
.date-dialog {
  width: 100%; max-width: 520px; margin: auto auto 0; border-radius: 24px 24px 0 0;
  background: var(--bg); border-top: 1px solid var(--line);
}
.date-dialog[open], .numpad:not([hidden]) { animation: sheetUp .2s ease; }
@keyframes sheetUp { from { transform: translateY(24px); opacity: .5; } }
.dp { padding: 14px 12px calc(14px + var(--safe-b)); }
.dp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dp-head b { font-size: 19px; text-align: center; flex: 1; }
.dp-week, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.dp-week span { padding: 2px 0 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.dp-week span:first-child { color: var(--expense); } /* Sunday */
.dp-key, .dp-day {
  min-height: 46px; border: 0; border-radius: 14px; background: #fff; box-shadow: var(--shadow);
  font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums;
}
.dp-key:active, .dp-day:active { background: var(--primary-50); transform: scale(.97); }
.dp-day { font-size: 18px; }
.dp-day.today { box-shadow: inset 0 0 0 2.5px var(--sun), var(--shadow); }
.dp-day.sel { background: var(--primary); color: #fff; box-shadow: none; }
.dp-day:disabled { color: #d9cfc0; background: transparent; box-shadow: none; }
.dp-nav { width: 56px; font-size: 26px; background: var(--track); box-shadow: none; color: var(--text-2); }
.dp-nav:disabled { opacity: .35; }
.dp-foot { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-top: 12px; }
.dp-foot .dp-key { min-height: 52px; font-size: 17px; box-shadow: none; }
.dp-fn { background: var(--track); color: var(--text-2); }
.dp-ok { background: var(--sun); color: var(--sun-ink); }

@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 28px; }
  .sheet form::before { display: none; }
}
@media (max-width: 360px) {
  body { font-size: 16px; }
  .keypad { grid-template-columns: repeat(3, 68px); gap: 14px 18px; }
  .keypad button { width: 68px; height: 68px; }
  .hero-amount { font-size: 34px; }
  .stat-val { font-size: 14px; }
  .nav-btn { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
