:root {
  --bg: #0a0a0a; --bg2: #161616; --bg3: #1e1e1e;
  --border: #2a2a2a; --text: #f0f0f0; --muted: #666;
  --green: #2a9d5c; --red: #e24b4a; --amber: #ef9f27; --blue: #4a9eff;
  --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; height: 100dvh; }
body {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text);
  height: 100%; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}
.page-wrapper {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 16px) 16px 16px;
}
h1 { font-size: 22px; font-weight: 600; margin-bottom: 2px; }
.sub { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
/* Bottom tabs */
.bottom-nav {
  flex-shrink: 0;
  background: var(--bg2); border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
.bnav-btn {
  flex: 1; padding: 10px 4px 8px;
  background: transparent; border: none; cursor: pointer;
  font-size: 10px; color: var(--muted); font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.bnav-btn .icon { font-size: 20px; }
.bnav-btn.active { color: var(--green); }

/* Month nav */
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.month-nav button { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: 16px; }
.month-nav span { flex: 1; text-align: center; font-size: 15px; font-weight: 500; }

/* Cards */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.card .lbl { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.card .v { font-size: 19px; font-weight: 600; }

/* Progress */
.prog-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.prog-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.prog-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 3px; transition: width 0.4s, background 0.4s; background: linear-gradient(90deg, var(--green), #5edc9a); }
.prog-fill.warn { background: linear-gradient(90deg, #c47d00, var(--amber)); }
.prog-fill.danger { background: linear-gradient(90deg, #b52020, var(--red)); }

/* Form */
.form-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.type-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.type-btn { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: transparent; cursor: pointer; font-size: 14px; color: var(--muted); font-family: inherit; }
.type-btn.exp.active { background: #e24b4a18; color: var(--red); border-color: #e24b4a55; }
.type-btn.inc.active { background: #2a9d5c18; color: var(--green); border-color: #2a9d5c55; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input[type=number], input[type=text], select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg3); color: var(--text);
  font-size: 15px; font-family: inherit; outline: none;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: none; height: 56px; }
.btn-main { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg3); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit; margin-bottom: 8px; }
.btn-sec { width: 100%; padding: 11px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; font-family: inherit; margin-bottom: 8px; }

/* Section visibility */
.page { display: none; }
.page.active { display: block; }

/* History */
.tx-list { display: flex; flex-direction: column; gap: 6px; }
.tx-item { display: flex; justify-content: space-between; align-items: center; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; }
.tx-cat { font-size: 14px; font-weight: 500; }
.tx-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tx-right { display: flex; align-items: center; gap: 10px; }
.tx-amt { font-size: 15px; font-weight: 600; }
.tx-del { background: none; border: none; cursor: pointer; color: #444; font-size: 20px; padding: 2px 6px; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem; font-size: 14px; }

/* Totals */
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.sum-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.sum-card .s-lbl { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; }
.sum-card .s-v { font-size: 16px; font-weight: 600; }
.cat-block { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.cat-title { font-size: 12px; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; }
.cat-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.cat-row:last-child { border-bottom: none; }

/* Savings */
.savings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.savings-header span { font-size: 13px; font-weight: 500; }
.savings-header button { padding: 6px 14px; border: 1px solid var(--green); border-radius: 8px; background: transparent; color: var(--green); font-size: 13px; cursor: pointer; font-family: inherit; }
.goal-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; }
.goal-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.goal-name { font-size: 15px; font-weight: 600; }
.goal-del { background: none; border: none; color: #444; font-size: 18px; cursor: pointer; padding: 0 4px; }
.goal-amounts { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.goal-amounts span { color: var(--green); font-weight: 500; }
.goal-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.goal-bar { height: 100%; border-radius: 3px; transition: width 0.4s; }
.goal-actions { display: flex; gap: 8px; }
.goal-btn { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; font-size: 13px; font-family: inherit; }
.goal-btn.add-money { color: var(--green); border-color: #2a9d5c44; }
.goal-btn.withdraw { color: var(--muted); }
.savings-total { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.savings-total .lbl { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.savings-total .v { font-size: 22px; font-weight: 600; color: var(--green); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: #000a; z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg2); border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); width: 100%; max-width: 560px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 4px; }
.modal-btn { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--text); font-size: 15px; font-weight: 500; cursor: pointer; font-family: inherit; }
.modal-btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.scan-status { font-size: 12px; text-align: center; padding: 6px 0; display: none; }
.scan-status.show { display: block; }
.scan-status.ok { color: var(--green); }
.scan-status.err { color: var(--red); }
.tx-recurring { font-size: 10px; color: var(--amber); margin-left: 4px; }
.cat-budget-row { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.cat-budget-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.cat-budget-bar-wrap { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.cat-budget-bar { height: 100%; border-radius: 3px; transition: width 0.3s; }
.cat-budget-input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg3); color: var(--text); font-size: 14px; font-family: inherit; }
