/* ============================================================
   Ledger — warm paper envelope-budgeting aesthetic
   Fraunces (display/figures) + Hanken Grotesk (UI), cream paper,
   forest green for money, clay for spending/over-budget.
   ============================================================ */
:root {
  --paper:   #F4EEE1;
  --paper-2: #ECE3D1;
  --card:    #FCF9F1;
  --ink:     #231F18;
  --ink-soft:#6E6757;
  --ink-faint:#9A917F;
  --line:    #E2D9C6;
  --line-2:  #D8CDB6;
  --green:   #2C5D3D;
  --green-2: #3E7A52;
  --green-wash:#E7EEE3;
  --clay:    #B5532D;
  --clay-wash:#F3E2D6;
  --gold:    #BE942A;
  --serif: 'Fraunces', 'Hoefler Text', Georgia, serif;
  --sans: 'Hanken Grotesk', -apple-system, system-ui, sans-serif;
  --r: 18px;
  --r-sm: 12px;
  --shadow: 0 1px 2px rgba(45,38,24,.05), 0 8px 24px -12px rgba(45,38,24,.18);
  --shadow-lg: 0 12px 40px -10px rgba(45,38,24,.32);
  --maxw: 540px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01";
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }

.tnum, .amt, .hero-balance, .detail-hero, .acct-balance, .env-remaining,
.week-now-val, .week-left, .stat-value, .bd-amt, .code-box {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* subtle paper grain */
.paper-grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .5;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(190,148,42,.05), transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(44,93,61,.05), transparent 45%);
  mix-blend-mode: multiply;
}

/* ---------- App chrome ---------- */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40; height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: -.02em;
}
.brand-dot { color: var(--green); }

.view-shell {
  position: relative; z-index: 1;
  max-width: var(--maxw); margin: 0 auto;
  padding: 72px 18px calc(110px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
.view { display: flex; flex-direction: column; gap: 20px; }

/* boot screen */
.boot {
  position: fixed; inset: 0; z-index: 60; display: grid; place-content: center;
  text-align: center; gap: 10px; background: var(--paper); color: var(--ink-soft);
}
.boot-mark { font-size: 40px; animation: floaty 2s ease-in-out infinite; }
@keyframes floaty { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-7px)} }

/* ---------- Tab bar + FAB ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 45;
  width: 100%; max-width: var(--maxw);
  display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; align-items: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: 0; cursor: pointer; padding: 6px 0;
  color: var(--ink-faint); font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: .02em; transition: color .2s;
}
.tab-glyph { font-size: 17px; line-height: 1; }
.tab.active { color: var(--green); }
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  margin-top: -26px; background: var(--green); color: #fff; font-size: 30px; font-weight: 300;
  display: grid; place-content: center; line-height: 0;
  box-shadow: 0 8px 20px -6px rgba(44,93,61,.6); transition: transform .15s, box-shadow .2s;
}
.fab:active { transform: scale(.92); }

/* ---------- Month bar / section heads ---------- */
.month-bar {
  display: flex; align-items: center; justify-content: center; gap: 14px;
}
.month-label { font-family: var(--serif); font-size: 18px; font-weight: 500; min-width: 150px; text-align: center; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }
.section-title { font-family: var(--serif); font-weight: 600; font-size: 19px; margin: 0; letter-spacing: -.01em; }
.page-title { font-family: var(--serif); font-weight: 600; font-size: 30px; margin: 0 0 4px; letter-spacing: -.02em; }
.link-btn { background: none; border: 0; color: var(--green); font-weight: 600; font-size: 13px; cursor: pointer; font-family: var(--sans); }
.muted { color: var(--ink-soft); }
.over { color: var(--clay) !important; }

/* ---------- Hero ---------- */
.hero { display: flex; flex-direction: column; gap: 16px; }
.hero-block {
  background: linear-gradient(160deg, var(--card), color-mix(in srgb, var(--card) 70%, var(--paper-2)));
  border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px;
  box-shadow: var(--shadow);
  animation: rise .5s both;
}
.hero-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.hero-balance { font-family: var(--serif); font-size: clamp(38px, 12vw, 50px); font-weight: 500; letter-spacing: -.03em; line-height: 1.05; margin-top: 6px; }
.hero-free { margin-top: 8px; font-size: 14px; }
.hero-free strong { font-weight: 700; }

/* ---------- Cards: envelopes ---------- */
.env-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 460px) { .env-grid { grid-template-columns: 1fr 1fr; } }

