:root {
  --purple: #7c3aed;
  --purple-dark: #6d28d9;
  --green: #16a34a;
  --red: #ef4444;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1e2233;
  --muted: #8b90a0;
  --line: #eef0f5;
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ---------------- Login ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #7c3aed 0%, #6d28d9 100%);
}
.login-card {
  background: var(--card); width: 100%; max-width: 360px;
  border-radius: 24px; padding: 32px 24px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 14px 16px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 16px; margin-bottom: 12px;
}
.login-error { color: var(--red); font-size: 13px; display: block; min-height: 18px; margin-top: 8px; }

.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--purple); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ---------------- App shell ---------------- */
.app { max-width: 480px; margin: 0 auto; min-height: 100vh; position: relative; }
.view { display: flex; flex-direction: column; height: 100vh; }
.scroll {
  flex: 1; overflow-y: auto; padding: 16px 16px 96px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px; padding-top: max(16px, env(safe-area-inset-top));
}
.topbar-title { display: flex; align-items: center; gap: 8px; }
.topbar-title.center { flex: 1; justify-content: center; text-align: center; }
.topbar-label { font-size: 12px; color: var(--muted); display: block; }
.topbar-title strong { font-size: 17px; }
.month-nav {
  border: none; background: #ececf5; color: var(--purple);
  width: 30px; height: 30px; border-radius: 50%; font-size: 18px; cursor: pointer;
}
.icon-btn {
  border: none; background: #ececf5; width: 36px; height: 36px;
  border-radius: 50%; font-size: 16px; cursor: pointer; color: var(--text);
}

/* ---------------- Card saldo ---------------- */
.balance-card {
  background: linear-gradient(140deg, #7c3aed 0%, #6d28d9 100%);
  border-radius: var(--radius); padding: 20px; color: #fff;
  box-shadow: 0 12px 30px rgba(124,58,237,.35);
}
.balance-top { display: flex; justify-content: space-between; align-items: center; font-size: 14px; opacity: .9; }
.wallet { font-size: 22px; }
.balance-value { font-size: 34px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.balance-of { font-size: 13px; opacity: .8; margin-top: 2px; }

/* ---------------- Stats ---------------- */
.stats-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 14px; }
.stat {
  background: var(--card); border-radius: 14px; padding: 12px 10px; text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.04);
}
.stat-label { font-size: 12px; font-weight: 600; display: block; }
.stat strong { display: block; font-size: 14px; margin: 4px 0; }
.stat-icon { font-size: 12px; }
.green { color: var(--green); } .red { color: var(--red); } .gray { color: var(--muted); }

/* ---------------- Categorias ---------------- */
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 12px; }
.section-head h2 { font-size: 16px; }
.category-list { display: flex; flex-direction: column; gap: 14px; }
.cat-row { display: flex; align-items: center; gap: 12px; }
.cat-icon {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: #f0eefc;
}
.cat-main { flex: 1; min-width: 0; }
.cat-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.cat-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-amount { font-weight: 600; white-space: nowrap; }
.cat-bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.cat-bar span { display: block; height: 100%; border-radius: 4px; }
.cat-pct { font-size: 11px; color: var(--muted); margin-left: 8px; }
.cat-pct.over { color: var(--red); font-weight: 600; }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 30px 0; }

/* ---------------- Botões de ação ---------------- */
.action-row { display: flex; gap: 12px; margin-top: 24px; }
.btn-action {
  flex: 1; padding: 16px; border: none; border-radius: 14px;
  font-size: 15px; font-weight: 600; color: #fff; cursor: pointer;
}
.btn-action.income { background: var(--green); }
.btn-action.expense { background: var(--purple); }

/* ---------------- Lista de transações ---------------- */
.tx-list { display: flex; flex-direction: column; gap: 10px; }
.tx-item {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.04);
}
.tx-icon {
  width: 40px; height: 40px; border-radius: 12px; flex: none; background: #f0eefc;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 500; font-size: 14px; }
.tx-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tx-right { text-align: right; }
.tx-value { font-weight: 700; font-size: 15px; }
.tx-value.income { color: var(--green); }
.tx-value.expense { color: var(--text); }
.tx-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 3px; }
.tx-edit { border: none; background: none; color: var(--purple); font-size: 12px; font-weight: 600; cursor: pointer; }
.tx-del { border: none; background: none; color: var(--muted); font-size: 12px; cursor: pointer; }

