:root {
  --fundo: #f2f2f7;
  --cartao: #ffffff;
  --texto: #1c1c1e;
  --texto-2: #6c6c70;
  --linha: #e5e5ea;
  --verde: #1f9d5c;
  --verde-suave: #e3f5ea;
  --vermelho: #d92d20;
  --vermelho-suave: #fde8e6;
  --amarelo-suave: #fff6d6;
  --azul: #0a7aff;
  --sombra: 0 1px 2px rgba(0, 0, 0, 0.06);
  --raio: 14px;
  --altura-abas: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #000000;
    --cartao: #1c1c1e;
    --texto: #f2f2f7;
    --texto-2: #98989f;
    --linha: #38383a;
    --verde: #30c172;
    --verde-suave: #12321f;
    --vermelho: #ff6159;
    --vermelho-suave: #3a1513;
    --amarelo-suave: #3a3210;
    --azul: #3d9bff;
    --sombra: none;
  }
}

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

html, body { margin: 0; padding: 0; }

body {
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

main {
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 16px)
    calc(var(--altura-abas) + env(safe-area-inset-bottom) + 96px) calc(env(safe-area-inset-left) + 16px);
  max-width: 640px;
  margin: 0 auto;
}

.carregando { text-align: center; color: var(--texto-2); margin-top: 40vh; }

/* ---------- Cabeçalho ---------- */
.cabecalho {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px; margin-bottom: 8px;
}
.cabecalho h1 { font-size: 22px; margin: 0; text-align: center; flex: 1; }
.cabecalho .seta {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--verde);
  font-size: 26px; border-radius: 22px;
}
.cabecalho .seta:disabled { color: var(--linha); }
.titulo-aba { font-size: 28px; font-weight: 700; margin: 8px 0 12px; }

/* ---------- Cartões e seções ---------- */
.cartao {
  background: var(--cartao); border-radius: var(--raio); box-shadow: var(--sombra);
  padding: 16px; margin-bottom: 12px;
}
.secao-titulo {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--texto-2);
  margin: 20px 4px 6px; display: flex; justify-content: space-between; align-items: baseline;
}
.secao-titulo span:last-child { text-transform: none; letter-spacing: 0; }

.destaque .rotulo { color: var(--texto-2); font-size: 14px; }
.destaque .numero { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.negativo { color: var(--vermelho) !important; }
.positivo { color: var(--verde); }
.detalhe { color: var(--texto-2); font-size: 14px; }

.barra { height: 8px; border-radius: 4px; background: var(--linha); overflow: hidden; margin: 8px 0; }
.barra > div { height: 100%; background: var(--verde); border-radius: 4px; transition: width 0.3s; }
.barra.estourou > div { background: var(--vermelho); }

.resumo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.resumo .rotulo { font-size: 12px; color: var(--texto-2); }
.resumo .valor { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 15px; }
.resumo-rodape { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--linha); font-size: 14px; color: var(--texto-2); text-align: center; }