.env-card {
  position: relative; text-align: left; cursor: pointer; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent, var(--green));
  border-radius: var(--r); padding: 16px 16px 14px; font-family: var(--sans); color: var(--ink);
  box-shadow: var(--shadow); transition: transform .14s, box-shadow .2s;
  animation: rise .5s both;
}
.env-card:active { transform: scale(.985); }
.env-flap {
  position: absolute; top: 0; left: 0; right: 0; height: 26px;
  background: color-mix(in srgb, var(--accent, var(--green)) 12%, transparent);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  opacity: .5; pointer-events: none;
}
.env-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; }
.env-name { font-family: var(--serif); font-weight: 600; font-size: 18px; letter-spacing: -.01em; }
.pill {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--ink-soft);
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px;
}
.env-amounts { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 2px; }
.env-remaining { font-family: var(--serif); font-size: 27px; font-weight: 500; color: var(--green); letter-spacing: -.02em; }
.env-remaining.over { color: var(--clay); }
.env-of { font-size: 12px; color: var(--ink-faint); }
.env-week { display: flex; align-items: baseline; justify-content: space-between; margin-top: 10px; font-size: 13px; }
.env-week strong { font-weight: 700; }

/* progress bar */
.bar { height: 7px; border-radius: 999px; background: var(--paper-2); overflow: hidden; margin-top: 8px; border: 1px solid var(--line); }
.bar-fill { height: 100%; border-radius: 999px; background: var(--c, var(--green)); width: 0; transition: width .6s cubic-bezier(.2,.8,.2,1); }

/* ---------- Cards: accounts ---------- */
.acct-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 460px) { .acct-grid { grid-template-columns: 1fr 1fr; } }
.acct-card {
  text-align: left; cursor: pointer; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px; font-family: var(--sans); color: var(--ink);
  box-shadow: var(--shadow); transition: transform .14s; animation: rise .5s both;
}
.acct-card:active { transform: scale(.985); }
.acct-head { display: flex; align-items: center; justify-content: space-between; }
.acct-name { font-family: var(--serif); font-weight: 600; font-size: 17px; }
.acct-balance { font-family: var(--serif); font-size: 28px; font-weight: 500; letter-spacing: -.02em; margin: 8px 0 4px; }
.acct-meta { font-size: 13px; }
.acct-meta strong { font-weight: 700; }

/* ---------- Transactions ---------- */
.txn-list { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.txn { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--line); transition: background .15s; }
.txn:last-child { border-bottom: 0; }
.txn:active { background: var(--paper-2); }
.txn-glyph { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-content: center; font-size: 15px; }
.txn-glyph.income { background: var(--green-wash); color: var(--green); }
.txn-glyph.expense { background: var(--clay-wash); color: var(--clay); }
.txn-glyph.transfer { background: var(--paper-2); color: var(--ink-soft); }
.txn-main { flex: 1; min-width: 0; }
.txn-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-sub { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-side { text-align: right; flex: none; }
.amt { font-weight: 700; font-size: 15px; }
.amt.pos { color: var(--green); }
.amt.neg { color: var(--ink); }
.amt.neutral { color: var(--ink-soft); }
.txn-time { font-size: 11px; color: var(--ink-faint); margin-top: 1px; }

/* ---------- Detail headers ---------- */
.detail-head {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 22px 20px 18px; position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.detail-head:not(.plain) { border-top: 4px solid var(--accent, var(--green)); }
.detail-flap {
  position: absolute; top: 0; left: 0; right: 0; height: 40px;
  background: color-mix(in srgb, var(--accent, var(--green)) 14%, transparent);
  clip-path: polygon(0 0, 100% 0, 50% 100%); opacity: .4;
}
.detail-titlerow { display: flex; align-items: center; justify-content: space-between; position: relative; }
.detail-title { font-family: var(--serif); font-weight: 600; font-size: 26px; margin: 0; letter-spacing: -.02em; }
.detail-actions { display: flex; gap: 6px; }
.detail-hero { font-family: var(--serif); font-size: 42px; font-weight: 500; letter-spacing: -.03em; color: var(--green); margin: 12px 0 2px; }
.detail-hero.over { color: var(--clay); }
.detail-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
.acct-stats { display: flex; gap: 24px; margin-top: 14px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; }
.stat-value { font-family: var(--serif); font-size: 20px; font-weight: 500; margin-top: 2px; }

/* this-week callout */
.week-now {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--green-wash); border: 1px solid color-mix(in srgb, var(--green) 22%, var(--line));
  border-radius: var(--r); padding: 14px 18px;
}
.week-now-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--green-2); font-weight: 700; }
.week-now-val { font-family: var(--serif); font-size: 24px; font-weight: 500; color: var(--green); letter-spacing: -.02em; }
.week-now-day { text-align: right; }

/* weekly strip */
.weeks { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px; border-radius: var(--r-sm); }
.week-col.current { background: var(--green-wash); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--green) 35%, transparent); }
.week-col.off { opacity: .35; }
.week-track { width: 100%; height: 70px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: flex-end; overflow: hidden; }
.week-bar { width: 100%; background: var(--c, var(--green)); height: 0; transition: height .6s cubic-bezier(.2,.8,.2,1); }
.week-days { font-size: 10px; color: var(--ink-faint); font-weight: 600; }
.week-left { font-size: 12px; font-weight: 700; }

