:root {
  --bg: #f5f7f8; --surface: #ffffff; --text: #14211f; --muted: #5b6b68; --border: #dbe3e1;
  --primary: #0f766e; --primary-ink: #ffffff; --primary-soft: #d9f0ed;
  --paid: #15803d; --paid-soft: #dcf5e4; --late: #b91c1c; --late-soft: #fde2e2;
  --soon: #b45309; --soon-soft: #fdecc8; --pending-soft: #e8edec;
  --danger: #b91c1c; --radius: 14px; --tap: 48px; --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514; --surface: #17211f; --text: #e8efed; --muted: #9db0ac; --border: #2a3835;
    --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #12332f;
    --paid: #4ade80; --paid-soft: #12301d; --late: #f87171; --late-soft: #3a1717;
    --soon: #fbbf24; --soon-soft: #3a2c0c; --pending-soft: #222e2c; --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
h1, h2, h3, p, ul { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.app { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px; padding-top: calc(14px + env(safe-area-inset-top)); }
.topbar h1 { font-size: 1.1rem; font-weight: 700; min-width: 0; overflow-wrap: anywhere; flex: 1; }
.topbar-btn { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; }
.topbar-btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.view { padding: 8px 16px 16px; display: grid; gap: 14px; min-width: 0; outline: none; }
.view > * { min-width: 0; }
.screen-title { font-size: 1.35rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.lead { font-weight: 600; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* botões */
.btn {
  min-height: var(--tap); padding: 10px 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; text-align: center; overflow-wrap: anywhere;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 1.6rem; line-height: 1; flex: none;
}
.link { background: none; border: 0; color: var(--primary); text-decoration: underline; min-height: 32px; padding: 0 4px; font-size: .9rem; }

/* navegação de mês */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-title { text-align: center; min-width: 0; flex: 1; }
.month-title h2 { font-size: 1.2rem; text-transform: capitalize; overflow-wrap: anywhere; }

/* resumo */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; border-left-width: 5px; min-width: 0; }
.tile.topay { border-left-color: var(--primary); }
.tile.week { border-left-color: var(--soon); }
.tile.late { border-left-color: var(--late); }
.tile.paid { border-left-color: var(--paid); }
.tile-head { display: flex; justify-content: space-between; gap: 6px; align-items: flex-start; }
.tile-label { font-size: .82rem; color: var(--muted); display: block; margin-bottom: 4px; }
.count { background: var(--pending-soft); border-radius: 999px; font-size: .75rem; font-weight: 700; padding: 1px 8px; }
.tile-amount { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }

/* lista */
.list { list-style: none; padding: 0; display: grid; gap: 10px; }
.row { display: flex; align-items: stretch; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; border-left: 5px solid var(--border); }
.row.overdue { border-left-color: var(--late); }
.row.soon, .row.today { border-left-color: var(--soon); }
.row.paid { border-left-color: var(--paid); }
.row.paused { opacity: .6; }
.row-main {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; min-height: 64px;
}
.row-title { font-weight: 700; overflow-wrap: anywhere; grid-column: 1; }
.row-sub { grid-column: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: .85rem; }
.row-amount { grid-column: 2; grid-row: 1 / span 2; font-weight: 700; text-align: right; display: grid; gap: 2px; }
.row-amount.small { font-size: .85rem; }
.check {
  width: 64px; flex: none; border: 0; border-left: 1px solid var(--border); background: var(--pending-soft);
  font-size: 1.5rem; font-weight: 800; color: var(--paid);
}
.check.on { background: var(--paid-soft); }
.check:not(.on)::before { content: ""; display: block; width: 26px; height: 26px; margin: auto; border: 2px solid var(--muted); border-radius: 8px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--pending-soft); color: var(--muted); }
.badge.paid { background: var(--paid-soft); color: var(--paid); }
.badge.overdue { background: var(--late-soft); color: var(--late); }
.badge.soon, .badge.today { background: var(--soon-soft); color: var(--soon); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; }
.notice { background: var(--soon-soft); color: var(--soon); border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.empty { text-align: center; padding: 40px 16px; display: grid; gap: 12px; justify-items: center; }

/* formulário */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label, .label { font-weight: 600; font-size: .92rem; }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); text-align: left;
}
textarea.input { resize: vertical; min-height: 84px; }
.input[aria-invalid="true"] { border-color: var(--late); }
.locked-input { color: var(--primary); font-weight: 700; border-style: dashed; }
.field-error { color: var(--late); font-size: .88rem; font-weight: 600; }
.row-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.inline-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.type-sums { display: grid; gap: 10px; }
.type-sum { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.type-sum .tile-label { margin: 0; }
.type-sum-values { display: grid; text-align: right; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg-btn { min-height: var(--tap); background: var(--surface); border: 0; font-weight: 600; }
.seg-btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); font-weight: 700; }

/* detalhe */
.detail-info { display: grid; gap: 4px; }
.detail-amount { font-size: 1.8rem; font-weight: 800; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--pending-soft); border-radius: 10px; padding: 10px; }
.history { list-style: none; padding: 0; display: grid; gap: 6px; }
.history li { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }

/* anual */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 8px; align-items: center; font-size: .85rem; }
.bar-label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.bar-track { background: var(--pending-soft); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 999px; }
.bar-value { font-weight: 700; text-align: right; }
h3 { font-size: 1.02rem; margin-top: 6px; }

/* ajustes */
.settings { display: grid; gap: 14px; }
.setting { display: grid; gap: 8px; }
.setting > label { font-weight: 600; }
.paywall { display: grid; gap: 12px; }
.features { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* navegação */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { min-height: var(--nav-h); background: none; border: 0; display: grid; justify-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: .72rem; padding: 4px 2px; min-width: 0; }
.tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button[aria-current="page"] { color: var(--primary); font-weight: 700; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 11;
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink);
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
}

/* modal */
.modal { border: 0; padding: 0; background: transparent; width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); max-width: none; margin: auto; color: var(--text); }
.modal::backdrop { background: rgba(0, 0, 0, .5); }
.modal-card { background: var(--surface); border-radius: 18px; display: flex; flex-direction: column; max-height: calc(100dvh - 16px); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.15rem; overflow-wrap: anywhere; min-width: 0; }
.modal-body { padding: 16px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1 1 140px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #14211f; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 1000; max-width: calc(100vw - 32px); text-align: center; font-weight: 600;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) {
  .tabs { left: 50%; right: auto; width: 640px; transform: translateX(-50%); border-radius: 16px 16px 0 0; border: 1px solid var(--border); border-bottom: 0; }
  .fab { right: calc(50% - 320px + 16px); }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media print {
  body { background: #fff; color: #000; }
  .tabs, .fab, .no-print, .month-nav button, .toast { display: none !important; }
  .app { padding-bottom: 0; max-width: none; }
  .topbar { padding-top: 0; }
  .tile, .card { break-inside: avoid; border-color: #999; }
  .bar-track { border: 1px solid #999; }
  .bar-fill { background: #555 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
