/* =========================================================================
   Design tokens
   Palette: Ink (deep bottle-green-black) for the one hero surface + text,
   Paper (pale sage-white) as the everyday background, Cedi Gold as the
   single accent, Palm Green / Clay Red for positive/negative amounts.
   No external font is loaded — the whole point of this app is that it
   still works with no network at all, so type comes from the system
   stack rather than a CDN font that would vanish offline.
   ========================================================================= */
:root {
  --ink:        #14231F;
  --ink-soft:   #2A3C36;
  --paper:      #F1F3EE;
  --surface:    #FFFFFF;
  --line:       #DDE3DC;
  --gold:       #C79A3D;
  --gold-dark:  #A87F2E;
  --green:      #2E7D53;
  --red:        #B4472F;
  --muted:      #6B7A74;

  --radius:     14px;
  --radius-sm:  10px;
  --nav-height: 64px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-height) + 16px);
  min-height: 100vh;
}

button, input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ---- Amount typography: tabular figures, right-aligned like a ledger --- */
.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.amount--pos { color: var(--green); }
.amount--neg { color: var(--red); }
.amount--muted { color: var(--muted); font-weight: 600; }

/* ---------------------------- App shell -------------------------------- */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--paper);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 6px;
}
.topbar h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar .sync-pill {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.sync-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.sync-pill.offline .dot { background: var(--red); }
.sync-pill.syncing .dot { background: var(--gold); }

.page { padding: 8px 20px 24px; animation: fade-in .18s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ----------------------------- Cards ------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.hero-card {
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 14px;
}
.hero-card .label { font-size: 13px; color: #AEBFB8; margin-bottom: 6px; }
.hero-card .balance {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  letter-spacing: -0.02em;
}
.hero-card .greeting { font-size: 15px; color: #D7E0DB; margin: 0 0 14px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat-row .stat { text-align: left; }
.stat-row .stat .k { font-size: 12px; color: #AEBFB8; margin-bottom: 2px; }
.stat-row .stat .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.section-title {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin: 4px 2px 8px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row .icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--paper); display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.row .title { font-weight: 600; font-size: 14.5px; }
.row .subtitle { font-size: 12.5px; color: var(--muted); }
.row .meta { text-align: right; flex-shrink: 0; margin-left: 10px; }

.progress-track {
  height: 6px; border-radius: 999px; background: var(--paper); overflow: hidden; margin-top: 6px;
}
.progress-fill { height: 100%; background: var(--gold); border-radius: 999px; }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 14px;
}

/* ----------------------------- Buttons ----------------------------------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn-primary { background: var(--ink); color: #fff; width: 100%; }
.btn-gold { background: var(--gold); color: var(--ink); width: 100%; }
.btn-outline { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.btn-block { width: 100%; }
.btn-danger-text { background: none; color: var(--red); font-weight: 600; padding: 8px; }
.btn:disabled { opacity: .55; }

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.quick-grid button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 14px;
}
.quick-grid button.income { color: var(--green); }
.quick-grid button.expense { color: var(--red); }
.quick-grid button.borrow, .quick-grid button.lend { color: var(--ink); }

/* --------------------------- Bottom navigation ---------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  background: none; border: none; display: flex; flex-direction: column; align-items: center;
  gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; min-width: 44px; min-height: 44px;
  justify-content: center;
}
.nav-item .glyph { font-size: 20px; }
.nav-item.active { color: var(--ink); }
.nav-item.fab {
  width: 52px; height: 52px; border-radius: 50%; background: var(--gold);
  color: var(--ink); font-size: 26px; margin-top: -26px; box-shadow: 0 4px 10px rgba(20,35,31,.25);
}

/* ------------------------------ Sheets/modals ----------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20,35,31,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--paper);
  width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: sheet-up .2s ease;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 999px; margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; }
.sheet .sheet-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }

.action-tile {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px; margin-bottom: 10px; text-align: left;
}
.action-tile .icon { font-size: 22px; }
.action-tile .title { font-weight: 700; font-size: 14.5px; }
.action-tile .desc { font-size: 12.5px; color: var(--muted); }

/* ------------------------------- Forms ------------------------------------ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold);
}
.amount-input {
  font-size: 32px; font-weight: 700; text-align: center; border: none !important;
  background: transparent !important; font-variant-numeric: tabular-nums;
}
.type-toggle { display: flex; gap: 8px; }
.type-toggle button {
  flex: 1; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 13.5px; color: var(--muted);
}
.type-toggle button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button {
  flex: 1; padding: 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 13.5px; color: var(--muted);
}
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.banner {
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px;
}
.banner-error { background: #FBEAE5; color: var(--red); }
.banner-success { background: #E6F1EA; color: var(--green); }

.auth-wrap { padding: 48px 24px 24px; }
.auth-wrap .brand { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-wrap .tagline { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
.link-btn { background: none; border: none; color: var(--gold-dark); font-weight: 600; padding: 8px 0; }

/* ---- Modern auth hero + overlapping sheet card ---- */
.auth-hero {
  background: var(--ink);
  padding: 52px 24px 56px;
  text-align: center;
  border-radius: 0 0 32px 32px;
}
.auth-badge {
  width: 64px; height: 64px;
  background: var(--gold);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.auth-wordmark { color: var(--paper); font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
.auth-tagline { color: #AEBFB8; font-size: 13.5px; max-width: 240px; margin: 0 auto; }

.auth-card {
  background: var(--surface);
  border-radius: 24px;
  margin: -28px 16px 0;
  padding: 28px 20px 24px;
  box-shadow: 0 8px 24px rgba(20, 35, 31, 0.10);
  position: relative;
}
.auth-page { padding-bottom: 32px; }
.auth-footer { text-align: center; margin-top: 16px; }

.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 17px; padding: 8px 10px;
  color: var(--muted); min-width: 40px; min-height: 40px;
}

.date-group-label { font-size: 12.5px; color: var(--muted); font-weight: 700; margin: 18px 2px 6px; }

@media (min-width: 481px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}