/* ---------------- Custos fixos ---------------- */
.fixed-summary {
  background: linear-gradient(140deg, #efeafe, #f5f2ff); border-radius: var(--radius);
  padding: 18px; text-align: center;
}
.fs-label { font-size: 12px; color: var(--muted); }
.fs-total { font-size: 30px; font-weight: 700; color: var(--purple-dark); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.fs-sub { font-size: 12px; color: var(--muted); }
.fixed-list { display: flex; flex-direction: column; gap: 10px; }
.fixed-item {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.04);
}
.fixed-item.checked { background: #f2fbf5; }
.fixed-item .f-check {
  width: 26px; height: 26px; border-radius: 8px; flex: none; cursor: pointer;
  border: 2px solid #d5d8e2; background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.fixed-item .f-check.on { background: var(--green); border-color: var(--green); }
.fixed-item .f-icon { width: 40px; height: 40px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.fixed-item .f-main { flex: 1; min-width: 0; }
.fixed-item .f-title { font-weight: 500; font-size: 14px; }
.fixed-item .f-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.fixed-item .f-value { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.fixed-item .f-del { border: none; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 2px; }

/* ---------------- Bottom nav ---------------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; color: var(--muted); white-space: nowrap;
}
.nav-item.active { color: var(--purple); font-weight: 600; }
.nav-icon { font-size: 19px; }

/* ---------------- Relatórios (50/30/20) ---------------- */
.rep-income {
  background: var(--card); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px;
  display: flex; justify-content: space-between; align-items: center; box-shadow: 0 3px 10px rgba(0,0,0,.04);
}
.rep-income span { color: var(--muted); font-size: 13px; }
.rep-income strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.rep-card {
  background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
}
.rep-card-head { display: flex; align-items: center; gap: 12px; }
.rep-ico { width: 42px; height: 42px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.rep-head-main { flex: 1; min-width: 0; }
.rep-label { font-weight: 600; font-size: 15px; }
.rep-ideal { font-size: 12px; color: var(--muted); margin-top: 1px; }
.rep-actual { text-align: right; white-space: nowrap; }
.rep-actual-val { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.rep-actual-pct { font-size: 12px; color: var(--muted); }
.rep-bar { height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 12px 0 8px; }
.rep-bar span { display: block; height: 100%; border-radius: 5px; }
.rep-status { font-size: 12px; font-weight: 600; }
.rep-status.good { color: var(--green); }
.rep-status.warn { color: #d97706; }
.rep-status.bad { color: var(--red); }
.rep-cats { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.rep-cat { font-size: 12px; color: var(--muted); }
.rep-cat b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.rep-note { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 8px; background: #f3f0ff; padding: 12px 14px; border-radius: 12px; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,15,40,.45); display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%);} to { transform: translateY(0);} }
.modal-head { padding: 20px 20px 8px; text-align: center; position: relative; }
.modal-close {
  position: absolute; left: 16px; top: 16px; border: none; background: #f0f1f5;
  width: 34px; height: 34px; border-radius: 50%; font-size: 15px; cursor: pointer; color: var(--muted);
}
.form-badge {
  width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff; font-weight: 700;
}
.form-badge.expense { background: var(--red); }
.form-badge.income { background: var(--green); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-foot { padding: 12px 20px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

.field-label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 2px 8px; }
.amount-input {
  display: flex; align-items: center; gap: 8px; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 14px 16px; font-size: 22px; font-weight: 700;
}
.amount-input span { color: var(--muted); }
.amount-input input { border: none; outline: none; font-size: 22px; font-weight: 700; width: 100%; }
.text-input {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 15px; outline: none;
}
.text-input:focus, .amount-input:focus-within { border-color: var(--purple); }

/* ---------------- Parcelas ---------------- */
.inst-row { display: flex; align-items: center; gap: 10px; }
.inst-row .step {
  width: 42px; height: 42px; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 12px; font-size: 20px; color: var(--purple); cursor: pointer; flex: none;
}
.inst-row #f-installments {
  width: 60px; text-align: center; padding: 11px 4px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 16px; font-weight: 600; outline: none;
  -moz-appearance: textfield;
}
.inst-row #f-installments::-webkit-outer-spin-button,
.inst-row #f-installments::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inst-hint { font-size: 13px; color: var(--muted); }
.inst-hint.on { color: var(--purple-dark); font-weight: 600; }

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips.two { grid-template-columns: 1fr 1fr; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer;
  font-size: 13px; font-weight: 500; background: var(--card); text-align: left;
}
.chip .chip-icon { font-size: 16px; }
.chip.active { border-color: var(--purple); background: #f5f2ff; color: var(--purple-dark); }

.btn-save {
  width: 100%; padding: 16px; border: none; border-radius: 14px;
  font-size: 16px; font-weight: 600; color: #fff; cursor: pointer; background: var(--purple);
}
.btn-save.income { background: var(--green); }
.btn-danger {
  width: 100%; padding: 14px; border: none; border-radius: 14px; margin-top: 12px;
  font-size: 15px; font-weight: 600; color: var(--red); cursor: pointer; background: #fdecec;
}

/* ---------------- Botões auxiliares ---------------- */
.link-btn { border: none; background: none; color: var(--purple); font-size: 13px; font-weight: 600; cursor: pointer; }
.icon-btn.purple { background: var(--purple); color: #fff; font-size: 20px; }

/* ---------------- Categoria: limite ---------------- */
.cat-limit { margin-left: 6px; white-space: nowrap; }  /* herda fonte/peso/tamanho do .cat-amount */
.cat-limit.ok { color: var(--muted); }
.cat-limit.over { color: var(--red); }

/* ---------------- Metas: card resumo ---------------- */
.goal-summary {
  background: linear-gradient(140deg, #efeafe, #f5f2ff); border-radius: var(--radius);
  padding: 18px; display: flex; align-items: stretch; gap: 16px;
}
.gs-label { font-size: 12px; color: var(--muted); }
.gs-big { font-size: 26px; font-weight: 700; color: var(--purple-dark); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.gs-big.green { color: var(--green); }
.gs-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gs-divider { flex: none; width: 1px; background: #ddd6f3; }
.goal-summary > div { flex: 1; }

/* ---------------- Metas: cards ---------------- */
.goal-list { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.goal-card {
  background: var(--card); border-radius: 16px; padding: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
}
.goal-head { display: flex; align-items: flex-start; gap: 12px; }
.goal-icon { width: 42px; height: 42px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.goal-info { flex: 1; min-width: 0; }
.goal-name { font-weight: 600; font-size: 15px; }
.goal-sub { font-size: 12px; margin-top: 1px; }
.goal-amounts { text-align: right; white-space: nowrap; }
.goal-saved { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.goal-target { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.goal-menu { border: none; background: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 0 2px; align-self: center; }
.goal-bar { height: 7px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 12px 0 8px; }
.goal-bar span { display: block; height: 100%; border-radius: 5px; }
.goal-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.goal-foot .done { color: var(--green); font-weight: 600; }

/* ---------------- Metas: dica ---------------- */
.tip-banner {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 18px;
  background: #f3f0ff; border-radius: 14px; padding: 14px; font-size: 12px; color: #5b5470; line-height: 1.4;
}

/* ---------------- Seletor de ícone ---------------- */
.icon-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-opt {
  width: 46px; height: 46px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); font-size: 22px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-opt.active { border-color: var(--purple); background: #f5f2ff; }

/* ---------------- Limites ---------------- */
.modal-hint { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.limits-list { display: flex; flex-direction: column; gap: 10px; }
.limit-row { display: flex; align-items: center; gap: 12px; }
.limit-row .l-icon { width: 36px; height: 36px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.limit-row .l-name { flex: 1; font-size: 13px; font-weight: 500; }
.limit-row .l-input {
  display: flex; align-items: center; gap: 4px; border: 1.5px solid var(--line);
  border-radius: 10px; padding: 8px 10px; width: 120px;
}
.limit-row .l-input span { color: var(--muted); font-size: 13px; }
.limit-row .l-input input { border: none; outline: none; width: 100%; font-size: 14px; font-weight: 600; text-align: right; }
.limit-row .l-input:focus-within { border-color: var(--purple); }
