:root {
  --red: #d62828;
  --red-dark: #b51f1f;
  --red-soft: #fdecec;
  --green: #17803d;
  --green-soft: #e8f6ed;
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e6e4e0;
  --chip: #f0efec;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --red: #ef4b4b;
    --red-dark: #ff6b6b;
    --red-soft: #3a1d1d;
    --green: #4cc47a;
    --green-soft: #183223;
    --bg: #121212;
    --card: #1d1d1d;
    --text: #f1f1f1;
    --muted: #a3a3a3;
    --line: #2e2e2e;
    --chip: #2a2a2a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* Topo */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.top img { width: 30px; height: 30px; }
.top h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.2px; }
.sync {
  font-size: 12px; color: var(--muted); background: var(--chip);
  border: 0; border-radius: 99px; padding: 5px 10px; white-space: nowrap;
}
.sync.warn { color: var(--red); background: var(--red-soft); }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; color: var(--muted);
}
.icon-btn:active { background: var(--chip); }

main { max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* Cartões */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.label { font-size: 13px; color: var(--muted); }
.big { font-size: 34px; font-weight: 750; letter-spacing: -.5px; margin: 2px 0; }
.mid { font-size: 20px; font-weight: 700; }
.sub { font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid2 .card { margin: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.grid3 .card { margin: 0; padding: 12px 10px; min-width: 0; }
.grid3 .mid { font-size: clamp(12px, 3.7vw, 16px); letter-spacing: -.3px; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hero { border-top: 4px solid var(--red); }

/* Seletor de mês */
.month {
  display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px;
}
.month strong { font-size: 17px; }

/* Barras por categoria */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { padding: 9px 0; border-top: 1px solid var(--line); }
.bars li:first-child { border-top: 0; }
.bars .row { display: flex; align-items: center; gap: 8px; }
.bars .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .pct { color: var(--muted); font-size: 13px; width: 40px; text-align: right; }
.bar { height: 6px; background: var(--chip); border-radius: 9px; margin-top: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--red); border-radius: 9px; }
.subbars { margin: 6px 0 0 30px; font-size: 14px; color: var(--muted); }
.subbars div { display: flex; justify-content: space-between; padding: 3px 0; }
.emoji { width: 22px; text-align: center; }

/* Listas */
h2 { font-size: 15px; margin: 20px 4px 8px; color: var(--muted); font-weight: 600; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 12px 16px; border-top: 1px solid var(--line);
}
.item:first-child { border-top: 0; }
.item:active { background: var(--chip); }
.item .ic {
  width: 36px; height: 36px; border-radius: 50%; background: var(--chip);
  display: grid; place-items: center; font-size: 18px; flex: none;
}
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .d { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .v { font-weight: 650; text-align: right; white-space: nowrap; }
.item .v small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.dayhead { font-size: 13px; color: var(--muted); padding: 10px 16px 4px; background: var(--bg); }
.tag { font-size: 11px; background: var(--chip); color: var(--muted); padding: 2px 7px; border-radius: 99px; margin-left: 6px; font-weight: 500; }
.tag.wait { background: var(--red-soft); color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

/* Botões */
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 14px;
  font-weight: 650; background: var(--red); color: #fff; font-size: 16px;
}
.btn:active { background: var(--red-dark); }
.btn.ghost { background: var(--chip); color: var(--text); }
.btn.danger { background: transparent; color: var(--red); }
.btn + .btn { margin-top: 8px; }
.btn[disabled] { opacity: .5; }
.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--red); color: #fff;
  font-size: 30px; box-shadow: 0 4px 14px rgba(214,40,40,.35);
}
.link { border: 0; background: none; color: var(--red); font-weight: 600; padding: 6px 0; }

/* Navegação de baixo */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  flex: 1; border: 0; background: none; padding: 9px 0 10px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.nav button span { font-size: 20px; line-height: 1; }
.nav button.on { color: var(--red); font-weight: 650; }

/* Formulários */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--red); }
.input.money { font-size: 28px; font-weight: 700; padding: 10px 14px; }
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 12px; font-size: 14px;
}
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.chip.add { color: var(--red); border-style: dashed; }
.subchips { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.err { color: var(--red); font-size: 14px; margin: -4px 0 12px; min-height: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* Folha de baixo */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.kv:first-child { border-top: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; white-space: nowrap; }
.kv small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Login */
.auth { max-width: 400px; margin: 0 auto; padding: 48px 20px 20px; }
.auth .logo { display: block; width: 84px; height: 84px; margin: 0 auto 10px; }
.auth h1 { text-align: center; margin: 0 0 4px; font-size: 26px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.auth .switch { text-align: center; margin-top: 14px; }

/* Avisos */
#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
.banner {
  display: flex; align-items: center; gap: 10px; background: var(--red-soft); color: var(--text);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}
.banner .grow { flex: 1; }
.banner button { border: 0; background: var(--red); color: #fff; border-radius: 9px; padding: 7px 12px; font-weight: 600; }
.footnote { font-size: 12px; color: var(--muted); text-align: center; margin: 16px 0 8px; }
