:root {
  --asfalto: #0E0E0E;
  --painel: #151517;
  --campo: #0F0F11;
  --linha: #2A2A2E;
  --ouro: #D4AF37;
  --ouro-claro: #F3E5AB;
  --ouro-escuro: #AA8215;
  --ouro-fundo: #1E190A;
  --ouro-borda: #3A3110;
  --texto: #EEEAE0;
  --mudo: #A3A3AB;
  --alerta: #FF6B5E;
  --azul: #6EA8FF;
  --nav-h: 66px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--asfalto);
  color: var(--texto);
  line-height: 1.4;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}

:focus-visible { outline: 2px solid var(--ouro); outline-offset: 2px; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- cabeçalho ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(14, 14, 14, 0.94);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--linha);
}
.header-logo { width: 42px; height: 42px; border-radius: 11px; display: block; }
.marca h1 { margin: 0; font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; color: var(--ouro-claro); line-height: 1.1; }
.marca p { margin: 2px 0 0; font-size: 0.78rem; color: var(--mudo); }

/* ---------- estrutura ---------- */
.container { padding: 16px; max-width: 520px; margin: 0 auto; }
.section { display: none; }
.section.active { display: block; }

.painel {
  background: var(--painel);
  border: 1px solid var(--linha);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.painel h2 { margin: 0 0 14px; font-size: 1rem; font-weight: 650; color: var(--texto); }
.painel .dica { margin: -8px 0 14px; font-size: 0.82rem; color: var(--mudo); }

/* ---------- formulário ---------- */
.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.campo-grupo { margin-bottom: 12px; }
.campo-grupo:last-child { margin-bottom: 0; }
label { display: block; font-size: 0.82rem; color: var(--mudo); margin-bottom: 6px; }

.campo { position: relative; }
.campo input { padding-left: 14px; }
.campo .pre, .campo .suf {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 0.9rem; color: var(--mudo); pointer-events: none;
}
.campo .pre { left: 14px; }
.campo .suf { right: 14px; }
.campo.com-pre input { padding-left: 42px; }
.campo.com-suf input { padding-right: 46px; }

input {
  width: 100%; height: 52px; padding: 0 14px;
  background: var(--campo);
  border: 1px solid var(--linha);
  border-radius: 10px;
  color: var(--texto);
  font-size: 1.05rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
input::placeholder { color: #5E5E66; font-weight: 400; }
input:focus { outline: none; border-color: var(--ouro); box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.16); }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=date] { font-weight: 600; }

.rodado {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-top: 14px; padding: 12px 14px;
  background: var(--ouro-fundo);
  border: 1px solid var(--ouro-borda);
  border-radius: 10px;
}
.rodado span:first-child { font-size: 0.85rem; color: var(--mudo); }
.rodado .valor { font-size: 1.45rem; font-weight: 800; color: var(--ouro-claro); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.rodado.aviso { background: rgba(255, 107, 94, 0.08); border-color: rgba(255, 107, 94, 0.45); }
.rodado.aviso span:first-child, .rodado.aviso .valor { color: var(--alerta); }
.rodado.aviso .valor { font-size: 1rem; }

/* ---------- resultado do dia e métricas ---------- */
.resultado-valor { font-size: 2rem; font-weight: 800; color: var(--ouro-claro); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.resultado-valor.neg, .hero-valor.neg { color: var(--alerta); }

.metricas { display: grid; grid-template-columns: 1fr 1fr; margin-top: 14px; border-top: 1px solid var(--linha); }
.metrica { padding: 12px 0 2px; }
.metrica:nth-child(odd) { padding-right: 12px; border-right: 1px solid var(--linha); }
.metrica:nth-child(even) { padding-left: 16px; }
.metrica:nth-child(n+3) { border-top: 1px solid var(--linha); margin-top: 12px; }
.metrica .rot { font-size: 0.8rem; color: var(--mudo); }
.metrica .val { margin-top: 2px; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.metrica .val.vermelho { color: var(--alerta); }
.metrica .val.ouro { color: var(--ouro-claro); }

.btn-salvar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 56px; margin-top: 4px;
  background: linear-gradient(135deg, #F3E5AB 0%, #D4AF37 50%, #AA8215 100%);
  color: #0E0E0E; font-size: 1.02rem; font-weight: 800;
  border: none; border-radius: 12px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(212, 175, 55, 0.22);
}
.btn-salvar:active { transform: scale(0.985); }

/* ---------- marcador (aba Semana) ---------- */
.hero { padding: 16px 16px 18px; border-radius: 18px; border-color: var(--ouro-borda); background: linear-gradient(180deg, #19160B 0%, var(--painel) 62%); }
.hero-topo { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.hero-topo h2 { margin: 0; }
.hero-topo span { font-size: 0.82rem; color: var(--mudo); }

.marcador { max-width: 300px; margin: 0 auto; }
.marcador svg { display: block; width: 100%; height: auto; overflow: visible; }
.marcador .trilho { fill: none; stroke: #26262A; stroke-width: 14; stroke-linecap: round; }
.marcador .prog { fill: none; stroke: url(#gradOuro); stroke-width: 14; stroke-linecap: round; stroke-dasharray: 0 100; transition: stroke-dasharray 0.9s cubic-bezier(0.2, 0.8, 0.2, 1); }
.marcador .marca-escala { stroke: #4A4A50; stroke-width: 1.5; stroke-linecap: round; }
.marcador .marca-escala.forte { stroke: #7C7C84; stroke-width: 2; }
.agulha { transform-box: view-box; transform-origin: 120px 120px; transition: transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1); }
.escala-fim { display: flex; justify-content: space-between; margin-top: 2px; padding: 0 4px; font-size: 0.74rem; color: var(--mudo); }

.hero-valor { margin-top: 8px; text-align: center; font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; color: var(--ouro-claro); font-variant-numeric: tabular-nums; }
.hero-rotulo { text-align: center; margin-top: 2px; font-size: 0.9rem; font-weight: 600; color: var(--ouro); }
.hero-frase { text-align: center; margin: 6px 0 0; font-size: 0.85rem; color: var(--mudo); }

.duo { display: grid; grid-template-columns: 1fr 1fr; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--linha); }
.duo > div:first-child { padding-right: 12px; border-right: 1px solid var(--linha); }
.duo > div:last-child { padding-left: 16px; }
.duo .rot { font-size: 0.8rem; color: var(--mudo); }
.duo .val { margin-top: 2px; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.duo .val.vermelho { color: var(--alerta); }

.metricas.solta { margin-top: 0; border-top: none; }

/* ---------- distribuição ---------- */
.barra-empilhada { display: flex; gap: 3px; height: 14px; margin-bottom: 8px; }
.barra-empilhada span { display: block; height: 100%; border-radius: 4px; min-width: 0; transition: flex-basis 0.6s; }
.barra-vazia { height: 14px; border-radius: 4px; background: #26262A; margin-bottom: 8px; }
.linha-dist { display: flex; align-items: center; gap: 10px; padding: 12px 0 0; margin-top: 12px; border-top: 1px solid var(--linha); font-size: 0.92rem; }
.linha-dist:first-of-type { margin-top: 4px; }
.linha-dist .ponto { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.linha-dist .nome { flex: 1; }
.linha-dist .dinheiro { font-weight: 700; font-variant-numeric: tabular-nums; }
.linha-dist .pct { width: 52px; text-align: right; color: var(--mudo); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.vazio { margin: 0; font-size: 0.9rem; color: var(--mudo); }

/* ---------- histórico ---------- */
.dia { display: grid; grid-template-columns: 52px 1fr 44px; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--linha); }
.dia:first-child { border-top: none; padding-top: 2px; }
.dia:last-child { padding-bottom: 0; }
.data-chip { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 56px; background: var(--ouro-fundo); border: 1px solid var(--ouro-borda); border-radius: 10px; }
.data-chip b { font-size: 1.25rem; line-height: 1.1; color: var(--ouro-claro); font-variant-numeric: tabular-nums; }
.data-chip small { font-size: 0.72rem; color: var(--mudo); }
.dia-saldo { font-size: 1.1rem; font-weight: 800; color: var(--ouro-claro); font-variant-numeric: tabular-nums; }
.dia-saldo.neg { color: var(--alerta); }
.dia-linha { margin-top: 1px; font-size: 0.83rem; color: var(--mudo); }
.dia-linha.semana { color: var(--texto); }

.btn-del { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; background: transparent; color: var(--mudo); border: 1px solid var(--linha); border-radius: 10px; cursor: pointer; }
.btn-del:active { color: var(--alerta); border-color: var(--alerta); background: rgba(255, 107, 94, 0.1); }

.btn-sec { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 50px; margin-top: 10px; background: transparent; color: var(--ouro-claro); font-size: 0.95rem; font-weight: 650; border: 1px solid var(--ouro-borda); border-radius: 12px; cursor: pointer; }
.btn-sec:first-of-type { margin-top: 0; }
.btn-sec:active { background: var(--ouro-fundo); }
.btn-sec .ic { width: 20px; height: 20px; color: var(--ouro); }

/* ---------- aviso rápido ---------- */
.toast {
  position: fixed; left: 50%; z-index: 30;
  width: max-content;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100vw - 32px); padding: 12px 16px;
  background: #212125; border: 1px solid var(--linha); border-radius: 12px;
  font-size: 0.92rem; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .ic { width: 20px; height: 20px; }
.toast.ok .ic { color: var(--ouro); }
.toast.erro { border-color: rgba(255, 107, 94, 0.5); }
.toast.erro .ic { color: var(--alerta); }

/* ---------- navegação ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(14, 14, 14, 0.95);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--linha);
}
.tab-btn {
  position: relative; flex: 1; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: none; border: none; color: var(--mudo);
  font-size: 0.74rem; font-weight: 650; cursor: pointer;
}
.tab-btn:active { background: rgba(255, 255, 255, 0.04); }
.tab-btn.active { color: var(--ouro); }
.tab-btn.active::before { content: ""; position: absolute; top: 0; left: 50%; width: 30px; height: 3px; margin-left: -15px; border-radius: 0 0 3px 3px; background: var(--ouro); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
