:root {
  --bg: #0f1512;
  --bg-card: #161f1a;
  --bg-card-hover: #1c2620;
  --mint: #3ddc97;
  --mint-soft: rgba(61, 220, 151, 0.15);
  --red: #ff5c5c;
  --yellow: #ffc857;
  --text: #ffffff;
  --text-muted: #9aa39d;
  --border: rgba(255, 255, 255, 0.06);
  --glass-bg: rgba(22, 31, 26, 0.6);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

img, svg { max-width: 100%; }

.mono { font-family: 'JetBrains Mono', monospace; }

/* ---------- Auth (login/cadastro) ---------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
}

.auth-logo {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 4px;
}
.auth-logo span { color: var(--mint); }

.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  background: #0c130f;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--mint); }

.btn-primary {
  width: 100%;
  background: var(--mint);
  color: #06110c;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--mint);
  border: 1px solid var(--mint-soft);
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}
.auth-toggle a { color: var(--mint); text-decoration: none; font-weight: 600; }

.error-msg {
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.3);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ---------- App shell ---------- */
.app-shell { max-width: 480px; margin: 0 auto; padding: 20px 16px 110px; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.topbar-greeting { font-size: 15px; color: var(--text-muted); }
.topbar-greeting strong { color: var(--text); }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
}
.icon-btn .dot {
  position: absolute; top: 8px; right: 9px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
}

/* Gauge circular */
.gauge-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}
.gauge-wrap { position: relative; width: 110px; height: 110px; flex-shrink: 0; }
.gauge-wrap svg { transform: rotate(-90deg); }
.gauge-bg { fill: none; stroke: var(--border); stroke-width: 10; }
.gauge-fg { fill: none; stroke: var(--mint); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray 0.6s ease; }
.gauge-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge-label .pct { font-size: 20px; font-weight: 700; }
.gauge-label .txt { font-size: 10px; color: var(--text-muted); }

.gauge-info .status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  margin-bottom: 8px;
}
.status.verde { background: rgba(61,220,151,0.15); color: var(--mint); }
.status.amarelo { background: rgba(255,200,87,0.15); color: var(--yellow); }
.status.vermelho { background: rgba(255,92,92,0.15); color: var(--red); }
.status .bolinha { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.gauge-info .valor { font-size: 22px; font-weight: 700; }
.gauge-info .sub { font-size: 12px; color: var(--text-muted); }

/* Seções / listas */
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  margin: 22px 0 12px;
  font-size: 15px; font-weight: 700;
}
.section-title a { font-size: 13px; color: var(--mint); text-decoration: none; font-weight: 600; }

.card-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.card-item:hover { background: var(--bg-card-hover); }
.card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--mint-soft); color: var(--mint);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.card-info { flex: 1; min-width: 0; }
.card-info .nome { font-weight: 600; font-size: 14.5px; }
.card-info .detalhe { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.card-valor { text-align: right; }
.card-valor .num { font-weight: 700; font-size: 15px; }
.card-valor.negativo .num { color: var(--red); }
.card-valor.positivo .num { color: var(--mint); }

/* Lançamentos */
.lancamento {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.lancamento:last-child { border-bottom: none; }
.lancamento .cat-tag {
  font-size: 11px; color: var(--text-muted); background: rgba(255,255,255,0.04);
  padding: 2px 8px; border-radius: 8px; margin-top: 2px; display: inline-block;
}
.lancamento .desc { font-weight: 600; font-size: 14px; }
.lancamento .valor { font-weight: 700; font-size: 14.5px; margin-left: auto; }
.lancamento .valor.positivo { color: var(--mint); }
.lancamento .valor.negativo { color: var(--red); }
.lancamento .valor.riscado { text-decoration: line-through; opacity: 0.5; }

/* Navbar flutuante com glass */
.navbar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 448px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 22px;
  display: flex;
  padding: 8px;
  z-index: 50;
}
.navbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10.5px;
  border-radius: 16px;
  transition: color 0.2s, background 0.2s;
}
.navbar a.active { color: var(--mint); background: var(--mint-soft); }
.navbar a svg { width: 20px; height: 20px; }

/* FAB novo lançamento */
.fab {
  position: fixed; bottom: 92px; right: 24px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--mint); color: #06110c;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
  border: none; cursor: pointer;
  box-shadow: 0 6px 20px rgba(61,220,151,0.35);
  z-index: 51;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-overlay.aberto { display: flex; }
