/* ════════════════════════════════════════════════════
   Finan — Folha de Estilos Minimalista & Clássica
   ════════════════════════════════════════════════════ */

:root {
  /* Cores clássicas e sóbrias */
  --bg-app:        #f9fafb;
  --bg-card:       #ffffff;
  --text-primary:  #111827;
  --text-muted:    #4b5563;
  --text-hint:     #9ca3af;
  
  --border-color:  #e5e7eb;
  --border-focus:  #2563eb;
  
  /* Cores de Destaque */
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --success:       #059669;
  --success-light: #ecfdf5;
  
  --danger:        #dc2626;
  --danger-light:  #fef2f2;
  
  --secondary:     #4b5563;
  --secondary-hov: #374151;
  --secondary-lt:  #f3f4f6;

  /* Espaçamentos e Bordas */
  --radius:        6px;
  --transition:    all 0.15s ease-in-out;
}

/* ─── Reset Clássico ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ─── Utilitários ─── */
.hidden { display: none !important; }
.mono { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.font-bold { font-weight: 600; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted); }

/* ─── Animações e Transições Clássicas ─── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Telas de Autenticação (Login/Cadastro) ─── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.auth-logo-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.tab-btn {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  font-weight: 500;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Formulários */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
  color: var(--text-hint);
}

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding-right: 36px;
}

.input-prefix {
  position: relative;
  display: flex;
  align-items: center;
}

.prefix-text {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-weight: 500;
  pointer-events: none;
  user-select: none;
}

.form-input.has-prefix {
  padding-left: 36px;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--secondary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--secondary-lt);
  color: var(--text-primary);
}

.btn-export {
  background: var(--secondary-lt);
  color: var(--secondary);
  border-color: var(--border-color);
}

.btn-export:hover {
  background: #e5e7eb;
}

.btn-full {
  width: 100%;
  padding: 10px;
}

.btn-close {
  font-size: 18px;
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-close:hover {
  color: var(--text-primary);
}

.btn-spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── APP SCREEN & CONTAINER ─── */
.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.app-title-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.month-selector-wrap {
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  padding: 2px;
}

.btn-month-nav {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-month-nav:hover {
  color: var(--text-primary);
}

.select-clean {
  background: transparent;
  border: none;
  font-weight: 600;
  color: var(--text-primary);
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
  font-size: 13px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-greeting {
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.user-greeting:hover {
  text-decoration: underline;
  color: var(--primary);
}

.btn-logout {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: #f3f4f6;
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: var(--transition);
}

.btn-logout:hover {
  color: var(--text-primary);
  background: #e5e7eb;
}

/* ─── WORKSPACE (Layout Principal) ─── */
.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: start;
}

/* Coluna Esquerda: Widgets */
.workspace-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.widget {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 18px;
}

.widget-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
  margin-bottom: 14px;
}

/* Cards de Resumo */
.summary-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.summary-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.summary-val {
  font-size: 18px;
  font-weight: 700;
}

/* Comprometimento de Salário */
.salary-container {
  margin-top: 14px;
  border-top: 1px dashed var(--border-color);
  padding-top: 12px;
}

.salary-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.progress-bar-fill.danger {
  background: var(--danger);
}

.salary-hint {
  font-size: 11px;
}

/* Gastos por Origem (Faturas) */
.origens-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.origem-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-primary);
}

.origem-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.origem-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--secondary);
}

.origem-val {
  font-weight: 600;
}

/* Gráficos */
.chart-container {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

#category-chart {
  max-height: 200px;
}

#trend-chart {
  max-height: 150px;
}

/* Coluna Direita: Workspace Main */
.workspace-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Barra de Ações */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px 18px;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

/* Filtros */
.filters-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.filters-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filter-input {
  width: 100%;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}

.filter-input:focus {
  background: #ffffff;
  border-color: var(--border-focus);
}

/* Tabelas e Abas */
.table-widget {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-tabs {
  display: flex;
  background: #f3f4f6;
  border-bottom: 1px solid var(--border-color);
}

.table-tab-btn {
  flex: 1;
  text-align: center;
  padding: 12px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-right: 1px solid var(--border-color);
  background: transparent;
  transition: var(--transition);
}

.table-tab-btn:hover {
  background: #e5e7eb;
}

.table-tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  border-bottom: 1px solid var(--bg-card);
  margin-bottom: -1px;
}

