:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d2422;
  --muted: #6b736f;
  --line: #e6e1d8;
  --brand: #1f6f5c;
  --brand-soft: #e3f1ec;
  --good: #1d8a5b;
  --bad: #c8412f;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad-soft: #fbe9e6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1b2120;
    --ink: #edf1ef;
    --muted: #9aa5a0;
    --line: #2b3331;
    --brand: #4fbf9f;
    --brand-soft: #1d2f2a;
    --good: #4fcf94;
    --bad: #f07a68;
    --warn: #e7b25c;
    --warn-soft: #2e2617;
    --bad-soft: #321d1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }

/* Topo */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav strong { min-width: 128px; text-align: center; text-transform: capitalize; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  font-size: 20px; line-height: 1; cursor: pointer;
}
@media (max-width: 420px) { .brand span { display: none; } }

.view { max-width: 720px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.card h3 { margin: 0; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kpi b { overflow-wrap: anywhere; }
@media (max-width: 420px) { .kpi:not(.main) b { font-size: 14px; } .kpi { padding: 10px; } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; font-size: 12px; }
.kpi b { font-size: 17px; display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.main { grid-column: 1 / -1; background: var(--brand); color: #fff; border: 0; }
.kpi.main small { color: rgba(255,255,255,.8); }
.kpi.main b { font-size: 28px; }
@media (prefers-color-scheme: dark) { .kpi.main { color: #0d1513; } .kpi.main small { color: rgba(0,0,0,.65); } }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* Barra de progresso */
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.list .row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; cursor: pointer; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row .val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer; }
.row.paid .title, .row.paid .val { color: var(--muted); text-decoration: line-through; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

.check {
  appearance: none; width: 26px; height: 26px; flex: none;
  border: 2px solid var(--line); border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; background: var(--card);
}
.check:checked { background: var(--good); border-color: var(--good); }
.check:checked::after { content: "✓"; color: #fff; font-weight: 800; font-size: 15px; }

.empty { color: var(--muted); text-align: center; padding: 16px 0 8px; font-size: 14px; }

/* Botões */
.btn {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 9px 14px; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1513; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Alertas */
.alert {
  border-radius: var(--radius); padding: 12px 14px;
  background: var(--warn-soft); color: var(--ink); border: 1px solid var(--line);
}
.alert b { color: var(--warn); }
.alert.bad { background: var(--bad-soft); }
.alert.bad b { color: var(--bad); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* Divisão por pagamento */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.split > div { border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.split small { color: var(--muted); display: block; }
.split .line { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.split .line.total { font-weight: 700; font-size: 15px; border-top: 1px dashed var(--line); padding-top: 4px; }

/* Gráfico de rosca */
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
@media (max-width: 420px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; width: 100%; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend li span:nth-child(2) { flex: 1; }
.legend li b { font-variant-numeric: tabular-nums; }

.rule { display: grid; gap: 10px; margin-top: 16px; }
.rule .r-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.rule .r-head span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress.over > i { background: var(--bad); }

/* Barras do ano */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 160px; margin-top: 8px; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; cursor: pointer; }
.bar-pair { display: flex; gap: 2px; align-items: flex-end; height: 130px; width: 100%; justify-content: center; }
.bar-pair i { width: 42%; max-width: 14px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-pair i.in { background: var(--brand); }
.bar-pair i.out { background: var(--warn); }
.bar-col small { font-size: 10px; color: var(--muted); text-transform: capitalize; }
.bar-col.current small { color: var(--ink); font-weight: 700; }
.key { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.key span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.key .k-in::before { background: var(--brand); }
.key .k-out::before { background: var(--warn); }

.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 4px; border-top: 1px solid var(--line); text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; text-transform: capitalize; }
.table th { color: var(--muted); font-weight: 600; border-top: 0; }
.table tfoot td { font-weight: 700; }

/* Segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; padding: 3px; background: var(--bg); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); color: var(--brand); }

/* Barra de abas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: transparent; padding: 8px 0 10px; cursor: pointer;
  display: grid; justify-items: center; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 600;
}
.tabbar .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--brand); }
.tabbar button.active .ti { filter: none; opacity: 1; }

/* Diálogo */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 15, 13, .45); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field.check-field { display: flex; align-items: center; gap: 10px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Comprovante por foto */
.photo-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; border-radius: var(--radius); border: 2px dashed var(--brand);
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 16px; cursor: pointer;
}
.photo-btn small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.receipt-info { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; display: grid; gap: 3px; }
.receipt-info .r-line { display: flex; justify-content: space-between; gap: 10px; }
.receipt-info .r-line span:first-child { color: var(--muted); }
.receipt-info .r-line span:last-child { text-align: right; font-weight: 600; }
.receipt-info .note { color: var(--warn); margin-top: 4px; }
.busy {
  position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: rgba(10, 15, 13, .55); color: #fff; font-weight: 600;
}
.busy[hidden] { display: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Orçamento do casal */
.sync-badge {
  position: sticky; top: 61px; z-index: 4; text-align: center; font-size: 12px; font-weight: 600;
  padding: 4px 16px; background: var(--brand-soft); color: var(--brand);
}
.sync-badge[hidden] { display: none; }
.sync-badge.offline, .sync-badge.conectando { background: var(--warn-soft); color: var(--warn); }
.sync-badge.erro { background: var(--bad-soft); color: var(--bad); }
.sync-badge.demo { background: #f5c35b; color: #134a3d; }
.sync-badge.demo a { color: inherit; font-weight: 800; }
.convite-codigo {
  font-size: 32px; font-weight: 800; letter-spacing: 6px; text-align: center; padding: 12px;
  border: 2px dashed var(--brand); border-radius: 12px; color: var(--brand); background: var(--brand-soft);
  font-variant-numeric: tabular-nums;
}
.por { color: var(--brand); }

/* Ações rápidas: voz e comprovante */
.acoes-rapidas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.acoes-rapidas .photo-btn { padding: 12px 10px; font-size: 15px; }
.mic-btn { width: 100%; font-size: 16px; padding: 12px; }
.mic-btn.ouvindo { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); animation: pulsar 1.2s ease-in-out infinite; }
@keyframes pulsar { 50% { opacity: .6; } }

/* Tela de bloqueio */
#trava {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: grid; place-items: center; padding: 24px;
}
body.travado { overflow: hidden; }
body.travado .tabbar, body.travado .topbar, body.travado #view { visibility: hidden; }
.trava-caixa { width: min(320px, 100%); display: grid; gap: 12px; justify-items: center; text-align: center; }
.trava-caixa h2 { margin: 4px 0; font-size: 20px; }
.trava-caixa .btn { width: 100%; }
.trava-caixa form { display: grid; gap: 8px; width: 100%; }
.trava-caixa input { text-align: center; font-size: 22px; letter-spacing: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.trava-esqueci { font-size: 13px; color: var(--muted); display: grid; gap: 8px; }

/* Ajuda */
.ajuda-indice { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ajuda-indice .btn { text-align: left; }
.ajuda details { border-top: 1px solid var(--line); padding: 10px 0; }
.ajuda details:first-of-type { border-top: 0; }
.ajuda summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; gap: 8px; }
.ajuda summary::-webkit-details-marker { display: none; }
.ajuda summary::before { content: '▸'; color: var(--brand); transition: transform .15s; }
.ajuda details[open] summary::before { transform: rotate(90deg); }
.ajuda details p { margin: 8px 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.ajuda.destaque { border: 2px solid var(--brand); }
.ajuda { scroll-margin-top: 80px; }
.link-ajuda { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; text-decoration: underline; cursor: pointer; font-size: 13px; }

.method .card-head { flex-wrap: wrap; }
.seg button { white-space: nowrap; }
.method p { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.debt-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.order { width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; }
.debt { padding: 12px 0; border-top: 1px solid var(--line); }
.debt:first-child { border-top: 0; }
.debt.done { opacity: .6; }
