:root {
  --primaria: #4f46e5;
  --primaria-escura: #3730a3;
  --primaria-clara: #818cf8;
  --acento: #f59e0b;
  --verde: #16a34a;
  --vermelho: #dc2626;
  --bg: #f6f5fb;
  --card-bg: #ffffff;
  --texto: #1f2933;
  --texto-suave: #6b7280;
  --borda: #e6e4f2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--texto);
  padding-bottom: 90px;
}

.hidden { display: none !important; }

/* ---------- login ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--primaria) 0%, var(--primaria-escura) 100%);
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 36px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 18px;
  display: block;
  object-fit: cover;
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; font-weight: 800; color: var(--texto); }
.login-sub { color: var(--texto-suave); font-size: 14px; margin: 0 0 24px; }
.google-btn-wrap { display: flex; justify-content: center; }
.login-aviso {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--vermelho);
  background: #fef2f2;
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- topbar / tabs ---------- */
.topbar {
  background: var(--primaria);
  color: white;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 10px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 800; flex-shrink: 0; }
.tab-nav { display: flex; gap: 4px; background: rgba(255,255,255,0.12); border-radius: 12px; padding: 4px; }
.tab-btn {
  background: transparent;
  border: none;
  color: white;
  opacity: 0.75;
  font-size: 16px;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}
.tab-btn.active { background: rgba(255,255,255,0.25); opacity: 1; }
.config-wrap { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 16px;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,0.6); }

/* ---------- navegação de mês ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
}
.nav-btn {
  background: var(--card-bg);
  border: 1px solid var(--borda);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
}
.month-label {
  font-size: 18px;
  font-weight: 700;
  min-width: 160px;
  text-align: center;
  text-transform: capitalize;
}
.limpar-btn {
  background: transparent;
  color: var(--texto-suave);
  border: 1px solid var(--borda);
  width: 36px;
  height: 36px;
  font-size: 15px;
}
.limpar-btn:hover { color: var(--vermelho); border-color: var(--vermelho); }

.saldo-anterior {
  margin: 0 16px 12px;
  padding: 10px 14px;
  background: #eef2ff;
  color: var(--primaria-escura);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}
.saldo-anterior.negativo { background: #fef2f2; color: var(--vermelho); }

/* ---------- resumo ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
}
.summary.cols-2 { grid-template-columns: repeat(2, 1fr); padding-top: 0; }
.summary-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.summary-card .label { font-size: 11px; color: var(--texto-suave); }
.summary-card .value { font-size: 14.5px; font-weight: 800; }
.summary-card.receita .value { color: var(--verde); }
.summary-card.pago .value { color: var(--vermelho); }
.summary-card.saldo .value { color: var(--primaria); }
.summary-card.total .value { color: var(--texto); }
.summary-card.apagar .value { color: var(--vermelho); }

/* ---------- secoes (entradas / categorias de despesa) ---------- */
.secao-entradas { padding: 0 16px 8px; }
.secao-categoria { padding: 0 16px; margin-bottom: 6px; }
.secao-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 2px 8px;
}
.secao-titulo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--texto);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.icone-secao { width: 18px; height: 18px; color: var(--primaria); flex-shrink: 0; }
.secao-total { font-weight: 800; color: var(--texto); font-size: 14px; }
.btn-add-secao {
  background: var(--primaria);
  color: white;
  border: none;
  border-radius: 8px;
  width: 26px;
  height: 26px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.lista { display: flex; flex-direction: column; gap: 8px; }
.vazio-mini { color: var(--texto-suave); font-size: 12.5px; padding: 6px 2px 10px; }

.workspace-item { flex-direction: column; align-items: stretch; gap: 8px; }
.workspace-cabecalho { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.workspace-emails { display: flex; flex-wrap: wrap; gap: 6px; }
.email-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f1f2f4;
  border-radius: 999px;
  padding: 4px 6px 4px 10px;
  font-size: 12.5px;
}
.chip-remover, .chip-convite {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.chip-remover { font-size: 16px; }
.chip-convite:hover { color: var(--primaria); }
.chip-convite:disabled { opacity: 0.5; cursor: default; }
.workspace-item .add-item-row { padding: 0; }

.item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  flex-wrap: wrap;
}
.item.pago { opacity: 0.55; }
.item .check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--primaria);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  background: transparent;
}
.item.pago .check { background: var(--primaria); }
.item .star {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 18px;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}
.item .star.on { color: var(--acento); }
.item .info { flex: 1; min-width: 100px; }
.item .nome { font-weight: 700; font-size: 14.5px; display: block; }
.item .categoria { font-size: 11.5px; color: var(--texto-suave); }
.item .valor {
  width: 90px;
  text-align: right;
  border: none;
  background: transparent;
  font-weight: 800;
  font-size: 14.5px;
  color: var(--texto);
}
.item .valor[readonly] { color: var(--texto-suave); }
.item .del {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}
/* entradas funcionam ao contrário das despesas: em vez de esmaecer quando
   concluída, ela "acende" quando o dinheiro cai (recebida) */
