:root {
  --bg: #000;
  --surface: #000;
  --surface-2: #111113;
  --surface-3: #1c1c1f;
  --line: #1a1a1d;
  --text: #ececee;
  --text-2: #b4b4ba;
  --muted: #7d7d84;
  --gold: #d8b77f;
  --gold-strong: #e6c48a;
  --gold-bg: rgba(216, 183, 127, .14);
  --green: #7fcf9a;
  --red: #e08a8a;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  padding-bottom: 110px;
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.btn-round {
  width: 52px; height: 52px; border-radius: 50%;
  background: #1c1c1f; display: grid; place-items: center; flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.btn-round svg { width: 26px; height: 26px; stroke-width: 2; }
.month-nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
.month-nav h1 { font-size: 20px; font-weight: 500; white-space: nowrap; cursor: pointer; }
.month-nav .ano { color: var(--muted); }
.chev { color: var(--muted); padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.chev:hover { color: var(--text); }
.chev svg { width: 18px; height: 18px; }
.chev-prev { margin-left: -6px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.btn-square {
  position: relative; width: 48px; height: 48px; border-radius: 14px;
  background: var(--surface-3); display: grid; place-items: center; color: var(--gold);
}
.btn-square .dot {
  position: absolute; top: 9px; right: 9px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--gold-strong); box-shadow: 0 0 0 2px var(--surface-3);
}
.btn-gear {
  width: 44px; height: 44px; border-radius: 50%;
  background: #2a2318; color: var(--gold); display: grid; place-items: center;
}

/* ---------- Resumo ---------- */
.resumo {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--line);
}
.kpi { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-esq { align-items: flex-start; }
.kpi-dir { align-items: flex-end; text-align: right; }
.kpi-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.kpi-btn { padding: 0; text-align: right; white-space: nowrap; }
.kpi-btn:hover > span { text-decoration: underline; text-underline-offset: 4px; }
#saldoHoje.neg { color: var(--red); }
.kpi-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--text-2);
}
.kpi-valor { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-valor small { font-size: 14px; font-weight: 400; color: var(--muted); }
.kpi-gold .kpi-label, .kpi-gold .kpi-valor > span { color: var(--gold); }
.info {
  width: 17px; height: 17px; border-radius: 50%; background: var(--gold); color: var(--surface);
  font-size: 11px; font-weight: 800; font-style: italic; font-family: Georgia, serif; line-height: 17px;
}

/* ---------- Tabela ---------- */
.tabela { padding: 0 0 0 16px; }
.row-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr 1.2fr;
  align-items: center;
  column-gap: 6px;
  padding-right: 16px;
}
.row-grid > :not(:first-child) { text-align: right; }
.thead {
  padding-top: 16px; padding-bottom: 4px;
  font-size: 13px; font-weight: 500; letter-spacing: .03em; text-transform: uppercase; color: var(--text-2);
  position: sticky; top: 81px; background: var(--surface); z-index: 5;
}
.thead span:nth-child(2) { text-align: left; padding-left: 8px; }

.linha {
  height: 48px; border-bottom: 1px solid var(--line);
  font-size: 17px; font-variant-numeric: tabular-nums; color: var(--text-2);
  cursor: pointer; user-select: none; position: relative;
  transition: background .15s;
}
.linha:hover { background: rgba(255,255,255,.025); }
.linha .dia { color: var(--text); white-space: nowrap; }
.linha .dia .dow { color: var(--text-2); }
.linha .dia .caret { display: inline-block; width: 0; height: 0; margin-left: 4px; vertical-align: middle;
  border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid var(--text-2); transition: transform .2s; }
.linha.aberta .dia .caret { transform: rotate(180deg); }
.linha .saldo { color: var(--gold); font-weight: 500; }
.linha .entrada { color: var(--green); }
.linha .diario { color: var(--muted); }
.linha .diario.meta-ok { color: var(--gold); font-weight: 600; }
.linha .diario.proj { color: var(--muted); opacity: .8; }
.linha.domingo .dia, .linha.domingo .dow { color: var(--muted); }
.linha.negativo .saldo { color: var(--red); }

/* futuro / projetado */
.linha.futuro .saldo { color: var(--text-2); font-weight: 400; }
.linha.futuro .diario.proj { color: var(--muted); opacity: .85; }
.linha.futuro.negativo .saldo { color: var(--red); }

/* hoje */
.linha.hoje {
  background: var(--gold-bg);
  margin-left: -16px; padding-left: 16px;
  box-shadow: inset 5px 0 0 var(--gold);
  border-bottom-color: transparent;
}
.linha.hoje .dia, .linha.hoje .dow, .linha.hoje .saldo { color: var(--gold-strong); }

.linha.fora { opacity: .35; cursor: default; }

/* detalhe do dia */
.detalhe {
  padding: 6px 16px 14px 0;
  border-bottom: 1px solid var(--line);
  background: #000;
  animation: abre .18s ease-out;
}
@keyframes abre { from { opacity: 0; transform: translateY(-4px); } }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-top: 6px; border-radius: 12px; background: var(--surface-2);
}
.item .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 7px; border-radius: 6px; }
.tag.entrada { background: rgba(127,207,154,.14); color: var(--green); }
.tag.saida { background: rgba(224,138,138,.14); color: var(--red); }
.tag.diario { background: var(--gold-bg); color: var(--gold); }
.item .desc { flex: 1; min-width: 0; color: var(--text); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .val { font-variant-numeric: tabular-nums; color: var(--text-2); }
.item .acoes { display: flex; gap: 2px; }
.item .acoes button { color: var(--muted); padding: 4px; border-radius: 6px; }
.item .acoes button:hover { color: var(--text); background: var(--surface-3); }
.item .acoes svg { width: 17px; height: 17px; }
.vazio { color: var(--muted); font-size: 14px; padding: 8px 0 2px; }
.btn-add-dia {
  margin-top: 10px; width: 100%; padding: 11px; border-radius: 12px;
  border: 1px dashed #3a3a40; color: var(--gold); font-weight: 600; font-size: 15px;
}
.btn-add-dia:hover { background: var(--gold-bg); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20;
  left: 50%; transform: translateX(calc(min(240px, 50vw) - 100% - 20px));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--gold); color: #1a1408; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }

/* etiquetas extras no detalhe do dia (painéis e formulários ficam em ui.css) */
.tag.meta { background: var(--gold); color: #000; }
.item .tag-meta, .item .tag-cat { font-size: 11px; white-space: nowrap; max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
.item .tag-meta { color: var(--gold); }
.tag.fixo { background: rgba(224,138,138,.22); color: #f0b0b0; }
.item .fx-tag { font-size: 12px; color: var(--muted); }
.item .fx-tag.ok { color: var(--green); }
.item .fx-tag.atraso { color: var(--red); font-weight: 700; }
a.btn-round { color: var(--text); text-decoration: none; }
.botoes a.btn { text-decoration: none; display: grid; place-items: center; }
.item .tag-cat { color: var(--muted); border: 1px solid var(--surface-3); border-radius: 6px; padding: 2px 6px; }

.carregando, .erro-load { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 15px; }
.erro-load p { margin-bottom: 14px; color: var(--red); }
.erro-load button { padding: 10px 18px; border-radius: 12px; background: var(--surface-3); color: var(--text); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 90;
  transform: translate(-50%, 140%); opacity: 0;
  width: calc(100% - 32px); max-width: 448px;
  background: #1c1c1f; border-radius: 22px; padding: 24px 28px;
  font-size: 16px; color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 380px) {
  .linha { font-size: 15px; }
  .thead { font-size: 11px; }
  .kpi-valor { font-size: 20px; }
  .resumo { gap: 18px; }
  .month-nav h1 { font-size: 18px; }
}
