/* cores do cliente: #F1FAEE #A8DADC #457B9D #1D3557 #2A9D8F */
:root {
  --radius: 14px;
  --tabbar: 60px;
  --bg: #E8F1F3;
  --card: #FFFFFF;
  --field: #F7FBFB;
  --ink: #1D3557;
  --muted: #457B9D;
  --soft: #A8DADC;
  --line: #E2ECEE;
  --btn: #E8F1F3;
  --accent: #2A9D8F;
  --accent-ink: #23867A;
  --on-accent: #FFFFFF;
  --neg: #B5483B;
  --hero: #A8DADC;
  --on-hero: #1D3557;
  --hero-sub: #2B5675;
  --hero-neg: #8C2E25;
  --hero-line: rgba(29, 53, 87, .18);
  --hero-hint: rgba(255, 255, 255, .4);
  --sel-row: #E3F4F0;
  --paid-bg: #D6EAEC;
  --paid-fg: #7FA9BD;
  --placeholder: #9DB4C4;
  --shadow: rgba(29, 53, 87, .25);
  --backdrop: rgba(29, 53, 87, .45);
  color-scheme: light;
}

/* modo escuro: segue o celular, a não ser que o tema seja escolhido nos ajustes */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1D30;
    --card: #172A44;
    --field: #0F1D30;
    --ink: #F1FAEE;
    --muted: #A8DADC;
    --soft: #457B9D;
    --line: rgba(168, 218, 220, .14);
    --btn: rgba(168, 218, 220, .14);
    --accent: #2A9D8F;
    --accent-ink: #4CC0B1;
    --on-accent: #FFFFFF;
    --neg: #EB8A7E;
    --hero: #1F4468;
    --on-hero: #F1FAEE;
    --hero-sub: #A8DADC;
    --hero-neg: #F2B8B0;
    --hero-line: rgba(168, 218, 220, .25);
    --hero-hint: rgba(168, 218, 220, .15);
    --sel-row: rgba(42, 157, 143, .14);
    --paid-bg: #22395A;
    --paid-fg: #5F8299;
    --placeholder: #6F8FA6;
    --shadow: rgba(0, 0, 0, .45);
    --backdrop: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1D30;
  --card: #172A44;
  --field: #0F1D30;
  --ink: #F1FAEE;
  --muted: #A8DADC;
  --soft: #457B9D;
  --line: rgba(168, 218, 220, .14);
  --btn: rgba(168, 218, 220, .14);
  --accent: #2A9D8F;
  --accent-ink: #4CC0B1;
  --on-accent: #FFFFFF;
  --neg: #EB8A7E;
  --hero: #1F4468;
  --on-hero: #F1FAEE;
  --hero-sub: #A8DADC;
  --hero-neg: #F2B8B0;
  --hero-line: rgba(168, 218, 220, .25);
  --hero-hint: rgba(168, 218, 220, .15);
  --sel-row: rgba(42, 157, 143, .14);
  --paid-bg: #22395A;
  --paid-fg: #5F8299;
  --placeholder: #6F8FA6;
  --shadow: rgba(0, 0, 0, .45);
  --backdrop: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .3; cursor: default; }

svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

[hidden] { display: none !important; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(var(--tabbar) + 96px + env(safe-area-inset-bottom));
}

.num, .row-value, .hero-value, .sec-total { font-variant-numeric: tabular-nums; }

/* ---------- navegação de ciclo ---------- */
.cycle {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 0 12px;
}
.cycle-mid { display: flex; align-items: center; gap: 4px; }
.cycle-side { width: 40px; flex: none; }
.cycle-label { min-width: 104px; }
.cycle-label {
  display: flex; flex-direction: column; align-items: center;
  font-size: 20px; font-weight: 700; padding: 2px 8px;
}
.cycle-label small { font-weight: 400; font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--muted);
}
.icon-btn:active { background: var(--line); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 18px; height: 18px; }

