* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #16181d;
  --ink-2: #5b6472;
  --ink-3: #98a1ae;
  --line: #e7e9ee;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --ok-bg: #e9f7ee;
  --warn: #d97706;
  --warn-bg: #fdf3e3;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 33, .05), 0 4px 16px rgba(20, 24, 33, .05);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: 84px;
}

#app { max-width: 680px; margin: 0 auto; padding: 12px 14px 20px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 34px 28px; width: 100%; max-width: 360px; text-align: center;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.login-card p { color: var(--ink-2); font-size: .9rem; margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 1.05rem; text-align: center; margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 14px; }
.topbar h1 { font-size: 1.25rem; letter-spacing: -.02em; }
.topbar h1 span { color: var(--accent); }

.month-nav {
  display: flex; align-items: center; justify-content: center; gap: 4px; margin-bottom: 12px;
}
.month-nav button {
  border: none; background: var(--card); box-shadow: var(--shadow); color: var(--ink-2);
  width: 38px; height: 38px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
}
.month-nav .month-label {
  font-weight: 700; font-size: 1.06rem; min-width: 170px; text-align: center; text-transform: capitalize;
}
.month-nav .month-label small { display: block; font-weight: 500; color: var(--ink-3); font-size: .72rem; }

/* ---------- resumo ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px;
}
.stat .label { font-size: .72rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.05rem; font-weight: 700; margin-top: 3px; white-space: nowrap; }
.stat.bad .value { color: var(--bad); }
.stat.ok .value { color: var(--ok); }

/* ---------- filtros ---------- */
.chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink-2);
  padding: 7px 14px; border-radius: 999px; font-size: .84rem; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- listas ---------- */
.group-title {
  font-size: .78rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: .05em; margin: 18px 4px 8px;
}
.group-title.bad { color: var(--bad); }

