/* =========================================================
   Componentes — cards, métricas, listas, badges, modais...
   ========================================================= */

/* ---------- Card padrão do sistema ---------- */
.app-card,
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.card { padding: var(--space-5); }
.card.flush, .card.bodyless { padding: 0; }
.card-tight { padding: var(--space-4); }

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-header-row.tight { margin-bottom: var(--space-2); }
.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.card-title i { color: var(--text-muted); margin-right: 4px; }
.card-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.card-link:hover { color: var(--color-primary-hover); text-decoration: none; }

.card .list-flush { padding: 0 var(--space-5) var(--space-4); margin: 0; list-style: none; }
.card .card-header-flush { padding: var(--space-5) var(--space-5) 0; }

/* ---------- Cards de métrica ---------- */
.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
}
.metric-card .metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.metric-card .metric-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.metric-card .metric-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--bg-hover);
  color: var(--text-muted);
  flex-shrink: 0;
}
.metric-card.primary .metric-icon { background: var(--color-primary-soft); color: var(--color-primary); }
.metric-card.success .metric-icon { background: var(--color-success-soft); color: var(--color-success); }
.metric-card.danger  .metric-icon { background: var(--color-danger-soft);  color: var(--color-danger); }
.metric-card.warning .metric-icon { background: var(--color-warning-soft); color: var(--color-warning); }

.metric-card .metric-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text-primary);
}
.metric-card .metric-sub { font-size: 12px; color: var(--text-muted); }

/* Ícone quadrado reutilizável (contas, metas...) */
.icon-tile {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.icon-tile.primary { background: var(--color-primary-soft); color: var(--color-primary); }

/* ---------- Botões ---------- */
.btn { border-radius: var(--radius-md); font-weight: 500; }

.btn-primary {
  --bs-btn-bg: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-color: var(--color-on-primary);
  --bs-btn-hover-bg: var(--color-primary-hover);
  --bs-btn-hover-border-color: var(--color-primary-hover);
  --bs-btn-hover-color: var(--color-on-primary);
  --bs-btn-active-bg: var(--color-primary-hover);
  --bs-btn-active-border-color: var(--color-primary-hover);
  --bs-btn-active-color: var(--color-on-primary);
  --bs-btn-disabled-bg: var(--color-primary);
  --bs-btn-disabled-border-color: var(--color-primary);
}

.btn-primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}
.btn-primary-cta:hover { background: var(--color-primary-hover); color: var(--color-on-primary); text-decoration: none; }
.btn-primary-cta:disabled { opacity: 0.7; cursor: wait; }
.btn-primary-cta i { font-size: 16px; line-height: 1; }
.btn-primary-cta.danger { background: var(--color-danger); color: var(--color-on-danger); }
.btn-primary-cta.danger:hover { filter: brightness(1.1); background: var(--color-danger); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}
.btn-ghost:hover { background: var(--bg-hover); text-decoration: none; color: var(--text-primary); }

.btn-outline-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.btn-outline-soft:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.btn-outline-soft.danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-outline-soft.success:hover { background: var(--color-success-soft); color: var(--color-success); }
.btn-outline-soft.warning:hover { background: var(--color-warning-soft); color: var(--color-warning); }

/* Spinner dentro de botões durante requisições HTMX */
.btn-loading { pointer-events: none; opacity: 0.75; }
.btn-loading .btn-label, .btn-loading > i { visibility: hidden; }
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.btn-primary-cta, .btn-ghost { position: relative; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------- Badges de status ---------- */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.badge-status { display: inline-flex; align-items: center; gap: 5px; }
.badge-status.prevista { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-status.realizada { background: var(--color-success-soft); color: var(--color-success); }
.badge-status.recorrente { background: var(--bg-hover); color: var(--text-muted); }
.badge-status.inativa { background: var(--bg-hover); color: var(--text-muted); }
.badge-status.ativa { background: var(--color-success-soft); color: var(--color-success); }
.badge-status.concluida { background: var(--color-success-soft); color: var(--color-success); }

/* ---------- Item de transação (dashboard e listagens) ---------- */
.tx-list { margin: 0; padding: 0; list-style: none; }
.tx-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--border-default);
}
.tx-item:last-child { border-bottom: 0; }
.tx-item .tx-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 16px;
  flex-shrink: 0;
}
.tx-item.receita .tx-icon { background: var(--color-success-soft); color: var(--color-success); }
.tx-item.despesa .tx-icon { background: var(--color-danger-soft); color: var(--color-danger); }
.tx-item .tx-meta { flex: 1 1 auto; min-width: 0; }
.tx-item .tx-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}
.tx-item .tx-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tx-item .tx-value {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: right;
  white-space: nowrap;
}
.tx-item .sub-actions {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 2px;
}

