/* ==========================================================================
   Finanças da Família — tema indigo/violeta (primário), esmeralda (receita),
   rosa (despesa). Mobile-first, PWA. Fonte Poppins auto-hospedada.
   ========================================================================== */
:root {
  --primary: #6366f1;      /* indigo */
  --primary-dark: #4f46e5;
  --violet: #a855f7;
  --ink: #1e1b4b;          /* indigo escuríssimo (superfícies escuras) */
  --ink-2: #312e81;
  --bg: #f5f4fb;           /* fundo levemente lilás */
  --surface: #ffffff;
  --line: #e7e5f2;
  --text: #201d3a;
  --text-2: #4b4870;
  --text-3: #6f6c92;
  --green: #16a34a;        /* receita */
  --green-bg: #e8f7ee;
  --red: #e11d48;          /* despesa (rosa-vermelho) */
  --red-bg: #fdeaf0;
  --amber: #d97706;
  --amber-bg: #fdf0dc;
  --radius: 16px;
  --radius-lg: 26px;
  --shadow: 0 1px 2px rgba(30,27,75,.05), 0 8px 24px rgba(30,27,75,.06);
  --shadow-lg: 0 12px 40px rgba(49,46,129,.16);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }
.tabnum { font-variant-numeric: tabular-nums; }

/* ---------------- LOGIN ---------------- */
.tela-login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #312e81 0%, #1e1b4b 55%, #12103a 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--radius-lg); padding: 34px 26px 28px; box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: grid; place-items: center; font-size: 34px; box-shadow: 0 8px 22px rgba(99,102,241,.4);
}
.login-card h1 { font-size: 22px; font-weight: 800; color: var(--ink); letter-spacing: -.02em; }
.login-sub { color: var(--text-3); font-size: 13.5px; margin: 4px 0 22px; }
#form-login { display: grid; gap: 14px; text-align: left; }
#form-login label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
#form-login input {
  padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fbfbfe;
  transition: border-color .15s, box-shadow .15s;
}
#form-login input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.erro { color: var(--red); font-size: 13px; text-align: center; }

.btn-primary {
  padding: 14px; border-radius: 13px; font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 6px 18px rgba(79,70,229,.32); transition: transform .1s, opacity .15s;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; }

