/* MF Financier Web 3.0 — design system com dois temas.
   Escuro suave (padrão) e claro. Tudo em variáveis: nenhum componente
   usa cor fixa. Toggle no shell (core.js) grava em localStorage e aplica
   data-theme no <html>. */

:root, :root[data-theme="dark"] {
  --bg: #131c26;
  --bg-grad: linear-gradient(180deg, #111a24 0%, #16202b 100%);
  --panel: #1a2530;
  --panel-strong: #1e2a37;
  --panel-raise: #243242;
  --line: rgba(148, 171, 190, 0.17);
  --line-strong: rgba(148, 171, 190, 0.32);
  --card-line: rgba(148, 171, 190, 0.10);
  --text: #edf3f8;
  --muted: #a4b6c6;
  --accent: #2dd4bf;
  --accent-ink: #062e29;
  --accent-2: #38bdf8;
  --accent-grad: linear-gradient(135deg, #2dd4bf, #38bdf8);
  --accent-dim: rgba(45, 212, 191, 0.12);
  --danger: #f87171;
  --success: #34d399;
  --income: #4ade80;
  --expense: #f87171;
  --neutral: #60a5fa;
  --warn: #fbbf24;
  --income-dim: rgba(74, 222, 128, 0.12);
  --expense-dim: rgba(248, 113, 113, 0.12);
  --neutral-dim: rgba(96, 165, 250, 0.12);
  --warn-dim: rgba(251, 191, 36, 0.12);
  --chart-grid: rgba(148, 171, 190, 0.14);
  --shadow: 0 10px 32px rgba(4, 10, 16, 0.35);
  --shadow-sm: 0 2px 10px rgba(4, 10, 16, 0.22);
  --radius: 20px;
  --radius-sm: 13px;
  --font-main: "Segoe UI Variable Text", "Segoe UI", -apple-system, "Inter", Roboto, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, monospace;
  --bottom-nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f2f5f8;
  --bg-grad: linear-gradient(180deg, #f4f7fa 0%, #eef2f6 100%);
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --panel-raise: #f4f7fa;
  --line: rgba(23, 43, 61, 0.12);
  --line-strong: rgba(23, 43, 61, 0.26);
  --card-line: rgba(23, 43, 61, 0.07);
  --text: #10202c;
  --muted: #4e6375;
  --accent: #0d9488;
  --accent-ink: #ffffff;
  --accent-2: #0284c7;
  --accent-grad: linear-gradient(135deg, #0d9488, #0891b2);
  --accent-dim: rgba(13, 148, 136, 0.10);
  --danger: #dc2626;
  --success: #16a34a;
  --income: #15803d;
  --expense: #dc2626;
  --neutral: #2563eb;
  --warn: #b45309;
  --income-dim: rgba(22, 163, 74, 0.10);
  --expense-dim: rgba(220, 38, 38, 0.09);
  --neutral-dim: rgba(37, 99, 235, 0.09);
  --warn-dim: rgba(180, 83, 9, 0.10);
  --chart-grid: rgba(23, 43, 61, 0.08);
  --shadow: 0 10px 30px rgba(23, 43, 61, 0.10);
  --shadow-sm: 0 1px 6px rgba(23, 43, 61, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
html, body {
  margin: 0; min-height: 100%;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text); font-family: var(--font-main); font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
img { max-width: 100%; }

/* ============ cores semânticas utilitárias (usar em vez de hex no JS) ============ */
.pos, .txt-income { color: var(--income); }
.neg, .txt-expense { color: var(--expense); }
.txt-neutral { color: var(--neutral); }
.txt-warn { color: var(--warn); }
.txt-accent { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); }

/* ============ layout ============ */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: 200px; flex: 0 0 200px; display: flex; flex-direction: column;
  background: var(--panel-strong);
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.brand { display: flex; gap: 11px; align-items: center; padding: calc(20px + var(--safe-t)) 18px 12px; }
.brand-logo { width: 38px; height: 38px; border-radius: 11px; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { color: var(--muted); font-size: 11px; }
.nav-list { flex: 1; display: flex; flex-direction: column; gap: 1px; padding: 10px; }
.nav-item {
  display: flex; gap: 11px; align-items: center; text-align: left;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  padding: 9px 13px; color: var(--muted); font-size: 13.5px; font-weight: 500; border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.nav-item img.icon { opacity: 0.75; transition: opacity 0.15s; }
:root[data-theme="light"] .nav-item img.icon { filter: none; }
.nav-item:hover { background: var(--panel-raise); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim); color: var(--accent); font-weight: 650;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}
.nav-item.active img.icon { opacity: 1; }
.sidebar-foot { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + var(--safe-t)) 28px 12px;
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 30;
  border-bottom: 1px solid var(--card-line);
}
.topbar-title { font-size: 18px; }
.topbar .brand-mini { display: none; align-items: center; gap: 8px; }
.topbar .brand-mini img { width: 26px; height: 26px; border-radius: 8px; }
.content { padding: 22px 28px calc(48px + var(--safe-b)); max-width: 1480px; margin: 0 auto; width: 100%; }
.tab-pane { display: flex; flex-direction: column; gap: 16px; animation: fadeUp 0.2s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ============ navegação inferior (mobile) ============ */
.bottom-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--bottom-nav-h) + var(--safe-b));
  padding: 6px 4px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--panel-strong) 94%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  grid-template-columns: repeat(5, 1fr);
}
.bnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: transparent; border: 0; border-radius: 12px; padding: 4px 2px;
  color: var(--muted); font-size: 10.5px; font-weight: 550;
}
.bnav-item img.icon { width: 22px; height: 22px; opacity: 0.7; }
.bnav-item.active { color: var(--accent); }
.bnav-item.active img.icon { opacity: 1; }
.bnav-item .bnav-more { font-size: 20px; line-height: 22px; }

.sheet-overlay {
  position: fixed; inset: 0; background: rgba(9, 16, 23, 0.55); z-index: 50;
  backdrop-filter: blur(2px); display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; background: var(--panel-strong); border-radius: 20px 20px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 16px calc(20px + var(--safe-b));
  max-height: 78vh; overflow-y: auto; animation: sheetUp 0.22s ease;
}
@keyframes sheetUp { from { transform: translateY(40%); } to { transform: none; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 99px; background: var(--line-strong); margin: 4px auto 14px; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sheet-item {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--panel-raise); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 4px; color: var(--muted); font-size: 11px; font-weight: 550;
}
.sheet-item img.icon { width: 24px; height: 24px; }
.sheet-item.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ============ cartões / grids ============ */
.card {
  background: var(--panel); border: 1px solid var(--card-line);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.card.hero {
  background: linear-gradient(135deg, var(--accent-dim), transparent 55%), var(--panel);
}
.card-title, .section-title {
  font-size: 11.5px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px; font-weight: 700;
}
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }

.hscroll {
  display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 10px;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.hscroll > * { flex: 0 0 auto; scroll-snap-align: start; }

/* ============ botões ============ */
.btn {
  border: 1px solid var(--line); background: var(--panel-raise);
  color: var(--text); border-radius: var(--radius-sm); padding: 8px 15px; font-size: 13px;
  font-weight: 550; transition: background 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 37px;
}
.btn:hover { background: var(--panel-raise); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent-grad); border: 0; color: var(--accent-ink); font-weight: 650; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--expense-dim); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-raise); }
.btn.small { padding: 4px 10px; font-size: 12px; min-height: 29px; }
.btn-warn { background: var(--warn-dim); border-color: color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }

