/* ==========================================================================
   VARIÁVEIS DE CORES E TEMA (DRE Analytics)
   ========================================================================== */
:root {
  /* Cores Principais */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  
  /* Fundos e Bordas */
  --bg-body: #f8fafc;
  --bg-panel: #ffffff;
  --border-light: #e2e8f0;
  --border-mid: #cbd5e1;
  
  /* Textos */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  
  /* Indicadores e Status */
  --green: #10b981;
  --green-mid: #059669;
  --red: #ef4444;
  --red-mid: #dc2626;
  --blue: #3b82f6;
  --teal: #14b8a6;
  --purple: #8b5cf6;
  --gold: #f59e0b;
}

/* ==========================================================================
   RESET E BASE
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-body);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.saas-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar (Menu Lateral) */
.sidebar {
  width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 40px;
  color: var(--ink);
  padding: 0 8px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--muted);
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s;
}

.sidebar-nav a:hover {
  background: var(--bg-body);
  color: var(--ink);
}

.sidebar-nav a.active {
  background: #eef2ff;
  color: var(--primary);
}

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

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.avatar {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-info span {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-info small {
  color: var(--muted);
  font-size: 0.75rem;
}

/* Área de Conteúdo Central */
.main-content {
  flex: 1;
  padding: 32px 40px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ==========================================================================
   CABEÇALHOS E BOTÕES
   ========================================================================== */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 32px;
}

.header-titles h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.header-titles p {
  color: var(--muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.btn-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border-mid);
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-outline:hover {
  background: var(--bg-body);
  border-color: var(--ink-2);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  transition: 0.2s;
}

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

/* ==========================================================================
   CARDS DE INDICADORES (KPIs)
   ========================================================================== */
.saas-card {
  background: var(--bg-panel);
  border-radius: 12px;
  border: 1px solid var(--border-light);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.kpi-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.icon-blue { background: #e0e7ff; color: var(--primary); }
.icon-teal { background: #ccfbf1; color: var(--teal); }
.icon-purple { background: #ede9fe; color: var(--purple); }
.icon-green { background: #d1fae5; color: var(--green-mid); }

.kpi-card strong {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

.kpi-trend {
  font-size: 0.8rem;
  display: flex;
  gap: 4px;
  align-items: center;
  font-weight: 500;
}

.kpi-trend.positive { color: var(--green-mid); }
.kpi-trend.negative { color: var(--red); }
.text-muted { color: var(--muted); }

/* ==========================================================================
   CARDS DE UPLOAD (Bancos e ERP)
   ========================================================================== */
.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title-wrap h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.inline-select {
  padding: 8px 12px;
  border: 1px solid var(--border-mid);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

.bank-cards-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.hidden-input {
  display: none;
}

.bank-card {
  background: var(--bg-panel);
  border: 1px dashed var(--border-mid);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bank-card:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

.bank-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bank-card-top img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.bank-card-top div {
  display: flex;
  flex-direction: column;
}

.bank-card-top strong {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.bank-card-top span {
  font-size: 0.75rem;
  color: var(--muted);
}

.bank-card-bottom {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.bank-card-bottom div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bank-card-bottom small {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
}

.bank-card-bottom span {
  font-size: 0.85rem;
  font-weight: 600;
}

.status-dot {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  background: var(--green-mid);
  border-radius: 50%;
}

/* ==========================================================================
   BARRA DE FILTROS TOTALMENTE REFEITA E ALINHADA
   ========================================================================== */
.saas-filters-bar {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  background: var(--bg-panel);
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border-light);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  flex-wrap: wrap;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 200px; /* Largura mínima aumentada para não esmagar textos longos */
}

/* O grupo de data inicial/final precisa de mais espaço */
.filter-item:first-child {
  min-width: 320px;
  flex: 1.5;
}

.filter-item label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Estilo padrão para todos os inputs e selects na barra */
.filter-item select, 
.filter-item input {
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-item select:focus, 
.filter-item input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Altura padronizada para inputs de 1 linha */
.filter-item select:not([multiple]), 
.filter-item input[type="date"],
.filter-item input[type="text"] {
  height: 44px;
}

/* Fix específico para caixas de Seleção Múltipla não quebrarem o layout */
.filter-item select[multiple] {
  height: 96px; /* Trava a altura */
  padding: 6px;
  resize: none;
}

.filter-item select[multiple] option {
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 2px;
  cursor: pointer;
}

.filter-item select[multiple] option:checked {
  background-color: #e0e7ff;
  color: var(--primary);
  font-weight: 500;
}

/* Customizando a barra de rolagem (Fica muito mais elegante) */
.filter-item select[multiple]::-webkit-scrollbar {
  width: 6px;
}
.filter-item select[multiple]::-webkit-scrollbar-track {
  background: transparent;
}
.filter-item select[multiple]::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 10px;
}
.filter-item select[multiple]::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.date-group {
  display: flex;
  align-items: center;
  gap: 12px;
}
.date-group input {
  flex: 1;
}

/* Área dos Botões de Limpar e Aplicar na Barra */
.filter-actions-right {
  display: flex;
  gap: 12px;
  align-items: center;
  align-self: flex-end; /* Joga os botões para a base do container */
  height: 44px; /* Mesma altura de um input de 1 linha */
  margin-left: auto;
}

/* Botões dentro da barra de filtros herdam a altura padronizada */
.filter-actions-right button {
  height: 44px;
}

/* ==========================================================================
   TABELAS E PAINÉIS
   ========================================================================== */
.panel-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.saas-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.saas-table th {
  padding: 12px 24px;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  background: #f8fafc;
}

.saas-table td {
  padding: 16px 24px;
  font-size: 0.9rem;
  color: var(--ink-2);
  border-bottom: 1px solid var(--border-light);
}

.saas-table tr:hover td {
  background: #f8fafc;
}

.row-total td {
  font-weight: 700;
  color: var(--ink);
  background: #f1f5f9;
}

.row-positive {
  color: var(--green-mid) !important;
  font-weight: 600;
}

.row-negative {
  color: var(--red) !important;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 40px !important;
  color: var(--muted) !important;
  font-style: italic;
}

/* ==========================================================================
   GRID SECUNDÁRIO (DRE vs Patrimônio)
   ========================================================================== */
.content-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.right-col-stack { display: flex; flex-direction: column; gap: 24px; }
.mini-stat-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border-radius: 8px; border: 1px solid transparent; }
.mini-stat-card.highlight { background: #f8fafc; border-color: var(--border-light); }
.mini-stat-card .label { font-size: 0.8rem; color: var(--muted); display: block; margin-bottom: 2px; }
.mini-stat-card strong { font-size: 1.1rem; color: var(--ink); display: block; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; }
.dot-green { background: var(--green-mid); }
.dot-blue { background: var(--blue); }
.dot-purple { background: var(--purple); }
.dot-red { background: var(--red); }

/* ==========================================================================
   GRÁFICOS
   ========================================================================== */
.charts-row { display: flex; gap: 24px; margin-top: 24px; }
.flex-2 { flex: 2; }
.flex-1 { flex: 1; }
.chart-card { padding: 24px; display: flex; flex-direction: column; }
.chart-header { display: flex; justify-content: space-between; margin-bottom: 20px; align-items: center; }
.chart-header h3 { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chart-legend { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.canvas-wrap { flex: 1; position: relative; min-height: 250px; }

/* ==========================================================================
   BADGES (Pílulas de Categorias)
   ========================================================================== */
.category-pill { display: inline-block; padding: 4px 10px; border-radius: 99px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.category-pill.revenue { background: #d1fae5; color: #065f46; }
.category-pill.expense { background: #ffe4e6; color: #9f1239; }
.category-pill.cost { background: #fef3c7; color: #92400e; }
.category-pill.other { background: #f1f5f9; color: #475569; }
.category-pill.is-clickable { cursor: pointer; transition: 0.2s; }
.category-pill.is-clickable:hover { opacity: 0.8; }

.category-inline-select { padding: 6px 8px; border: 1px solid var(--border-mid); border-radius: 6px; font-size: 0.8rem; outline: none; background: #fff; }

.cnpj-pill { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: 600; background: #e2e8f0; color: #334155; }
.cnpj-pill.is-clickable { cursor: pointer; }
.cnpj-pill.is-clickable:hover { background: #cbd5e1; }

.is-collapsed { display: none !important; }

/* ==========================================================================
   TOAST (Alertas flutuantes)
   ========================================================================== */
.toast { position: fixed; bottom: 24px; right: 24px; padding: 16px 24px; border-radius: 8px; color: #fff; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,0.15); opacity: 0; pointer-events: none; transition: 0.3s; z-index: 9999; }
.toast--visible { opacity: 1; pointer-events: auto; }
.toast--success { background: var(--green-mid); }
.toast--error { background: var(--red); }
.toast--warning { background: var(--gold); }

/* ==========================================================================
   MODAIS
   ========================================================================== */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.rateio-modal { background: #fff; padding: 24px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); width: 100%; max-width: 500px; }
.field-block { display: flex; flex-direction: column; gap: 6px; }
.field-block span { font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }
.field-block input, .field-block select { padding: 10px; border: 1px solid var(--border-mid); border-radius: 6px; outline: none; }
.grid-2-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.rule-modal { position: absolute; background: #fff; border: 1px solid var(--border-mid); box-shadow: 0 4px 12px rgba(0,0,0,0.15); padding: 16px; border-radius: 8px; z-index: 100; width: 280px; top: var(--modal-top); left: var(--modal-left); }
.rule-modal__msg { font-size: 0.85rem; margin-bottom: 12px; color: var(--ink-2); line-height: 1.4; }
.rule-modal__actions { display: flex; gap: 8px; flex-wrap: wrap; }