:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201e;
  --muted: #5b6764;
  --line: #dfe5e3;
  --brand: #0f7a6c;
  --brand-ink: #ffffff;
  --brand-soft: #e1f2ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --ok: #1d7a3a;
  --ok-soft: #e5f5ea;
  --in: #1d6fb8;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 2px 8px rgba(16, 24, 22, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --surface: #171e1c;
    --surface-2: #1f2826;
    --text: #e8eeec;
    --muted: #9aa8a4;
    --line: #2a3532;
    --brand: #3fb8a5;
    --brand-ink: #06231f;
    --brand-soft: #173a35;
    --danger: #ff8a7f;
    --danger-soft: #3a1d1a;
    --warn: #f3b25a;
    --warn-soft: #3a2a12;
    --ok: #6fd18f;
    --ok-soft: #173322;
    --in: #7bb8f0;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1413; --surface: #171e1c; --surface-2: #1f2826; --text: #e8eeec; --muted: #9aa8a4; --line: #2a3532;
  --brand: #3fb8a5; --brand-ink: #06231f; --brand-soft: #173a35; --danger: #ff8a7f; --danger-soft: #3a1d1a;
  --warn: #f3b25a; --warn-soft: #3a2a12; --ok: #6fd18f; --ok-soft: #173322; --in: #7bb8f0; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- entrada ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: 48px 16px 32px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.auth h1 { font-size: 24px; margin: 28px 0 6px; }
.auth p.lead { color: var(--muted); margin: 0 0 24px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 17px;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.block { width: 100%; padding: 13px 16px; font-size: 17px; }
.btn.small { padding: 6px 10px; font-size: 14px; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: default; }
.error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 15px; }
.hint { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 24px; font-size: 15px; }
.hint b { display: block; margin-bottom: 4px; }
.hint code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-weight: 700; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; text-decoration: underline; font-size: 15px; }

/* ---------- app ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px; border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; max-width: 980px; margin: 0 auto; }
.top-row .brand { font-size: 17px; }
.top-row .brand img { width: 28px; height: 28px; border-radius: 7px; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; max-width: 980px; margin: 0 auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

main { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.month { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.month h2 { font-size: 20px; margin: 0; min-width: 0; flex: 1; text-transform: capitalize; }
.iconbtn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 18px; line-height: 1; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 21px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 13px; color: var(--muted); }
.tile.danger .value { color: var(--danger); }
.tile.ok .value { color: var(--ok); }
.tile.in .value { color: var(--in); }

.grid2 { display: grid; gap: 18px; }
@media (min-width: 860px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } }
section.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
section.card > h3 { font-size: 16px; margin: 0; padding: 14px 16px 10px; display: flex; align-items: center; gap: 8px; }
section.card > h3 .more { margin-left: auto; font-size: 14px; font-weight: 600; }
.empty { padding: 4px 16px 16px; color: var(--muted); font-size: 15px; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); min-width: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amount { font-weight: 700; text-align: right; white-space: nowrap; }
.row .amount.in { color: var(--in); }
.row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.date { flex: none; width: 46px; text-align: center; line-height: 1.1; }
.date .d { font-size: 18px; font-weight: 700; }
.date .w { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.date.overdue .d, .date.overdue .w { color: var(--danger); }
.date.due_today .d, .date.due_today .w { color: var(--warn); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.overdue { background: var(--danger-soft); color: var(--danger); }
.pill.due_today { background: var(--warn-soft); color: var(--warn); }
.pill.settled { background: var(--ok-soft); color: var(--ok); }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 0 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); margin-right: 4px; }
.row.done .title { color: var(--muted); }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 14px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.total { display: flex; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-weight: 700; }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.warn > i { background: var(--warn); }
.bar.danger > i { background: var(--danger); }
.cardbox { padding: 12px 16px 14px; border-top: 1px solid var(--line); }
.cardbox .head { display: flex; gap: 8px; align-items: baseline; }
.cardbox .head b { font-size: 16px; }
.cardbox .small { font-size: 13px; color: var(--muted); }

.search { width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 14px; }
.note { padding: 12px 16px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.note .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .in { display: flex; width: 100%; max-width: 620px; }
nav.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 2px 9px; cursor: pointer; color: var(--muted);
  font-size: 12px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.tabs button .ic { font-size: 20px; line-height: 1.1; }
nav.tabs button[aria-current="page"] { color: var(--brand); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; max-width: calc(100% - 32px);
}
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 28px; }

/* ---------- contas pelo painel (v2) ---------- */
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--surface-2); }
.row.clickable:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 7;
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 999px; padding: 13px 20px;
  font-weight: 700; font-size: 16px; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); cursor: pointer;
}
dialog.sheet {
  border: 0; padding: 0 16px 20px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
@media (max-width: 600px) {
  dialog.sheet { margin: auto 0 0; max-width: none; border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; gap: 10px; padding: 16px 0 10px; z-index: 1; }
.sheet-head h2 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; color: var(--text);
}
.field textarea { resize: vertical; font: inherit; }
.field select:focus, .field textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.field small { display: block; margin-top: 4px; font-size: 13px; }
.muted { color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2[hidden] { display: none; }
.more-fields { margin: 4px 0 14px; }
.more-fields summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: 15px; margin-bottom: 12px; }
.scope { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 14px; }
.scope legend { font-size: 14px; font-weight: 600; padding: 0 4px; }
.scope label { display: block; padding: 4px 0; }
.kvs { margin: 4px 0 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv span { color: var(--muted); }
.kv b { text-align: right; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 30%; padding: 12px; }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