.fab {
  display: none; position: fixed; right: 18px; bottom: calc(var(--bottom-nav-h) + var(--safe-b) + 16px);
  width: 52px; height: 52px; border-radius: 17px; border: 0; z-index: 35;
  background: var(--accent-grad); color: var(--accent-ink); font-size: 25px; font-weight: 700;
  box-shadow: var(--shadow);
}

/* ============ inputs ============ */
.in {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 13px; min-width: 0; width: 100%;
  min-height: 39px; transition: border-color 0.15s, box-shadow 0.15s;
}
:root[data-theme="light"] .in { background: #fff; }
.in:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
select.in option { background: var(--panel); color: var(--text); }
textarea.in { resize: vertical; min-height: 80px; }
input[type="checkbox"] { accent-color: var(--accent); width: 17px; height: 17px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld-label { font-size: 12px; color: var(--muted); font-weight: 650; }
.fld-hint { font-size: 11px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--card-line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.toolbar .fld { min-width: 130px; flex: 1 1 130px; }
.toolbar .btn { flex-shrink: 0; }

/* ============ tabelas ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--panel); -webkit-overflow-scrolling: touch; box-shadow: var(--shadow-sm); border: 1px solid var(--card-line); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; padding: 10px 14px; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; background: var(--panel-raise);
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.data td { padding: 9px 13px; border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: var(--panel-raise); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .actions { white-space: nowrap; text-align: right; }

@media (max-width: 700px) {
  table.data.cards-sm thead { display: none; }
  table.data.cards-sm, table.data.cards-sm tbody { display: block; }
  table.data.cards-sm tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data.cards-sm tr:last-child { border-bottom: 0; }
  table.data.cards-sm td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 3px 0; border: 0; text-align: right;
  }
  table.data.cards-sm td::before {
    content: attr(data-label); color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.04em; font-weight: 650; text-align: left;
  }
  table.data.cards-sm td:not([data-label])::before { content: none; }
  table.data.cards-sm td:not([data-label]):not(.actions) {
    justify-content: flex-start; text-align: left; font-weight: 650;
  }
  table.data.cards-sm td.actions { justify-content: flex-end; }
  .grid.stack-sm { grid-template-columns: 1fr !important; }
  .hide-sm { display: none !important; }
}

/* ============ pills / estados ============ */
.pill {
  display: inline-block; padding: 2.5px 10px; border-radius: 999px; font-size: 11.5px;
  background: var(--panel-raise); color: var(--muted); border: 1px solid var(--line);
  font-weight: 550; white-space: nowrap;
}
.pill.ok { background: var(--income-dim); color: var(--income); border-color: transparent; }
.pill.warn { background: var(--warn-dim); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--expense-dim); color: var(--expense); border-color: transparent; }
.pill.info { background: var(--neutral-dim); color: var(--neutral); border-color: transparent; }

.empty-state {
  padding: 34px 20px; text-align: center; color: var(--muted);
  background: var(--panel-raise); border-radius: var(--radius); font-size: 13.5px;
  border: 1px dashed var(--line-strong);
}

.bar { height: 8px; border-radius: 99px; background: var(--panel-raise); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.4s ease; }
.bar > span.warn { background: var(--warn); }
.bar > span.bad { background: var(--danger); }

/* Fatura por categoria: lista de barras de uma série só — uma cor, valor em
   texto fora da barra, e as compras de cada categoria abrem embaixo. */
.bar.thin { height: 6px; margin-top: 7px; }
.catlist { display: flex; flex-direction: column; gap: 2px; }
.catrow { padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.catrow:hover, .catrow.open { background: var(--panel-raise); }
.catrow-head { display: flex; align-items: baseline; gap: 10px; }
.catrow-seta { color: var(--muted); width: 12px; flex: 0 0 12px; font-size: 11px; }
.catrow-name { font-weight: 700; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catrow-meta { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.catrow-total { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.catitems { margin: 2px 0 8px 23px; padding-left: 12px; border-left: 1px solid var(--line); }
.catitem { display: flex; align-items: baseline; gap: 10px; padding: 7px 4px; border-radius: 6px; cursor: pointer; }
.catitem:hover { background: var(--panel-raise); }
.catitem-date { color: var(--muted); font-size: 12px; min-width: 40px; font-variant-numeric: tabular-nums; }
.catitem-desc { flex: 1 1 auto; min-width: 0; }
.catitem-raw { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catitem-amt { white-space: nowrap; font-variant-numeric: tabular-nums; }
.catitem .pill { margin-left: 6px; }
@media (max-width: 700px) {
  .catrow-meta .so-largo { display: none; }
  .catitems { margin-left: 8px; padding-left: 8px; }
}

/* ============ modal ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(9, 16, 23, 0.6); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 18px;
}
.modal-box {
  background: var(--panel-strong); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(560px, 100%); max-height: 88vh; max-height: 88dvh;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
  animation: fadeUp 0.2s ease;
}
.modal-box.modal-wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.modal-x { padding: 4px 11px; min-height: 32px; }
.confirm-msg { margin: 0; line-height: 1.55; }
@media (max-width: 700px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box, .modal-box.modal-wide {
    width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; border-bottom: 0;
    animation: sheetUp 0.24s ease;
  }
  .modal-actions .btn { flex: 1; }
}

/* ============ toast ============ */
.toast-holder {
  position: fixed; bottom: calc(var(--bottom-nav-h) + var(--safe-b) + 10px); right: 16px; left: 16px;
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: flex-end;
}
.toast {
  background: var(--panel-strong); border: 1px solid var(--line); border-left: 4px solid var(--neutral);
  border-radius: var(--radius-sm); padding: 12px 16px; max-width: 380px;
  opacity: 0; transform: translateY(14px); transition: all 0.28s; box-shadow: var(--shadow); font-size: 13px;
}
.toast.show { opacity: 1; transform: none; }
.toast-ok { border-left-color: var(--success); }
.toast-erro { border-left-color: var(--danger); }

/* ============ mês nav ============ */
.month-nav { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px; }
.month-nav .btn { border: 0; background: transparent; min-height: 31px; padding: 4px 12px; border-radius: 999px; }
.month-label { min-width: 72px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13.5px; }

/* ============ login ============ */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: calc(20px + var(--safe-t)) 20px 20px; }
.login-card {
  background: var(--panel-strong); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); width: min(380px, 100%); padding: 36px 30px calc(36px + var(--safe-b));
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 16px; }
.login-card .fld { text-align: left; }
.login-btn { margin-top: 6px; padding: 12px; font-size: 15px; }
.login-msg { min-height: 18px; color: var(--danger); font-size: 12.5px; }
.offline-status { min-height: 18px; }

/* ============ app instalado (PWA) ============ */
/* tela de abertura: fica no <body> do index até o login ou o app montarem;
   só aparece se o carregamento passar de 150 ms (sem piscar no desktop) */
.boot-splash {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  opacity: 0; animation: bootIn 0.3s ease 0.15s forwards;
}
.boot-splash img { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35); }
.boot-bar { width: 120px; height: 3px; border-radius: 99px; background: var(--line); overflow: hidden; }
.boot-bar span {
  display: block; width: 40%; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, #2dd4bf, #38bdf8); animation: bootBar 1.1s ease-in-out infinite;
}
@keyframes bootIn { to { opacity: 1; } }
@keyframes bootBar { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.btn-install { color: var(--accent); }
/* toque longo em botão não seleciona texto nem abre menu do sistema */
.nav-item, .bnav-item, .sheet-item, .btn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }   /* sem "elástico" nas bordas, como app nativo */
}

/* ============ calendário ============ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 10.5px; text-transform: uppercase; padding: 4px 0; font-weight: 700; }
.cal-day {
  min-height: 82px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 6px; background: var(--panel); cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; transition: border-color 0.15s;
}
.cal-day:hover { border-color: var(--accent); }
.cal-day.other { opacity: 0.4; }
.cal-day.today { border-color: var(--accent); background: var(--accent-dim); }
.cal-day.has-income { background: var(--income-dim); }
.cal-day.has-expense { background: var(--expense-dim); }
.cal-day .d { font-weight: 700; font-size: 12px; }
.cal-day .cal-item { font-size: 10px; border-radius: 4px; padding: 1px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--panel-raise); }
.cal-day .cal-dot-row { display: none; }
@media (max-width: 700px) {
  .cal-grid { gap: 3px; }
  .cal-day { min-height: 56px; padding: 4px; border-radius: 8px; }
  .cal-day .cal-item { display: none; }
  .cal-day .cal-dot-row { display: flex !important; gap: 2px; flex-wrap: wrap; }
}

/* ============ chat ============ */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 190px); min-height: 380px; }
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 6px 2px 14px; -webkit-overflow-scrolling: touch; }
.chat-msg { max-width: 82%; padding: 11px 15px; border-radius: 16px; line-height: 1.55; font-size: 13.5px; white-space: pre-wrap; word-wrap: break-word; }
.chat-user { align-self: flex-end; background: var(--accent-dim); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-bottom-right-radius: 5px; }
.chat-ai { align-self: flex-start; background: var(--panel-strong); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-input-row { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-input-row .in { flex: 1; }
@media (max-width: 700px) {
  .chat-wrap { height: calc(100dvh - var(--bottom-nav-h) - 170px); }
  .chat-msg { max-width: 92%; }
}

/* ============ responsivo geral ============ */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .bottom-nav { display: grid; }
  .fab { display: flex; align-items: center; justify-content: center; }
  .topbar { padding: calc(11px + var(--safe-t)) 16px 11px; }
  .topbar .brand-mini { display: flex; }
  .topbar-title { font-size: 17px; }
  .content { padding: 14px 14px calc(var(--bottom-nav-h) + var(--safe-b) + 26px); }
  .toolbar { padding: 10px 12px; }
  .toolbar .fld { min-width: calc(50% - 10px); }
}
@media (max-width: 700px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.auto { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 18px; }
  .card { padding: 14px 15px; }
}
@media (max-width: 420px) {
  html, body { font-size: 14px; }
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 38%, transparent); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 55%, transparent); }
::-webkit-scrollbar-track { background: transparent; }

