:root {
  --bg: #e8e7e2;
  --surface: #ffffff;
  --surface-2: #f7f7f4;
  --text: #1c1c1a;
  --text-2: #5f5e5a;
  --text-3: #8b8a84;
  --border: #e3e2dc;
  --border-2: #d3d1c7;
  --info: #185fa5;
  --danger: #a32d2d;
  --success: #3b6d11;
  --radius: 10px;
  --radius-sm: 7px;
  --maxw: 920px;
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f; --surface: #232320; --surface-2: #2b2b27;
    --text: #ededea; --text-2: #b4b2a9; --text-3: #888780;
    --border: #36352f; --border-2: #44443f;
    --info: #85b7eb; --danger: #f09595; --success: #97c459;
  }
}

/* The sheet always renders as paper, in both light and dark mode. */
.sheet {
  --paper: #fcfbf7; --pink: #1c1c1a; --pip: #1c1c1a;
  --rule: #c8c6bb; --bar: #1f1e1b; --barink: #fcfbf7;
  --field: #b6b4a9; --gray-box: #ece9e1;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h2 { margin: 0; font-weight: 600; }
a { color: var(--info); }

/* ---------- top app bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark { width: 34px; height: 34px; border-radius: 8px; background: var(--text); color: var(--surface); display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.brand__name { font-weight: 600; font-size: 15px; }
.topbar__actions { display: flex; align-items: flex-end; gap: 12px; }
.field--inline { display: flex; flex-direction: column; gap: 3px; }
.field--inline > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 500; }

/* ---------- page ---------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- THE SHEET ---------- */
.sheet {
  background: var(--paper); color: var(--pink);
  border: 1px solid var(--border-2);
  border-radius: 4px; padding: 30px 34px 36px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 30px rgba(0,0,0,.05);
}
.sheet__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 12px; }
.head-fields { flex: 1; display: flex; flex-direction: column; gap: 12px; max-width: 460px; }
.wordmark { font-family: var(--serif); font-size: 26px; font-weight: 700; color: var(--pink); white-space: nowrap; letter-spacing: .01em; }
.wordmark span { font-weight: 600; font-style: italic; }

/* label tab + underline field */
.tabfield { display: flex; align-items: center; gap: 10px; }
.tab { background: var(--bar); color: var(--barink); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 4px 10px; border-radius: 2px; white-space: nowrap; }
.tabfield input { flex: 1; }

.goal { font-size: 12.5px; color: var(--pink); margin: 4px 0 18px; line-height: 1.5; }
.goal strong { font-weight: 600; }

.doc-title { font-family: var(--serif); font-size: 23px; font-weight: 700; color: var(--pink); margin: 24px 0 12px; }

/* inputs on the sheet: fill-in-the-blank underline style */
.sheet input[type=text], .sheet input[type=number] {
  font: inherit; font-size: 13.5px; color: var(--pink);
  background: transparent; border: none; border-bottom: 1px solid var(--field);
  border-radius: 0; padding: 2px 4px; width: 100%; height: 26px; transition: border-color .12s;
}
.sheet input::placeholder { color: #b0aea3; }
.sheet input:focus { outline: none; border-bottom-color: var(--info); border-bottom-width: 2px; padding-bottom: 1px; }
.sheet input[readonly] { color: #6f6e68; }

/* topbar month input keeps the boxed style */
.topbar input[type=month] { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-sm); height: 34px; padding: 0 10px; }
.topbar input:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px color-mix(in srgb, var(--info) 18%, transparent); }

/* ---------- income statement grid ---------- */
.is-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 30px; align-items: start; }
.is-left { display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 760px) { .is-grid { grid-template-columns: 1fr; gap: 22px; } }

