:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e4e7ef;
  --text: #1a1d2b;
  --muted: #6b7185;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --income: #059669;
  --income-soft: #e7f8f1;
  --expense: #dc2626;
  --expense-soft: #fdeeee;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 4px 16px rgba(20, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1e222d;
    --border: #2a2f3c;
    --text: #e8eaf2;
    --muted: #949bb0;
    --primary: #818cf8;
    --primary-soft: #23264a;
    --income: #34d399;
    --income-soft: #11291f;
    --expense: #f87171;
    --expense-soft: #2e1717;
    --warn: #fbbf24;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.error { color: var(--expense); font-size: .9rem; min-height: 1.2em; margin: .4rem 0 0; }

/* ---------- botões e campos ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .55rem .95rem; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.income { background: var(--income-soft); border-color: transparent; color: var(--income); }
.btn.expense { background: var(--expense-soft); border-color: transparent; color: var(--expense); }
.btn.danger { color: var(--expense); }
.btn.sm { padding: .35rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }
.icon-btn {
  background: none; border: 0; color: var(--muted); font-size: 1.25rem; cursor: pointer;
  width: 2rem; height: 2rem; border-radius: 8px; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-size: .85rem; font-weight: 500; color: var(--muted); margin-bottom: .8rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type="color"] { padding: .2rem; height: 2.6rem; }
input[type="checkbox"] { width: auto; display: inline; margin: 0 .4rem 0 0; accent-color: var(--primary); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.check { display: flex; align-items: center; color: var(--text); font-size: .95rem; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 2rem; box-shadow: var(--shadow);
}
.auth-card p { margin: .4rem 0 1.4rem; }

/* ---------- layout ---------- */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; }
.brand.big { font-size: 1.3rem; }
.logo {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 9px;
  background: var(--primary); color: #fff; font-size: .78rem; font-weight: 800;
}
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.6rem;
  padding: 1.4rem 1rem; background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.sidebar nav a {
  display: flex; gap: .75rem; align-items: center; padding: .6rem .75rem; border-radius: 10px;
  color: var(--muted); font-weight: 500;
}
.sidebar nav a i { font-style: normal; width: 1.2rem; text-align: center; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; padding: 0 .5rem; }

.main { min-width: 0; padding: 1.4rem 2rem 3rem; }
.topbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.topbar h1 { flex: 1; }
.month-picker {
  display: flex; align-items: center; gap: .25rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .15rem;
}
.month-picker span { min-width: 9.5rem; text-align: center; font-weight: 600; }
.quick-add { display: flex; gap: .5rem; }
.fab { display: none; }

/* ---------- cartões ---------- */
.grid { display: grid; gap: 1rem; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1rem; }
.cols-2 { grid-template-columns: 1.4fr 1fr; }
.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.15rem 1.25rem; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .9rem; }
.kpi .label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: .25rem; letter-spacing: -.01em; }
.kpi .hint { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.kpi.highlight { background: var(--primary); border-color: var(--primary); color: #fff; }
.kpi.highlight .label, .kpi.highlight .hint { color: rgba(255,255,255,.8); }
.chart-box { position: relative; height: 240px; }
.empty { text-align: center; color: var(--muted); padding: 1.6rem .5rem; font-size: .92rem; }

/* listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: .65rem; height: .65rem; border-radius: 50%; flex: none; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.badge.late { background: var(--expense-soft); color: var(--expense); }
.badge.soon { background: #fef3c7; color: #92400e; }
@media (prefers-color-scheme: dark) { .badge.soon { background: #3a2d0c; color: var(--warn); } }

.progress { height: .5rem; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.progress > span { display: block; height: 100%; border-radius: 99px; }

/* ---------- lançamentos ---------- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; margin: 0; padding: .5rem .65rem; font-size: .9rem; }
.filters input[type="search"] { flex: 1; min-width: 160px; }
.summary-bar { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: .92rem; }
.day-group { margin-bottom: 1rem; }
.day-head { display: flex; justify-content: space-between; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 0 .25rem .4rem; }
.tx { display: flex; align-items: center; gap: .8rem; padding: .7rem 1rem; border-top: 1px solid var(--border); cursor: pointer; }
.tx:first-child { border-top: 0; }
.tx:hover { background: var(--surface-2); }
.tx .icon {
  width: 2.2rem; height: 2.2rem; border-radius: 10px; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: .95rem; color: #fff;
}
.tx .meta { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx.pending .title { opacity: .75; }
.paid-toggle {
  border: 1.5px solid var(--border); background: var(--surface); width: 1.6rem; height: 1.6rem; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center; color: transparent; font-size: .8rem; flex: none;
}
.paid-toggle.on { background: var(--income); border-color: var(--income); color: #fff; }
.card.flush { padding: 0; overflow: hidden; }

/* tipo do lançamento */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: .25rem; border-radius: 10px; margin-bottom: 1rem; }
.segmented button { border: 0; background: none; padding: .5rem; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button.on[data-kind="receita"] { color: var(--income); }
.segmented button.on[data-kind="despesa"] { color: var(--expense); }
.segmented button.on[data-kind="transferencia"] { color: var(--primary); }
.amount-input { font-size: 1.5rem; font-weight: 700; }
details.more { margin-bottom: .8rem; }
details.more summary { cursor: pointer; color: var(--primary); font-weight: 500; font-size: .9rem; margin-bottom: .8rem; }

/* ---------- modal ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 17, 25, .5); backdrop-filter: blur(2px); }
dialog form { padding: 1.3rem 1.4rem; max-height: 90vh; overflow: auto; }
dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
dialog footer { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
dialog footer .spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); background: var(--text); color: var(--bg);
  padding: .7rem 1.1rem; border-radius: 10px; font-weight: 500; transition: transform .25s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- responsivo ---------- */
@media (max-width: 960px) {
  .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20; padding: .3rem .4rem calc(.3rem + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border); flex-direction: row;
  }
  .sidebar .brand, .sidebar-foot, .desktop-only { display: none !important; }
  .sidebar nav { flex-direction: row; justify-content: space-around; }
  .sidebar nav a { flex-direction: column; gap: .1rem; font-size: .68rem; padding: .4rem .3rem; flex: 1; }
  .sidebar nav a i { font-size: 1.1rem; }
  .main { padding: 1rem 16px 6rem; }
  .topbar { gap: .6rem; }
  .topbar h1 { font-size: 1.2rem; }
  .quick-add { display: none; }
  .month-picker { order: 3; width: 100%; justify-content: space-between; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(4.6rem + env(safe-area-inset-bottom)); z-index: 21;
    width: 3.4rem; height: 3.4rem; border-radius: 50%; border: 0; background: var(--primary); color: #fff;
    font-size: 1.8rem; box-shadow: 0 6px 20px rgba(79,70,229,.45); cursor: pointer;
  }
  .toast { bottom: calc(5.2rem + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 1.15rem; }
  .kpi.highlight { grid-column: 1 / -1; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .filters select { flex: 1; }
}
