:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15181d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --in: #15803d;
  --out: #b91c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #20242a;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --line: #2a2f36;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --in: #4ade80;
    --out: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.in { color: var(--in); }
.out { color: var(--out); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 120px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.top h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* hero balance */
.hero { padding: 8px 0 16px; }
.hero .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hero .big { font-size: 36px; font-weight: 700; letter-spacing: -.02em; }
.hero .split { display: flex; gap: 18px; font-size: 14px; margin-top: 2px; }

/* cards & lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 22px 4px 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-top: 1px solid var(--line); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0;
}
.row:first-child { border-top: 0; }
button.row:hover, a.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { text-align: right; font-weight: 600; white-space: nowrap; }
.row .amt .sub { font-weight: 400; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-left: 6px; vertical-align: middle; }

.month-head {
  display: flex; justify-content: space-between; padding: 8px 16px; font-size: 13px; color: var(--muted);
  background: var(--surface-2); font-weight: 600;
}

/* toolbar */
.toolbar { display: flex; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.search {
  flex: 1 1 200px; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--surface-2);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: transparent; color: var(--out); }
.btn.block { width: 100%; }
.more { display: block; margin: 12px auto 0; }

.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25); display: grid; place-items: center; z-index: 6;
}
.fab svg { width: 28px; height: 28px; }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* sheet */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; font-size: 18px; margin: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"].out-btn { background: var(--surface); color: var(--out); box-shadow: var(--shadow); }
.seg button[aria-pressed="true"].in-btn { background: var(--surface); color: var(--in); box-shadow: var(--shadow); }

.amount-input {
  width: 100%; font-size: 40px; font-weight: 700; text-align: center; border: 0; background: transparent; padding: 6px 0 12px;
  font-variant-numeric: tabular-nums;
}
.amount-input:focus { outline: none; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
.field textarea { min-height: 60px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 2px 14px; font-size: 15px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; }
.actions .primary { flex: 1; }
.error { color: var(--out); font-size: 14px; margin: 4px 2px 10px; min-height: 1em; }

/* login */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login h1 { font-size: 26px; margin: 0 0 18px; }
.login input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

.menu { display: flex; flex-direction: column; gap: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 4px; }
.summary { font-size: 13px; margin: 0 4px 8px; }
select.chip { appearance: none; -webkit-appearance: none; padding-right: 12px; }
.maaser {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 12px;
  background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.maaser .check { margin: 0; font-weight: 600; }
.maaser-amt { padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); text-align: right; min-width: 0; }
.maaser-amt:disabled { opacity: .45; }
.maaser-help { grid-column: 1 / -1; font-size: 13px; }
.maaser.hidden { display: none; }
