:root {
  --bg: #f5f3ef; --surface: #ffffff; --surface2: #efece6; --text: #2f3437; --muted: #767b80;
  --line: #e6e2da;
  --primary: #5f927f; --primary-ink: #ffffff; --primary-soft: #e2efe9;
  --pending: #b9791f; --pending-soft: #fbefd9;
  --paid: #44896d; --paid-soft: #dff0e8;
  --expense: #bf6464; --expense-soft: #f9e5e3;
  --accent: #8377bd; --accent-soft: #ebe8f7;
  --shadow: 0 1px 2px rgba(60, 50, 30, .05), 0 6px 20px rgba(60, 50, 30, .06);
  --radius: 18px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1e2125; --surface2: #272b30; --text: #e9e7e3; --muted: #9aa0a6;
  --line: #2f343a;
  --primary: #86b8a7; --primary-ink: #10231c; --primary-soft: #22342e;
  --pending: #e3b566; --pending-soft: #3a3020;
  --paid: #7fc4a6; --paid-soft: #1f3329;
  --expense: #e39a96; --expense-soft: #3b2726;
  --accent: #b4a9e3; --accent-soft: #2c2942;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

.splash { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; font-size: 48px; }

/* ---------- estrutura ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding-top: env(safe-area-inset-top); border-bottom: 1px solid transparent;
}
.top-in { display: flex; align-items: center; gap: 8px; height: 56px; }
.top h1 { font-size: 20px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 19px;
  background: var(--surface); box-shadow: var(--shadow); flex: none;
}
.icon-btn:active { transform: scale(.94); }
.view { padding-top: 6px; padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-in { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 2px 7px;
  font-size: 10.5px; font-weight: 600; color: var(--muted); min-width: 0;
}
.tab span.e { font-size: 21px; line-height: 1.15; filter: grayscale(.7); opacity: .75; transition: transform .15s; }
.tab.on { color: var(--primary); }
.tab.on span.e { filter: none; opacity: 1; transform: translateY(-1px) scale(1.1); }

.fab {
  position: fixed; z-index: 31; right: max(16px, calc(50% - 344px));
  bottom: calc(74px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 20px 0 16px; border-radius: 28px;
  background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 15px;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 6px 18px rgba(60, 110, 90, .35);
}
.fab b { font-size: 24px; font-weight: 500; line-height: 1; margin-top: -2px; }
.fab:active { transform: scale(.96); }

/* ---------- cartões ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .card + .section, .section + .card { margin-top: 12px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 4px 8px; }
.section-head h2 { font-size: 15px; font-weight: 700; }
.section-head a, .link { font-size: 13.5px; font-weight: 600; color: var(--primary); }
.hello { margin: 4px 4px 14px; }
.hello h2 { font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
.hello p { color: var(--muted); font-size: 14px; }

.hero { background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft)); }
.hero .label { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0; }
.hero .sub { font-size: 13.5px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 12px; min-width: 0; }
.stat .label { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .value { font-size: 16.5px; font-weight: 750; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows-title { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.rowline { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; font-size: 15px; }
.rowline b { font-size: 16px; font-weight: 750; white-space: nowrap; }
.rowline.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 11px; padding-bottom: 0; }
.rowline.total b { font-size: 18px; }
.c-paid { color: var(--paid); } .c-pending { color: var(--pending); } .c-expense { color: var(--expense); }
.c-muted { color: var(--muted); }

/* ---------- listas ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item-main { flex: 1; min-width: 0; text-align: left; display: block; }
.item-title { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.item-side { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.amount { font-weight: 750; font-size: 15px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 750; font-size: 16px;
}
.avatar.cat { background: var(--surface2); font-size: 19px; }
.chev { color: var(--muted); font-size: 20px; flex: none; }
.month-head { font-size: 12.5px; font-weight: 700; color: var(--muted); margin: 18px 6px 8px; display: flex; justify-content: space-between; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill.pending { background: var(--pending-soft); color: var(--pending); }
.pill.paid { background: var(--paid-soft); color: var(--paid); }
button.pill:active { transform: scale(.94); }

.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .e { font-size: 38px; display: block; margin-bottom: 6px; }
.empty p { font-size: 14.5px; }

/* ---------- filtros ---------- */
.seg { display: flex; background: var(--surface2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button, .seg label {
  flex: 1; text-align: center; padding: 8px 6px; border-radius: 11px; font-size: 13.5px; font-weight: 650;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg button.on, .seg input:checked + label { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthnav strong { font-size: 16px; display: block; }
.monthnav strong::first-letter, .rows-title::first-letter, .cap1::first-letter, .month-head span::first-letter { text-transform: uppercase; }
.cap1, .month-head span { display: block; }

/* ---------- formulários ---------- */
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 2px 5px; }
.input, select.input, textarea.input {
  width: 100%; height: 48px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
  padding: 0 14px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; min-width: 0;
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; min-height: 72px; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 36px;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.sm { height: 42px; font-size: 15px; }
input[type="date"].input { display: block; line-height: 44px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.total-box {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--primary-soft);
  display: flex; justify-content: space-between; align-items: center; font-weight: 650;
}
.total-box strong { font-size: 20px; font-weight: 800; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 48px; padding: 0 18px;
  border-radius: 14px; font-weight: 700; font-size: 15px; background: var(--surface2); color: var(--text);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--expense-soft); color: var(--expense); }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.block { width: 100%; }
.btn.sm { height: 40px; font-size: 13.5px; padding: 0 13px; border-radius: 12px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 2px 0; }

/* ---------- folha (modal) ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 20, 25, .45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  animation: up .2s ease-out; overscroll-behavior: contain;
}
.sheet-bar { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { font-size: 19px; font-weight: 750; }
.sheet-head .icon-btn { box-shadow: none; background: var(--surface2); width: 36px; height: 36px; font-size: 15px; }
@media (min-width: 640px) {
  .backdrop { align-items: center; padding: 20px; }
  .sheet { border-radius: 24px; }
  .sheet-bar { visibility: hidden; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .backdrop, .sheet, .toast { animation: none; } }

#toast-root {
  position: fixed; left: 0; right: 0; z-index: 60; bottom: calc(140px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 14px; padding: 11px 16px;
  font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 14px; max-width: 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: up .2s ease-out;
}
.toast button { color: inherit; font-weight: 800; text-decoration: underline; }
.toast.err { background: var(--expense); color: #fff; }

/* ---------- login ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 20px; }
.auth-box { width: 100%; max-width: 380px; text-align: center; }
.auth-box img { width: 84px; height: 84px; border-radius: 22px; box-shadow: var(--shadow); }
.auth-box h1 { font-size: 24px; margin-top: 14px; }
.auth-box > p { color: var(--muted); font-size: 14.5px; margin-top: 4px; }
.auth-box form { text-align: left; margin-top: 14px; }

/* ---------- relatório ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; margin-top: 14px; }
.chart .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; }
.chart .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.chart .bar { width: 42%; max-width: 20px; border-radius: 5px 5px 2px 2px; min-height: 2px; }
.chart .bar.in { background: var(--paid); } .chart .bar.out { background: var(--expense); opacity: .8; }
.chart .lbl { font-size: 10.5px; color: var(--muted); font-weight: 650; text-transform: capitalize; }
.chart .col.sel .lbl { color: var(--text); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: right; font-size: 11.5px; color: var(--muted); font-weight: 700; padding: 4px 0 8px 8px; white-space: nowrap; }
.table td { text-align: right; padding: 9px 0 9px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; padding-left: 0; white-space: normal; font-weight: 650; }
.catbar { margin-top: 12px; }
.catbar .top-line { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 650; }
.catbar .track { height: 7px; border-radius: 4px; background: var(--surface2); margin-top: 5px; overflow: hidden; }
.catbar .fill { height: 100%; border-radius: 4px; background: var(--expense); opacity: .8; }

/* ---------- cliente ---------- */
.client-head { display: flex; align-items: center; gap: 14px; }
.client-head .avatar { width: 54px; height: 54px; font-size: 22px; }
.client-head h2 { font-size: 20px; font-weight: 750; }
.client-head p { font-size: 13.5px; color: var(--muted); }

/* ---------- nota ---------- */
.check { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.paper {
  background: #fff; color: #2f3437; border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
  font-size: 13.5px;
}
.paper-head { background: linear-gradient(135deg, #dcebe4, #e6e1f5); padding: 18px 18px 16px; }
.paper-head h3 { font-size: 20px; font-weight: 800; }
.paper-head p { font-size: 12.5px; color: #5d6367; }
.paper-body { padding: 16px 18px 18px; }
.paper-title { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #5f927f; }
.paper-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 13px; flex-wrap: wrap; }
.paper-meta b { font-size: 15px; }
.paper table { width: 100%; border-collapse: collapse; margin-top: 14px; }
.paper th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #7b8085; text-align: right; padding: 0 0 6px 8px; border-bottom: 1.5px solid #e6e2da; }
.paper td { padding: 8px 0 8px 8px; border-bottom: 1px solid #efece6; text-align: right; vertical-align: top; white-space: nowrap; }
.paper th:first-child, .paper td:first-child { text-align: left; padding-left: 0; white-space: normal; }
.paper td small { display: block; color: #7b8085; font-size: 11.5px; }
.paper-total { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #e2efe9; font-weight: 700; }
.paper-total strong { font-size: 21px; font-weight: 800; }
.paper-extra { margin-top: 12px; font-size: 13px; line-height: 1.6; }
.paper-foot { margin-top: 14px; font-size: 11px; color: #8b9094; text-align: center; }

@media print {
  body { background: #fff; }
  .top, .tabs, .fab, #toast-root, #sheet-root, .no-print { display: none !important; }
  .view { padding: 0; }
  .wrap { max-width: none; padding: 0; }
  .paper { box-shadow: none; border-radius: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (max-width: 359px) {
  .stat .value { font-size: 14.5px; }
  .tab { font-size: 9.5px; }
}
