/* =========================================================
   CENTRAL COMERCIAL AGENFLEX
   Arquivo: historico.css

   Responsabilidade:
   - Estilizar o histórico
   - Organizar busca e filtros
   - Organizar tabela
   - Diferenciar revisão e status comercial
   - Exibir origem comercial
   - Exibir modal R0/R1/R2/R3...
   - Exibir aviso de revisão histórica em somente leitura
   ========================================================= */


/* =========================================================
   ## 1. BARRA DE BUSCA E FILTROS
   ========================================================= */

.history-toolbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}


.history-search {
  flex: 1 1 300px;
  min-width: 260px;
}


.history-search input {
  width: 100%;
}


.history-filter {
  flex: 0 1 190px;
  min-width: 170px;
}


.history-filter select {
  width: 100%;
}


.history-count {
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  padding: 10px 0;
}


/* =========================================================
   ## 2. TABELA
   ========================================================= */

.history-table {
  min-width: 1120px;
}


.history-table th {
  white-space: nowrap;
}


.history-table td {
  vertical-align: middle;
}


.history-muted {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}


/* =========================================================
   ## 3. ORIGEM COMERCIAL
   ========================================================= */

.history-origin-wrap {
  margin-top: 7px;
}


.history-origin {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 4px 8px;

  border-radius: 999px;

  font-size: 9px;
  font-weight: 900;
  letter-spacing: .4px;

  white-space: nowrap;

  background: #eef2f7;
  color: #475569;
}


.history-origin.leads_mkt {
  background: #eef2ff;
  color: #4338ca;
}


.history-origin.prospeccao {
  background: #eaf4ff;
  color: #145da0;
}


.history-origin.gestao_carteira {
  background: #f1ecff;
  color: #6842a8;
}


.history-origin.sem-origem {
  background: #f1f3f5;
  color: #6b7280;
}


/* =========================================================
   ## 4. REVISÃO
   ========================================================= */

.history-revision {
  display: flex;
  flex-direction: column;
  align-items: flex-start;

  gap: 6px;
}


.history-revision > b {
  font-size: 13px;
}


.history-revision-count {
  font-size: 10px;

  color: var(--muted);

  white-space: nowrap;
}


/* =========================================================
   ## 5. BADGES
   ========================================================= */

.history-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: 82px;

  padding: 6px 9px;

  border-radius: 999px;

  font-size: 10px;
  font-weight: 900;
  letter-spacing: .4px;

  white-space: nowrap;
}


.history-badge.rascunho {
  background: #fff4d6;
  color: #7a5200;
}


.history-badge.enviada {
  background: #e7f6ec;
  color: #146c2e;
}


.history-badge.commercial {
  min-width: 110px;
}


.history-badge.commercial.proposta {
  background: #edf2f7;
  color: #334155;
}


.history-badge.commercial.andamento {
  background: #e8f2ff;
  color: #155fa0;
}


.history-badge.commercial.concluido {
  background: #e7f6ec;
  color: #146c2e;
}


.history-badge.commercial.nao_conquistado {
  background: #fdebec;
  color: #a61b29;
}


.history-current-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 5px 8px;

  border-radius: 999px;

  background: #eaf4ff;
  color: #145da0;

  font-size: 9px;
  font-weight: 900;
  letter-spacing: .35px;

  white-space: nowrap;
}


/* =========================================================
   ## 6. AÇÕES DA TABELA
   ========================================================= */

.history-actions {
  display: flex;
  align-items: center;

  gap: 7px;

  white-space: nowrap;
}


.history-open,
.history-revisions {
  padding: 7px 11px;

  white-space: nowrap;
}


/* =========================================================
   ## 7. ESTADOS DA LISTAGEM
   ========================================================= */

.history-loading,
.history-empty {
  text-align: center;

  padding: 28px !important;

  color: var(--muted);
}


#historicoVazio {
  display: none;

  margin-top: 14px;
  padding: 22px;

  border: 1px dashed #cfd6df;
  border-radius: 12px;

  text-align: center;

  color: var(--muted);

  background: #f8fafc;
}


/* =========================================================
   ## 8. MODAL DE REVISÕES
   ========================================================= */

.history-revisions-modal {
  position: fixed;

  inset: 0;

  z-index: 10020;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 24px;

  overflow-y: auto;

  background:
    rgba(
      15,
      23,
      42,
      .60
    );

  backdrop-filter:
    blur(3px);
}


.history-revisions-modal[hidden] {
  display: none !important;
}


body.history-modal-open {
  overflow: hidden;
}


.history-revisions-dialog {
  width: min(
    100%,
    760px
  );

  max-height:
    calc(
      100vh - 48px
    );

  overflow-y: auto;

  border: 1px solid #dbe2ea;
  border-radius: 16px;

  background: #fff;

  box-shadow:
    0 24px 70px
    rgba(
      15,
      23,
      42,
      .24
    );
}


.history-revisions-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  gap: 20px;

  padding: 22px;

  border-bottom:
    1px solid #e5eaf0;
}