/* ---------- Linha de entidade (categorias) ---------- */
.entity-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 0;
  border-bottom: 1px solid var(--border-default);
}
.entity-row:last-child { border-bottom: 0; }
.entity-row .entity-name { font-size: 14px; color: var(--text-primary); }
.entity-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ---------- Estado vazio ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-5) var(--space-4);
  max-height: 180px;
  gap: 4px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 18px;
  margin-bottom: 4px;
}
.empty-state .empty-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.empty-state .empty-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; max-width: 320px; }

/* ---------- Chip de mês ---------- */
.month-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  min-height: 40px;
}
.month-chip i { color: var(--text-muted); }

/* ---------- Paginação ---------- */
.pagination { gap: 2px; }
.pagination .page-link {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-secondary);
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 13px;
}
.pagination .page-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.pagination .page-item.active .page-link,
.pagination .page-item.active .page-link:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}
.pagination .page-item.disabled .page-link {
  background: var(--bg-surface);
  color: var(--text-muted);
  border-color: var(--border-default);
}
.list-summary {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  font-size: 13px;
  flex-wrap: wrap;
}

/* ---------- Progresso (metas) ---------- */
.progress {
  background: var(--bg-hover);
  border-radius: 999px;
  height: 8px;
}
.progress-bar { background: var(--color-primary); border-radius: 999px; }
.progress-bar.bg-success { background: var(--color-success); }

/* ---------- Modais ---------- */
.modal-content {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.modal-backdrop.show { opacity: 0.5; }
.modal-header {
  border-bottom: 1px solid var(--border-default);
  padding: 14px 20px;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.modal-title i { color: var(--text-muted); }
.modal-body { padding: 20px; }
.modal-footer {
  border-top: 1px solid var(--border-default);
  padding: 14px 20px;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
.modal-footer .btn-primary-cta, .modal-footer .btn-ghost { min-width: 110px; }
.btn-close {
  filter: none;
  opacity: 0.6;
}
html[data-theme="dark"] .btn-close { filter: invert(1) grayscale(1); }
.btn-close:hover { opacity: 1; }

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: var(--space-1);
}
.dropdown-item {
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  padding: 8px 10px;
}
.dropdown-item:hover, .dropdown-item:focus {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.dropdown-item.danger, .dropdown-item.danger i { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }
.dropdown-item[data-theme-set].active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.dropdown-item[data-theme-set].active i { color: var(--color-primary); }
.dropdown-divider { border-top: 1px solid var(--border-default); margin: var(--space-1) 0; opacity: 1; }
.dropdown-header { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 6px 10px 4px; }

/* ---------- Alertas ---------- */
.alert {
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px;
  padding: 10px 14px;
}
.alert-success { background: var(--color-success-soft); color: var(--color-success); border-color: var(--color-success-soft); }
.alert-danger { background: var(--color-danger-soft); color: var(--color-danger); border-color: var(--color-danger-soft); }
.alert-info { background: var(--color-primary-soft); color: var(--color-primary); border-color: var(--color-primary-soft); }
.alert-warning { background: var(--color-warning-soft); color: var(--color-warning); border-color: var(--color-warning-soft); }
.alert .btn-close { padding: 12px; }

/* ---------- Filtros ---------- */
.filters-card .form-label { font-size: 12px; }

/* ---------- Utilitários ---------- */
.row-gap-3 { row-gap: var(--space-3); }
.entity-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
