/* Componentes reutilizáveis — cards, KPIs, filtros, tabelas, badges, botões */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card h2, .card-title {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0 0 12px;
}

/* ---------- Filter bar (horizontal) ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label {
  font-size: 12px; color: var(--text-muted); font-weight: 600; white-space: nowrap;
}
.date-input, .search-input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-sans);
}
.date-input:focus, .search-input:focus, .multiselect-btn:focus {
  outline: 2px solid var(--primary-soft);
  outline-offset: 1px;
  border-color: var(--primary);
}
.date-type-select {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}

.quick-range { display: flex; gap: 4px; }
.quick-range button {
  font-size: 11.5px;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.quick-range button:hover { background: var(--bg-hover); }
.quick-range button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.status-toggle-row { display: flex; flex-wrap: wrap; gap: 8px; }
.status-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  transition: all var(--transition);
}
.status-btn .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-btn .count { color: var(--text-muted); font-weight: 600; }
.status-btn:hover { border-color: var(--primary); }
.status-btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.status-btn.active .count { color: var(--primary); }

/* Multiselect dropdown */
.multiselect { position: relative; }
.multiselect-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.multiselect-btn:hover { background: var(--bg-hover); }
.multiselect-btn .chevron { font-size: 10px; color: var(--text-muted); }
.multiselect-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 1px 6px;
}
.multiselect-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 240px;
  max-height: 320px;
  display: none;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px;
}
.multiselect-panel.open { display: flex; }
.multiselect-search {
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
}
.multiselect-search:focus {
  outline: 2px solid var(--primary-soft);
  outline-offset: 1px;
  border-color: var(--primary);
}
.multiselect-options {
  overflow-y: auto;
}
.multiselect-panel label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.multiselect-panel label:hover { background: var(--bg-hover); }
.multiselect-panel input { flex-shrink: 0; accent-color: var(--primary); }
.multiselect-panel label[hidden] { display: none; }

.clear-filters-btn {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 7px 4px;
  white-space: nowrap;
}
.clear-filters-btn:hover { text-decoration: underline; }

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card { display: flex; flex-direction: column; gap: 4px; }
.kpi-label {
  font-size: 12px; color: var(--text-muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em;
  display: flex; align-items: center; gap: 6px;
}
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.kpi-sub { font-size: 12px; color: var(--text-muted); }
.kpi-card.kpi-danger .kpi-value { color: var(--vencido); }
.kpi-card.kpi-danger { background: var(--vencido-soft); border-color: transparent; }
.kpi-card.kpi-danger .kpi-label { color: var(--vencido); }

/* ---------- Charts row ---------- */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .charts-row { grid-template-columns: 1fr; } }
.chart-box { position: relative; height: 240px; }
.card-hint { font-weight: 400; text-transform: none; opacity: .7; letter-spacing: 0; }

/* Lista de centros de custo (barras em HTML/CSS, rolável) */
.cost-center-scroll {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.cc-row {
  display: grid;
  grid-template-columns: 160px 1fr 64px;
  align-items: center;
  gap: 8px;
}
.cc-label {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cc-track {
  height: 10px;
  background: var(--bg-hover);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.cc-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-pill);
}
.cc-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

/* ---------- Table ---------- */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.table-count { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }

/* Barra de seleção de títulos (relatório de pagamento) */
.selecao-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
}
/* IMPORTANTE: "[hidden]" do navegador e ".selecao-bar" têm a mesma
   especificidade -- sem esta regra, "display:flex" acima vence e o
   atributo hidden (usado pra esconder a barra quando a seleção zera) não
   tem efeito visual nenhum, mesmo com JS setando bar.hidden = true. */
.selecao-bar[hidden] { display: none; }
.selecao-bar .selecao-total { font-weight: 400; }
/* Os dois botões ficam num grupo à parte (não cada um "solto" no flex da
   barra) -- assim eles nunca se separam ao quebrar linha em telas
   estreitas, o que antes deixava "Limpar seleção" isolado e confuso. */
.selecao-bar-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-left: auto;
}
.selecao-bar-actions .clear-filters-btn {
  padding: 5px 10px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.selecao-bar-actions #limparSelecao { color: var(--vencido); border-color: var(--vencido); }
.cpg-select-col { width: 34px; }
.cpg-select-col input, td.cpg-select-col input { accent-color: var(--primary); cursor: pointer; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 9px 10px;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { color: var(--primary); }
thead th .sort-arrow { font-size: 10px; margin-left: 4px; opacity: .4; }
thead th.sorted .sort-arrow { opacity: 1; color: var(--primary); }
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.active-row { background: var(--bg-hover); box-shadow: inset 3px 0 0 var(--primary); }
.table-scroll { max-height: 460px; overflow-y: auto; border-radius: var(--radius-md); }

.badge {
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 700; color: #fff; white-space: nowrap;
  letter-spacing: .02em;
}
.badge.PAGO { background: var(--pago); }
.badge.VENCIDO { background: var(--vencido); }
.badge.NAO_VENCIDO { background: var(--naovencido); }
.badge.CANCELADO { background: var(--cancelado); }
.badge.FILA_PAGAMENTO { background: var(--primary); }

.pagination {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 6px; margin-top: 12px; flex-wrap: wrap;
}
.pagination button {
  min-width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.pagination button:hover:not(:disabled) { background: var(--bg-hover); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination-info { font-size: 12px; color: var(--text-muted); margin-right: 6px; }

.loading { opacity: .5; pointer-events: none; }
.empty-msg { color: var(--text-muted); font-size: 13px; padding: 20px; text-align: center; }

/* ---------- Theme toggle switch ---------- */
.theme-toggle {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-pill);
  padding: 4px;
  cursor: pointer;
}
.theme-toggle .seg {
  width: 28px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  font-size: 13px;
  color: var(--text-muted);
}
.theme-toggle .seg.active { background: var(--primary); color: #fff; }

/* ---------- Tabela da DRE ---------- */
.dre-table-scroll { max-height: 640px; overflow: auto; }
.dre-table { white-space: nowrap; }
.dre-table .dre-label-col {
  position: sticky;
  left: 0;
  background: var(--bg-elevated);
  text-align: left;
  min-width: 260px;
  z-index: 1;
}
.dre-table thead th.dre-label-col { z-index: 2; }
.dre-table .dre-val { text-align: right; font-variant-numeric: tabular-nums; }
.dre-table .dre-neg { color: var(--vencido); }
.dre-row-item td { font-size: 12.5px; color: var(--text-muted); }
.dre-row-subtotal td { font-weight: 700; background: var(--bg-hover); }
.dre-row-final td { font-weight: 800; background: var(--primary-soft); color: var(--primary); }
.dre-row-manual td { font-style: italic; }
.dre-row-manual .dre-label-col { color: var(--primary); }
.dre-manual-input {
  width: 100px;
  text-align: right;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--primary);
  font-size: 12.5px;
  font-family: var(--font-sans);
}
.dre-manual-input:focus {
  outline: 2px solid var(--primary-soft);
  outline-offset: 1px;
  border-color: var(--primary);
}