.history-revisions-head > div:first-child {
  min-width: 0;
}


.history-revisions-kicker {
  display: block;

  margin-bottom: 5px;

  color: #64748b;

  font-size: 9px;
  font-weight: 900;

  letter-spacing: .6px;
}


.history-revisions-head h3 {
  margin: 0;

  color: #0f172a;

  font-size: 20px;
  line-height: 1.25;
}


.history-revisions-head p {
  margin: 6px 0 0;

  color: #64748b;

  font-size: 12px;
  line-height: 1.5;
}


.history-revisions-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 34px;

  width: 34px;
  height: 34px;

  padding: 0;

  border: 1px solid #dbe2ea;
  border-radius: 9px;

  background: #fff;

  color: #475569;

  font-size: 23px;
  line-height: 1;

  cursor: pointer;
}


.history-revisions-close:hover {
  background: #f8fafc;

  color: #0f172a;
}


.history-revisions-content {
  display: flex;
  flex-direction: column;

  gap: 12px;

  padding: 18px 22px 22px;
}


.history-revisions-loading,
.history-revisions-empty,
.history-revisions-error {
  padding: 30px 18px;

  border: 1px dashed #cfd6df;
  border-radius: 12px;

  background: #f8fafc;

  color: #64748b;

  text-align: center;
}


.history-revisions-error b,
.history-revisions-error span {
  display: block;
}


.history-revisions-error span {
  margin-top: 6px;

  font-size: 12px;
}


/* =========================================================
   ## 9. CARD DE CADA REVISÃO
   ========================================================= */

.history-revision-card {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 18px;

  padding: 16px;

  border: 1px solid #dbe2ea;
  border-radius: 13px;

  background: #fff;
}


.history-revision-card.current {
  border-color: #b9d7f5;

  background: #f8fbff;
}


.history-revision-card-main {
  min-width: 0;

  flex: 1 1 auto;
}


.history-revision-card-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  gap: 7px;
}


.history-revision-card-title > strong {
  color: #0f172a;

  font-size: 18px;
}


.history-revision-card-meta {
  display: flex;
  flex-wrap: wrap;

  gap: 7px 14px;

  margin-top: 9px;

  color: #64748b;

  font-size: 11px;
}


.history-revision-card-client {
  margin-top: 7px;

  color: #334155;

  font-size: 12px;
  font-weight: 800;
}


.history-revision-card-actions {
  display: flex;
  align-items: center;

  gap: 8px;

  flex: 0 0 auto;
}


.history-revision-card-actions .btn {
  white-space: nowrap;
}


/* =========================================================
   ## 10. AVISO DE REVISÃO HISTÓRICA
   ========================================================= */

.revisao-historica-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 16px;

  margin: 0 0 18px;
  padding: 14px 16px;

  border: 1px solid #f2dfab;
  border-radius: 12px;

  background: #fff9e9;

  color: #5f4500;
}


.revisao-historica-banner[hidden] {
  display: none !important;
}


.revisao-historica-banner strong,
.revisao-historica-banner span {
  display: block;
}


.revisao-historica-banner strong {
  margin-bottom: 4px;

  font-size: 12px;
  font-weight: 900;
}


.revisao-historica-banner span {
  font-size: 11px;
  line-height: 1.5;
}


/* Revisão antiga:
   mantém PDF,
   esconde ações de edição. */

body.consulta-historica-ativa #btnSalvarPropostaNuvem,
body.consulta-historica-ativa #btnEnviarRevisao,
body.consulta-historica-ativa #btnCriarNovaRevisao,
body.consulta-historica-ativa [onclick="saveDraft()"],
body.consulta-historica-ativa [onclick="clearForm()"] {
  display: none !important;
}


/* =========================================================
   ## 11. RESPONSIVIDADE
   ========================================================= */

@media (max-width: 1100px) {

  .history-filter {
    flex: 1 1 180px;
  }

}


@media (max-width: 900px) {

  .history-toolbar {
    align-items: stretch;
  }


  .history-search {
    flex-basis: 100%;
  }


  .history-filter {
    flex-basis:
      calc(
        50% - 6px
      );
  }


  .history-table {
    min-width: 1080px;
  }

}


@media (max-width: 700px) {

  .history-revisions-modal {
    align-items: flex-start;

    padding: 12px;
  }


  .history-revisions-dialog {
    width: 100%;

    max-height:
      calc(
        100vh - 24px
      );

    border-radius: 13px;
  }


  .history-revisions-head {
    padding: 18px 16px 15px;
  }


  .history-revisions-content {
    padding: 14px 16px 18px;
  }


  .history-revision-card {
    align-items: stretch;

    flex-direction: column;
  }


  .history-revision-card-actions {
    width: 100%;
  }


  .history-revision-card-actions .btn {
    flex: 1 1 0;
  }


  .revisao-historica-banner {
    align-items: stretch;

    flex-direction: column;
  }

}