/* ============ Design tokens (mesmo sistema do gym-evolution) ============ */
:root {
  --bg: #000000;
  --card: #151517;
  --card-2: #1c1c1e;
  --card-3: #232326;
  --border: #26262a;
  --border-soft: #1f1f22;
  --border-hover: #48484c;
  --text: #f5f5f7;
  --muted: #98989f;
  --muted-2: #6b6b72;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --blue: #0a84ff;
  --radius: 20px;
  --radius-lg: 24px;
  --spring: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

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

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
input, select { font-family: inherit; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }

/* ============ Botões ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 18px;
  transition: transform 0.25s var(--spring), background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.btn:active { transform: scale(0.96); }

.btn-primary { background: #fff; color: #000; }
.btn-primary:hover { box-shadow: 0 6px 18px rgba(255, 255, 255, 0.15); transform: translateY(-1px); }

.btn-secondary {
  background: var(--card-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--border-hover); transform: translateY(-1px); }

.btn-danger { background: transparent; color: var(--red); border-color: var(--border); }
.btn-danger:hover { border-color: var(--red); }

.btn-sm { padding: 6px 12px; font-size: 0.75rem; }

/* ============ Login ============ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 36px 30px;
  box-shadow: var(--shadow);
  animation: pop 0.5s var(--spring);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.logo-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--green), #1fa347);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #04220d;
  margin-bottom: 18px;
}

.auth-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 24px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 16px; /* evita zoom no iOS */
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .field select:focus { border-color: var(--muted-2); }
.field input::placeholder { color: var(--muted-2); }

.auth-card .btn { width: 100%; padding: 13px; font-size: 0.95rem; margin-top: 8px; }

.auth-toggle { text-align: center; margin-top: 18px; font-size: 0.85rem; color: var(--muted); }
.auth-toggle button {
  background: none;
  border: none;
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  font-size: 0.85rem;
}

.form-error {
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.35);
  color: var(--red);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.8rem;
  margin-bottom: 14px;
  display: none;
}
.form-error.show { display: block; }

/* ============ Layout do app ============ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border-soft);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 20px;
}
.sidebar .brand .logo-mark { width: 36px; height: 36px; border-radius: 11px; margin: 0; font-size: 0.8rem; }
.sidebar .brand strong { font-size: 0.95rem; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 11px 14px;
  text-align: left;
  transition: background 0.2s, color 0.2s;
}
.nav-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-btn:hover { color: var(--text); background: var(--card); }
.nav-btn.active { color: var(--text); background: var(--card-2); border-color: var(--border-soft); font-weight: 600; }

.sidebar .spacer { flex: 1; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border-soft);
}
.user-chip .avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--card-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.user-chip .info { min-width: 0; flex: 1; }
.user-chip .info .name { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .info .mail { font-size: 0.68rem; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .logout {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  display: flex;
}
.user-chip .logout:hover { color: var(--red); background: var(--card-2); }

.main { padding: 28px 32px 80px; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 1.6rem; }
.topbar .date { color: var(--muted); font-size: 0.82rem; }

/* hamburger mobile */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  align-items: center;
  justify-content: center;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
}
.backdrop.show { display: block; }

