/* Money Inbox — mobile-first, theme-aware */
:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #eef0f6;
  --text: #171a21; --muted: #6b7180; --line: #e2e5ee;
  --accent: #4f46e5; --accent-ink: #ffffff;
  --pos: #12813f; --neg: #c02a37;
  --ready: #0e7d6b; --pending: #9a6a00;
  --radius: 16px; --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #141a2b; --surface-2: #1c2439;
    --text: #eef1f8; --muted: #9aa2b6; --line: #26304a;
    --accent: #7c7bff; --accent-ink: #0b1020;
    --pos: #4ade80; --neg: #ff7b86; --ready: #4fd1c5; --pending: #e6b34d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ---------- layout ---------- */
.app { max-width: 680px; margin: 0 auto; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line); padding: max(12px, env(safe-area-inset-top)) 16px 10px;
}
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tabs { display: flex; gap: 6px; margin-top: 12px; }
.tab {
  flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: var(--tap);
  justify-content: center;
}
.tab.on { background: var(--accent); color: var(--accent-ink); }
.tab .n { font-size: 16px; }
.toolbar { display: flex; gap: 8px; padding: 10px 16px 4px; flex-wrap: wrap; align-items: center; }
.acct-filter { flex: 1; min-width: 140px; }

.list { padding: 8px 12px calc(120px + var(--safe-b)); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 10px 4px; overflow: hidden; transition: border-color .15s;
}
.card.open { border-color: var(--accent); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 13px 14px; min-height: var(--tap); }
.card-main { flex: 1; min-width: 0; }
.card-payee { font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.amt.neg { color: var(--neg); } .amt.pos { color: var(--pos); }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.pill.cat { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.pill.tr { background: color-mix(in srgb, var(--ready) 18%, transparent); color: var(--ready); }
.pill.split { background: color-mix(in srgb, var(--pending) 20%, transparent); color: var(--pending); }
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- editor ---------- */
.editor { border-top: 1px solid var(--line); padding: 6px 14px 14px; display: none; }
.card.open .editor { display: block; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
label.fld { display: block; margin-top: 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
select, input[type=text], input[type=number], input[type=date], textarea {
  width: 100%; padding: 11px 12px; margin-top: 5px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); min-height: var(--tap);
}
textarea { min-height: 60px; resize: vertical; }
.seg { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; margin-top: 5px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.split-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; margin-top: 8px;
  padding: 10px; background: var(--surface-2); border-radius: 12px; }
.split-row .sub { grid-column: 1 / -1; display: flex; gap: 8px; }
.split-row .sub > * { flex: 1; }
.split-x { grid-column: 1/-1; text-align: right; }
.split-x button { color: var(--neg); font-size: 12px; font-weight: 600; padding: 4px; }
.remainder { margin-top: 8px; font-size: 13px; font-weight: 600; text-align: right; }
.remainder.ok { color: var(--pos); } .remainder.bad { color: var(--neg); }

.actions { display: flex; gap: 8px; margin-top: 16px; }
.btn { flex: 1; padding: 12px; border-radius: 12px; font-weight: 700; font-size: 14px; min-height: var(--tap);
  background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.small { flex: 0 0 auto; padding: 10px 14px; font-size: 13px; }
.btn:active { transform: scale(.98); }

/* ---------- fab + sheet + login ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 30;
  width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  font-size: 28px; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: grid; place-items: end center; }
.sheet { background: var(--surface); width: 100%; max-width: 680px; border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(22px + var(--safe-b)); box-shadow: 0 -8px 40px rgba(0,0,0,.3); }
.sheet h2 { margin: 4px 0 4px; font-size: 18px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .box { width: 100%; max-width: 340px; text-align: center; }
.login h1 { font-size: 24px; margin-bottom: 4px; }
.login p { color: var(--muted); margin-top: 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13px;
  font-weight: 600; z-index: 60; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.err { color: var(--neg); font-size: 13px; min-height: 18px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
