:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2523;
  --muted: #64716d;
  --line: #dfe5e3;
  --accent: #1f6f5c;
  --accent-soft: #e2f1ec;
  --good: #1f8a4c;
  --bad: #c8363d;
  --warn: #c27a00;
  --track: #e9eeec;
  --on-accent: #ffffff;   /* texto em cima da cor de destaque */
  --warn-bg: #fdf0d5;
  --warn-fg: #8a5a00;
  --radius: 14px;
  color-scheme: light;
}
/* Tema escuro: automático (segue o aparelho) ou escolhido em Ajustes (data-theme no <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111615; --card: #1b2220; --text: #e8eeec; --muted: #9aa8a4; --line: #2c3533;
    --accent: #4cc2a0; --accent-soft: #1e3a33; --good: #4cc27a; --bad: #ff6b72; --warn: #f2b84b;
    --track: #2a3331; --on-accent: #08201a; --warn-bg: #3d2f12; --warn-fg: #f2b84b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111615; --card: #1b2220; --text: #e8eeec; --muted: #9aa8a4; --line: #2c3533;
  --accent: #4cc2a0; --accent-soft: #1e3a33; --good: #4cc27a; --bad: #ff6b72; --warn: #f2b84b;
  --track: #2a3331; --on-accent: #08201a; --warn-bg: #3d2f12; --warn-fg: #f2b84b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; margin-bottom: .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; margin: .2rem 0 .6rem; }
.error { color: var(--bad); min-height: 1.2em; margin: .4rem 0 0; font-size: .9rem; }
input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .5rem 0; }
label > input, label > select { margin-top: .25rem; color: var(--text); font-size: 1rem; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: .6rem 1rem; min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: .3rem; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 1.8rem; width: 48px; height: 48px; cursor: pointer; color: var(--text); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.spacer { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card label { text-align: left; }
.login-card .btn { width: 100%; margin-top: .6rem; }
.login-card h1 { font-size: 1.4rem; margin-top: .4rem; }

/* Topo e abas */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); padding: max(env(safe-area-inset-top), 4px) 8px 4px; border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.15rem; }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 140px; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs button { background: none; border: 0; padding: .8rem .1rem; font-size: .74rem; color: var(--muted); cursor: pointer; min-height: 52px; }
.tabs button.active { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
.fab {
  position: fixed; right: 18px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 6;
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent);
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer;
}

/* Resumo */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .8rem; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; }
.stat span { display: block; font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); } .neg { color: var(--bad); }

.progress { height: 10px; background: var(--track); border-radius: 6px; overflow: hidden; margin: .4rem 0; }
.progress > div { height: 100%; background: var(--accent); border-radius: 6px; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { padding: .55rem 0; border-top: 1px solid var(--line); cursor: pointer; }
.bars li:first-child { border-top: 0; }
.bars .head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.bars .name { display: flex; align-items: center; gap: .45rem; }
.bars .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bars .val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bars .bar { height: 8px; background: var(--track); border-radius: 5px; margin-top: .35rem; overflow: hidden; }
.bars .bar > div { height: 100%; border-radius: 5px; }
.bars .note { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.bars .note.over { color: var(--bad); font-weight: 600; }
.bars .note.near { color: var(--warn); }

/* Listas */
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.plain li:first-child { border-top: 0; }
.grow { flex: 1; min-width: 0; }
.grow small { display: block; color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.day-head { font-size: .8rem; color: var(--muted); margin: 1rem 0 .3rem; }
.day-head::first-letter { text-transform: uppercase; }
.tx { display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem; margin-bottom: .4rem; cursor: pointer; }
.tx .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.tx .income { color: var(--good); }
.tx .saving { color: var(--accent); }
.filter-row { display: flex; justify-content: space-between; align-items: center; background: var(--accent-soft); border-radius: 10px; padding: .4rem .8rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.checklist label { display: flex; align-items: center; gap: .7rem; margin: 0; padding: .6rem 0; color: var(--text); font-size: 1rem; cursor: pointer; }
.checklist input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); flex: none; }
.checklist .paid .grow { text-decoration: line-through; color: var(--muted); }

#catEdit li { gap: .4rem; flex-wrap: wrap; }
#catEdit input[type=color] { width: 40px; padding: 2px; flex: none; }
#catEdit .cat-name { flex: 1 1 0; min-width: 0; }
#catEdit .cat-budget { flex: 0 0 104px; }
#catEdit .btn { flex: none; padding: .3rem .55rem; }
#catEdit input { margin: 0; }
.money-input { position: relative; }
.money-input.big input { font-size: 1.6rem; font-weight: 700; text-align: center; }

/* Janelas */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px));
  background: var(--card); color: var(--text); max-height: calc(100vh - 24px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 1.1rem; }