/* ---------- calendário do extrato ---------- */
.cal { background: var(--card); border-radius: var(--radius); padding: 4px 8px 8px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head strong { font-weight: 600; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-wd { font-size: 12px; color: var(--muted); padding: 2px 0 6px; }
.cal-day { position: relative; height: 44px; display: grid; place-items: center; }
.cal-day span {
  position: relative;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 15px; font-variant-numeric: tabular-nums;
}
.cal-day span.has { padding-bottom: 4px; }
.cal-day.today span { color: var(--accent-ink); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--soft); }
.cal-day.sel span { background: var(--ink); color: var(--bg); box-shadow: none; }
/* bolinha de "tem registro" dentro do círculo do dia */
.cal-day i {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-day.sel i { background: var(--bg); }
.day-title { margin: 14px 4px 8px; font-weight: 600; font-size: 15px; }

/* ---------- resumo (início) ---------- */
.hero {
  background: var(--hero);
  color: var(--on-hero);
  border-radius: 18px;
  padding: 18px 18px 14px;
}
.hero-label { font-size: 14px; color: var(--hero-sub); }
.hero-value { display: block; font-size: 38px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 12px; }
.hero-value.neg { color: var(--hero-neg); }
.hero-lines { margin: 0; }
.hero-lines > * {
  display: flex; justify-content: space-between; width: 100%;
  padding: 5px 0; font-size: 15px; text-align: left;
}
.hero-lines span:first-child { color: var(--hero-sub); }
.hero-lines button { color: inherit; }
.hero-foot {
  display: flex; justify-content: space-between;
  border-top: 1px solid var(--hero-line);
  margin-top: 8px; padding-top: 10px;
  font-size: 15px;
}
.hero-foot + .hero-foot { border-top: 0; margin-top: 0; padding-top: 2px; }
.hero-foot span:first-child { color: var(--hero-sub); }
.hero-hint {
  display: block; width: 100%; margin-top: 10px; padding: 10px;
  border-radius: 10px; background: var(--hero-hint);
  color: var(--on-hero); font-size: 14px; text-align: center;
}

/* ---------- seções e listas ---------- */
.sec-head {
  display: flex; align-items: center; gap: 8px;
  margin: 22px 0 8px; min-height: 32px;
}
.sec-head h2 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; }
.sec-total { color: var(--muted); font-size: 15px; }
.tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--accent-ink); border: 1px solid currentColor;
  border-radius: 99px; padding: 1px 7px; margin-left: 6px; vertical-align: 2px;
  font-weight: 500;
}
.link { color: var(--accent-ink); font-weight: 500; font-size: 15px; padding: 4px 0; }

.list, .card {
  list-style: none; margin: 0; padding: 0;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}
.row {
  display: flex; align-items: center;
  min-height: 56px;
  padding-left: 12px;
}
.row + .row { border-top: 1px solid var(--line); }
.row-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px 10px 12px;
  text-align: left;
}
.row:not(:has(.check)) .row-main { padding-left: 2px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-value { white-space: nowrap; }
/* contas já pagas ficam apagadas, sem destaque */
.row.paid .row-text, .row.paid .row-value { opacity: .45; }
.row.paid .row-value { text-decoration: line-through; }

.check {
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--soft);
  display: grid; place-items: center;
  color: transparent;
  position: relative;
}
.check::after { content: ""; position: absolute; inset: -10px; }
.check svg { width: 15px; height: 15px; stroke-width: 3; }
/* pago: discreto; selecionado para pagar: verde, o que está ativo agora */
.check[aria-pressed="true"] { background: var(--paid-bg); border-color: var(--paid-bg); color: var(--paid-fg); }
.check.sel[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.row.selected { background: var(--sel-row); }

.empty { margin: 0; padding: 14px; color: var(--muted); font-size: 14px; background: var(--card); border-radius: var(--radius); }

/* ---------- fatura ---------- */
/* o resumo fica preso no topo enquanto a lista rola */
.summary {
  padding: 14px 16px;
  position: sticky; top: calc(env(safe-area-inset-top) + 6px); z-index: 4;
  overflow: visible;
  box-shadow: 0 6px 18px -10px var(--shadow);
}
/* cobre a faixa acima do card fixo para a lista não aparecer passando por ali */
.summary::before {
  content: ""; position: absolute; left: -16px; right: -16px;
  bottom: 100%; height: calc(env(safe-area-inset-top) + 6px);
  background: var(--bg);
}
.sum-line { display: flex; justify-content: space-between; align-items: baseline; }
.sum-line strong { font-size: 26px; }
.sum-period { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.bar { display: flex; height: 8px; border-radius: 4px; background: var(--line); margin: 10px 0; overflow: hidden; }
.bar i { display: block; height: 100%; }
.bar .f, .dot.f { background: var(--accent); }
.bar .x, .dot.x { background: var(--muted); }
.legend { display: grid; grid-template-columns: 1fr auto; row-gap: 2px; font-size: 14px; color: var(--muted); }
.legend .num { color: var(--ink); text-align: right; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.pay-row { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.pay-row .btn { margin-top: 0; flex: 1; }
.undo-all { margin-top: 12px; }

.sec { background: var(--card); border-radius: var(--radius); margin-top: 10px; overflow: hidden; }
.sec-bar { display: flex; align-items: center; min-height: 56px; padding: 0 6px 0 12px; }
.sec-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 14px 4px 14px 12px; text-align: left; }
.sec-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec-count { font-size: 12px; color: var(--muted); background: var(--btn); border-radius: 99px; padding: 0 7px; line-height: 18px; }
.sec-toggle .sec-total { margin-left: auto; color: var(--ink); font-weight: 600; font-size: 15px; white-space: nowrap; }
.chev { display: grid; color: var(--muted); transition: transform .15s; }
.chev svg { width: 16px; height: 16px; }
.sec.open .chev, .chev.open { transform: rotate(90deg); }
.row-main .chev { margin-left: -4px; }
/* itens de uma pessoa, abertos abaixo da linha dela */
.row.child { padding-left: 46px; min-height: 48px; }
.row.child .row-main { padding-top: 8px; padding-bottom: 8px; }
.row.child .row-title { font-size: 15px; }
.sec-toggle .sec-total.done { color: var(--muted); font-weight: 500; }
.sec-info { margin: 0; padding: 0 16px 10px 50px; font-size: 13px; color: var(--muted); }
.sec-info b { color: var(--ink); font-weight: 600; }
.sec .list { border-radius: 0; border-top: 1px solid var(--line); }
.sec-empty { margin: 0; padding: 12px 16px 14px 50px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.check-gap { width: 26px; flex: none; }
.sum-sub { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.summary > .btn { margin-top: 12px; }
.ok { margin: 10px 0 0; color: var(--accent-ink); font-weight: 500; text-align: center; }

/* ---------- ajustes ---------- */
.title { font-size: 22px; margin: 10px 0 16px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 0 16px;
}
.card.divided > * + * { border-top: 1px solid var(--line); }
.set-row input {
  width: 9em; text-align: right;
  border: 0; background: none; padding: 10px 0;
  color: var(--ink); font-weight: 600;
  outline: none;
}
.set-row input:focus { color: var(--accent-ink); }
.row-btn {
  display: block; width: 100%; text-align: left;
  padding: 16px; color: var(--ink);
  cursor: pointer;
}
.row-btn.danger { color: var(--neg); }
.hint { font-size: 13px; color: var(--muted); margin: 8px 4px 0; }

/* ---------- botões ---------- */
.btn {
  display: block; width: 100%;
  height: 48px; border-radius: 12px;
  font-weight: 600;
  background: var(--btn); color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: none; color: var(--muted); font-weight: 500; height: 44px; }
.btn.danger { color: var(--neg); }
.btn.primary.danger { background: var(--neg); color: var(--on-accent); }
.btn:active { filter: brightness(.95); }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 260px + 16px));
  bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  box-shadow: 0 4px 14px var(--shadow);
  z-index: 5;
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 6;
}
.tabbar button {
  flex: 1; max-width: 174px; height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); opacity: .75;
}
.tabbar button.on { color: var(--ink); opacity: 1; font-weight: 600; }

/* ---------- folha (formulários) ---------- */
#sheet {
  margin: auto auto 0;
  width: 100%; max-width: 520px;
  max-height: 92dvh;
  padding: 0; border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--card); color: var(--ink);
}
#sheet::backdrop { background: var(--backdrop); }
#sheet-form {
  display: flex; flex-direction: column; gap: 14px;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-right: -8px; }