/* ============ Cards e grids ============ */
.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.25s var(--spring), transform 0.25s var(--spring);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.stat .label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat .value { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
.stat .hint { font-size: 0.72rem; color: var(--muted-2); margin-top: 2px; }
.stat .value.pos { color: var(--green); }
.stat .value.neg { color: var(--red); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.dot.orange { background: var(--orange); }

.insight-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.records-card {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 16px 22px;
}
.record-item { display: flex; align-items: center; gap: 12px; min-width: 0; }
.record-emoji { font-size: 1.4rem; }
.record-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.record-value { font-size: 0.95rem; font-weight: 700; }
.record-value .pos { color: var(--green); }
.record-value .neg { color: var(--red); }

.goal-card { margin-bottom: 14px; }
.goal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.goal-numbers { display: flex; align-items: baseline; gap: 8px; margin: 14px 0 10px; flex-wrap: wrap; }
.goal-current { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; color: var(--green); }
.goal-of { color: var(--muted); font-size: 0.85rem; }
.goal-of strong { color: var(--text); }
.goal-pct {
  margin-left: auto;
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 3px 12px;
  font-variant-numeric: tabular-nums;
}
.goal-track { height: 12px; margin-bottom: 10px; }
.goal-msg { font-size: 0.8rem; color: var(--muted); }
.goal-msg.done { color: var(--green); font-weight: 600; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.card h3 { font-size: 0.95rem; margin-bottom: 4px; }
.card .card-sub { font-size: 0.75rem; color: var(--muted); margin-bottom: 16px; }

.chart-card { grid-column: 1 / -1; }

.legend { display: flex; gap: 16px; font-size: 0.75rem; color: var(--muted); margin-bottom: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* barras horizontais (categorias / clientes) */
.hbar-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.hbar-row .name { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; transition: width 0.6s var(--spring); }
.hbar-row .val { font-size: 0.78rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty {
  color: var(--muted-2);
  font-size: 0.82rem;
  text-align: center;
  padding: 26px 10px;
}

/* ============ Gráfico SVG ============ */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

.chart-tooltip {
  position: fixed;
  z-index: 90;
  background: var(--card-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.75rem;
  pointer-events: none;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 240px;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .tt-title { font-weight: 700; margin-bottom: 4px; text-transform: capitalize; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.chart-tooltip .tt-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ============ Filtros / pílulas ============ */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }

.pill-group { display: flex; background: var(--card); border: 1px solid var(--border-soft); border-radius: 999px; padding: 3px; }
.pill-group button {
  background: none;
  border: none;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 14px;
  transition: background 0.2s, color 0.2s;
}
.pill-group button.active { background: var(--card-3); color: var(--text); }

.month-input {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 0.8rem;
  outline: none;
  color-scheme: dark;
}

/* ============ Lista de transações ============ */
.tx-list { display: flex; flex-direction: column; gap: 8px; }

.tx-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 13px 16px;
  transition: border-color 0.2s, transform 0.25s var(--spring);
}
.tx-row:hover { border-color: var(--border-hover); }

.tx-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}
.tx-icon.income { background: rgba(48, 209, 88, 0.12); color: var(--green); }
.tx-icon.expense { background: rgba(255, 69, 58, 0.12); color: var(--red); }
.tx-icon.recv { background: rgba(255, 159, 10, 0.12); color: var(--orange); }
.tx-icon.rec { background: rgba(10, 132, 255, 0.12); color: var(--blue); }

.tag.overdue { color: var(--red); border-color: rgba(255, 69, 58, 0.35); }
.tx-row.paused { opacity: 0.45; }
.tx-row.overdue-row { border-color: rgba(255, 69, 58, 0.35); }

.tx-info { flex: 1; min-width: 0; }
.tx-info .desc { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.tag {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 2px 9px;
}
.tag.client { color: var(--blue); border-color: rgba(10, 132, 255, 0.3); }
.tx-meta .when { font-size: 0.68rem; color: var(--muted-2); }

.tx-amount { font-weight: 700; font-size: 0.92rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }

.tx-actions { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--muted-2);
  padding: 7px;
  border-radius: 9px;
  display: flex;
  transition: background 0.2s, color 0.2s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn.del:hover { color: var(--red); }

/* ============ Caixinhas ============ */
.boxes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

.box-card .box-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.box-card h3 { font-size: 1rem; }
.box-card .box-balance { font-size: 1.5rem; font-weight: 800; margin: 10px 0 2px; letter-spacing: -0.02em; }
.box-card .box-target { font-size: 0.72rem; color: var(--muted-2); margin-bottom: 12px; }

.progress-track { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), #7ce69a); transition: width 0.6s var(--spring); }

.box-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.saved-hero { display: flex; align-items: baseline; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.saved-hero .big { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; }
.saved-hero .lbl { color: var(--muted); font-size: 0.85rem; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 80;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.show { display: flex; }

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  box-shadow: var(--shadow);
  animation: slideUp 0.35s var(--spring);
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: none; }
}

.modal h2 { font-size: 1.15rem; margin-bottom: 18px; }

.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.type-switch button {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 11px;
  transition: all 0.2s;
}
.type-switch button.income.active { background: rgba(48, 209, 88, 0.14); border-color: var(--green); color: var(--green); }
.type-switch button.expense.active { background: rgba(255, 69, 58, 0.14); border-color: var(--red); color: var(--red); }

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

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; padding: 12px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 0.82rem;
  font-weight: 600;
  z-index: 100;
  transition: transform 0.35s var(--spring), opacity 0.35s;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 40px);
  opacity: 0;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============ Responsivo ============ */
@media (min-width: 641px) {
  .modal-backdrop { align-items: center; }
}

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .insight-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .insight-grid { grid-template-columns: 1fr; }
  .records-card { gap: 14px; flex-direction: column; align-items: flex-start; }
}

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: var(--card);
    z-index: 65;
    transform: translateX(-105%);
    transition: transform 0.35s var(--spring);
    border-right: 1px solid var(--border);
  }
  .sidebar.open { transform: none; }

  .menu-toggle { display: flex; }

  .main { padding: 76px 16px 60px; }
  .topbar h1 { font-size: 1.3rem; }
}

@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 1.15rem; }
  .card { padding: 16px; }
  .hbar-row { grid-template-columns: 84px 1fr auto; }
  .tx-row { padding: 11px 12px; gap: 10px; }
  .tx-icon { width: 32px; height: 32px; border-radius: 10px; }
  .field-row { grid-template-columns: 1fr; }
  .topbar .btn span.txt { display: none; }
  .filters { gap: 8px; }
  .saved-hero .big { font-size: 1.7rem; }
}