.conta {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px;
  cursor: pointer; transition: transform .06s;
}
.conta:active { transform: scale(.99); }
.conta .due {
  width: 44px; min-width: 44px; text-align: center; border-radius: 10px; padding: 5px 0;
  background: var(--bg); color: var(--ink-2);
}
.conta .due b { display: block; font-size: 1.05rem; }
.conta .due small { font-size: .62rem; text-transform: uppercase; }
.conta.atrasada .due { background: var(--bad-bg); color: var(--bad); }
.conta.hoje .due { background: var(--warn-bg); color: var(--warn); }
.conta.paga .due { background: var(--ok-bg); color: var(--ok); }
.conta .info { flex: 1; min-width: 0; }
.conta .nome { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conta .meta { font-size: .76rem; color: var(--ink-3); margin-top: 2px; }
.conta .meta .tag { background: var(--bg); border-radius: 6px; padding: 1px 6px; margin-right: 4px; }
.conta .valor { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.conta.paga .valor { color: var(--ink-3); text-decoration: line-through; text-decoration-thickness: 1px; }

.paybtn {
  border: none; min-width: 46px; height: 40px; border-radius: 12px; font-size: 1.15rem; cursor: pointer;
  background: var(--bg); color: var(--ink-3); font-weight: 700; transition: all .12s;
}
.paybtn:hover { background: var(--ok-bg); color: var(--ok); }
.conta.paga .paybtn, .paybtn.paid { background: var(--ok); color: #fff; }
.conta.auto .paybtn { background: #eef2ff; color: #4f46e5; font-size: .78rem; }

.empty { text-align: center; color: var(--ink-3); padding: 40px 10px; font-size: .92rem; }
.empty .big { font-size: 2rem; margin-bottom: 8px; }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: max(18px, calc(50% - 322px)); bottom: 86px; z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.7rem; line-height: 1;
  box-shadow: 0 6px 20px rgba(37, 99, 235, .4);
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; max-width: 160px; border: none; background: none; cursor: pointer;
  color: var(--ink-3); font-size: .7rem; font-weight: 600; padding: 6px 2px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.tabbar button .ico { font-size: 1.25rem; }
.tabbar button.active { color: var(--accent); }
.tabbar .badge {
  position: absolute; top: 0; right: calc(50% - 22px); background: var(--bad); color: #fff;
  font-size: .62rem; border-radius: 999px; padding: 1px 5px; font-weight: 700;
}

/* ---------- sheet/modal ---------- */
.sheet-back {
  position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 680px; border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
}
.sheet h2 { font-size: 1.1rem; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet h2 .close { border: none; background: var(--bg); border-radius: 50%; width: 30px; height: 30px; cursor: pointer; color: var(--ink-2); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .76rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 11px;
  font-size: .95rem; background: #fff; color: var(--ink); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 3px; }
.seg button {
  flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; cursor: pointer;
  font-size: .86rem; font-weight: 600; color: var(--ink-2);
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 13px 18px; font-size: .95rem; font-weight: 700;
  cursor: pointer; background: var(--bg); color: var(--ink);
}
.btn.primary { background: var(--accent); color: #fff; width: 100%; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { background: none; color: var(--ink-2); }
.btn.small { padding: 8px 13px; font-size: .82rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn.primary { flex: 1; }

/* ---------- comissões ---------- */
.quickadd {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 16px;
}
.quickadd h3 { font-size: .84rem; color: var(--ink-2); margin-bottom: 10px; }
.quickadd .calc-preview { font-size: .8rem; color: var(--ink-2); margin-top: 8px; }
.quickadd .calc-preview b { color: var(--ok); }

.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .7rem; text-transform: uppercase; color: var(--ink-3); letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbfc; }

/* ---------- faturas ---------- */
.fatura {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px;
}
.fatura .from { font-size: .78rem; color: var(--ink-3); }
.fatura .subj { font-weight: 600; font-size: .92rem; margin: 4px 0 8px; }
.fatura .vals { display: flex; gap: 14px; font-size: .86rem; margin-bottom: 10px; flex-wrap: wrap; }
.fatura .vals b { font-size: 1rem; }
.fatura select { padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 9px; font-size: .86rem; max-width: 100%; }
.fatura .acts { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- config ---------- */
.cfg-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.cfg-card h3 { font-size: .95rem; margin-bottom: 4px; }
.cfg-card .desc { font-size: .8rem; color: var(--ink-2); margin-bottom: 12px; }
.cfg-card .hint { font-size: .76rem; color: var(--ink-3); margin-top: 8px; line-height: 1.5; }
.copybox {
  display: flex; gap: 8px; align-items: center; background: var(--bg); border-radius: 10px; padding: 9px 12px;
  font-size: .78rem; word-break: break-all;
}
.copybox code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--bad); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 60;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 11px 18px; font-size: .88rem;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

@media (min-width: 700px) {
  body { padding-bottom: 20px; }
  #app { padding-top: 20px; }
  .tabbar { top: 0; bottom: auto; border-top: none; border-bottom: 1px solid var(--line); }
  #app { margin-top: 64px; }
  .fab { bottom: 30px; }
  #toast { bottom: 30px; }
  .stats .stat .value { font-size: 1.25rem; }
}

/* ---------- botão do boleto ---------- */
.boletobtn {
  border: none; min-width: 40px; height: 40px; border-radius: 12px; font-size: 1.05rem; cursor: pointer;
  background: var(--bg); color: var(--ink-3); transition: all .12s;
}
.boletobtn:hover { background: #fff7ed; color: #ea580c; }

/* ---------- líquido + evolução ---------- */
.stat.liq .value { color:#0f766e; }
.stat .sub { font-size:.7rem; color:var(--ink-3); margin-top:2px; }
.evo-wrap { margin: 6px 0 10px; }
.evo-panel { margin-top:10px; }
.evo-cats { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; }
.evo-card { background:var(--card,#fff); border:1px solid #eef0f3; border-radius:14px; padding:10px 12px; }
.evo-h { font-size:.8rem; color:var(--ink-2,#475569); margin-bottom:6px; display:flex; justify-content:space-between; align-items:baseline; gap:6px; }
.evo-h b { color:var(--ink,#0f172a); }
.evo-h .up { color:#dc2626; font-weight:700; font-size:.72rem; }
.evo-h .down { color:#16a34a; font-weight:700; font-size:.72rem; }
.spark { display:flex; align-items:flex-end; gap:3px; height:54px; }
.spark span { flex:1; background:linear-gradient(180deg,#6366f1,#a5b4fc); border-radius:3px 3px 0 0; min-height:6px; }
.evo-x { font-size:.66rem; color:var(--ink-3); margin-top:4px; }
.evo-top { margin-top:12px; background:#fff; border:1px solid #eef0f3; border-radius:14px; padding:10px 12px; }
.evo-row { display:flex; justify-content:space-between; padding:4px 0; border-bottom:1px dashed #eef0f3; font-size:.86rem; }
.evo-row:last-child { border-bottom:none; }
@media (min-width:820px){ .stats { max-width:none; } }

/* categorias do cartão */
.cat-row{display:flex;align-items:center;gap:8px;padding:3px 0;font-size:.82rem;}
.cat-n{width:130px;color:var(--ink-2,#475569);}
.cat-bar{flex:1;background:#eef0f3;border-radius:6px;height:10px;overflow:hidden;}
.cat-bar i{display:block;height:100%;background:linear-gradient(90deg,#6366f1,#a5b4fc);}
.cat-v{width:84px;text-align:right;font-weight:600;}
