:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #ece9e1;
  --ink: #17201c;
  --muted: #6b726d;
  --line: #e2ded4;
  --accent: #1f7a54;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe4;
  --warn: #b7791f;
  --warn-soft: #fbf0d9;
  --danger: #c2412d;
  --danger-soft: #fbe3de;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #18201c;
    --surface-2: #212b26;
    --ink: #eef2ef;
    --muted: #93a099;
    --line: #26312b;
    --accent: #3ccf8e;
    --accent-ink: #06150e;
    --accent-soft: #173527;
    --warn: #f0b545;
    --warn-soft: #3a2e12;
    --danger: #ff7a66;
    --danger-soft: #3d1c17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 104px);
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.big-num, .mid-num, .bill-amt { font-variant-numeric: tabular-nums; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 12px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 16px; font-weight: 600; line-height: 1; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { min-height: 54px; font-size: 17px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:active { transform: scale(.985); }
.btn .ic, .lock-ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 12px; cursor: pointer; }
.link.danger { color: var(--danger); }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 16px; line-height: 1.3; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 22px; height: 22px; padding: 0; border-radius: 6px; flex: none; display: grid; place-content: center; }
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.check-inline { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); font-size: 15px; }
.stack { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin-bottom: 10px; }
.card > .btn + .muted, .card > .btn + p { margin-top: 8px; }
.callout { display: grid; gap: 4px; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-soft); margin-bottom: 14px; }
.pill { display: inline-block; justify-self: start; margin: 0; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 600; }