.sheet-head h2 { font-size: 18px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input {
  width: 100%; height: 48px;
  padding: 0 12px;
  border: 1px solid var(--soft); border-radius: 10px;
  background: var(--field);
  outline: none;
  -webkit-appearance: none; appearance: none;
}
.field input[type="date"] { display: block; line-height: 46px; }
.field input[data-money] { font-variant-numeric: tabular-nums; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(42, 157, 143, .15); }
.field input::placeholder { color: var(--placeholder); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2.wide { grid-template-columns: 1.6fr 1fr; }

.seg {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg); border-radius: 10px; padding: 3px;
}
.seg button { height: 38px; border-radius: 8px; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px var(--shadow); }
/* fora de uma folha (nos ajustes) o seletor fica sobre o fundo da página */
.seg.on-page { background: var(--card); }
.seg.on-page button.on { background: var(--bg); }

.calc { margin: -6px 2px 0; font-size: 14px; color: var(--accent-ink); min-height: 1.4em; }
.actions { display: flex; flex-direction: column; gap: 2px; margin-top: -4px; }
.sheet-sub { font-size: 13px; color: var(--muted); margin: 2px 0 -10px; font-weight: 500; }
.ant-list { list-style: none; margin: 0; padding: 0; }
.ant-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 14px; }
.ant-list li + li { border-top: 1px solid var(--line); }
.ant-list .grow { flex: 1; }
.ant-list button { color: var(--muted); font-weight: 500; padding: 6px 0 6px 8px; }

/* popup de confirmação */
#ask {
  width: calc(100% - 48px); max-width: 340px;
  padding: 0; border: 0; border-radius: 18px;
  background: var(--card); color: var(--ink);
  box-shadow: 0 12px 40px var(--shadow);
}
#ask::backdrop { background: var(--backdrop); }
.ask { padding: 22px 18px 16px; }
.ask p { margin: 0 4px 18px; font-size: 16px; line-height: 1.45; }
.ask-btns { display: flex; gap: 8px; }
.ask-btns .btn { flex: 1; height: 44px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  background: var(--ink); color: var(--bg);
  padding: 8px 16px; border-radius: 99px; font-size: 14px;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
