:root {
  --bg: #F6F1E7;
  --card: #FFFFFF;
  --card-2: #FBF7EF;
  --border: #EAE2D0;
  --texto: #2A2620;
  --texto-suave: #948A76;
  --dourado: #B8842A;
  --dourado-hover: #9C6F20;
  --dourado-fundo: #F3E6C8;
  --verde: #2F7D52;
  --verde-fundo: #E7F3EC;
  --vermelho: #BE5738;
  --vermelho-fundo: #F8EAE2;
  --raio: 18px;
  --raio-sm: 12px;
  --sombra: 0 1px 2px rgba(40,32,14,0.05), 0 4px 14px rgba(40,32,14,0.06);
}

html[data-theme="dark"] {
  --bg: #131722;
  --card: #1C2230;
  --card-2: #232A3B;
  --border: #2E3648;
  --texto: #EDEFF4;
  --texto-suave: #8D95AC;
  --dourado: #E3B15C;
  --dourado-hover: #EEC178;
  --dourado-fundo: #3A3220;
  --verde: #62C08F;
  --verde-fundo: #1C3129;
  --vermelho: #E28A6C;
  --vermelho-fundo: #3A2820;
  --sombra: 0 1px 2px rgba(0,0,0,0.35), 0 4px 14px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  transition: background 0.15s, color 0.15s;
}

svg { width: 22px; height: 22px; display: block; }

/* ---------- Cabeçalho ---------- */
.topo {
  padding: 20px 20px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topo h1 { font-size: 22px; font-weight: 700; margin: 0; color: var(--texto); letter-spacing: -0.3px; }
.topo h1 span { color: var(--dourado); }

.topo-acoes { display: flex; align-items: center; gap: 14px; }
.topo-acoes a { color: var(--texto-suave); text-decoration: none; font-size: 13px; font-weight: 600; }
.topo-saudacao { color: var(--texto-suave); font-size: 13px; font-weight: 600; }
@media (max-width: 360px) { .topo-saudacao { display: none; } }

.btn-tema {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--dourado);
  box-shadow: var(--sombra);
}
.btn-tema svg { width: 18px; height: 18px; }
.btn-tema .icone-lua { display: none; }
html[data-theme="dark"] .btn-tema .icone-sol { display: none; }
html[data-theme="dark"] .btn-tema .icone-lua { display: block; }

/* ---------- Conteúdo ---------- */
.conteudo { padding: 14px 16px 8px; max-width: 640px; margin: 0 auto; }

h3 { font-size: 14px; color: var(--texto-suave); font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; margin: 24px 0 10px; }

/* ---------- Cartões estilo "Caixa" ---------- */
.cartoes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.cartoes.linha-unica { grid-template-columns: 1fr; }

.cartao {
  background: var(--card);
  border-radius: var(--raio);
  padding: 18px 18px;
  box-shadow: var(--sombra);
}

.cartao .rotulo { font-size: 11.5px; color: var(--texto-suave); margin-bottom: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.cartao .valor { font-size: 24px; font-weight: 700; letter-spacing: -0.4px; color: var(--texto); }
.cartao.receita .valor { color: var(--verde); }
.cartao.despesa .valor { color: var(--vermelho); }
.cartao.saldo .valor { color: var(--dourado); }
.cartao.destaque { background: var(--dourado); }
.cartao.destaque .rotulo { color: rgba(255,255,255,0.75); }
.cartao.destaque .valor { color: #ffffff; font-size: 30px; }

/* ---------- Listas (substituem tabelas cruas) ---------- */
table { width: 100%; border-collapse: collapse; background: transparent; }
table, thead, tbody, th, td, tr { display: block; }
thead { display: none; }

tr {
  background: var(--card);
  border-radius: var(--raio-sm);
  box-shadow: var(--sombra);
  margin-bottom: 8px;
  padding: 2px 4px;
}
td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 11px 14px;
  text-align: right;
  font-size: 14px;
}
td:last-child { border-bottom: none; }
td[data-label]:before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--texto-suave);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: left;
  flex-shrink: 0;
}
td[data-label=""]:before { content: none; }
td input { text-align: right; }

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

/* ---------- Lançamentos (entradas/despesas) ---------- */
.lista-lancamentos { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.linha-lancamento {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--raio-sm);
  padding: 10px 12px;
  box-shadow: var(--sombra);
}
.linha-lancamento .nome-lancamento { flex: 1; font-size: 14px; font-weight: 600; }
.linha-lancamento input[type="text"] { width: 120px; flex-shrink: 0; }
.linha-lancamento button { flex-shrink: 0; padding: 10px 14px; }