.faixa {
  background: var(--amarelo-suave); border-radius: var(--raio); padding: 10px 14px; margin-bottom: 12px;
  font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.faixa button { border: 0; background: transparent; color: var(--azul); font-weight: 600; padding: 6px; }

/* ---------- Listas ---------- */
.lista { background: var(--cartao); border-radius: var(--raio); box-shadow: var(--sombra); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 52px;
  border-bottom: 1px solid var(--linha); width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0;
  text-align: left;
}
.item:last-child { border-bottom: 0; }
.item .meio { flex: 1; min-width: 0; }
.item .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--texto-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .valor { font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.pago .nome, .item.pago .valor { color: var(--texto-2); }
.item.pulado .nome, .item.pulado .valor { color: var(--texto-2); text-decoration: line-through; }
.item.sub-item { padding-left: 30px; background: var(--fundo); min-height: 44px; }
.item-vazio { padding: 16px; color: var(--texto-2); text-align: center; font-size: 14px; }
.toque { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; border: 0; background: transparent; padding: 0; text-align: left; }

.check {
  width: 30px; height: 30px; flex: none; border-radius: 15px; border: 2px solid var(--texto-2);
  background: transparent; display: grid; place-items: center; padding: 0; color: #fff; font-size: 16px; font-weight: 700;
}
.check.pago { background: var(--verde); border-color: var(--verde); }
.check.pulado { border-style: dashed; color: var(--texto-2); }
.check.calculado { border-color: var(--linha); color: var(--texto-2); font-size: 12px; }

.selo {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 8px; margin-left: 6px;
  background: var(--linha); color: var(--texto-2); vertical-align: 1px; font-weight: 500;
}
.selo.verde { background: var(--verde-suave); color: var(--verde); }
.bolinha { width: 10px; height: 10px; border-radius: 5px; flex: none; }
.seta-dir { color: var(--texto-2); font-size: 18px; }

.ordem { display: flex; gap: 2px; }
.ordem button {
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: var(--fundo); color: var(--texto-2); font-size: 14px;
}
.ordem button:disabled { opacity: 0.3; }

/* ---------- Botões ---------- */
.botoes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.botao {
  border: 0; border-radius: 12px; padding: 13px 14px; font-weight: 600; background: var(--cartao);
  color: var(--verde); box-shadow: var(--sombra); min-height: 48px; width: 100%;
}
.botao.primario { background: var(--verde); color: #fff; }
.botao.perigo { color: var(--vermelho); }
.botao.secundario { background: var(--fundo); color: var(--texto); }
.botao-link { border: 0; background: transparent; color: var(--azul); padding: 12px 14px; font-weight: 600; width: 100%; text-align: left; }

.fab {
  position: fixed; z-index: 20;
  right: calc(env(safe-area-inset-right) + 18px);
  bottom: calc(var(--altura-abas) + env(safe-area-inset-bottom) + 18px);
  width: 60px; height: 60px; border-radius: 30px; border: 0;
  background: var(--verde); color: #fff; font-size: 34px; line-height: 1; font-weight: 300;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.fab:active { transform: scale(0.95); }

/* ---------- Abas ---------- */
.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--cartao) 88%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-top: 1px solid var(--linha);
}
.abas button {
  height: var(--altura-abas); border: 0; background: transparent; color: var(--texto-2);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.abas button.ativa { color: var(--verde); }
.abas .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Semanas ---------- */
.semanas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.semana {
  background: var(--cartao); border-radius: var(--raio); padding: 12px; border: 2px solid transparent; text-align: left;
  box-shadow: var(--sombra); font-size: 13px;
}
.semana.selecionada { border-color: var(--verde); }
.semana .titulo { font-weight: 700; font-size: 15px; }
.semana .linha { display: flex; justify-content: space-between; color: var(--texto-2); font-variant-numeric: tabular-nums; }
.semana .saldo { font-size: 18px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.semana .atual { font-size: 11px; color: var(--verde); font-weight: 600; }

/* ---------- Gráficos ---------- */
.grafico h2 { font-size: 17px; margin: 0 0 4px; }
.grafico .legenda { font-size: 12px; color: var(--texto-2); margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.grafico .legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.hbar { margin-bottom: 10px; }
.hbar .topo { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 3px; gap: 8px; }
.hbar .topo span:last-child { color: var(--texto-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar .trilho { height: 10px; background: var(--fundo); border-radius: 5px; overflow: hidden; }
.hbar .trilho > div { height: 100%; border-radius: 5px; min-width: 2px; }
.colunas { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.colunas .grupo { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.colunas .barras { display: flex; align-items: flex-end; gap: 2px; height: 100%; width: 100%; justify-content: center; }
.colunas .barras > div { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.colunas .rot { font-size: 11px; color: var(--texto-2); margin-top: 4px; white-space: nowrap; }
.tabela-mini { width: 100%; font-size: 12px; color: var(--texto-2); margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabela-mini td { padding: 2px 0; }
.tabela-mini td:not(:first-child) { text-align: right; }

/* ---------- Folha (formulários) ---------- */
#camada-folha, #camada-pergunta { position: relative; z-index: 50; }
#camada-pergunta { z-index: 60; }
.veu { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); animation: aparecer 0.15s; }
.folha {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--fundo); border-radius: 16px 16px 0 0;
  padding: 8px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px);
  max-width: 640px; margin: 0 auto; animation: subir 0.2s ease-out;
}
.folha .alca { width: 36px; height: 5px; border-radius: 3px; background: var(--linha); margin: 0 auto 8px; }
.folha-topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.folha-topo h2 { font-size: 18px; margin: 0; }
.folha-topo button { border: 0; background: transparent; color: var(--azul); font-weight: 600; padding: 8px; }
.aviso { font-size: 13px; color: var(--texto-2); margin: 4px 4px 12px; }

.campos { background: var(--cartao); border-radius: var(--raio); overflow: hidden; margin-bottom: 14px; }
.campo { display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 50px; border-bottom: 1px solid var(--linha); }
.campo:last-child { border-bottom: 0; }
.campo > span { flex: none; width: 112px; color: var(--texto-2); font-size: 15px; }
.campo input, .campo select, .campo textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; padding: 12px 0; outline: none; text-align: right;
}
.campo textarea { text-align: left; resize: none; }
.campo input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 24px; }
.campo.valor-grande input { font-size: 28px; font-weight: 600; text-align: left; }
.campo.valor-grande > span { width: auto; font-size: 22px; }
.segmentado { display: flex; flex: 1; background: var(--fundo); border-radius: 9px; padding: 2px; margin: 8px 0; }
.segmentado label { flex: 1; text-align: center; font-size: 14px; padding: 6px 4px; border-radius: 7px; }
.segmentado input { position: absolute; opacity: 0; pointer-events: none; }
.segmentado label:has(input:checked) { background: var(--cartao); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 600; }
.chave { position: relative; width: 51px; height: 31px; flex: none; margin-left: auto; }
.chave input { opacity: 0; width: 0; height: 0; position: absolute; }
.chave i { position: absolute; inset: 0; background: var(--linha); border-radius: 16px; transition: 0.2s; }
.chave i::after { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.chave input:checked + i { background: var(--verde); }
.chave input:checked + i::after { transform: translateX(20px); }
.cores { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 0; flex: 1; justify-content: flex-end; }
.cores label { width: 28px; height: 28px; border-radius: 14px; border: 3px solid transparent; }
.cores input { position: absolute; opacity: 0; pointer-events: none; }
.cores label:has(input:checked) { border-color: var(--texto); }
.erro-form { color: var(--vermelho); font-size: 14px; margin: -6px 4px 12px; }

/* ---------- Pergunta ---------- */
.pergunta {
  position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px);
  max-width: 520px; margin: 0 auto; animation: subir 0.2s ease-out;
}
.pergunta .caixa { background: var(--cartao); border-radius: var(--raio); overflow: hidden; margin-bottom: 8px; }
.pergunta .msg { padding: 16px; text-align: center; font-size: 14px; color: var(--texto-2); border-bottom: 1px solid var(--linha); white-space: pre-line; }
.pergunta .msg strong { display: block; color: var(--texto); font-size: 16px; margin-bottom: 4px; }
.pergunta .op { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--linha); background: transparent; padding: 15px; font-size: 17px; color: var(--azul); }
.pergunta .op:last-child { border-bottom: 0; }
.pergunta .op.perigo { color: var(--vermelho); }
.pergunta .op.cancelar { background: var(--cartao); border-radius: var(--raio); font-weight: 600; }
.pergunta select { width: calc(100% - 32px); margin: 0 16px 12px; padding: 10px; border-radius: 10px; border: 1px solid var(--linha); background: var(--fundo); font-size: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 70; left: 16px; right: 16px; max-width: 480px; margin: 0 auto;
  bottom: calc(var(--altura-abas) + env(safe-area-inset-bottom) + 90px);
  background: #2c2c2e; color: #fff; border-radius: 12px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); animation: subir 0.2s ease-out;
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: transparent; color: #5ed38f; font-weight: 700; padding: 8px 10px; }

@keyframes subir { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

.vazio-grafico { color: var(--texto-2); font-size: 14px; text-align: center; padding: 12px; }
.rodape-versao { text-align: center; color: var(--texto-2); font-size: 12px; margin-top: 24px; }
