:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1f24;
  --muted: #6b6f78;
  --line: #e6e3dc;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efec;
  --warn: #b45309;
  --bad: #b91c1c;
  --key: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #1f2229;
    --ink: #eceef2;
    --muted: #9aa0ab;
    --line: #2e323b;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --accent-soft: #123a36;
    --warn: #f59e0b;
    --bad: #f87171;
    --key: #262a32;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.invisible { visibility: hidden; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 4px 8px; }
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; }
.list { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.row:first-child { border-top: 0; }
.row .ico { font-size: 22px; width: 28px; text-align: center; flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .main div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 600; }
a.row { color: inherit; text-decoration: none; }
.amt.plus { color: var(--accent); }

/* month header */
.month { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.month b { font-size: 20px; }
.month button { width: 44px; height: 44px; border-radius: 22px; font-size: 22px; color: var(--muted); }

/* the one number */
.hero { padding: 20px 18px; }
.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 6px; }
.hero .cmp { font-size: 14px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 8px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: 14px; }
.offline { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; }

.bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.wallet button.mini { padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); font-size: 14px; }

/* bottom tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; align-items: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabs button { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 4px 0; }
#tabs button span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
#tabs button.on { color: var(--ink); }
#tabs button.on span { filter: none; opacity: 1; }
#tabs #plus {
  order: 0; justify-self: center; width: 58px; height: 58px; margin-top: -26px; border-radius: 29px;
  background: var(--accent); color: var(--accent-ink); font-size: 34px; line-height: 1; font-weight: 300;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .35);
}
#tabs [data-tab="home"] { order: -1; }

/* sheet (entry / edit) */
#sheet {
  position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet { max-width: 560px; margin: 0 auto; }
.sheet-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-top .x { width: 40px; height: 40px; border-radius: 20px; font-size: 22px; color: var(--muted); }
.chip { padding: 8px 12px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; }
.datechip { position: relative; }
.datechip input { position: absolute; inset: 0; width: 100%; opacity: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--line); margin: 6px 0 4px; }
.seg button { padding: 8px 4px; border-radius: 9px; font-size: 14px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }
.amount { text-align: center; font-size: 44px; font-weight: 700; padding: 8px 0 6px; min-height: 70px; }
.amount.empty { color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { height: 54px; border-radius: 14px; background: var(--key); box-shadow: var(--shadow); font-size: 24px; font-weight: 500; }
.keypad button:active, .cat:active { transform: scale(.97); }
.note { width: 100%; margin: 10px 0 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.flags { display: flex; gap: 8px; margin: 6px 0 10px; }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 11px; line-height: 1.15; text-align: center; min-height: 72px; }
.cat span { font-size: 24px; }
.cat.on { outline: 2px solid var(--accent); }
.big-btn { display: block; width: 100%; margin-top: 12px; padding: 15px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 17px; }
.big-btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.big-btn.danger { background: transparent; color: var(--bad); box-shadow: none; }
.hint { font-size: 14px; color: var(--muted); text-align: center; margin: 6px 0 0; }

/* forms */
.field { display: block; margin: 0 0 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 4px; }
.field input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.error { color: var(--bad); font-size: 14px; margin: 8px 4px; }
.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { font-size: 28px; margin: 0 0 4px; }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(86px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
#toast button { color: var(--accent); font-weight: 600; filter: brightness(1.4); }