fieldset { border: 0; padding: 0; margin: .5rem 0; }
legend { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .45rem .8rem;
  cursor: pointer; display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; font-size: .9rem;
}
.chips button .dot { width: 9px; height: 9px; border-radius: 50%; }
.chips button.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: .6rem 0; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: block; text-align: center; padding: .6rem; cursor: pointer; color: var(--text); font-size: .95rem; }
.segmented input:checked + span { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.cat-details { flex-basis: 100%; margin: .1rem 0 0 46px; }
.cat-details summary { cursor: pointer; color: var(--accent); font-size: .85rem; padding: .3rem 0; }
.cat-details .cat-bills li { gap: .35rem; padding: .45rem 0; }
.cat-details .cat-bills .btn { flex: none; }
.cat-details > .btn { margin: .3rem 0 .4rem; }
/* Escanear recibo */
.fab-scan { bottom: calc(140px + env(safe-area-inset-bottom)); width: 52px; height: 52px; right: 22px; display: grid; place-items: center; background: var(--card); color: var(--accent); border: 2px solid var(--accent); }
.scan-busy { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); display: grid; place-content: center; justify-items: center; color: #fff; gap: .6rem; }
.spinner { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.scan-note { background: var(--accent-soft); border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; margin: .5rem 0 0; }

/* Semana */
.week-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.week-total { font-variant-numeric: tabular-nums; }

/* Saldo e projeção */
.bal-main { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .4rem 0; }
.bal-main span { display: block; font-size: .78rem; color: var(--muted); }
.bal-main strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.proj { list-style: none; margin: .4rem 0 0; padding: 0; }
.proj li { display: grid; grid-template-columns: 4.2rem 1fr 6.6rem; gap: .5rem; align-items: center; padding: .3rem 0; font-variant-numeric: tabular-nums; }
.proj .m { font-size: .85rem; color: var(--muted); }
.proj .track { position: relative; height: 10px; }
.proj .track::before { content: ""; position: absolute; left: var(--zero); top: -3px; bottom: -3px; width: 1px; background: var(--muted); opacity: .5; }
.proj .fill { position: absolute; top: 0; height: 100%; border-radius: 3px; background: var(--accent); }
.proj .fill.neg { background: var(--bad); }
.proj .v { text-align: right; font-weight: 600; font-size: .9rem; white-space: nowrap; }
.proj .ev { grid-column: 2 / -1; font-size: .75rem; color: var(--muted); margin-top: -.3rem; }
.tag.warn { background: var(--warn-bg); color: var(--warn-fg); }
/* Avisos e assistente */
.alerts { border-left: 4px solid var(--warn); }
.alerts ul { list-style: none; margin: .3rem 0 0; padding: 0; }
.alerts li { display: flex; gap: .5rem; padding: .35rem 0; font-size: .92rem; border-top: 1px solid var(--line); }
.alerts li:first-child { border-top: 0; }
.alerts li .ic { flex: none; }
textarea { width: 100%; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font: inherit; color: var(--text); margin-top: .25rem; resize: vertical; }
.advice { margin-top: .6rem; }
.advice-box { background: var(--accent-soft); border-radius: 12px; padding: .7rem .9rem; margin-top: .6rem; font-size: .95rem; }
.advice-box p { margin: .3rem 0; }
.advice-box ul { margin: .3rem 0; padding-left: 1.2rem; }
.advice-box .meta { font-size: .75rem; color: var(--muted); margin-top: .4rem; }
.advice-q { font-weight: 600; margin-top: .8rem; }
/* Imposto (tax) */
.tax-box { border-left: 3px solid var(--accent); padding: .2rem 0 .2rem .8rem; margin-top: .4rem; }
.photo-row { margin-top: .4rem; }
.tag.tax { background: var(--accent-soft); color: var(--accent); }
.tax-sum { list-style: none; margin: .6rem 0 0; padding: 0; font-variant-numeric: tabular-nums; }
.tax-sum li { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-top: 1px solid var(--line); }
.tax-sum li.total { font-weight: 700; }
#taxList li { flex-wrap: wrap; }
/* Painel (só 3 números + botões grandes) */
.dash h2 { font-size: .95rem; color: var(--muted); font-weight: 600; }
.dash .big-number { font-size: 2.2rem; }
.dash .small { margin: .1rem 0 0; }
.menu { display: grid; gap: .6rem; margin-top: .4rem; }
.menu button {
  display: flex; align-items: center; gap: .8rem; width: 100%; min-height: 60px; padding: .8rem 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 600; text-align: left; cursor: pointer; color: var(--text);
}
.menu button span { font-size: 1.4rem; }
.menu button b { margin-left: auto; color: var(--muted); font-size: 1.4rem; font-weight: 400; }
body.on-painel .tabs { display: none; }
body.on-painel main { padding-bottom: 110px; }
body.on-painel .fab { bottom: calc(20px + env(safe-area-inset-bottom)); }
body.on-painel .fab-scan { bottom: calc(90px + env(safe-area-inset-bottom)); }
/* Painel */
.big-number { font-size: 1.8rem; font-weight: 700; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.near-txt { color: var(--warn); }
#nextBillsCard .plain li, #weeksCard .plain li { gap: .5rem; }
/* Gastos por pessoa */
.people { list-style: none; margin: .3rem 0 0; padding: 0; }
.people li { border-top: 1px solid var(--line); padding: .6rem 0; }
.people li:first-child { border-top: 0; }
.people .head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.people .sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.check-line { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .9rem; margin: .6rem 0 0; cursor: pointer; }
.check-line input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); flex: none; }
.pause-box { margin-top: .6rem; border: 1px solid var(--line); border-radius: 10px; padding: .4rem .7rem; }
.pause-box summary { cursor: pointer; color: var(--accent); font-size: .9rem; padding: .2rem 0; }
.pause-box .btn { margin-top: .3rem; }
.stop-box { background: var(--accent-soft); border-radius: 10px; padding: .6rem .8rem; margin-top: .4rem; }
.stop-box p { margin: 0 0 .4rem; }
.stopped .grow { color: var(--muted); }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 6px; background: var(--track); color: var(--muted); margin-left: .3rem; vertical-align: middle; }
.tag.end { background: var(--accent-soft); color: var(--accent); }
.segmented.two-seg { grid-template-columns: repeat(2, 1fr); }

/* Plano x Real */
.compare { display: grid; grid-template-columns: auto 1fr 1fr; gap: .35rem .8rem; align-items: baseline; font-variant-numeric: tabular-nums; }
.compare .h { font-size: .78rem; color: var(--muted); text-align: right; }
.compare .l { color: var(--muted); }
.compare .v { text-align: right; font-weight: 600; white-space: nowrap; }
.compare .total { border-top: 1px solid var(--line); padding-top: .35rem; }
.plan-rows li { display: block; }
.plan-rows .head { display: flex; justify-content: space-between; gap: .5rem; }
.plan-rows .name { display: flex; align-items: center; gap: .45rem; }
.plan-rows .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.plan-rows .sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.alert { border-left: 4px solid var(--bad); }
.alert-ok { border-left: 4px solid var(--good); }
.cat-hint { flex-basis: 100%; font-size: .75rem; color: var(--muted); margin: -.2rem 0 0 46px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 20; max-width: calc(100vw - 32px);
}