.cartao-despesa {
  background: transparent;
  border-radius: var(--raio-sm);
  margin-bottom: 4px;
}
.cartao-despesa .linha-lancamento { border-bottom-left-radius: 0; border-bottom-right-radius: 0; box-shadow: none; border: 1px solid var(--border); border-bottom: none; }
.cartao-despesa.esta-pago .linha-lancamento { background: var(--verde-fundo); }

.botao-pago {
  width: 100%;
  background: var(--card-2);
  color: var(--texto-suave);
  border-radius: 0 0 var(--raio-sm) var(--raio-sm);
  font-size: 12.5px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-top: 1px dashed var(--border);
}
.botao-pago.pago { background: var(--verde-fundo); color: var(--verde); }

.despesas-colapsaveis { margin-top: 24px; }
.despesas-colapsaveis summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--texto-suave);
  padding: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}
.despesas-colapsaveis summary::-webkit-details-marker { display: none; }
.despesas-colapsaveis summary::before {
  content: '▸';
  color: var(--dourado);
  font-size: 12px;
  transition: transform 0.15s;
}
.despesas-colapsaveis[open] summary::before { transform: rotate(90deg); }
.etiqueta-pendente {
  background: var(--vermelho-fundo);
  color: var(--vermelho);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: none;
  letter-spacing: normal;
}
form.linha { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }

input, select {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--raio-sm);
  font-family: inherit;
  font-size: 15px;
  background: var(--card);
  color: var(--texto);
  min-height: 46px;
}
input:focus, select:focus { outline: none; border-color: var(--dourado); box-shadow: 0 0 0 3px var(--dourado-fundo); }
input.copiado { border-style: dashed; border-color: var(--dourado); background: var(--dourado-fundo); }

button, .botao {
  background: var(--dourado);
  color: #ffffff;
  border: none;
  padding: 12px 22px;
  border-radius: var(--raio-sm);
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  transition: opacity 0.15s;
}
button:hover, .botao:hover { opacity: 0.88; }
button:active, .botao:active { opacity: 0.75; }

/* ---------- Metas ---------- */
.barra-meta { background: var(--border); border-radius: 6px; height: 8px; overflow: hidden; margin-top: 10px; }
.barra-meta-fill { background: var(--dourado); height: 100%; border-radius: 6px; }

.avaliacao { font-size: 12.5px; margin-top: 10px; padding: 9px 11px; border-radius: var(--raio-sm); line-height: 1.4; font-weight: 600; }
.avaliacao.ok { background: var(--verde-fundo); color: var(--verde); }
.avaliacao.risco { background: var(--vermelho-fundo); color: var(--vermelho); }
.avaliacao.neutro { background: var(--card-2); color: var(--texto-suave); }

/* ---------- Login ---------- */
.login-box {
  max-width: 340px;
  width: 100%;
  margin: 14vh auto;
  background: var(--card);
  padding: 34px 28px;
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  text-align: center;
}
.login-box h1 { color: var(--dourado); margin-bottom: 24px; font-size: 22px; }
.login-box select, .login-box input { width: 100%; margin-bottom: 12px; }
.login-box button { width: 100%; }

/* ---------- Gráficos ---------- */
.grafico-caixa { background: var(--card); border-radius: var(--raio); padding: 16px; margin-bottom: 16px; box-shadow: var(--sombra); }
.grafico-caixa h3 { margin-top: 0; }

/* ---------- Barra inferior + botão flutuante ---------- */
.menu-inferior {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
.menu-inferior a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--texto-suave);
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 8px;
  min-width: 52px;
}
.menu-inferior a svg { width: 22px; height: 22px; }
.menu-inferior a.activo { color: var(--dourado); }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(68px + env(safe-area-inset-bottom));
  width: 54px; height: 54px;
  background: var(--dourado);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(184,132,42,0.45);
  z-index: 31;
  text-decoration: none;
}
.fab svg { width: 26px; height: 26px; }

/* Página "Mais" — lista de atalhos */
.lista-atalhos { display: flex; flex-direction: column; gap: 10px; }
.atalho {
  background: var(--card);
  border-radius: var(--raio);
  padding: 16px 18px;
  box-shadow: var(--sombra);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
  color: var(--texto);
}
.atalho .rotulo-atalho { font-weight: 700; font-size: 15px; }
.atalho .desc-atalho { font-size: 12.5px; color: var(--texto-suave); margin-top: 3px; }
.atalho svg { color: var(--dourado); flex-shrink: 0; }

@media (min-width: 640px) {
  .conteudo { max-width: 760px; }
}
