/* Ledger UI — warm, editorial, calm. Origin-inspired but its own thing.
   Sand/cream canvas, deep-evergreen accent, serif display headings. */

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

:root {
  /* warm canvas */
  --bg: #f4efe7;
  --bg2: #efe9df;
  --surface: #fffdf9;
  --surface2: #faf6ef;
  --ink: #2c2822;
  --ink2: #6b6357;
  --muted: #a49a8b;
  --line: #e9e1d5;
  --line2: #ddd3c4;

  /* deep evergreen accent + warm supports */
  --primary: #3f5c4a;
  --primary-soft: #e7ede8;
  --primary-deep: #2f4638;
  --clay: #b5714f;
  --clay-soft: #f3e6dd;
  --gold: #c99a3f;
  --gold-soft: #f5ecd6;

  --green: #4f7a5c;
  --green-soft: #e6efe7;
  --red: #b0503f;
  --red-soft: #f4e2dc;
  --amber: #c2913f;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60,48,32,0.04), 0 8px 24px rgba(60,48,32,0.05);
  --shadow-lg: 0 4px 12px rgba(60,48,32,0.06), 0 20px 48px rgba(60,48,32,0.08);

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, #efe7d9 0%, transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, #eef0e9 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 32px 28px 64px; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 32px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px; border-radius: 13px;
  background: linear-gradient(150deg, var(--primary), var(--primary-deep));
  display: grid; place-items: center; color: #f4efe7; font-weight: 600; font-size: 22px;
  font-family: var(--serif); box-shadow: 0 6px 18px rgba(47,70,56,0.28);
}
.brand h1 { font-family: var(--serif); font-size: 26px; margin: 0; letter-spacing: -0.02em; font-weight: 600; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); letter-spacing: 0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.month-pill {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border: 1px solid var(--line2); border-radius: 999px; padding: 8px 8px 8px 18px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
}
.month-pill .nav {
  width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--surface2);
  color: var(--ink2); cursor: pointer; font-size: 16px; display: grid; place-items: center;
  transition: all 0.15s ease;
}
.month-pill .nav:hover { background: var(--primary-soft); color: var(--primary); }
.btn {
  border: 1px solid var(--line2); background: var(--surface); color: var(--ink2);
  border-radius: 999px; padding: 10px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease; box-shadow: var(--shadow);
}
.btn:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft); }
.btn-primary { background: var(--primary); color: #f4efe7; border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.08); background: var(--primary); color: #fff; }

/* ---- cards / grid ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.kpi-value { font-family: var(--serif); font-size: 30px; font-weight: 600; margin-top: 8px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12.5px; margin-top: 8px; font-weight: 600; }
.up { color: var(--green); } .down { color: var(--red); } .neutral { color: var(--ink2); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1.1fr; gap: 18px; margin-bottom: 18px; }
.full { grid-column: 1 / -1; }
.card h3 { font-family: var(--serif); font-size: 18px; margin: 0 0 3px; letter-spacing: -0.01em; font-weight: 600; }
.card .sub { font-size: 12px; color: var(--muted); margin: 0 0 16px; }

/* ---- AI panel (deep evergreen glass) ---- */
.ai {
  background: linear-gradient(150deg, #2f4638 0%, #3f5c4a 60%, #46503a 100%);
  color: #eef2ea; border: none; position: relative; overflow: hidden;
}
.ai { color: #eef2ea; }
.ai::after { content:""; position:absolute; right:-50px; top:-50px; width:200px; height:200px;
  background: radial-gradient(circle, rgba(201,154,63,0.28), transparent 70%); }
.ai-badge { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  background: rgba(201,154,63,0.22); color: #e7c886; padding: 5px 12px; border-radius: 999px; }
.ai h3 { color:#fdfbf6; margin: 14px 0; }
.ai-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid rgba(255,255,255,0.10); font-size: 13.5px; line-height: 1.5; }
.ai-item:last-child { border-bottom: none; }
.dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.dot.g { background: #7fb389; } .dot.r { background: #dd8a6e; } .dot.a { background: #e7c886; } .dot.v { background: #c9b28f; }
.ai-item b { color: #fdfbf6; } .ai-item span { color: #cdd6c9; }

/* ---- transactions ---- */
.txn { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.txn:last-child { border: none; }
.txn-left { display: flex; align-items: center; gap: 10px; }
.tag { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px; letter-spacing: 0.03em; }
.tag.rec { background: var(--primary-soft); color: var(--primary); }
.tag.one { background: var(--clay-soft); color: var(--clay); }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- allocation ---- */
.alloc-bar { flex: 1; height: 16px; border-radius: 999px; background: var(--line); overflow: hidden; display: flex; }
.seg-mort { background: var(--primary); height: 100%; }
.seg-inv { background: var(--gold); height: 100%; }
.legend { display: flex; gap: 20px; margin-top: 16px; font-size: 12.5px; color: var(--ink2); flex-wrap: wrap; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 7px; vertical-align: middle; }

h2.section { font-family: var(--serif); font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 32px 0 14px; font-weight: 600; }

/* ---- health ---- */
.health-top { display: flex; align-items: center; gap: 20px; margin-bottom: 10px; }
.health-ring { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.health-ring svg { transform: rotate(-90deg); }
.health-ring .score { position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--serif); font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.health-grade { font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.health-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.factor { display: flex; align-items: center; gap: 9px; padding: 8px 0; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.factor:last-child { border-bottom: none; }
.factor .fdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.factor .fdot.good { background: var(--green); }
.factor .fdot.ok { background: var(--gold); }
.factor .fdot.bad { background: var(--red); }
.factor .fname { font-weight: 600; min-width: 130px; }
.factor .fnote { color: var(--ink2); }

/* ---- goals ---- */
.goals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; margin-bottom: 8px; }
.goal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.goal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.goal-name { font-family: var(--serif); font-weight: 600; font-size: 16px; }
.goal-badge { font-size: 10.5px; font-weight: 700; padding: 4px 11px; border-radius: 999px; letter-spacing: 0.02em; }
.goal-badge.on { background: var(--green-soft); color: var(--green); }
.goal-badge.off { background: var(--clay-soft); color: var(--clay); }
.goal-bar { height: 9px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 10px 0; }
.goal-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--gold)); }
.goal-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.goal-note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }

/* ---- ways to save ---- */
.save-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 8px; }
.save { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; position: relative; box-shadow: var(--shadow); }
.save-amt { font-family: var(--serif); font-size: 26px; font-weight: 600; color: var(--green); font-variant-numeric: tabular-nums; }
.save-amt span { font-size: 12px; color: var(--muted); font-weight: 500; font-family: var(--sans); }
.save-title { font-weight: 600; font-size: 13.5px; margin: 8px 0; }
.save-detail { font-size: 12px; color: var(--ink2); line-height: 1.5; }
.save-diff { position: absolute; top: 16px; right: 16px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 9px; border-radius: 6px; }
.save-diff.easy { background: var(--green-soft); color: var(--green); }
.save-diff.medium { background: var(--gold-soft); color: var(--amber); }
.save-diff.hard { background: var(--clay-soft); color: var(--clay); }

/* ---- budget bars ---- */
.bbar-row { margin: 13px 0; }
.bbar-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.bbar-name { font-weight: 600; }
.bbar-val { font-variant-numeric: tabular-nums; color: var(--ink2); }
.bbar-track { height: 9px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bbar-fill { height: 100%; border-radius: 999px; }
.bbar-fill.under { background: var(--green); }
.bbar-fill.near { background: var(--gold); }
.bbar-fill.over { background: var(--clay); }

/* ---- login ---- */
.login-overlay { position: fixed; inset: 0; background:
  radial-gradient(1000px 500px at 80% -10%, #efe7d9 0%, transparent 60%), var(--bg);
  display: grid; place-items: center; z-index: 50; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 36px; width: 380px; box-shadow: var(--shadow-lg); }
.login-card h2 { font-family: var(--serif); margin: 14px 0 4px; font-size: 24px; font-weight: 600; }
.login-card p { margin: 0 0 22px; font-size: 13px; color: var(--muted); }
.login-card label { font-size: 12px; color: var(--ink2); font-weight: 600; display: block; margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 12px 15px; border: 1px solid var(--line2); border-radius: var(--radius-sm); font-size: 14px; font-family: var(--sans); background: var(--surface2); }
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.login-card .btn-primary { width: 100%; margin-top: 22px; padding: 13px; }
.login-err { color: var(--red); font-size: 12.5px; margin-top: 14px; min-height: 16px; }
.hidden { display: none !important; }
.banner { background: var(--gold-soft); border: 1px solid #ecdcb2; color: #8a6d1a; border-radius: var(--radius-sm); padding: 11px 16px; font-size: 12.5px; margin-bottom: 18px; }

@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fadeIn 0.5s ease-out both; }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
}
@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid, .grid-3, .goals-grid, .save-grid { grid-template-columns: 1fr; }
}


/* ===== v3: vest planner, affordability, annual summary ===== */

/* Annual savings summary panel */
.annual-big { font-family: var(--serif); font-size: 34px; font-weight: 600; letter-spacing: -0.02em; margin: 4px 0; }
.annual-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.annual-row:last-child { border-bottom: none; }
.annual-row .lbl { color: var(--ink2); }
.annual-row .val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Vest planner */
.vest-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.vest-gross { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.vest-bar { display: flex; height: 30px; border-radius: 8px; overflow: hidden; margin: 16px 0 18px; }
.vest-seg { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.vest-seg.muted { background: var(--muted); }
.vest-seg.gold  { background: var(--gold); }
.vest-seg.primary { background: var(--primary); }
.vest-seg.clay { background: var(--clay); }
.vest-seg.green { background: var(--green); }
.vest-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.vest-item { display: flex; gap: 10px; align-items: flex-start; }
.vest-item .vdot { width: 10px; height: 10px; border-radius: 3px; margin-top: 4px; flex-shrink: 0; }
.vest-item .vlabel { font-weight: 600; font-size: 13px; }
.vest-item .vamt { font-family: var(--serif); font-size: 15px; }
.vest-item .vnote { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

/* Affordability */
.afford-input { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.afford-input input { padding: 11px 15px; border: 1px solid var(--line2); border-radius: var(--radius-sm); font-size: 15px; font-family: var(--sans); background: var(--surface2); width: 160px; }
.afford-input input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.afford-verdict { border-radius: var(--radius-sm); padding: 16px 18px; margin-top: 6px; font-size: 14px; line-height: 1.5; }
.afford-verdict.yes { background: var(--green-soft); color: var(--primary-deep); border: 1px solid #cfe0d2; }
.afford-verdict.tight { background: var(--gold-soft); color: #7a5f18; border: 1px solid #ecdcb2; }
.afford-verdict.no { background: var(--clay-soft); color: #7a3a26; border: 1px solid #e6c9ba; }
.afford-verdict b { font-weight: 700; }
.afford-paths { margin-top: 12px; font-size: 13px; color: var(--ink2); }
.afford-paths li { margin: 5px 0; }


/* ===== v4: transaction entry + ledger ===== */
.txn-form { display: grid; grid-template-columns: 140px 1.4fr 1fr 1fr 1fr 1.2fr auto; gap: 10px; align-items: center; }
.txn-form input, .txn-form select {
  padding: 10px 12px; border: 1px solid var(--line2); border-radius: var(--radius-sm);
  font-size: 13px; font-family: var(--sans); background: var(--surface2); width: 100%;
}
.txn-form input:focus, .txn-form select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.txn-form .btn-primary { padding: 10px 20px; white-space: nowrap; }
.tx-msg { font-size: 12.5px; margin-top: 12px; min-height: 16px; }
.tx-msg.ok { color: var(--green); }
.tx-msg.err { color: var(--red); }

.tx-table-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; color: var(--ink2); }
.tx-row { display: grid; grid-template-columns: 96px 1.6fr 1fr 1fr 110px 32px; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.tx-row:last-child { border-bottom: none; }
.tx-row .tx-d { color: var(--ink2); font-variant-numeric: tabular-nums; }
.tx-row .tx-amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.tx-row .tx-amt.pos { color: var(--green); }
.tx-row .tx-amt.neg { color: var(--ink); }
.tx-cat-chip { font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); justify-self: start; }
.tx-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 15px; border-radius: 6px; width: 28px; height: 28px; }
.tx-del:hover { background: var(--clay-soft); color: var(--clay); }
.tx-empty { color: var(--muted); font-size: 13px; padding: 16px 0; }

@media (max-width: 760px) {
  .txn-form { grid-template-columns: 1fr 1fr; }
  .tx-row { grid-template-columns: 80px 1fr 90px 28px; }
  .tx-row .tx-cat, .tx-row .tx-acct { display: none; }
}


/* ===== v5: dashboard / transactions tab switcher ===== */
.tabs { display: inline-flex; background: var(--surface2); border: 1px solid var(--line2);
  border-radius: 999px; padding: 3px; gap: 2px; }
.tab { border: none; background: transparent; color: var(--ink2); cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: var(--sans); padding: 8px 18px;
  border-radius: 999px; transition: all 0.15s ease; }
.tab:hover { color: var(--primary); }
.tab.active { background: var(--surface); color: var(--primary);
  box-shadow: 0 1px 3px rgba(60,48,32,0.10); }


/* ===== v6: import page ===== */
#import-box { width: 100%; min-height: 180px; padding: 14px 16px; border: 1px solid var(--line2);
  border-radius: var(--radius-sm); font-family: var(--mono, ui-monospace, "SF Mono", Menlo, monospace);
  font-size: 12.5px; line-height: 1.6; background: var(--surface2); color: var(--ink); resize: vertical; }
#import-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.import-actions, .import-commit { display: flex; align-items: center; gap: 16px; margin-top: 14px; flex-wrap: wrap; }
.import-opt { font-size: 12.5px; color: var(--ink2); display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.import-month { margin: 18px 0 8px; font-family: var(--serif); font-size: 15px; font-weight: 600; display: flex; align-items: baseline; gap: 10px; }
.import-month .cnt { font-family: var(--sans); font-size: 12px; color: var(--muted); font-weight: 500; }
.import-tot { font-family: var(--sans); font-size: 12px; color: var(--ink2); font-weight: 600; margin-left: auto; }
.imp-row { display: grid; grid-template-columns: 90px 1.6fr 1fr 100px; gap: 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.imp-row .d { color: var(--ink2); font-variant-numeric: tabular-nums; }
.imp-row .a { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.imp-row select { padding: 5px 8px; border: 1px solid var(--line2); border-radius: 7px; font-size: 12px; background: var(--surface); font-family: var(--sans); }
.imp-row select.flag { border-color: var(--clay); background: var(--clay-soft); }
.import-summary-box { display: flex; gap: 20px; flex-wrap: wrap; padding: 4px 0 8px; font-size: 13px; color: var(--ink2); }
.import-summary-box b { color: var(--ink); }


/* ===== v7: net-worth import ===== */
.import-mode-toggle { display: inline-flex; background: var(--surface2); border: 1px solid var(--line2);
  border-radius: 999px; padding: 3px; gap: 2px; margin-bottom: 14px; }
.imode { border: none; background: transparent; color: var(--ink2); cursor: pointer;
  font-size: 12.5px; font-weight: 600; font-family: var(--sans); padding: 7px 16px; border-radius: 999px; transition: all 0.15s ease; }
.imode:hover { color: var(--primary); }
.imode.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(60,48,32,0.10); }
#import-nw-box { width: 100%; min-height: 160px; padding: 14px 16px; border: 1px solid var(--line2);
  border-radius: var(--radius-sm); font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px; line-height: 1.6; background: var(--surface2); color: var(--ink); resize: vertical; }
#import-nw-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.nwmap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.nwmap-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.nwmap-row .acct { font-weight: 600; font-size: 13px; flex: 1; }
.nwmap-row select { padding: 5px 9px; border: 1px solid var(--line2); border-radius: 7px; font-size: 12px; background: var(--surface); font-family: var(--sans); }
.nw-type-cash { color: var(--green); } .nw-type-inv { color: var(--primary); } .nw-type-ret { color: var(--gold); }


/* ===== v8: file upload in import ===== */
.import-upload { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.import-file-btn { cursor: pointer; display: inline-flex; align-items: center; }
.import-file-btn input { display: none; }
.import-file-name { font-size: 12.5px; color: var(--ink2); font-style: italic; }
.import-file-name.err { color: var(--red); font-style: normal; }
