:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0f766e;
  --primary-soft: #ccfbf1;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --eric: #2563eb;
  --nayme: #db2777;
  --casa: #0f766e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1218;
    --card: #131c24;
    --text: #e6edf3;
    --muted: #8b9bab;
    --line: #223040;
    --primary: #2dd4bf;
    --primary-soft: #123a37;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --bad: #f87171;
    --bad-soft: #3b1515;
    --eric: #60a5fa;
    --nayme: #f472b6;
    --casa: #2dd4bf;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .6rem; color: var(--muted); font-weight: 600; }

/* Topo */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  flex-wrap: wrap;
  padding: calc(.6rem + env(safe-area-inset-top, 0px)) 1rem .6rem;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.sync-badge {
  border: 0; border-radius: 999px; padding: .15rem .55rem; font-size: .72rem; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.sync-badge.ok { background: var(--ok-soft); color: var(--ok); }
.sync-badge.offline { background: var(--warn-soft); color: var(--warn); }
.sync-badge.auth { background: var(--primary-soft); color: var(--primary); }
.who { display: flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.who button {
  border: 0; background: none; padding: .3rem .8rem; border-radius: 999px;
  font-size: .85rem; font-weight: 600; color: var(--muted);
}
.who button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.who button.active[data-view="eric"] { color: var(--eric); }
.who button.active[data-view="nayme"] { color: var(--nayme); }
.who button.active[data-view="casa"] { color: var(--casa); }

.monthbar {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  padding: .6rem 1rem; text-transform: capitalize;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 1.3rem; line-height: 1;
}

main { max-width: 980px; margin: 0 auto; padding: 0 1rem; }

/* Cartões */
.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: .8rem; }
.grid-2 { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); margin-bottom: .8rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: .8rem; min-width: 0;
}
.grid > .card, .grid-2 > .card { margin-bottom: 0; }
.kpi .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 1.35rem; font-weight: 750; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.progress { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: .5rem 0 .3rem; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress.ok > div { background: var(--ok); }
.progress.warn > div { background: var(--warn); }
.progress.bad > div { background: var(--bad); }

/* Alertas */
.alert {
  display: flex; gap: .6rem; align-items: center; padding: .65rem .8rem; border-radius: 10px;
  margin-bottom: .5rem; font-size: .9rem;
}
.alert.bad { background: var(--bad-soft); }
.alert.warn { background: var(--warn-soft); }
.alert.ok { background: var(--ok-soft); }
.alert .grow { flex: 1; min-width: 0; }
.alert button { flex-shrink: 0; }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: .7rem; padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list .ico {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 1.15rem; flex-shrink: 0; background: var(--bg);
}
.list .info { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--muted); font-size: .8rem; }
.list .amount { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.list li.clickable { cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 1.2rem .5rem; }

.tag {
  display: inline-block; font-size: .7rem; font-weight: 700; padding: .05rem .45rem;
  border-radius: 999px; background: var(--bg); color: var(--muted); vertical-align: middle;
}
.tag.eric { color: var(--eric); }
.tag.nayme { color: var(--nayme); }
.tag.casa { color: var(--casa); }
.tag.paid { background: var(--ok-soft); color: var(--ok); }
.tag.late { background: var(--bad-soft); color: var(--bad); }
.tag.soon { background: var(--warn-soft); color: var(--warn); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.section-head h2 { margin: 0; }

/* Botões */
.btn {
  border: 1px solid var(--line); background: var(--card); padding: .5rem .9rem;
  border-radius: 10px; font-weight: 600; font-size: .9rem;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04201d; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

.check {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line);
  background: transparent; display: grid; place-items: center; flex-shrink: 0; font-size: .9rem;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.fab {
  position: fixed; right: 1rem; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .4);
}

/* Navegação inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: .45rem 0 .5rem;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: .72rem; color: var(--muted); font-weight: 600;
}
.tabs button span { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--primary); }
.tabs button.active span { filter: none; opacity: 1; }

.credits { text-align: center; color: var(--muted); font-size: .78rem; padding: 1rem 1rem 1.5rem; }
.credits strong { color: var(--primary); }

/* Formulário / modal */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 2rem));
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(2, 6, 23, .5); }
dialog form { padding: 1.2rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%; padding: .6rem .7rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg);
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field .hint { font-size: .75rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg label {
  flex: 1; text-align: center; padding: .5rem; border: 1px solid var(--line); border-radius: 10px;
  font-weight: 600; font-size: .85rem; color: var(--text); cursor: pointer;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--primary); }
.seg label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.modal-actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.spacer { flex: 1; }

.choice { display: grid; gap: .6rem; }
.choice button {
  text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: .8rem;
}
.choice b { display: block; }
.choice small { color: var(--muted); }

/* Gráficos */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .5rem; font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.donut-wrap { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.donut-wrap svg { width: 150px; height: 150px; flex-shrink: 0; }
.donut-wrap .legend { flex-direction: column; flex: 1; min-width: 150px; margin: 0; }
.donut-wrap .legend span { justify-content: space-between; width: 100%; }
.hbar { margin-bottom: .55rem; }
.hbar .row { display: flex; justify-content: space-between; font-size: .85rem; }

/* Calendário */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: .72rem; color: var(--muted); font-weight: 700; padding: .2rem 0; }
.cal .day {
  min-height: 58px; border-radius: 10px; background: var(--bg); padding: 4px; font-size: .78rem;
  border: 2px solid transparent; display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-width: 0;
}
.cal .day.out { visibility: hidden; }
.cal .day.today { border-color: var(--primary); }
.cal .day.sel { background: var(--primary-soft); }
.cal .day .n { font-weight: 700; }
.cal .dots { display: flex; flex-wrap: wrap; gap: 2px; }
.cal .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.paid { background: var(--ok); }
.dot.late { background: var(--bad); }
.dot.soon { background: var(--warn); }
.dot.pend { background: var(--muted); }
.dot.avulso { background: var(--eric); border-radius: 2px; }
.cal .sum { font-size: .65rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tabela */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { padding: .5rem .4rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; text-transform: capitalize; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(150px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  background: #111827; color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  max-width: calc(100vw - 2rem);
}

@media (min-width: 760px) {
  .tabs { justify-content: center; }
  .tabs button { flex: 0 0 110px; }
}