/* seleção de texto e foco por teclado coerentes com o tema */
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, .nav-item:focus-visible, .bnav-item:focus-visible { outline-offset: 1px; }


/* ícones SVG monocromáticos */
.icon-svg { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-svg svg { display: block; }

/* modo claro: input com fundo cinza claro em vez de branco duro sobre branco */
:root[data-theme="light"] .in { background: var(--panel-raise); }
:root[data-theme="light"] .in:focus { background: #fff; }


/* ============ sidebar retrátil (hambúrguer no topbar) ============ */
.sidebar-toggle { font-size: 17px; min-height: 34px; padding: 4px 10px; }
.sidebar { transition: width 0.18s ease, flex-basis 0.18s ease; }
html[data-sidebar="mini"] .sidebar { width: 64px; flex: 0 0 64px; }
html[data-sidebar="mini"] .brand { justify-content: center; padding: calc(18px + var(--safe-t)) 8px 10px; }
html[data-sidebar="mini"] .brand > div { display: none; }
html[data-sidebar="mini"] .nav-item { justify-content: center; padding: 10px 0; gap: 0; }
html[data-sidebar="mini"] .nav-label { display: none; }
html[data-sidebar="mini"] .sidebar-foot { display: none; }
@media (max-width: 860px) {
  .sidebar-toggle { display: none; }
}

/* ============ ajustes finos de celular ============
   Vieram de uso real no S23: modal cortado, contagem de lançamentos
   estourando a linha e o chat espremido. */
@media (max-width: 700px) {
  /* modal vira folha: precisa caber com o teclado aberto e rolar por dentro */
  .modal-box, .modal-box.modal-wide { max-height: 88dvh; }
  .modal-head { padding: 13px 14px; font-size: 15px; }
  .modal-body { padding: 14px 13px; }
  .modal-actions { padding: 12px 13px calc(12px + var(--safe-b)); gap: 8px; }
  .modal-actions .btn { flex: 1; min-height: 44px; }   /* alvo de toque */

  /* grades de 4 colunas dentro de modal viravam tiras ilegíveis */
  .modal-body .grid.cols-4, .modal-body .grid.cols-3 { grid-template-columns: 1fr 1fr; }
  .modal-body .form-grid { grid-template-columns: 1fr; }

  /* tabela dentro de modal: rola sozinha em vez de espremer a coluna */
  .modal-body .table-wrap { max-height: 46dvh; overflow: auto; }

  /* linha de contagem dos Lançamentos estourava a largura */
  .count-line { display: flex; flex-wrap: wrap; gap: 4px 10px; line-height: 1.5; }

  /* barra de filtros: dois campos por linha em vez de um por linha */
  .toolbar .fld { min-width: calc(50% - 6px); flex: 1 1 calc(50% - 6px); }
  .toolbar .btn { flex: 1 1 auto; min-height: 40px; }

  /* chat: bolhas mais largas e input fixo confortável */
  .chat-msg { max-width: 94%; font-size: 14px; }
  .chat-input-row { gap: 6px; padding-bottom: calc(6px + var(--safe-b)); }
  .chat-input-row .btn { min-width: 52px; min-height: 44px; }
  .chat-wrap { height: calc(100dvh - var(--bottom-nav-h) - 210px); }
  /* abas de atalho do chat roláveis lado a lado, sem quebrar linha */
  .chat-actions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .chat-actions .btn { flex: 0 0 auto; }
}

/* Modal que passava do rodapé no celular (botões Salvar/Excluir fora da tela):
   num flex column, o filho rolável NÃO encolhe abaixo do conteúdo sem
   min-height:0 — então o box crescia além do max-height e empurrava as ações
   para fora. Vale para qualquer altura de tela, não só celular. */
.modal-box { max-height: 88vh; max-height: 88dvh; min-height: 0; }
.modal-body { min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }
.modal-head, .modal-actions { flex: 0 0 auto; }
@media (max-width: 700px) {
  .modal-box, .modal-box.modal-wide { max-height: 90vh; max-height: 90dvh; }
}

/* O overlay usava inset:0 (viewport de LAYOUT) e o box max-height em dvh
   (viewport VISÍVEL). No celular os dois diferem — a barra do Chrome e a de
   gestos ficam por cima — e as ações do modal (Salvar/Excluir) caíam atrás
   delas. Fixando a altura do overlay em dvh, o fundo do modal passa a ser o
   fundo do que se enxerga. */
.modal-overlay { height: 100dvh; align-items: center; }
@media (max-width: 700px) {
  /* folga para os botoes nunca encostarem na barra de gestos */
  .modal-overlay { align-items: flex-end; padding-bottom: calc(var(--safe-b) + 8px); }
  /* e o topo nunca entra embaixo da barra de status do iPhone (app instalado) */
  .modal-box, .modal-box.modal-wide { max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 12px); }
}

/* ============ simulador ============ */
.sim-range { width: 100%; margin-top: 10px; accent-color: var(--accent); }
.sim-necessario { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; }
.sim-meta { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
.sim-gastos { display: flex; flex-direction: column; gap: 8px; }
.sim-gasto {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 0.8fr) auto;
  gap: 8px; align-items: end;
}
.sim-gasto-x { min-height: 38px; }
.sim-calc { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.sim-calc > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.sim-calc-saida { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 700px) {
  .sim-gasto { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .sim-gasto .fld:first-child { grid-column: 1 / -1; }
}
.sim-aviso { margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--accent-dim); color: var(--text); }
.sim-tabela th, .sim-tabela td { padding: 8px 9px; }
.sim-premissas > summary { list-style: none; }
.sim-premissas > summary::-webkit-details-marker { display: none; }
.sim-premissas > summary::after { content: " ▸"; }
.sim-premissas[open] > summary::after { content: " ▾"; }
.sim-premissas-corpo { margin-top: 14px; }
.sim-lista { display: flex; flex-direction: column; gap: 4px; }
.sim-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 7px 10px; border-radius: var(--radius-sm); background: var(--panel-raise); cursor: pointer;
}
.sim-item-rotulo { min-width: 0; overflow-wrap: anywhere; }
.sim-cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 22px; }
@media (max-width: 700px) {
  .sim-cats { grid-template-columns: 1fr; }
  .sim-emprestimo { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ============ a receber de terceiros (Contas a Vencer) ============ */
.terc-pessoa {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.terc-nome { font-weight: 650; }
.terc-valores { font-variant-numeric: tabular-nums; }
.terc-detalhe { padding: 0 0 12px; }
.sim-terceiro { grid-template-columns: auto 1fr minmax(0, 220px); }
.sim-terceiro select { font-size: 12.5px; }
@media (max-width: 700px) { .sim-terceiro { grid-template-columns: auto 1fr; } .sim-terceiro select { grid-column: 1 / -1; } }

/* Acertos */
.acertos { display: grid; gap: 18px; max-width: 1040px; }
.acerto-topo, .acerto-acoes { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.acerto-topo { justify-content: space-between; }
.acerto-topo .fld { width: min(100%, 320px); min-width: 0; }
.acerto-resumo {
  display: grid; grid-template-columns: 1fr 1fr 1.2fr; margin: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.acerto-resumo-item { min-width: 0; padding: 18px 20px; }
.acerto-resumo-item + .acerto-resumo-item { border-inline-start: 1px solid var(--line); }
.acerto-resumo-item dt { color: var(--muted); font-weight: 600; font-size: 13px; }
.acerto-resumo-item dd {
  margin: 5px 0 0; font-size: clamp(19px, 2.6vw, 29px); font-weight: 710;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.acerto-resumo-final { background: var(--panel-raise); }
.acerto-secao { padding: 16px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.acerto-secao h2 { margin: 0; font-size: 16px; }
.acerto-secao p { margin: 5px 0 12px; }
.acerto-parcelas summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; }
.acerto-parcelas summary::before { content: "▸"; color: var(--muted); }
.acerto-parcelas[open] summary::before { content: "▾"; }
.acerto-parcelas summary span:first-child { flex: 1; font-weight: 650; }
.acerto-parcelas .acerto-lista { margin-top: 12px; }
.acerto-lista { list-style: none; padding: 0; margin: 0; }
.acerto-linha {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center;
  gap: 10px 18px; border-top: 1px solid var(--line); padding: 11px 0;
}
.acerto-linha > div { overflow-wrap: anywhere; }
.acerto-linha .small { line-height: 1.4; }
.acerto-valor { text-align: right; font-weight: 660; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acerto-form { display: grid; gap: 12px; }
.acerto-form-par { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 600px) {
  .acerto-topo .fld { width: 100%; }
  .acerto-acoes { width: 100%; }
  .acerto-acoes .btn { flex: 1; min-height: 44px; }
  .acerto-resumo { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .acerto-resumo-item, .acerto-secao { padding: 12px 14px; }
  .acerto-resumo .acerto-resumo-final { grid-column: 1 / -1; border-inline-start: 0; border-top: 1px solid var(--line); }
  .acerto-linha { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
  .acerto-linha .btn { grid-column: 2; justify-self: end; min-height: 40px; }
}
