/* ==========================================================================
   VÉRTICE FINANCEIRO • DASHBOARDS EXECUTIVOS EM 4 TELAS FOCADAS (VIEWPORT-FIT)
   Otimizado para notebooks (1366x768) e tablets usando 100% os tokens de tema
   ========================================================================== */

.dash-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow: hidden;
}

/* Barra Única Compacta no Topo do Dashboard */
.dash-topbar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.dash-subtabs {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
  flex-shrink: 0;
}

.dash-subtab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.34rem 0.72rem;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.dash-subtab-btn:hover {
  background: var(--color-primary-subtle);
  color: var(--text-primary);
}

.dash-subtab-btn.active {
  background: var(--color-primary-btn-bg);
  color: var(--color-primary-btn-text);
}

.dash-controls-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.regime-switch {
  display: inline-flex;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.regime-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.3rem 0.62rem;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.regime-btn.active {
  background: var(--color-primary-btn-bg);
  color: var(--color-primary-btn-text);
}

.period-pills {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.period-pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.34rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.period-pill.active {
  background: var(--color-primary-btn-bg);
  color: var(--color-primary-btn-text);
}

/* Telas Individuais (somente a ativa é exibida) */
.dash-screen {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 0.6rem;
  overflow: hidden;
}

.dash-screen.active {
  display: flex;
}

/* Grids de KPI Balanceados (zero card órfão) */
.kpi-row-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  flex-shrink: 0;
}

.kpi-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  flex-shrink: 0;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--kpi-accent, var(--color-primary-btn-bg));
  border-radius: var(--radius-md);
  padding: 0.62rem 0.85rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.28rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card.kpi-clickable {
  cursor: pointer;
}

.kpi-card.kpi-clickable:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
  box-shadow: var(--shadow-md);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.kpi-label {
  font-size: 0.69rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-sub {
  font-size: 0.71rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-sub strong {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Containers de Gráficos */
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  min-height: 0;
}

.chart-card-full {
  flex: 1;
  min-height: 0;
}

.dash-split-50 {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.dash-split-treasury {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 0.65rem;
}

.chart-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chart-card-head h3 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-primary);
}

.chart-card-head p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.chart-hint-tag {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.chart-canvas-fill {
  position: relative;
  flex: 1;
  min-height: 210px;
  width: 100%;
}

/* Painel Lateral de Pendências & Atrasos (Tela Tesouraria) */
.pending-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.pending-card-head {
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pending-card-head h3 {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-primary);
}

.pending-card-head p {
  font-size: 0.71rem;
  color: var(--text-secondary);
}

.pending-list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pending-item {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pending-item.is-overdue {
  border-left-color: var(--badge-danger-text);
}

.pending-item.is-pending {
  border-left-color: var(--badge-warning-text);
}

.pending-item:hover {
  background: var(--table-row-hover);
  border-color: var(--border-focus);
}

.pending-item-main {
  min-width: 0;
  flex: 1;
}

.pending-item-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-item-right {
  text-align: right;
  flex-shrink: 0;
}

.pending-item-val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 800;
}

/* Tela 4: DRE Gerencial em Tela Cheia com Cabeçalho Fixo */
.dre-card {
  flex: 1;
  min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.dre-card-head {
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.62rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.dre-card-head h3 {
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 800;
  color: var(--text-primary);
}

.dre-card-head p {
  font-size: 0.73rem;
  color: var(--text-secondary);
}

.dre-table-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: auto;
}

table.dre-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.79rem;
}

table.dre-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--table-header-bg);
  color: var(--table-header-text);
  font-weight: 700;
  padding: 0.54rem 0.75rem;
  text-align: left;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}

table.dre-table thead th.num,
table.dre-table tbody td.num {
  text-align: right;
  font-family: var(--font-mono);
}

table.dre-table tbody td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--table-border);
  color: var(--text-primary);
}

table.dre-table tbody tr.dre-group-row {
  background: var(--bg-surface-elevated);
  font-weight: 700;
  cursor: pointer;
}

table.dre-table tbody tr.dre-group-row:hover {
  background: var(--table-row-hover);
}

table.dre-table tbody tr.dre-line-row {
  background: var(--table-row-bg);
  cursor: pointer;
}

table.dre-table tbody tr.dre-line-row:hover {
  background: var(--table-row-hover);
}

table.dre-table tbody tr.dre-subtotal-row {
  background: var(--bg-card-header);
  font-weight: 800;
}

table.dre-table tbody tr.dre-final-row {
  background: var(--table-row-selected-bg);
  color: var(--table-row-selected-text);
  font-weight: 800;
}

table.dre-table tbody tr.dre-final-row td {
  color: var(--table-row-selected-text);
}

.dre-cat-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.45rem;
  vertical-align: middle;
}

.av-bar-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  justify-content: flex-end;
  min-width: 110px;
}

.av-bar-track {
  width: 56px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-page);
  overflow: hidden;
}

.av-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--color-primary-btn-bg);
}

/* Responsividade para Tablets e Telas Estreitas */
@media (max-width: 1024px) {
  .dash-screen.active {
    overflow-y: auto;
  }
  .kpi-row-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi-row-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dash-split-50,
  .dash-split-treasury {
    grid-template-columns: 1fr;
    flex: none;
  }
  .chart-card,
  .pending-card {
    min-height: 300px;
  }
}

@media (max-width: 640px) {
  .kpi-row-4,
  .kpi-row-3 {
    grid-template-columns: 1fr;
  }
}

@media print {
  .dash-layout, .dash-screen, .dre-card, .dre-table-wrap {
    overflow: visible !important;
    height: auto !important;
  }
  .dash-topbar {
    display: none !important;
  }
}