/* ---------------- TOPBAR ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  background: linear-gradient(135deg, #312e81, #1e1b4b);
  color: #fff; box-shadow: 0 4px 18px rgba(30,27,75,.28);
}
.topbar-menu { font-size: 22px; color: #fff; width: 38px; height: 38px; border-radius: 11px; }
.topbar-menu:active { background: rgba(255,255,255,.12); }
.topbar-eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #c7d2fe; }
.topbar-titulos h2 { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }

/* ---------------- LAYOUT ---------------- */
main { padding: 16px 16px calc(112px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
.section-titulo { font-size: 13px; font-weight: 700; color: var(--text-2); margin: 22px 4px 10px; text-transform: uppercase; letter-spacing: .04em; }
.section-titulo:first-child { margin-top: 6px; }

/* seletor de mês */
.mes-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface); border-radius: 14px; padding: 6px; box-shadow: var(--shadow); margin-bottom: 14px; }
.mes-nav button { width: 40px; height: 36px; border-radius: 10px; font-size: 18px; color: var(--primary); font-weight: 700; }
.mes-nav button:active { background: #eef0fe; }
.mes-nav .mes-label { font-weight: 700; color: var(--ink); text-transform: capitalize; }

/* ---------------- CARDS ---------------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }

/* card de saldo (herói) */
.saldo-hero {
  background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 55%, #7c3aed 100%);
  color: #fff; border-radius: var(--radius-lg); padding: 22px 20px; box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
}
.saldo-hero::after { content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.08); }
.saldo-hero .rotulo { font-size: 12.5px; color: #d5d3f7; font-weight: 600; }
.saldo-hero .valor { font-size: 33px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.saldo-hero .contas-dots { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.saldo-hero .dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: rgba(255,255,255,.14); padding: 5px 10px; border-radius: 20px; }
.saldo-hero .dot i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* fluxo do mês (2 colunas) */
.fluxo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.fluxo-cel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.fluxo-cel .rot { font-size: 12px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.fluxo-cel .num { font-size: 20px; font-weight: 800; margin-top: 4px; letter-spacing: -.01em; }
.num.receita, .txt-receita { color: var(--green); }
.num.despesa, .txt-despesa { color: var(--red); }

/* ---------------- LISTAS / ITENS ---------------- */
.lista { display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.item .ava {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 20px; background: #eef0fe;
}
.item .corpo { flex: 1; min-width: 0; }
.item .titulo { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; }
.item .direita { text-align: right; flex-shrink: 0; }
.item .valor { font-weight: 800; font-size: 15px; white-space: nowrap; }
.item .quando { font-size: 11px; color: var(--text-3); }
.item.tap:active { background: #fafaff; }

.pill { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.pill-membro { background: #eef0fe; color: var(--primary-dark); }
.pill-atraso { background: var(--red-bg); color: var(--red); }
.pill-aberto { background: var(--amber-bg); color: var(--amber); }
.chip-conta { display: inline-flex; align-items: center; gap: 5px; }
.chip-conta i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------------- ORÇAMENTO ---------------- */
.orc-total { display: grid; gap: 4px; }
.orc-total .barra-wrap { margin-top: 6px; }
.barra-wrap { height: 8px; background: #eceaf6; border-radius: 20px; overflow: hidden; }
.barra { height: 100%; border-radius: 20px; transition: width .4s ease; }
.orc-item { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 13px 14px; }
.orc-item + .orc-item { margin-top: 8px; }
.orc-item .linha1 { display: flex; align-items: center; gap: 10px; }
.orc-item .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; }
.orc-item .nome { font-weight: 600; flex: 1; }
.orc-item .frac { font-size: 12.5px; color: var(--text-3); font-weight: 600; text-align: right; }
.orc-item .frac b { color: var(--text); }
.orc-item .barra-wrap { margin-top: 9px; }
.orc-alerta { color: var(--red) !important; }

/* ---------------- KPI ---------------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.kpi-rot { font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.kpi-val { font-size: 19px; font-weight: 800; margin-top: 5px; letter-spacing: -.01em; white-space: nowrap; }
.kpi-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ---------------- CONTAS ---------------- */
.conta-card { display: flex; align-items: center; gap: 13px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.conta-card + .conta-card { margin-top: 8px; }
.conta-card .marca { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px; flex-shrink: 0; }
.conta-card .nome { font-weight: 700; }
.conta-card .tipo { font-size: 12px; color: var(--text-3); text-transform: capitalize; }
.conta-card .saldo { text-align: right; font-weight: 800; }
.conta-card .saldo-col { margin-left: auto; text-align: right; }
.conta-card .saldo-conv { font-size: 11.5px; color: var(--text-3); font-weight: 600; margin-top: 2px; white-space: nowrap; }

/* ---------------- FORMULÁRIOS / MODAL ---------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal::before { content: ''; position: absolute; inset: 0; background: rgba(20,18,50,.5); backdrop-filter: blur(2px); }
.modal-sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 26px 26px 0 0; padding: 10px 20px calc(28px + var(--safe-b));
  box-shadow: var(--shadow-lg); animation: sobe .28s cubic-bezier(.16,1,.3,1);
}
@keyframes sobe { from { transform: translateY(30px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-grip { width: 42px; height: 5px; background: #dcdaec; border-radius: 10px; margin: 4px auto 14px; }
.modal h3 { font-size: 18px; font-weight: 800; color: var(--ink); margin-bottom: 4px; }
.modal .modal-sub { color: var(--text-3); font-size: 13px; margin-bottom: 16px; }

.form-grid { display: grid; gap: 14px; }
.form-grid label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 12px 13px; border: 1.5px solid var(--line); border-radius: 12px; background: #fbfbfe; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* toggle receita/despesa */
.tipo-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tipo-toggle button {
  padding: 12px; border-radius: 12px; font-weight: 700; border: 1.5px solid var(--line); color: var(--text-3); background: #fbfbfe;
  transition: all .15s;
}
.tipo-toggle button.on-despesa { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.tipo-toggle button.on-receita { border-color: var(--green); color: var(--green); background: var(--green-bg); }

/* seletor de categoria (grade de emojis) */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.cat-op { display: grid; gap: 4px; place-items: center; padding: 10px 4px; border-radius: 12px; border: 1.5px solid var(--line); background: #fbfbfe; font-size: 10.5px; color: var(--text-2); text-align: center; }
.cat-op .em { font-size: 20px; }
.cat-op.sel { border-color: var(--primary); background: #eef0fe; color: var(--primary-dark); font-weight: 600; }
.cat-op span { line-height: 1.1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* seletor de membro (pílulas) */
.membro-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.membro-pills button { padding: 9px 15px; border-radius: 20px; border: 1.5px solid var(--line); background: #fbfbfe; font-weight: 600; color: var(--text-2); display: inline-flex; align-items: center; gap: 7px; }
.membro-pills button i { width: 12px; height: 12px; border-radius: 50%; }
.membro-pills button.sel { border-color: var(--primary); background: #eef0fe; color: var(--primary-dark); }

.btn-bloco { display: grid; gap: 10px; margin-top: 20px; }
.btn-secondary { padding: 13px; border-radius: 12px; font-weight: 700; color: var(--text-2); background: #f0effa; }
.btn-danger { padding: 13px; border-radius: 12px; font-weight: 700; color: var(--red); background: var(--red-bg); }
.btn-ghost { padding: 11px; border-radius: 12px; font-weight: 600; color: var(--text-3); }

/* input de valor grande */
.valor-input { position: relative; }
.valor-input .cifrao { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 700; color: var(--text-3); font-size: 20px; }
.valor-input input { font-size: 26px !important; font-weight: 800; padding-left: 40px !important; letter-spacing: -.01em; }

/* ---------------- FAB + BOTTOM NAV ---------------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(38px + var(--safe-b)); z-index: 45;
  width: 60px; height: 60px; border-radius: 50%; font-size: 30px; font-weight: 300; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  box-shadow: 0 8px 22px rgba(124,58,237,.45); display: grid; place-items: center;
  transition: transform .12s;
}
.fab:active { transform: translateX(-50%) scale(.94); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); box-shadow: 0 -4px 20px rgba(30,27,75,.06);
}
.bottomnav button { display: grid; place-items: center; gap: 2px; padding: 9px 0 7px; font-size: 10.5px; font-weight: 600; color: var(--text-3); }
.bottomnav button .ico { font-size: 19px; line-height: 1; }
.bottomnav button.ativo { color: var(--primary); }
.nav-fab-spacer { pointer-events: none; }

/* ---------------- SIDEBAR ---------------- */
.sidebar { position: fixed; inset: 0; z-index: 70; }
.sidebar-bg { position: absolute; inset: 0; background: rgba(20,18,50,.5); backdrop-filter: blur(2px); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sidebar-panel {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(82vw, 320px);
  background: linear-gradient(180deg, #312e81 0%, #1e1b4b 100%); color: #fff;
  display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top,0px) + 22px) 18px 22px;
  box-shadow: var(--shadow-lg); animation: entra .26s cubic-bezier(.16,1,.3,1);
}
@keyframes entra { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.sidebar-top { display: flex; align-items: center; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar-logo { width: 50px; height: 50px; border-radius: 15px; background: linear-gradient(135deg, var(--primary), var(--violet)); display: grid; place-items: center; font-size: 22px; font-weight: 800; }
.sidebar-nome { font-weight: 700; font-size: 16px; }
.sidebar-papel { font-size: 12px; color: #b5b2e8; }
.sidebar-nav { display: grid; gap: 3px; margin-top: 16px; flex: 1; }
.sidebar-nav button { display: flex; align-items: center; gap: 13px; padding: 13px 14px; border-radius: 12px; color: #dcdafd; font-weight: 600; font-size: 14.5px; text-align: left; }
.sidebar-nav button .ico { font-size: 18px; width: 22px; text-align: center; }
.sidebar-nav button:active { background: rgba(255,255,255,.1); }
.sidebar-nav button.ativo { background: rgba(255,255,255,.14); color: #fff; position: relative; }
.sidebar-nav button.ativo::before { content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--violet); }
.sidebar-rodape { border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.sidebar-sair { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: #fca5c4; font-weight: 700; width: 100%; }
.sidebar-versao { font-size: 11px; color: #8582c4; margin-top: 8px; text-align: center; }

/* ---------------- ESTADO VAZIO ---------------- */
.vazio { text-align: center; padding: 40px 20px; color: var(--text-3); }
.vazio .em { font-size: 44px; display: block; margin-bottom: 10px; }
.vazio p { font-size: 14px; }
.vazio .dica { font-size: 12.5px; margin-top: 4px; }

/* ---------------- TOAST / OFFLINE ---------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(110px + var(--safe-b)); z-index: 90;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); max-width: 88vw; text-align: center;
  animation: sobe .25s;
}
.toast.erro { background: var(--red); }
.offline-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 100; background: var(--amber); color: #fff; text-align: center; font-size: 12.5px; font-weight: 600; padding: 6px; }

/* skeleton de carregamento */
.skel { background: linear-gradient(90deg, #eeecf8 25%, #f6f5fc 50%, #eeecf8 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* util */
.spacer-8 { height: 8px; }
.linha-add { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px; border-radius: 13px; border: 1.5px dashed var(--line); color: var(--primary); font-weight: 700; width: 100%; background: transparent; }
.linha-add:active { background: #eef0fe; }