/* breakdown */
.breakdown { display: flex; flex-direction: column; gap: 14px; }
.bd-row { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; box-shadow: var(--shadow); }
.bd-top { display: flex; align-items: baseline; justify-content: space-between; }
.bd-name { font-weight: 600; }
.bd-amt { font-family: var(--serif); font-weight: 500; font-size: 17px; color: var(--green); }
.bd-sub { font-size: 11px; margin-top: 6px; }

/* ---------- Buttons / inputs ---------- */
.btn {
  font-family: var(--sans); font-weight: 700; font-size: 14px; cursor: pointer;
  border-radius: 12px; padding: 12px 18px; border: 1px solid transparent; transition: transform .12s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--green); color: #fff; }
.btn.ghost { background: var(--card); color: var(--ink); border-color: var(--line-2); }
.btn.danger { background: var(--clay); color: #fff; }
.btn.block { width: 100%; display: block; }
.icon-btn {
  background: none; border: 0; cursor: pointer; color: var(--ink-soft); font-size: 18px;
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-content: center; transition: background .15s;
}
.icon-btn:active { background: var(--paper-2); }
.icon-btn.round { background: var(--card); border: 1px solid var(--line); border-radius: 50%; font-size: 22px; color: var(--ink); }

.input {
  width: 100%; font-family: var(--sans); font-size: 16px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px;
  transition: border-color .15s, box-shadow .15s; appearance: none;
}
.input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-wash); }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236E6757' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.amount-input { font-family: var(--serif); font-size: 28px; font-weight: 500; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-fields { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.field-hint { font-size: 12px; color: var(--ink-faint); }
.row-gap { display: flex; gap: 10px; align-items: center; }
.row-gap .input { flex: 1; }

.segmented { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg-btn { border: 0; background: none; padding: 9px; border-radius: 9px; font-family: var(--sans); font-weight: 700; font-size: 13px; color: var(--ink-soft); cursor: pointer; transition: background .15s, color .15s; }
.seg-btn[aria-pressed="true"] { background: var(--card); color: var(--green); box-shadow: var(--shadow); }

.inline-warn { background: var(--clay-wash); color: var(--clay); border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 600; }
.alloc-hint { font-size: 13px; color: var(--green-2); font-weight: 600; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; transition: transform .12s; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--c); transform: scale(1.08); }

/* ---------- Cards / settings ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card.pad { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.code-box { font-family: var(--serif); font-size: 18px; letter-spacing: .02em; background: var(--paper-2); border: 1px dashed var(--line-2); border-radius: 12px; padding: 14px; word-break: break-all; text-align: center; }
.cat-list { display: flex; flex-direction: column; }
.cat-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); margin-left: 8px; background: var(--paper-2); padding: 2px 7px; border-radius: 999px; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 36px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { font-size: 44px; color: var(--green); opacity: .85; }
.empty h3 { font-family: var(--serif); font-size: 22px; margin: 6px 0 0; }
.empty p { color: var(--ink-soft); max-width: 34ch; margin: 0 0 8px; line-height: 1.5; }
.empty-note { color: var(--ink-faint); font-size: 14px; text-align: center; padding: 12px; }

.back-bar { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-weight: 600; }
.skeleton { height: 180px; border-radius: var(--r); background: linear-gradient(100deg, var(--paper-2) 30%, var(--card) 50%, var(--paper-2) 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Bottom sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(35,31,24,.42); opacity: 0; transition: opacity .24s; backdrop-filter: blur(2px); }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 100%); z-index: 71;
  width: 100%; max-width: var(--maxw); max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0; border: 1px solid var(--line);
  box-shadow: var(--shadow-lg); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  padding: 8px 18px calc(28px + env(safe-area-inset-bottom));
}
.sheet.show { transform: translate(-50%, 0); }
.sheet-grab { width: 40px; height: 4px; border-radius: 999px; background: var(--line-2); margin: 8px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 12px; }
.sheet-title { font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 0; }
.sheet-body { padding-bottom: 4px; }

/* ---------- Dialog ---------- */
.dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -46%) scale(.96); z-index: 72;
  width: calc(100% - 48px); max-width: 360px; background: var(--card); border-radius: 18px;
  border: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 22px; opacity: 0;
  transition: opacity .18s, transform .18s;
}
.dialog.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.dialog-msg { white-space: pre-line; line-height: 1.5; margin: 0 0 18px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); z-index: 80;
  background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; box-shadow: var(--shadow-lg); max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--clay); }
.toast.ok { background: var(--green); }

/* staggered reveal */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.env-grid > *:nth-child(2) { animation-delay: .05s; }
.env-grid > *:nth-child(3) { animation-delay: .1s; }
.env-grid > *:nth-child(4) { animation-delay: .15s; }
.env-grid > *:nth-child(n+5) { animation-delay: .2s; }
.acct-grid > *:nth-child(2) { animation-delay: .05s; }
.acct-grid > *:nth-child(n+3) { animation-delay: .1s; }

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