.modal-sheet {
  background: var(--bg-card);
  width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px 32px;
  max-height: 88vh; overflow-y: auto;
  animation: subir 0.25s ease;
}
@keyframes subir { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-header h3 { font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab-btn {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); font-weight: 600; font-size: 13px; cursor: pointer;
}
.tab-btn.active { background: var(--mint-soft); color: var(--mint); border-color: var(--mint-soft); }

.empty-state { text-align: center; color: var(--text-muted); font-size: 13.5px; padding: 24px 0; }

.back-btn {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 14px; margin-bottom: 16px;
}

.timeline-mes {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 16px;
}
.timeline-mes .mes-chip {
  flex-shrink: 0; padding: 10px 14px; border-radius: 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  text-align: center; cursor: pointer; min-width: 72px;
}
.timeline-mes .mes-chip.active { background: var(--mint-soft); border-color: var(--mint); }
.timeline-mes .mes-nome { font-size: 11px; color: var(--text-muted); }
.timeline-mes .mes-valor { font-size: 12.5px; font-weight: 700; margin-top: 2px; }

.parcela-linha {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.parcela-linha:last-child { border-bottom: none; }
.parcela-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--mint); flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.parcela-check.marcada { background: var(--mint); color: #06110c; font-size: 13px; }

.navbar-logo {
  display: none;
  font-size: 19px; font-weight: 700; color: var(--text);
}
.navbar-logo span { color: var(--mint); }

.loading { text-align: center; padding: 40px 0; color: var(--text-muted); font-size: 13px; }

/* ================= RESPONSIVO (mobile) ================= */
@media (max-width: 480px) {
  .app-shell {
    padding: 16px 14px 130px;
  }

  .auth-wrapper { padding: 16px; }
  .auth-card { padding: 28px 20px; max-width: 100%; }

  .topbar-greeting { font-size: 14px; }

  /* Gauge: empilha em vez de ficar espremido lado a lado */
  .gauge-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 16px;
    gap: 14px;
  }
  .gauge-info { display: flex; flex-direction: column; align-items: center; }
  .gauge-wrap { width: 96px; height: 96px; }
  .gauge-wrap svg { width: 96px; height: 96px; }
  .gauge-info .valor { font-size: 20px; }

  .section-title { font-size: 14px; margin: 18px 0 10px; }

  .card-item { padding: 13px; gap: 10px; }
  .card-icon { width: 38px; height: 38px; font-size: 13px; }
  .card-info .nome { font-size: 13.5px; }
  .card-info .detalhe { font-size: 11.5px; }
  .card-valor .num { font-size: 13.5px; }

  .lancamento .desc { font-size: 13px; }
  .lancamento .valor { font-size: 13px; }

  /* Navbar flutuante: ocupa a largura útil e reduz padding */
  .navbar {
    bottom: max(14px, env(safe-area-inset-bottom));
    width: calc(100% - 20px);
    padding: 6px;
    border-radius: 20px;
  }
  .navbar a { font-size: 9.5px; padding: 6px 0; gap: 3px; }
  .navbar a svg { width: 18px; height: 18px; }

  .fab {
    bottom: calc(78px + max(14px, env(safe-area-inset-bottom)));
    right: 16px;
    width: 52px; height: 52px; font-size: 24px;
  }

  /* Modais: ocupam a tela quase inteira, sem esmagar os campos */
  .modal-sheet {
    padding: 20px 16px 28px;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
  }
  .modal-header h3 { font-size: 16px; }
  .field input, .field select { padding: 11px 12px; font-size: 14.5px; }

  /* Tabs: permite quebrar linha em telas bem pequenas */
  .tabs { gap: 6px; }
  .tab-btn { font-size: 12px; padding: 9px 4px; }

  .timeline-mes { gap: 6px; }
  .timeline-mes .mes-chip { min-width: 62px; padding: 8px 10px; }
  .timeline-mes .mes-nome { font-size: 10px; }
  .timeline-mes .mes-valor { font-size: 11px; }

  /* Cards de saldo (empréstimo) empilham melhor */
  .gauge-card > div[style*="display:flex"] {
    flex-direction: column !important;
    gap: 10px !important;
    align-items: center !important;
  }
}

@media (max-width: 360px) {
  .gauge-wrap { width: 84px; height: 84px; }
  .gauge-wrap svg { width: 84px; height: 84px; }
  .navbar a { font-size: 9px; }
  .fab { width: 48px; height: 48px; font-size: 22px; right: 14px; }
}

/* ================= DESKTOP (notebook/PC) ================= */
@media (min-width: 901px) {
  body { display: flex; }
  .app-shell, .auth-wrapper { flex: 1; min-width: 0; }

  /* Navbar vira sidebar fixa à esquerda */
  .navbar {
    position: fixed;
    left: 0; top: 0; bottom: auto;
    transform: none;
    width: 232px; height: 100vh; max-width: none;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 4px;
    padding: 28px 14px;
    border-radius: 0;
    border-right: 1px solid var(--border);
    border-top: none; border-left: none; border-bottom: none;
    background: var(--bg-card);
    backdrop-filter: none;
  }
  .navbar-logo { display: flex; margin: 0 10px 22px; }
  .navbar a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    font-size: 14px;
    border-radius: 12px;
  }
  .navbar a svg { width: 20px; height: 20px; }

  /* Conteúdo principal desloca pra direita da sidebar só quando ela existe
     (telas de detalhe/configurações não têm navbar, então ficam centralizadas) */
  body:has(.navbar) .app-shell {
    margin-left: 232px;
  }
  .app-shell {
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 48px 60px;
  }

  .auth-wrapper { margin-left: 0; }

  body:has(.navbar) .fab {
    right: calc(50% - 440px + 24px);
  }
  .fab { bottom: 40px; }
  /* Fallback pra telas menores que 880+232+margens: mantém no canto */
  @media (max-width: 1300px) {
    body:has(.navbar) .fab { right: 32px; }
  }

  .topbar-greeting { font-size: 17px; }
  .gauge-card { padding: 28px 32px; }
  .gauge-info .valor { font-size: 26px; }

  /* Dashboard: cartões e empréstimos lado a lado */
  .dash-columns { display: flex; gap: 24px; align-items: flex-start; }
  .dash-col { flex: 1; min-width: 0; }

  /* Modais viram diálogo centralizado em vez de sheet subindo do rodapé */
  .modal-overlay { align-items: center; }
  .modal-sheet {
    max-width: 460px;
    border-radius: 20px;
    animation: aparecer 0.2s ease;
  }
  @keyframes aparecer { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

  .card-item:hover { transform: translateY(-1px); }
  .tab-btn { cursor: pointer; }
}

/* Sidebar precisa do rótulo certo (JS-free, via atributo) */
.navbar { position: fixed; }

