:root { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; background: #f4f6f9; color: #1c2733;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; font-size: 15px; line-height: 1.45; }
.wrap { max-width: 920px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 70px max(16px, env(safe-area-inset-left)); }
h1 { font-size: 22px; margin: 0 0 2px; color: #1f4e78; }
.sub { color: #6b7785; font-size: 13px; margin: 0 0 16px; }
.hidden { display: none !important; }

/* top bar with user / household */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.topbar .who { font-size: 13px; color: #6b7785; }
.topbar .who b { color: #1c2733; }
.btn { border: 1px solid #cfd8e3; background: #fff; border-radius: 8px; padding: 7px 12px; font-size: 13px;
  cursor: pointer; color: #1f4e78; font-weight: 600; }
.btn:hover { background: #eef3f9; }
.btn.primary { background: #1f4e78; color: #fff; border-color: #1f4e78; }
.btn.primary:hover { background: #163a5a; }

/* auth + onboarding cards */
.authwrap { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; }
.authcard { background: #fff; border: 1px solid #e6ebf1; border-radius: 16px; padding: 26px; box-shadow: 0 2px 12px rgba(0,0,0,.05); }
.authcard h2 { margin: 0 0 4px; color: #1f4e78; font-size: 20px; }
.authcard p.lead { margin: 0 0 18px; color: #6b7785; font-size: 14px; }
.authcard label { display: block; font-size: 12px; color: #6b7785; margin: 12px 0 4px; }
.authcard input { width: 100%; padding: 12px 12px; border: 1px solid #cfd8e3; border-radius: 9px; font-size: 16px; color: #1c2733; }
.authcard .btn.primary { width: 100%; margin-top: 18px; padding: 13px; font-size: 15px; }
.authcard .switch { margin-top: 14px; font-size: 13px; color: #6b7785; text-align: center; }
.authcard .switch a { color: #1f4e78; font-weight: 600; cursor: pointer; }
.msg { margin-top: 12px; font-size: 13px; padding: 9px 11px; border-radius: 8px; display: none; }
.msg.err { background: #fbecea; color: #b3261e; display: block; }
.msg.ok  { background: #e7f4e8; color: #2f6f33; display: block; }
.divider { display: flex; align-items: center; gap: 10px; color: #aab3bd; font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #e6ebf1; }

.tabs { display: flex; gap: 6px; background: #e7edf4; padding: 5px; border-radius: 12px; margin-bottom: 20px; }
.tab { flex: 1; border: none; background: transparent; padding: 10px 8px; border-radius: 9px; font-size: 14px; font-weight: 600; color: #5a6775; cursor: pointer; }
.tab.active { background: #fff; color: #1f4e78; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.bar button.nav { border: 1px solid #cfd8e3; background: #fff; border-radius: 8px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; color: #1f4e78; }
.bar button.nav:hover { background: #eef3f9; }
.month { font-weight: 700; font-size: 17px; min-width: 150px; text-align: center; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
.card { background: #fff; border: 1px solid #e6ebf1; border-radius: 12px; padding: 14px; }
.card .lbl { font-size: 12px; color: #6b7785; text-transform: uppercase; letter-spacing: .03em; }
.card .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.card.income .val { color: #1f4e78; } .card.budget .val { color: #2e75b6; }
.card.spent .val { color: #b45309; } .card.left .val { color: #548235; }
.card.left.over .val { color: #c0392b; }
.card.accent .val { color: #1f4e78; } .card.good .val { color: #548235; } .card.warn .val { color: #b45309; }
.card .editable { border: 1px solid transparent; border-radius: 6px; background: transparent; font: inherit;
  font-size: 22px; font-weight: 700; width: 100%; color: inherit; padding: 0; }
.card .editable:hover { border-color: #cfd8e3; } .card .editable:focus { border-color: #2e75b6; background: #fff; outline: none; }

.section-title { font-size: 13px; font-weight: 700; color: #1f4e78; text-transform: uppercase; letter-spacing: .04em; margin: 22px 0 8px; }
.bigbar { background: #eef2f6; border-radius: 10px; height: 22px; overflow: hidden; margin: 6px 0 4px; }
.bigfill { height: 100%; border-radius: 10px; transition: width .3s; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; color: #fff; font-size: 12px; font-weight: 700; }
.bigfill.debt { background: linear-gradient(90deg,#548235,#6aa23f); }
.bigfill.save { background: linear-gradient(90deg,#2e75b6,#4a93d6); }

form.add { background: #fff; border: 1px solid #e6ebf1; border-radius: 12px; padding: 14px; display: grid; grid-template-columns: 1.4fr .8fr 1.4fr auto; gap: 10px; align-items: end; margin-bottom: 8px; }
form.add.debtpay, form.add.deposit { grid-template-columns: 1fr 1.6fr auto; }
form.add label { font-size: 12px; color: #6b7785; display: block; margin-bottom: 4px; }
form.add select, form.add input { width: 100%; padding: 11px 10px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 16px; background: #fff; color: #1c2733; }
form.add button.add { background: #1f4e78; color: #fff; border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; height: 38px; }
form.add button.add:hover { background: #163a5a; }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e6ebf1; border-radius: 12px; overflow: hidden; }
th, td { padding: 9px 12px; text-align: left; font-size: 14px; }
thead th { background: #f0f4f9; color: #44515f; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { border-top: 1px solid #eef2f6; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.track { background: #eef2f6; border-radius: 6px; height: 8px; width: 130px; overflow: hidden; }
.fill { height: 100%; border-radius: 6px; }
.fill.ok { background: #548235; } .fill.warn { background: #d49a00; } .fill.over { background: #c0392b; }
.budget-edit { width: 78px; padding: 4px 6px; border: 1px solid transparent; border-radius: 6px; text-align: right; font-size: 14px; background: transparent; color: #1c2733; font-variant-numeric: tabular-nums; }
.budget-edit:hover { border-color: #cfd8e3; } .budget-edit:focus { border-color: #2e75b6; background: #fff; outline: none; }
.cat-name { width: 100%; min-width: 90px; padding: 5px 6px; border: 1px solid transparent; border-radius: 6px; font-size: 14px; background: transparent; color: #1c2733; font-family: inherit; }
.cat-name:hover { border-color: #cfd8e3; } .cat-name:focus { border-color: #2e75b6; background: #fff; outline: none; }
.del-cat { border: none; background: transparent; color: #c2cad3; font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.del-cat:hover { color: #c0392b; background: #fbecea; }
tfoot td { font-weight: 700; background: #f0f4f9; border-top: 2px solid #d7dee6; }
form.add-cat { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
form.add-cat input { padding: 9px 10px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 14px; background: #fff; color: #1c2733; }
form.add-cat input.grow { flex: 1; min-width: 160px; } form.add-cat input.small { width: 110px; }
form.add-cat button { border: 1px solid #2e75b6; background: #eef3f9; color: #1f4e78; border-radius: 8px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
form.add-cat button:hover { background: #dceaf6; }

.txns { margin-top: 8px; }
.txn { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border: 1px solid #e6ebf1; border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; }
.txn .meta { font-size: 13px; color: #44515f; } .txn .meta b { color: #1c2733; }
.txn .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.txn button { border: none; background: transparent; color: #b0b9c3; font-size: 17px; cursor: pointer; line-height: 1; }
.txn button:hover { color: #c0392b; }
.empty { color: #8c97a3; font-size: 14px; padding: 14px; text-align: center; background: #fff; border: 1px dashed #d7dee6; border-radius: 10px; }
.hint { font-size: 12px; color: #8c97a3; margin-top: 10px; }
.panel { background: #fff; border: 1px solid #e6ebf1; border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 4px; font-size: 16px; }
.inline-field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; font-size: 14px; color: #44515f; }
.inline-field input { padding: 8px 10px; border: 1px solid #cfd8e3; border-radius: 8px; font-size: 15px; width: 130px; color: #1c2733; }
.goalcard { background: #fff; border: 1px solid #e6ebf1; border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.goalhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.goal-name { font-size: 16px; font-weight: 700; border: 1px solid transparent; border-radius: 6px; padding: 3px 6px; background: transparent; color: #1c2733; font-family: inherit; min-width: 120px; }
.goal-name:hover { border-color: #cfd8e3; } .goal-name:focus { border-color: #2e75b6; background: #fff; outline: none; }
.codebox { font-family: ui-monospace, Menlo, monospace; background: #f0f4f9; border: 1px dashed #cfd8e3; border-radius: 8px; padding: 8px 12px; font-size: 16px; letter-spacing: .08em; display: inline-block; color: #1f4e78; font-weight: 700; }

@media (max-width: 680px) {
  body { font-size: 16px; }
  .cards, .cards.three { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card .val, .card .editable { font-size: 20px; }
  form.add { grid-template-columns: 1fr 1fr; }
  form.add > div:nth-child(3) { grid-column: 1 / -1; }
  form.add.debtpay, form.add.deposit { grid-template-columns: 1fr 1fr; }
  form.add button.add { grid-column: 1 / -1; width: 100%; height: 46px; font-size: 16px; }
  form.add select, form.add input { padding: 12px 11px; }
  .month { font-size: 18px; } .bar button.nav { width: 42px; height: 42px; font-size: 20px; }
  th, td { padding: 10px 8px; font-size: 14px; }
  .track { width: 70px; } .budget-edit { font-size: 16px; width: 70px; } .cat-name { font-size: 15px; }
  .del-cat { font-size: 22px; padding: 4px 8px; }
  .txn { padding: 12px; } .txn button { font-size: 22px; padding: 4px 6px; }
  form.add-cat input, form.add-cat button { font-size: 16px; }
  form.add-cat input.grow { flex: 1 1 100%; } form.add-cat input.small { flex: 1; } form.add-cat button { flex: 1 1 100%; height: 44px; }
}
