:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f0ece3;
  --ink: #1b2622;
  --muted: #69736d;
  --line: #e3ddd0;
  --brand: #16302a;
  --brand-2: #23493f;
  --accent: #c9a96e;
  --pos: #2f8f6b;
  --neg: #d0533f;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(22, 48, 42, .06), 0 8px 24px rgba(22, 48, 42, .06);
  --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:not([data-theme="light"]) {
    --bg: #0f1513;
    --surface: #171f1c;
    --surface-2: #1f2925;
    --ink: #eef1ee;
    --muted: #9aa59f;
    --line: #2a3531;
    --brand: #0c1a16;
    --brand-2: #1d3a32;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f1513;
    --surface: #171f1c;
    --surface-2: #1f2925;
    --ink: #eef1ee;
    --muted: #9aa59f;
    --line: #2a3531;
    --brand: #0c1a16;
    --brand-2: #1d3a32;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(120% 70% at 50% 0%, var(--brand-2), var(--brand) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 28px; padding: 32px 24px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.login-card h1 { font-size: 26px; margin: 16px 0 4px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 20px; }
.brand-mark { display: inline-flex; align-items: baseline; gap: 2px; font: 600 30px/1 Georgia, "Times New Roman", serif; color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-mark { color: var(--ink); } }
:root[data-theme="dark"] .brand-mark { color: var(--ink); }
.brand-mark i { color: var(--accent); font-style: italic; font-size: 24px; }
form label, .field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
form label input, .field input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-weight: 500; font-size: 16px; outline: none;
}
form label input:focus, .field input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.form-error { color: var(--neg); font-size: 14px; margin: 0 0 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 600; }
.btn-primary { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { background: var(--accent); color: #1b1408; } }
:root[data-theme="dark"] .btn-primary { background: var(--accent); color: #1b1408; }
.btn-primary:active { transform: scale(.98); }
.btn-primary[disabled] { opacity: .6; }
.btn-ghost { border: 1px solid var(--line); }
.btn-block { width: 100%; }
.link { color: var(--brand-2); font-weight: 600; font-size: 14px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .link { color: var(--accent); } }
:root[data-theme="dark"] .link { color: var(--accent); }

/* ---------- app shell ---------- */
.app { min-height: 100dvh; padding-bottom: calc(96px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(10px + var(--safe-t)) 12px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.danger { color: var(--neg); }
.month-label { flex: 1; text-align: center; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.sync-pill { position: absolute; right: 56px; top: calc(16px + var(--safe-t)); display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px; background: #fdecc8; color: #7a5410; }
.sync-pill svg { width: 14px; height: 14px; }
.view { padding: 4px 16px 16px; max-width: 640px; margin: 0 auto; }

.hero {
  border-radius: 24px; padding: 20px; color: #fff; margin-bottom: 14px;
  background: linear-gradient(140deg, var(--brand-2), var(--brand) 70%);
  box-shadow: 0 12px 30px rgba(22, 48, 42, .25);
  position: relative; overflow: hidden;
}
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle, rgba(201, 169, 110, .45), transparent 70%); }
.hero-label { margin: 0; opacity: .8; font-size: 14px; }
.hero-value { margin: 2px 0 16px; font-size: 34px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-stat { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, .09); border-radius: 16px; padding: 10px; }
.hero-stat small { display: block; opacity: .75; font-size: 12px; }
.hero-stat strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.dot { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; }
.dot svg { width: 18px; height: 18px; }
.dot-in { background: rgba(80, 200, 150, .25); color: #9ff0cc; }
.dot-out { background: rgba(240, 120, 100, .25); color: #ffb4a6; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 16px; letter-spacing: -.01em; }
.card-head h2 svg { width: 18px; height: 18px; color: var(--accent); }

.settle-text { margin: 0 0 12px; font-size: 15px; }
.settle-text strong { font-variant-numeric: tabular-nums; }
.settle-bars { display: grid; gap: 8px; }
.settle-row { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.settle-track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.settle-fill { height: 100%; border-radius: 99px; }

.donut-wrap { position: relative; width: 190px; margin: 4px auto 14px; }
.donut { width: 190px; height: 190px; display: block; transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center small { color: var(--muted); font-size: 12px; }
.donut-center strong { font-size: 20px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.legend .pct { color: var(--muted); font-size: 12px; margin-left: 6px; }
.legend .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; }
.cat-ico svg { width: 18px; height: 18px; }

.bars { width: 100%; height: auto; display: block; }
.bars .bar { fill: var(--accent); }
.bars .bar.today { fill: var(--brand-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bars .bar.today { fill: #6fd1a8; } }
:root[data-theme="dark"] .bars .bar.today { fill: #6fd1a8; }
.bars .axis { stroke: var(--line); stroke-width: 1; }
.bars text { fill: var(--muted); font-size: 9px; }

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

.tx-list { list-style: none; margin: 0; padding: 0; }
.tx { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.tx:last-child { border-bottom: 0; }
.tx .cat-ico { width: 40px; height: 40px; border-radius: 13px; }
.tx-main { min-width: 0; }
.tx-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tx-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-amt.in { color: var(--pos); }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.shared { background: color-mix(in srgb, var(--accent) 22%, transparent); color: #8a6a2c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.shared { color: var(--accent); } }
:root[data-theme="dark"] .badge.shared { color: var(--accent); }
.badge.pending { background: #fdecc8; color: #7a5410; }
.person { display: inline-flex; align-items: center; gap: 4px; }
.person i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.group-title { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 4px 6px; text-transform: capitalize; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 6px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; }
.chip.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.is-on { background: var(--accent); border-color: var(--accent); color: #1b1408; } }
:root[data-theme="dark"] .chip.is-on { background: var(--accent); border-color: var(--accent); color: #1b1408; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: 1fr 1fr 72px 1fr 1fr; align-items: center;
  padding: 8px 10px calc(8px + var(--safe-b)); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px); border-top: 1px solid var(--line);
}
.tab { display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; }
.tab.is-on { color: var(--ink); }
.tab.is-on svg { color: var(--accent); }
.fab { width: 58px; height: 58px; justify-self: center; margin-top: -26px; border-radius: 20px; display: grid; place-items: center; color: #fff; background: linear-gradient(140deg, var(--accent), #b08a48); box-shadow: 0 10px 24px rgba(176, 138, 72, .45); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:active { transform: scale(.95); }

/* ---------- sheets ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 94dvh;
  border-radius: 26px 26px 0 0; background: var(--surface); color: var(--ink); box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
}
dialog.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
dialog.sheet::backdrop { background: rgba(10, 20, 17, .45); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 26px; } }
dialog.sheet form { padding: 8px 18px calc(18px + var(--safe-b)); overflow-y: auto; max-height: 94dvh; }
.sheet-head { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; margin-bottom: 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; padding-top: 6px; }
.sheet-head h2 { text-align: center; font-size: 17px; margin: 0; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; border-radius: 14px; background: var(--surface-2); margin-bottom: 14px; }
.segmented.small { margin-bottom: 10px; }
.seg { min-height: 40px; border-radius: 11px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.amount-field { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 4px 0 16px; color: var(--ink); }
.amount-field .currency { font-size: 22px; font-weight: 600; color: var(--muted); }
.amount-field input {
  width: auto; max-width: 260px; border: 0; background: none; text-align: center; font-size: 44px; font-weight: 700;
  letter-spacing: -.03em; min-height: 0; padding: 0; color: var(--ink); font-variant-numeric: tabular-nums; outline: none;
}
.amount-field.is-expense input { color: var(--ink); }
.amount-field.is-income input { color: var(--pos); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-opt { display: grid; justify-items: center; gap: 4px; padding: 8px 2px; border-radius: 14px; border: 1.5px solid transparent; font-size: 11.5px; font-weight: 600; color: var(--ink); text-align: center; line-height: 1.15; }
.cat-opt .cat-ico { width: 40px; height: 40px; border-radius: 13px; }
.cat-opt.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.who { display: grid; grid-auto-flow: column; gap: 6px; }
.who-opt { min-height: 48px; border-radius: 14px; border: 1.5px solid var(--line); font-weight: 600; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink); }
.who-opt i { width: 10px; height: 10px; border-radius: 50%; }
.who-opt.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.split-detail { display: grid; gap: 10px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .chip { min-height: 32px; font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.split-explain { margin: 0; font-size: 14px; font-weight: 500; color: var(--ink); }

.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 8px 0; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row.archived { opacity: .5; }
.cat-row small { color: var(--muted); }
.icon-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.icon-pick button { height: 44px; border-radius: 12px; display: grid; place-items: center; border: 1.5px solid var(--line); color: var(--ink); }
.icon-pick button.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.color-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.color-pick button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); }
.color-pick button.is-on { box-shadow: 0 0 0 2.5px var(--ink); }
.check { display: flex !important; align-items: center; gap: 10px; color: var(--ink) !important; font-weight: 500 !important; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%); z-index: 20; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- viagens ---------- */
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.section-head h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.section-head p { margin: 2px 0 0; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 14px; }
.btn-sm svg { width: 18px; height: 18px; }
.trip-card { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); color: var(--ink); }
.trip-card.archived { opacity: .6; }
.trip-card .cat-ico { width: 48px; height: 48px; border-radius: 15px; }
.trip-card .cat-ico svg { width: 24px; height: 24px; }
.trip-card h3 { margin: 0; font-size: 16px; }
.trip-card .meta { font-size: 13px; color: var(--muted); }
.trip-card .amt { font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.trip-card .budget-track { margin-top: 8px; }
.trip-top { display: flex; justify-content: space-between; align-items: center; margin: 0 -6px 4px; }
.trip-hero { padding-top: 16px; }
.trip-name { margin: 2px 0 6px; font-size: 24px; letter-spacing: -.02em; }
.trip-hero .hero-value { margin-bottom: 6px; }
.budget { margin-top: 8px; }
.budget-track { height: 8px; border-radius: 99px; background: rgba(127, 127, 127, .2); overflow: hidden; }
.budget-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.budget-fill.over { background: #ff8a73; }
.budget-text { margin: 6px 0 0; font-size: 13px; opacity: .85; }
.add-in-trip { margin-bottom: 14px; }
.trip-pick { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.trip-pick::-webkit-scrollbar { display: none; }
.trip-pick .chip { display: inline-flex; align-items: center; gap: 6px; }
.trip-pick .chip svg { width: 16px; height: 16px; }
.trip-pick .chip.is-on svg { color: inherit; }
.badge.trip { background: color-mix(in srgb, #4a7bd0 16%, transparent); color: #3a64ad; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.trip { color: #9dbbf0; } }
:root[data-theme="dark"] .badge.trip { color: #9dbbf0; }
.tab span { font-size: 10.5px; }
.topbar.no-month #prev-month, .topbar.no-month #next-month, .topbar.no-month #month-label { visibility: hidden; }
.auth-switch { display: block; margin: 14px auto 0; }
.form-ok { color: var(--pos); font-size: 14px; margin: 0 0 12px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
#login form p.muted { margin: 0 0 14px; }

/* ---------- contas a pagar ---------- */
.bill-list { list-style: none; margin: 0; padding: 0; }
.bill { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.bill:last-child { border-bottom: 0; }
.bill-date { width: 44px; height: 48px; border-radius: 12px; background: var(--surface-2); display: grid; place-content: center; text-align: center; line-height: 1; }
.bill-date b { font-size: 18px; font-variant-numeric: tabular-nums; }
.bill-date small { font-size: 10px; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-top: 2px; }
.bill-main { min-width: 0; text-align: left; }
.bill-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.bill-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bill-pay { min-height: 36px; padding: 0 14px; border-radius: 11px; background: var(--brand); color: #fff; font-weight: 700; font-size: 13px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bill-pay { background: var(--accent); color: #1b1408; } }
:root[data-theme="dark"] .bill-pay { background: var(--accent); color: #1b1408; }
.bill.paid .bill-name { text-decoration: line-through; text-decoration-color: var(--muted); }
.badge.late { background: #fde0da; color: #a5321f; }
.badge.today { background: #fdecc8; color: #7a5410; }
.badge.ok { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.badge.cal { background: var(--surface-2); color: var(--muted); }
a.btn { text-decoration: none; }

.theme-btn { font-size: 18px; line-height: 1; }