.secao-entradas .item .check { border-color: var(--verde); }
.secao-entradas .item.recebida {
  opacity: 1;
  background: #ecfdf5;
  box-shadow: 0 0 0 1.5px var(--verde) inset;
}
.secao-entradas .item.recebida .check { background: var(--verde); }
.secao-entradas .item.recebida .nome { color: var(--verde); }

.detalhar-btn {
  background: #eef2ff;
  color: var(--primaria);
  border: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.vazio {
  text-align: center;
  color: var(--texto-suave);
  padding: 40px 20px;
  font-size: 14px;
}

.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primaria);
  color: white;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  cursor: pointer;
}

/* ---------- modais ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31,41,51,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.modal .hint { font-size: 12px; color: var(--texto-suave); margin: -8px 0 4px; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--texto-suave);
  font-weight: 700;
}
.modal input[type=text], .modal input[type=number], .modal select {
  padding: 10px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  font-size: 15px;
  color: var(--texto);
  font-family: inherit;
}
.recorrencia-meses-lista {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  padding: 6px;
}
.recorrencia-mes-linha {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  padding: 6px 4px;
  font-size: 13px !important;
  font-weight: 600 !important;
  text-transform: capitalize;
}
.recorrencia-mes-linha .rec-mes-label { flex: 1; }
.recorrencia-mes-linha .rec-mes-valor {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--borda);
  border-radius: 6px;
  font-size: 13px;
  text-align: right;
  font-family: inherit;
}
.checkbox-line {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 14px !important;
}
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--primaria); color: white; }
.btn.secondary { background: #f1f2f4; color: var(--texto); }

/* ---------- itens de fatura ---------- */
.itens-fatura-lista { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.item-fatura-linha {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13.5px;
}
.item-fatura-linha .nome-item { flex: 1; }
.item-fatura-linha .valor-item { font-weight: 700; }
.item-fatura-total { text-align: right; font-weight: 800; padding: 6px 4px 0; font-size: 14px; }
.add-item-fatura-row { display: flex; gap: 8px; }
.add-item-fatura-row input[type=text] { flex: 2; }
.add-item-fatura-row input[type=number] { flex: 1; }
.add-item-fatura-row input {
  padding: 10px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  font-size: 14px;
}

/* ---------- telas secundárias (reserva / equilíbrio / lista) ---------- */
.tela-secundaria { padding-bottom: 40px; }
.secundaria-header { padding: 20px 16px 8px; }
.secundaria-header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.secundaria-header .hint { color: var(--texto-suave); font-size: 13px; margin: 0; }

.card-form {
  margin: 8px 16px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.pergunta-line { display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 700; }
.toggle-yn { display: flex; gap: 8px; }
.toggle-yn .yn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--borda);
  background: white;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--texto-suave);
}
.toggle-yn .yn.selected { background: var(--primaria); border-color: var(--primaria); color: white; }

.resultado-card {
  margin: 8px 16px;
  background: #eef2ff;
  border-radius: 14px;
  padding: 16px;
}
.resultado-linha { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 14px; }
.resultado-linha strong { color: var(--primaria-escura); font-size: 17px; }
.resultado-hint { margin-top: 8px; font-size: 12px; color: var(--texto-suave); }

.equilibrio-renda { font-size: 14px; margin-bottom: 6px; }
.equilibrio-linha { padding: 10px 0; border-top: 1px solid var(--borda); }
.equilibrio-linha:first-of-type { border-top: none; }
.equilibrio-linha-topo { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.equilibrio-barra { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.equilibrio-barra-fill { height: 100%; background: var(--primaria); border-radius: 999px; }
.equilibrio-real { font-size: 12px; color: var(--texto-suave); margin-top: 6px; }
.equilibrio-real.acima { color: var(--vermelho); font-weight: 700; }
.equilibrio-real.muted { font-style: italic; }

/* ---------- lista de compras ---------- */
.add-item-row { display: flex; gap: 8px; padding: 0 16px 16px; }
.add-item-row input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.add-item-row .btn { flex: none; padding: 12px 18px; }

.itens-lista {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 90px;
}
.item-compra {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.item-compra.comprado { opacity: 0.5; }
.item-compra.comprado .nome-item { text-decoration: line-through; }
.item-compra .check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--primaria);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  background: transparent;
}
.item-compra.comprado .check { background: var(--primaria); }
.item-compra .nome-item { flex: 1; font-size: 14.5px; }
.item-compra .del {
  background: none;
  border: none;
  color: var(--texto-suave);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.fechar-compra-btn {
  position: fixed;
  bottom: 24px;
  left: 16px;
  right: 16px;
  width: auto;
}