/* a ledger block = dark bar header + ruled lines */
.ledger { border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.bar { background: var(--bar); color: var(--barink); font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; padding: 7px 12px; }
.ledger > :not(.bar) { padding-left: 12px; padding-right: 12px; }
.ledger > .rowset, .ledger > #expense-list, .ledger > #re-income { padding-top: 6px; }
.ledger .btn--sm { margin: 4px 12px 12px; }
.colheads { display: flex; justify-content: space-between; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding-top: 8px; padding-bottom: 2px; border-bottom: 1px solid var(--rule); }

.sub { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 600; margin: 12px 0 4px; }

/* a labelled fill line: "Salary .............. [amount]" */
.line { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px dotted var(--rule); }
.line__label { font-size: 13.5px; color: var(--pink); flex: 1 1 auto; }
.amt { text-align: right; }
.line .amt { flex: 0 0 96px; }

/* desc + amount rows (real estate, assets, liabilities) */
.rowset .row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dotted var(--rule); }
.row .desc { flex: 1 1 auto; min-width: 0; }
.row .amt { flex: 0 0 88px; }
.row .del { border: none; background: none; color: var(--text-3); cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 5px; border-radius: 5px; flex: 0 0 auto; }
.row .del:hover { background: rgba(163,45,45,.12); color: var(--danger); }

/* ---------- auditor / right column ---------- */
.is-right { display: flex; flex-direction: column; }
.is-right .tabfield { margin-bottom: 2px; }
.micro { font-size: 11px; color: var(--text-3); margin: 3px 0 10px; line-height: 1.4; }

.bigtotal { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; border-bottom: 2px solid var(--pink); padding: 6px 2px 5px; margin-top: 8px; }
.bigtotal__k { font-size: 13.5px; font-weight: 600; color: var(--pink); }
.bigtotal__k em { font-style: italic; font-weight: 400; color: var(--text-2); }
.bigtotal__v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--pink); }
.bigtotal--payday { border-bottom-width: 3px; margin-top: 14px; }
.bigtotal--payday.neg .bigtotal__v { color: var(--danger); }

.kids { background: var(--gray-box); border-radius: 4px; padding: 10px 12px; margin: 14px 0 4px; }
.kids__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 3px 0; font-size: 12.5px; color: var(--pink); }
.kids__row input { width: 84px; text-align: right; }

.progress { margin-top: 20px; }
.progress__head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.progress__head span:last-child { font-weight: 600; color: var(--pink); }
.progress__track { height: 7px; background: #ddd9cd; border-radius: 99px; overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--info); border-radius: 99px; transition: width .25s; }
.progress__bar.won { background: var(--success); }

/* ---------- balance sheet ---------- */
.bs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 760px) { .bs-grid { grid-template-columns: 1fr; } }
.bs-grid .amt { flex: 0 0 84px; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 8px 14px; height: 36px; display: inline-flex; align-items: center; gap: 6px; transition: background .12s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn--primary:hover { opacity: .9; }
.btn--ghost { background: transparent; border-color: var(--field); color: var(--text-2); }
.btn--ghost:hover { background: rgba(0,0,0,.04); }
.btn--sm { height: 28px; padding: 3px 10px; font-size: 12.5px; }

/* ---------- snapshots panel ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 20px; }
.snapshots__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.snapshots__head h2 { font-size: 15px; }
.snapshots__tools { display: flex; gap: 6px; }
.snapshot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.snap { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.snap__info { min-width: 0; }
.snap__month { font-size: 14px; font-weight: 600; }
.snap__meta { font-size: 12px; color: var(--text-3); }
.snap__payday { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.snap__payday.neg { color: var(--danger); }
.snap__payday.pos { color: var(--success); }
.snap__actions { display: flex; gap: 4px; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--text-3); font-size: 13px; padding: 5px 7px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.empty { font-size: 13px; color: var(--text-3); margin: 6px 2px 0; }

/* ---------- footer + toast ---------- */
.footer { max-width: var(--maxw); margin: 0 auto; padding: 16px 20px 40px; font-size: 12px; color: var(--text-3); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--surface); font-size: 14px; padding: 10px 18px; border-radius: 99px; box-shadow: 0 4px 16px rgba(0,0,0,.18); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
