:root {
  --pfa-primary: #2f6f4f;
  --pfa-primary-dark: #22543d;
  --pfa-primary-light: #e8f3ec;
  --pfa-danger: #c0392b;
  --pfa-warning: #d68910;
  --pfa-success: #219653;
  --pfa-bg: #f4f6f5;
  --pfa-surface: #ffffff;
  --pfa-text: #1f2a24;
  --pfa-text-muted: #6b7a72;
  --pfa-border: #e3e8e5;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(16, 40, 30, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 40, 30, 0.08);
}

html.dark-mode,
body.dark-mode {
  --pfa-bg: #17211c;
  --pfa-surface: #223029;
  --pfa-text: #edf5ef;
  --pfa-text-muted: #a9b9ae;
  --pfa-border: #3b4b42;
  --pfa-primary-light: #2e4939;
}

.pfa-preferences {
  padding: 10px 8px 14px;
  border-bottom: 1px solid var(--pfa-border);
  margin-bottom: 12px;
}

.pfa-preferences label {
  color: var(--pfa-text-muted);
  font-size: .75rem;
  margin-bottom: 4px;
}

html.dark-mode body {
  background-color: var(--pfa-bg) !important;
  color: var(--pfa-text) !important;
}

html.dark-mode .sidebar,
html.dark-mode .pfa-card,
html.dark-mode .modal-content,
html.dark-mode .modal-header,
html.dark-mode .modal-footer {
  background-color: var(--pfa-surface);
  color: var(--pfa-text);
  border-color: var(--pfa-border);
}

html.dark-mode .form-control,
html.dark-mode .form-select,
html.dark-mode .modal-content {
  background-color: var(--pfa-surface);
  color: var(--pfa-text);
  border-color: var(--pfa-border);
}

html.dark-mode .btn-outline-pfa {
  background: var(--pfa-surface);
  color: var(--pfa-text);
}

html.dark-mode .table {
  --bs-table-color: var(--pfa-text);
  --bs-table-bg: var(--pfa-surface);
  --bs-table-border-color: var(--pfa-border);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  overflow-x: hidden;
}

body {
  background-color: var(--pfa-bg);
  color: var(--pfa-text);
  font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

a {
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled),
a {
  cursor: pointer;
}

/* ---------- Layout de autenticação ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--pfa-primary-dark), var(--pfa-primary) 60%, #3f8a63);
  padding: 24px;
}

.auth-card {
  background: var(--pfa-surface);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
}

.auth-card .form-control:focus,
.auth-card .form-select:focus {
  border-color: var(--pfa-primary);
  box-shadow: 0 0 0 .2rem rgba(47, 111, 79, .15);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.auth-brand .icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--pfa-primary-light);
  color: var(--pfa-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.brand-mark {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.auth-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--pfa-primary-dark);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--pfa-bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}

.auth-tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--pfa-text-muted);
  transition: all .15s ease;
}

.auth-tabs button.active {
  background: var(--pfa-surface);
  color: var(--pfa-primary-dark);
  box-shadow: var(--shadow-sm);
}

/* ---------- App shell (sidebar + conteúdo) ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--pfa-surface);
  border-right: 1px solid var(--pfa-border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--pfa-border);
}

.sidebar-brand .icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--pfa-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-brand span {
  font-weight: 700;
  color: var(--pfa-primary-dark);
  font-size: 1.05rem;
  line-height: 1.1;
}

.nav-link-pfa {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--pfa-text-muted);
  font-weight: 500;
  margin-bottom: 4px;
  transition: all .15s ease;
}

.nav-link-pfa i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.nav-link-pfa:hover {
  background: var(--pfa-primary-light);
  color: var(--pfa-primary-dark);
}

.nav-link-pfa.active {
  background: var(--pfa-primary);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--pfa-border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}

.user-chip:focus-visible {
  outline: 3px solid rgba(47, 111, 79, .25);
  outline-offset: 2px;
}

.user-chip .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--pfa-primary-light);
  color: var(--pfa-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.user-chip .name {
  font-size: .85rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.user-chip .email {
  font-size: .72rem;
  color: var(--pfa-text-muted);
  margin: 0;
}

.main-content {
  flex: 1;
  padding: 28px 32px 60px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h2 {
  font-weight: 700;
  margin: 0;
  color: var(--pfa-primary-dark);
}

.topbar p {
  margin: 2px 0 0;
  color: var(--pfa-text-muted);
  font-size: .9rem;
}

/* ---------- Cards ---------- */
.pfa-card {
  background: var(--pfa-surface);
  border-radius: var(--radius);
  border: 1px solid var(--pfa-border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.stat-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-height: 112px;
  overflow: hidden;
}

.savings-card {
  height: 112px;
  min-height: 112px;
}

.savings-card .label {
  line-height: 1.05;
}

.stat-card>div:first-child {
  min-width: 0;
  flex: none;
  width: 100%;
}

.stat-card .label {
  color: var(--pfa-text-muted);
  font-size: .82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.55rem;
  font-weight: 700;
  margin: 0;
  min-width: 0;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  line-height: 1.15;
}

.stat-card .icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  position: absolute;
  top: 16px;
  right: 16px;
}

.stat-card .value {
  margin-top: 16px;
  overflow: visible;
}

.icon-wrap.saldo {
  background: #e8f0fe;
  color: #1a56db;
}

.icon-wrap.receita {
  background: #e6f7ee;
  color: var(--pfa-success);
}

.icon-wrap.despesa {
  background: #fdecea;
  color: var(--pfa-danger);
}

.icon-wrap.poupanca {
  background: #fff4e0;
  color: var(--pfa-warning);
}

.balance-trigger {
  border: 0;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}

.balance-trigger:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.balance-trigger:focus-visible {
  outline: 3px solid rgba(26, 86, 219, .25);
  outline-offset: 3px;
}

.stat-trigger {
  border: 0;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}

.stat-trigger:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.stat-trigger:focus-visible {
  outline: 3px solid rgba(47, 111, 79, .25);
  outline-offset: 3px;
}

.section-title {
  font-weight: 700;
  color: var(--pfa-primary-dark);
  margin-bottom: 16px;
  font-size: 1.05rem;
}

.insight-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 10px;
  font-size: .88rem;
  align-items: flex-start;
}

