:root {
  --red: #d62828;
  --red-dark: #b51f1f;
  --red-soft: #fdecec;
  --wood: #3a1906;
  --wood-text: #fff4ea;
  --wood-muted: #e2c5ad;
  --green: #17803d;
  --green-soft: #e8f6ed;
  --bg: #f7f5f2;
  --card: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e8e3dd;
  --chip: #f1eeea;
  --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;
    --wood: #2b1306;
    --wood-text: #fff1e4;
    --wood-muted: #c9a68a;
    --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; object-fit: contain; }
.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); }
.add-top { display: none; }
.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); }
.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 { background: var(--wood); color: var(--wood-text); border-top: 4px solid var(--red); }
.hero .label, .hero .sub { color: var(--wood-muted); }
.hero .big.neg { color: #ff8a8a; }

/* Sócios */
.who { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--c); }
.who::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.avatar { background: var(--c) !important; color: #fff; font-weight: 700; font-size: 16px !important; }
.socio-row { align-items: center; }
.socio-row .num b { font-weight: 700; }
.socio-card { border-top: 4px solid var(--c); }
.socio-card .label { font-size: 15px; margin-bottom: 4px; }
.socio-card .kv { padding: 6px 0; }
.bal-top { display: grid; gap: 12px; margin-bottom: 12px; }
.bal-top .card { margin: 0; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; background: var(--c); box-shadow: inset 0 0 0 2px var(--card); }
.color.on { border-color: var(--text); }

/* Seletor de mês e filtros */
.month { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.month strong { font-size: 17px; }
.chips.filter { margin-bottom: 12px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.chips.filter::-webkit-scrollbar { display: none; }
.chips.filter .chip { white-space: nowrap; }
.chips.filter .chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chips.filter .chip.on .dot { box-shadow: 0 0 0 2px var(--bg); }

/* Barras por categoria */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.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; }

/* Tabela mês a mês */
.table-card { padding: 4px 0; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 10px 12px 6px; }
.tbl td { text-align: right; padding: 10px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tbody tr { cursor: pointer; }
@media (max-width: 859px) {
  .tbl { font-size: 13px; }
  .tbl th { padding: 10px 6px 6px; font-size: 11px; }
  .tbl td { padding: 10px 6px; }
}
.tbl tbody tr:active { background: var(--chip); }

/* 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 .d .who { font-size: 12px; margin-right: 4px; }
.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); }
.tag.fix { background: #f3e7dc; color: #8a5a3b; }
@media (prefers-color-scheme: dark) { .tag.fix { background: #3a2a1f; color: #e2b48f; } }
.arrow { color: var(--muted); margin: 0 4px; font-size: 12px; }
.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);
}

/* Navegação de baixo (celular) */
.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);
}
.rail-logo { display: none; }
.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; }
input[type="date"].input { -webkit-appearance: none; appearance: none; min-height: 48px; }
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.field .seg { margin-bottom: 0; }
.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); }
.who-seg button.on { color: var(--c); box-shadow: inset 0 0 0 2px var(--c); }
.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; }
.check { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--red); flex: none; }
.check small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* 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, .label + .kv { 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 pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Senha */
.auth { max-width: 400px; margin: 0 auto; padding: 48px 20px 20px; }
.auth .logo { display: block; width: 96px; height: 96px; object-fit: contain; 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; }

/* 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.soft { background: var(--chip); }
.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; }

/* ---------- Tablet e computador: menu lateral, duas colunas, janelas no centro ---------- */
@media (min-width: 860px) {
  body { padding-bottom: 24px; }
  .nav {
    top: 0; right: auto; width: 104px; flex-direction: column; justify-content: flex-start; gap: 6px;
    border-top: 0; border-right: 1px solid var(--line); padding: calc(16px + env(safe-area-inset-top)) 8px 16px;
  }
  .rail-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; font-size: 11px; font-weight: 700; color: var(--muted); }
  .rail-logo img { width: 58px; height: 58px; object-fit: contain; }
  .nav button { flex: none; padding: 12px 0; border-radius: 14px; font-size: 13px; gap: 4px; }
  .nav button span { font-size: 24px; }
  .nav button.on { background: var(--red-soft); }
  .page { margin-left: 104px; }
  .top { padding: calc(18px + env(safe-area-inset-top)) 32px 14px; }
  .top img { display: none; }
  .top h1 { font-size: 26px; }
  .add-top { display: block; border: 0; background: var(--red); color: #fff; font-weight: 650; border-radius: 12px; padding: 10px 18px; }
  .add-top.ghost { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
  .fab { display: none; }
  main { max-width: 1200px; padding: 0 32px; }
  main.ajustes { max-width: 640px; margin: 0; }

  .month { justify-content: flex-start; gap: 10px; }
  .month strong { font-size: 22px; min-width: 200px; text-align: center; }
  .cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 24px; align-items: start; }
  .cols > section > h2:first-child { margin-top: 4px; }
  .mes .cols > section:last-child { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow: auto; border-radius: var(--radius); }
  .grid3 { gap: 12px; }
  .grid3 .card { padding: 16px; }
  .grid3 .mid { font-size: 22px; }

  .bal-top { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .bal-top .hero { display: flex; flex-direction: column; justify-content: center; }
  .balanco .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-top: 8px; }

  .backdrop { align-items: center; padding: 24px; }
  .sheet { max-width: 540px; border-radius: 20px; max-height: 88vh; padding: 20px 24px 24px; animation: pop .18s ease; }
  .sheet .grab { display: none; }
  #toast { bottom: 32px; }
}
