:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1f2430;
  --text-suave: #6b7280;
  --borda: #e5e7eb;

  --azul: #2563eb;
  --azul-escuro: #1d4ed8;
  --verde: #16a34a;
  --verde-fundo: #ecfdf3;
  --vermelho: #dc2626;
  --vermelho-fundo: #fef2f2;
  --ambar: #d97706;
  --ambar-fundo: #fffbeb;

  --raio: 14px;
  --sombra: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: 84px;
}

a {
  color: inherit;
}

h1, h2, h3 {
  margin: 0 0 12px;
}

.topo {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--borda);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topo h1 {
  font-size: 18px;
  margin: 0;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  padding: 16px;
  margin-bottom: 12px;
}

.campo {
  margin-bottom: 16px;
}

.campo label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-suave);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--borda);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-primary {
  background: var(--azul);
  color: #fff;
}

.btn-primary:active {
  background: var(--azul-escuro);
}

.btn-secundario {
  background: var(--surface);
  border: 1px solid var(--borda);
  color: var(--text);
}

.btn-icone {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--azul);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-flutuante {
  position: fixed;
  right: 20px;
  bottom: 96px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  z-index: 20;
}

.toggle-tipo {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.toggle-tipo button {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: 2px solid var(--borda);
  background: var(--surface);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-suave);
}

.toggle-tipo button.ativo[data-tipo="despesa"] {
  border-color: var(--vermelho);
  background: var(--vermelho-fundo);
  color: var(--vermelho);
}

.toggle-tipo button.ativo[data-tipo="receita"] {
  border-color: var(--verde);
  background: var(--verde-fundo);
  color: var(--verde);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-pendente { background: var(--ambar-fundo); color: var(--ambar); }
.badge-vencido { background: var(--vermelho-fundo); color: var(--vermelho); }
.badge-pago { background: var(--verde-fundo); color: var(--verde); }

.valor-despesa { color: var(--vermelho); font-weight: 700; }
.valor-receita { color: var(--verde); font-weight: 700; }

.lancamento-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.lancamento-info {
  flex: 1;
  min-width: 0;
}

.lancamento-nome {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lancamento-meta {
  font-size: 13px;
  color: var(--text-suave);
  margin-top: 2px;
}

.lancamento-acoes {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.filtros {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.filtros select, .filtros input {
  min-width: 130px;
  width: auto;
}

.vazio {
  text-align: center;
  color: var(--text-suave);
  padding: 40px 20px;
}

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.visivel {
  opacity: 1;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--borda);
  display: flex;
  justify-content: space-around;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 30;
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--text-suave);
  font-size: 11px;
  padding: 6px 2px;
  border-radius: 10px;
}

.bottom-nav a.ativo {
  color: var(--azul);
  font-weight: 700;
}

.bottom-nav .icone {
  display: block;
  font-size: 20px;
  margin-bottom: 2px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--borda);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  color: var(--text-suave);
}

.tabs button.ativo {
  background: var(--azul);
  border-color: var(--azul);
  color: #fff;
}

.modal-fundo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.modal-fundo[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.resumo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.resumo-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--sombra);
}

.resumo-item .rotulo {
  font-size: 12px;
  color: var(--text-suave);
  margin-bottom: 4px;
}

.resumo-item .valor {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.link-topo {
  background: none;
  border: none;
  color: var(--azul);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