.insight-item i {
  font-size: 1.1rem;
  margin-top: 1px;
}

.insight-item.success {
  background: #e6f7ee;
  color: #1c6b45;
}

.insight-item.warning {
  background: #fff4e0;
  color: #92620a;
}

.insight-item.danger {
  background: #fdecea;
  color: #922016;
}

.insight-item.info {
  background: #eaf1fb;
  color: #1a4a8a;
}

.transaction-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--pfa-border);
  gap: 10px;
}

.transaction-row:last-child {
  border-bottom: none;
}

.cat-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 1rem;
}

.amount-receita {
  color: var(--pfa-success);
  font-weight: 700;
}

.amount-despesa {
  color: var(--pfa-danger);
  font-weight: 700;
}

.badge-pfa {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}

.btn-pfa-primary {
  background: var(--pfa-primary);
  border-color: var(--pfa-primary);
  color: #fff;
  font-weight: 600;
}

.btn-pfa-primary:focus-visible,
.btn-outline-pfa:focus-visible,
.auth-tabs button:focus-visible,
.nav-link-pfa:focus-visible {
  outline: 3px solid rgba(47, 111, 79, .25);
  outline-offset: 2px;
}

.btn-pfa-primary:disabled {
  opacity: .7;
  cursor: wait;
}

.btn-pfa-primary:hover {
  background: var(--pfa-primary-dark);
  border-color: var(--pfa-primary-dark);
  color: #fff;
}

.btn-outline-pfa {
  border: 1px solid var(--pfa-border);
  color: var(--pfa-text);
  font-weight: 500;
  background: #fff;
}

.btn-outline-pfa:hover {
  background: var(--pfa-bg);
}

.table-pfa thead th {
  color: var(--pfa-text-muted);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 700;
  border-bottom: 2px solid var(--pfa-border);
  padding: 10px 12px;
}

.table-pfa tbody td {
  padding: 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--pfa-border);
}

.table-pfa tbody tr:hover {
  background: var(--pfa-bg);
}

.table-pfa {
  min-width: 620px;
}

.progress-pfa {
  height: 10px;
  border-radius: 20px;
  background: var(--pfa-bg);
  overflow: hidden;
}

.progress-pfa .bar {
  height: 100%;
  border-radius: 20px;
  transition: width .3s ease;
}

.goal-card {
  border-left: 4px solid var(--pfa-primary);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--pfa-text-muted);
}

.empty-state i {
  font-size: 2.2rem;
  margin-bottom: 10px;
  display: block;
  color: var(--pfa-border);
}

.mobile-topbar {
  display: none;
}

@media (max-width: 991px) {
  .sidebar {
    position: fixed;
    left: -260px;
    z-index: 1050;
    transition: left .2s ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.open {
    left: 0;
  }

  .main-content {
    padding: 18px 16px 50px;
    width: 100%;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 1040;
  }

  .sidebar-backdrop.open {
    display: block;
  }
}

@media (max-width: 575px) {
  .auth-page {
    padding: 16px;
  }

  .auth-card {
    padding: 28px 20px;
  }

  .topbar h2 {
    font-size: 1.35rem;
  }

  .topbar .btn {
    width: 100%;
  }

  .topbar {
    align-items: stretch;
  }

  .pfa-card {
    padding: 16px;
  }

  .stat-card .value {
    font-size: 1.25rem;
  }
}

.toast-pfa {
  min-width: 280px;
}