:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f0f2f1;
  --text: #14201b;
  --muted: #6b7a73;
  --border: #e2e8e4;
  --brand: #0b7a52;
  --brand-deep: #0b3d2e;
  --brand-soft: #e3f5ec;
  --in: #0b9d63;
  --out: #d9534f;
  --shadow: 0 6px 24px rgba(11, 61, 46, 0.08);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1210;
    --surface: #141c18;
    --surface-2: #1b2620;
    --text: #e9f0ec;
    --muted: #8ba093;
    --border: #24322b;
    --brand: #22c98a;
    --brand-deep: #0b3d2e;
    --brand-soft: #14332612;
    --in: #34d399;
    --out: #f87171;
    --shadow: 0 8px 30px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--out); font-size: 14px; min-height: 18px; margin: 0; }
.empty { text-align: center; padding: 24px 0; }

/* ===== Botões ===== */
.btn { border: none; border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { transform: scale(0.99); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-danger { background: transparent; color: var(--out); border: 1px solid var(--border); }
.icon-btn { background: transparent; border: none; color: var(--text); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 8px; }

/* ===== Auth ===== */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: 22px; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff; font-weight: 800; font-size: 22px; flex: none;
}
.brand-mark.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.seg button { flex: 1; border: none; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; font-size: 14px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; font-family: inherit; width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); border-color: transparent; }

/* ===== App shell ===== */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: 96px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px calc(14px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav button { width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 16px; cursor: pointer; }
#monthLabel { min-width: 96px; text-align: center; font-weight: 600; font-size: 14px; text-transform: capitalize; }

main { padding: 16px; display: block; }
.view { display: flex; flex-direction: column; gap: 16px; }

/* ===== Cards de resumo ===== */
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat span { font-size: 13px; color: var(--muted); }
.stat strong { display: block; font-size: 22px; margin-top: 4px; }
.stat-in strong { color: var(--in); }
.stat-out strong { color: var(--out); }
.stat-bal { grid-column: 1 / -1; }
.stat-bal strong { font-size: 26px; }

/* ===== Painéis ===== */
.panel { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 16px; }

/* ===== Gráfico categorias ===== */
.cat-chart { display: flex; flex-direction: column; gap: 12px; }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.cat-row .cat-name { font-size: 14px; }
.cat-row .cat-val { font-size: 14px; font-weight: 600; }
.cat-bar { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.cat-bar i { display: block; height: 100%; border-radius: 6px; }

/* ===== Mini compromissos ===== */
.mini-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.mini { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.mini span { font-size: 12px; color: var(--muted); }
.mini strong { display: block; font-size: 18px; margin-top: 2px; }
.safe { display: flex; align-items: center; justify-content: space-between; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); border-radius: 12px; padding: 14px; }
.safe span { font-size: 13px; color: var(--muted); }
.safe strong { font-size: 20px; color: var(--brand); }

/* ===== Listas ===== */
.tx-list { display: flex; flex-direction: column; }
.tx { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tx:last-child { border-bottom: none; }
.tx-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; background: var(--surface-2); }
.tx-main { min-width: 0; }
.tx-desc { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--muted); }
.tx-amt { font-weight: 700; font-size: 15px; text-align: right; white-space: nowrap; }
.tx-amt.pos { color: var(--in); }
.tx-amt.neg { color: var(--out); }
.tx-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px; }

.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ===== FAB + Tabbar ===== */
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--brand); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 8px 20px rgba(11,122,82,.4); cursor: pointer; z-index: 30;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: repeat(4,1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  max-width: 640px; margin: 0 auto;
}
.tabbar button { border: none; background: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; font-family: inherit; }
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--brand); }

/* ===== Import ===== */
.drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px; border: 2px dashed var(--border); border-radius: 16px; cursor: pointer; text-align: center; margin-top: 12px; }
.drop.drag { border-color: var(--brand); background: var(--brand-soft); }
.drop-emoji { font-size: 34px; }
.preview-item { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: center; }
.preview-item select { font-size: 12px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: var(--surface); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto; animation: slideUp .22s ease; }
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 18px; }
@media (min-width: 640px) { .modal { align-items: center; } .modal-card { border-radius: 22px; } }

/* ===== Toggle receita/despesa ===== */
.type-toggle { display: flex; gap: 8px; }
.type-toggle button { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer; font-family: inherit; color: var(--muted); }
.type-toggle button.act-out { background: color-mix(in srgb, var(--out) 14%, transparent); border-color: var(--out); color: var(--out); }
.type-toggle button.act-in { background: color-mix(in srgb, var(--in) 14%, transparent); border-color: var(--in); color: var(--in); }

/* ===== Toast ===== */
.toast { position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--brand-deep); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