.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  min-width: 750px;
}

.data-table th {
  background: #f9fafb;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
}

.data-table td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.data-table tbody tr:hover {
  background: #f9fafb;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.empty-table {
  text-align: center;
  padding: 48px 0;
  color: var(--text-hint);
  font-size: 13px;
}

/* Badges e Ações na Tabela */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
}

.badge-cat {
  background: #f3f4f6;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.badge-parcela {
  background: #eff6ff;
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

.badge-recorrente {
  background: #fffbeb;
  color: #d97706;
  border: 1px solid #fde68a;
}

.badge-status-ativo {
  background: var(--success-light);
  color: var(--success);
}

.badge-status-pausado {
  background: #f3f4f6;
  color: var(--text-muted);
}

.table-row-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.btn-action-discreet {
  font-size: 13px;
  padding: 2px 6px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: var(--transition);
}

.btn-action-discreet:hover {
  background: #f3f4f6;
  color: var(--text-primary);
}

.btn-action-discreet.delete:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* Totalizador no Rodapé da Tabela */
.table-footer-summary {
  background: #f9fafb;
  border-top: 1px solid var(--border-color);
  padding: 12px 18px;
}

.summary-line-split {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  font-size: 13px;
  flex-wrap: wrap;
}

.summary-item-split {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-item-split span:first-child {
  color: var(--text-muted);
}

.summary-item-split span:last-child {
  font-size: 15px;
}

/* ─── MODAIS (Estrutura Minimalista) ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* Customizações do Form nos Modais */
.form-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.type-toggle {
  display: flex;
  background: #f3f4f6;
  border-radius: var(--radius);
  padding: 2px;
  border: 1px solid var(--border-color);
}

.type-opt {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 4px;
  transition: var(--transition);
}

.type-opt.selected-despesa {
  background: var(--danger);
  color: #ffffff;
  font-weight: 600;
}

.type-opt.selected-ganho {
  background: var(--success);
  color: #ffffff;
  font-weight: 600;
}

.type-opt.selected-invest {
  background: #3b82f6;
  color: #ffffff;
  font-weight: 600;
}

.type-opt.selected-resgate {
  background: #0284c7;
  color: #ffffff;
  font-weight: 600;
}

.parcelas-row {
  display: flex;
  gap: 12px;
  background: var(--bg-app);
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  align-items: center;
}

.parcelas-preview {
  font-size: 12px;
  color: var(--primary);
  font-weight: 500;
  margin-top: 14px;
}

/* ─── TOAST NOTIFICAÇÕES (Clássicas) ─── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  background: #1f2937;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  animation: slideIn 0.2s ease-out;
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ─── RESPONSIVIDADE (Desktop vs Mobile) ─── */
@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  
  .workspace-sidebar {
    order: 2; /* Gráficos e resumos vão para baixo */
  }
  
  .workspace-main {
    order: 1; /* Lançamentos e tabelas ficam em cima */
  }

  .summary-cards {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }

  .summary-card {
    flex: 1;
    min-width: 100px;
  }

  .chart-container {
    max-width: 400px;
    margin: 0 auto;
  }
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .header-left {
    justify-content: space-between;
  }
  
  .header-right {
    justify-content: space-between;
  }
  
  .filters-grid {
    grid-template-columns: 1fr;
  }
  
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .action-buttons {
    flex-direction: column;
  }

  /* Redefinição Responsiva da Tabela (Mobile to Cards) */
  .data-table {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
  }
  
  .data-table thead {
    display: none;
  }
  
  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    padding: 4px;
  }
  
  .data-table tr {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 14px;
    gap: 0;
    width: 100% !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
  }
  
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 !important;
    border: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
    width: 100% !important;
    text-align: left !important;
  }
  
  .data-table td:last-child {
    border-bottom: none !important;
    padding-top: 10px !important;
    justify-content: flex-end;
  }
  
  .data-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
  }
  
  .empty-table {
    padding: 32px 0;
  }
}
