@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Public+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #1C2B36;
  --ink-soft: #33475A;
  --paper: #FAF6EC;
  --paper-alt: #F1EADA;
  --paper-card: #FFFFFF;
  --sage: #2F6F5E;
  --sage-soft: #E4EFE9;
  --ochre: #C99A3D;
  --ochre-soft: #F6ECD6;
  --rust: #B5533F;
  --rust-soft: #F5E4E0;
  --ash: #8B8579;
  --line: #E4DCC9;

  --font-display: 'Fraunces', serif;
  --font-body: 'Public Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius-l: 22px;
  --radius-m: 14px;
  --radius-s: 9px;

  --shadow-card: 0 1px 2px rgba(28,43,54,0.04), 0 8px 24px -12px rgba(28,43,54,0.18);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

/* subtle ledger-line texture on the page background */
.app-shell {
  min-height: 100dvh;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 34px,
    rgba(28,43,54,0.035) 35px
  );
  padding-top: calc(var(--safe-top) + 14px);
  padding-bottom: calc(64px + var(--safe-bottom) + 20px);
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.mono, .amount { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

button {
  font-family: var(--font-body);
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

/* ---------- Top bar ---------- */
.topbar {
  padding: 4px 20px 18px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.topbar .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ash);
}
.topbar h1 { font-size: 26px; }

/* ---------- Views ---------- */
.view { display: none; padding: 0 16px; animation: fadeIn .25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--paper-card);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
  padding: 18px 18px 20px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-header h2 { font-size: 17px; }
.card-tag {
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  color: var(--ash);
  text-transform: uppercase;
}
.chevron {
  color: var(--ash);
  font-size: 18px;
}

/* stitched divider — the signature notebook motif */
.stitch {
  border: none;
  height: 1px;
  background-image: linear-gradient(to right, var(--line) 60%, transparent 0%);
  background-size: 10px 1px;
  background-repeat: repeat-x;
  margin: 14px 0;
}

/* ---------- Home summary cards ---------- */
.summary-grid { display: grid; gap: 14px; }
.summary-card { cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.summary-card:active { transform: scale(0.98); }

.summary-top-row { display: flex; justify-content: space-between; align-items: flex-start; }
.summary-icon {
  width: 38px; height: 38px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.icon-sage { background: var(--sage-soft); color: var(--sage); }
.icon-ochre { background: var(--ochre-soft); color: var(--ochre); }
.icon-rust { background: var(--rust-soft); color: var(--rust); }

.big-figure { font-family: var(--font-display); font-size: 30px; margin-top: 8px; }
.big-figure .cents { font-size: 18px; color: var(--ash); }
.sub-label { font-size: 12.5px; color: var(--ash); margin-top: 2px; }

/* mini bars for top categories preview on home */
.mini-bars { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.mini-bar-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.mini-bar-row .name { width: 78px; flex-shrink: 0; color: var(--ink-soft); }
.mini-bar-track { flex: 1; height: 6px; background: var(--paper-alt); border-radius: 4px; overflow: hidden; }
.mini-bar-fill { height: 100%; border-radius: 4px; background: var(--sage); transition: width .5s ease; }
.mini-bar-fill.over { background: var(--rust); }
.mini-bar-row .val { font-family: var(--font-mono); color: var(--ash); width: 44px; text-align: right; flex-shrink: 0; }

/* progress rings for goals preview */
.ring-row { display: flex; gap: 18px; margin-top: 14px; overflow-x: auto; padding-bottom: 4px; }
.ring-item { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; width: 68px; }
.ring-item svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--paper-alt); }
.ring-fill { stroke: var(--ochre); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring-label { font-size: 11px; text-align: center; color: var(--ink-soft); line-height: 1.2; }
.ring-pct { font-family: var(--font-mono); font-size: 12px; }

/* accounts preview list */
.account-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-size: 14px; }
.account-row .name { color: var(--ink-soft); }
.account-row .bal { font-family: var(--font-mono); font-weight: 600; }

/* ---------- Section header (inside detail views) ---------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 4px 16px;
}
.back-btn { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ash); }
.add-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
  box-shadow: var(--shadow-card);
}

/* ---------- Category list ---------- */
.cat-card { margin-bottom: 12px; }
.cat-top { display: flex; justify-content: space-between; align-items: center; }
.cat-name { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.cat-icon { font-size: 18px; }
.cat-figures { font-family: var(--font-mono); font-size: 13.5px; color: var(--ash); }
.cat-figures b { color: var(--ink); font-weight: 600; }
.bar-track { height: 9px; background: var(--paper-alt); border-radius: 6px; margin-top: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--sage); }
.bar-fill.over { background: var(--rust); }
.cat-actions { display:flex; gap:8px; margin-top: 12px; }
.pill-btn {
  font-size: 12.5px; padding: 6px 12px; border-radius: 999px;
  background: var(--paper-alt); color: var(--ink-soft);
}

/* transaction list inside a category */
.tx-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.tx-row:last-child { border-bottom: none; }
.tx-left .tx-note { color: var(--ink-soft); }
.tx-left .tx-date { color: var(--ash); font-size: 11.5px; }
.tx-amount { font-family: var(--font-mono); font-weight: 600; }

/* ---------- Goals detail ---------- */
.goal-card { display: flex; gap: 16px; align-items: center; }
.goal-ring { flex-shrink: 0; }
.goal-info { flex: 1; }
.goal-title { font-weight: 600; font-size: 15.5px; }
.goal-figures { font-family: var(--font-mono); font-size: 13px; color: var(--ash); margin-top: 3px; }
.goal-figures b { color: var(--sage); }
.goal-date { font-size: 11.5px; color: var(--ash); margin-top: 4px; }

/* ---------- Accounts detail ---------- */
.acc-card { display: flex; justify-content: space-between; align-items: center; }
.acc-left { display: flex; gap: 12px; align-items: center; }
.acc-type { font-size: 11px; color: var(--ash); text-transform: uppercase; letter-spacing: .04em; }
.acc-name { font-weight: 600; font-size: 15px; }
.acc-balance { font-family: var(--font-mono); font-size: 17px; font-weight: 600; }
.net-worth-line { display:flex; justify-content: space-between; align-items:baseline; margin-top: 4px; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--ash); }
.empty-state .glyph { font-size: 30px; margin-bottom: 8px; }
.empty-state p { margin: 4px 0 16px; font-size: 13.5px; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(250,246,236,0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 40;
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 8px;
  font-size: 10.5px;
  color: var(--ash);
}
.tab-btn .tab-icon { font-size: 19px; }
.tab-btn.active { color: var(--ink); }
.tab-btn.active .tab-icon { color: var(--sage); }

/* ---------- Modal / sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(28,43,54,0.42);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 60;
}
.sheet-backdrop.active { display: flex; }
.sheet {
  background: var(--paper);
  width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
  animation: slideUp .28s cubic-bezier(.32,.72,.35,1);
  max-height: 86dvh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(24px); opacity:.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 14px; }
.sheet h3 { font-size: 18px; margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--ash); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--paper-card);
  font-family: var(--font-body); font-size: 15px; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--sage); outline-offset: 1px; }

.icon-choice { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-choice button {
  width: 40px; height: 40px; border-radius: 10px; background: var(--paper-alt);
  font-size: 18px; display:flex; align-items:center; justify-content:center;
}
.icon-choice button.selected { background: var(--sage); color: #fff; }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn-primary, .btn-secondary {
  flex: 1; padding: 13px; border-radius: 12px; font-size: 14.5px; font-weight: 600; text-align: center;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-secondary { background: var(--paper-alt); color: var(--ink-soft); }
.btn-danger { color: var(--rust); background: var(--rust-soft); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive: tablet / desktop ---------- */
@media (min-width: 720px) {
  .app-shell { max-width: 900px; margin: 0 auto; padding-left: 4px; padding-right: 4px; }
  .view { padding: 0 8px; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .tabbar { max-width: 900px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .topbar { padding-left: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