/* auth */
body.auth .wrap { display: grid; min-height: 100dvh; align-content: center; padding-bottom: calc(var(--safe-b) + 24px); }
.auth-card { display: grid; gap: 14px; }
.brand { text-align: center; display: grid; justify-items: center; gap: 6px; margin-bottom: 16px; }
.brand img { border-radius: 16px; }
.brand h1 { font-size: 30px; }
.brand p { margin: 0; color: var(--muted); }
.lock-ic { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.lock-ic svg { width: 30px; height: 30px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* home */
.month-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; margin: 4px 0 16px; }
.month-head h1 { font-size: 26px; }
.arrow { font-size: 30px; line-height: 44px; height: 44px; border-radius: 12px; color: var(--ink); }
.arrow:active { background: var(--surface-2); }
.summary { background: var(--ink); color: var(--bg); border-radius: 22px; padding: 20px; margin-bottom: 8px; }
.sum-top { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.summary .label { display: block; font-size: 13px; opacity: .7; }
.big-num { font-size: 32px; font-weight: 700; letter-spacing: -.03em; }
.mid-num { font-size: 17px; font-weight: 600; }
.right { text-align: right; }
.bar { height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--bg) 22%, transparent); margin: 16px 0 10px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.sum-foot { opacity: .85; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; }
.sec.late-t { color: var(--danger); }

.bills { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.bills > li + li { border-top: 1px solid var(--line); }
.bill { display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 14px; color: var(--ink); cursor: pointer; }
.bills.plain .bill { padding-right: 14px; }
.bill-main { flex: 1; min-width: 0; display: grid; }
.bill-main strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bill-main small { color: var(--muted); font-size: 13px; }
.bill-amt { font-weight: 600; white-space: nowrap; }
.bill.late small, .bill.late .bill-amt { color: var(--danger); }
.bill.today small { color: var(--warn); font-weight: 600; }
.bill.paid strong, .bill.paid .bill-amt { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.chev { color: var(--muted); font-size: 20px; }
.cat { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.cat-cartao { background: #6c5ce7; } .cat-consumo { background: #f0a020; } .cat-telecom { background: #2d98da; }
.cat-moradia { background: #20a37a; } .cat-impostos { background: #c0392b; } .cat-educacao { background: #8e5ea2; }
.cat-saude { background: #e05780; } .cat-seguros { background: #3d7ea6; } .cat-assinaturas { background: #e17055; }
.check-form { margin: 0; }
.check { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; }
.check svg { width: 20px; height: 20px; fill: none; stroke: transparent; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.bill.paid .check { background: var(--accent); border-color: var(--accent); }
.bill.paid .check svg { stroke: var(--accent-ink); }
.bill.late .check { border-color: var(--danger); }
.empty { text-align: center; padding: 32px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .btn { width: auto; }

/* pages */
.page-head { margin: 4px 0 18px; }
.page-head h1 { font-size: 28px; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; margin-bottom: 6px; font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg label { display: block; position: relative; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; margin: 0; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 9px; color: var(--muted); font-size: 15px; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li div { display: grid; }
details summary { cursor: pointer; padding: 4px 0; }
details ol { padding-left: 20px; margin: 6px 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* bottom sheet */
.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--ink); }
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet form { display: grid; gap: 12px; padding: 10px 18px calc(var(--safe-b) + 18px); }
.sheet h3 { font-size: 20px; }
.sheet p { margin: -8px 0 4px; }
.grab { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 0 auto 6px; }
.sheet-actions { display: grid; gap: 8px; }
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr 72px 1fr 1fr; align-items: center;
  padding: 6px 12px calc(var(--safe-b) + 6px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: grid; justify-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0; }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .add { width: 52px; height: 52px; justify-self: center; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; padding: 0; }
.tabbar .add svg { stroke-width: 2.4; }

/* toasts */
.toasts { position: fixed; top: calc(var(--safe-t) + 10px); left: 0; right: 0; z-index: 50; display: grid; justify-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: 0 6px 24px rgb(0 0 0 / .18); animation: toast 3.6s forwards; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- v2: relatórios */
.chips { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 14px; font-weight: 600; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 2px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label, .proj .label, .trio .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi strong { font-size: 19px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { font-size: 12px; }
.delta { font-size: 12px; font-weight: 700; white-space: nowrap; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--accent); }
.callout.danger { background: var(--danger-soft); color: var(--ink); }
.callout.danger strong { color: var(--danger); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.insights li { position: relative; padding: 10px 12px 10px 36px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.insights li::before { position: absolute; left: 12px; top: 9px; font-size: 14px; }
.ins-up::before { content: "▲"; color: var(--danger); }
.ins-down::before { content: "▼"; color: var(--accent); }
.ins-info::before { content: "●"; color: #6c5ce7; }
.ins-warn::before { content: "!"; color: var(--warn); font-weight: 800; left: 16px; }
.ins-good::before { content: "✓"; color: var(--accent); font-weight: 800; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10.5px; font-family: inherit; }
.chart .axis.strong { fill: var(--ink); font-weight: 700; }
.chart .avg { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .55; }
.chart .hit { fill: transparent; }
.chart .bar { cursor: pointer; }
.chart .bar.sel .hit { fill: var(--surface-2); }
.chart .pt-label { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: inherit; }
.month-detail { margin-top: 10px; min-height: 40px; line-height: 1.5; }
.month-detail strong { color: var(--ink); }
.md-cats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.md-cats i, .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; flex: none; }
.donut-wrap { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center; }
.donut svg { display: block; }
.donut .track { stroke: var(--surface-2); }
.donut .d-label { fill: var(--muted); font-size: 12px; font-family: inherit; }
.donut .d-value { fill: var(--ink); font-size: 17px; font-weight: 700; font-family: inherit; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 2px; }
.lg-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; display: grid; }
.lg-val small { color: var(--muted); font-weight: 500; font-size: 11px; }
#bill-pick { margin-bottom: 10px; }
.trio, .proj { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.trio div, .proj div { background: var(--surface-2); border-radius: 12px; padding: 10px; display: grid; gap: 2px; min-width: 0; }
.trio strong, .proj strong { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .label { text-transform: capitalize; }
.proj small { font-size: 11px; }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li + li { border-top: 1px solid var(--line); }
.rank a { display: flex; align-items: center; gap: 10px; padding: 10px 0; color: var(--ink); }
.rk-main { flex: 1; min-width: 0; display: grid; }
.rk-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.rk-main small { font-size: 12px; }
.rk-val { text-align: right; display: grid; font-variant-numeric: tabular-nums; }
.rk-val strong { font-weight: 600; font-size: 14px; }
.spark { width: 64px; flex: none; }
@media (max-width: 360px) { .spark { display: none; } }
.payers { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.payers li { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; }
.py-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.py-bar { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.py-bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.py-val { text-align: right; display: grid; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.py-val small { color: var(--muted); font-weight: 500; font-size: 11px; }
.btn + .btn, .wrap > .btn { margin-top: 4px; }

/* início: atalhos */
.lock-btn { position: absolute; top: calc(var(--safe-t) + 14px); right: max(16px, calc(50% - 264px)); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); z-index: 2; }
.lock-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lock-btn:active { background: var(--surface-2); }
.month-head { padding: 0 40px; }
.sum-link { display: inline-block; margin-top: 10px; color: var(--accent); font-weight: 700; font-size: 14px; }
.vs { font-weight: 700; }

/* histórico da conta */
.mini-bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; height: 96px; align-items: end; margin: 6px 0 14px; }
.mini-bars div { height: 100%; display: grid; grid-template-rows: 1fr auto; justify-items: center; gap: 4px; }
.mini-bars span { align-self: end; width: 100%; max-width: 22px; background: var(--accent); border-radius: 4px 4px 2px 2px; min-height: 2px; opacity: .85; }
.mini-bars small { font-size: 10px; color: var(--muted); }

/* ---------- v2: administração, auditoria e visibilidade */
.lock-tag { font-size: 12px; margin-left: 2px; }
.scope { display: grid; gap: 6px; }
.scope-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.seg-sm { display: flex; margin-top: 10px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.seg-sm a { flex: 1; text-align: center; padding: 7px 4px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg-sm a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.admin-link { display: flex; align-items: center; justify-content: space-between; color: var(--ink); background: var(--accent-soft); border-color: transparent; }
.admin-link div { display: grid; }
.pw-box { gap: 8px; }
.pw-line { display: flex; gap: 8px; align-items: center; }
.pw-line code { flex: 1; font-size: 18px; padding: 10px 12px; background: var(--surface); letter-spacing: .05em; text-align: center; }
.small-btn { width: auto; min-height: 40px; padding: 8px 14px; }
.danger-t { color: var(--danger); }
.btn.danger-b { color: var(--danger); border-color: var(--danger-soft); }
.users { list-style: none; margin: 0; padding: 0; }
.users > li + li { border-top: 1px solid var(--line); }
.users li.off { opacity: .6; }
.users summary { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; list-style: none; cursor: pointer; }
.users summary::-webkit-details-marker { display: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; flex: none; }
.u-main { display: grid; gap: 1px; min-width: 0; }
.u-main small { font-size: 12px; line-height: 1.35; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; text-transform: uppercase; letter-spacing: .03em; }
.tag.off { background: var(--surface-2); color: var(--muted); }
.u-actions { display: grid; gap: 10px; padding: 0 0 14px 50px; }
.u-actions .link { justify-self: start; padding: 4px 0; text-decoration: none; }
.audit { list-style: none; margin: 0; padding: 0; }
.audit li { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.audit li:first-child { border-top: 0; }
.au-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.au-main { display: grid; gap: 1px; min-width: 0; }
.au-target { font-weight: 600; overflow-wrap: anywhere; }
.au-target.masked { font-weight: 500; color: var(--muted); font-style: italic; }
.au-main small { font-size: 12px; overflow-wrap: anywhere; }
.au-pagamento .au-time, .au-valor .au-time { color: var(--accent); }
.au-fail .au-main strong, .au-fail .au-time { color: var(--danger); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.pager { display: flex; justify-content: space-between; gap: 8px; }
.pager .btn { width: auto; }

/* v2: ajustes de leitura no celular */
.proj strong, .trio strong { font-size: 13px; white-space: normal; overflow: visible; }
@media (max-width: 440px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut { width: 160px; }
  .legend { width: 100%; }
}
