/* Configuração geral */
:root {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: #172638;
  background: #f2f5f9;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
}

.pagina {
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px;
}

h1 {
  font-size: 22px;
  margin: 5px 0 8px;
}

h2 {
  font-size: 17px;
  margin: 0 0 9px;
}

/* Cabeçalhos e organização dos campos */
.topo,
.linha-titulo,
.campos {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.topo,
.linha-titulo {
  align-items: center;
  justify-content: space-between;
}

.topo {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f2f5f9;
  padding: 5px 0;
}

.topo-acoes {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.voltar {
  color: #1559a8;
  text-decoration: none;
}

.topo-com-relatorios {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.topo-com-relatorios .topo-acoes {
  justify-self: end;
  justify-content: flex-end;
}

.topo-com-relatorios .mensagem {
  grid-column: 1 / -1;
}

.topo-link-relatorios {
  justify-self: center;
}

.linha-cabecalho {
  justify-content: flex-start;
  gap: 14px;
  align-items: baseline;
}

.linha-cabecalho h2,
.linha-cabecalho .meta {
  margin: 0;
}

/* Painéis */
.painel {
  background: #fff;
  padding: 14px;
  margin: 11px 0;
  border: 1px solid #dbe3ec;
  border-radius: 9px;
  box-shadow: 0 2px 5px #15223a0b;
}

/* Formulários */
label {
  display: block;
  font-weight: 600;
  min-width: 155px;
  flex: 1;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 36px;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid #aab7c6;
  border-radius: 6px;
  background: #fff;
  color: #172638;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid #1872c9;
  outline-offset: 1px;
}

.campo-data {
  max-width: 170px;
}

/* Botões */
button {
  min-height: 36px;
  padding: 7px 13px;
  border: 0;
  border-radius: 6px;
  background: #1559a8;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secundario {
  background: #e7eef7;
  color: #173b62;
}

.perigo {
  background: #a92d37;
}

/* Textos de apoio */
.ajuda,
.meta {
  color: #52647b;
}

.ajuda {
  margin: 10px 0 0;
  line-height: 1.4;
}

/* Contadores */
.resumo-contagem {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.resumo-contagem span {
  padding: 8px 11px;
  border-radius: 6px;
  font-weight: 600;
  background: #edf3fb;
  color: #24456a;
}

.resumo-contagem strong {
  font-size: 18px;
  margin-left: 5px;
}

.resumo-contagem .resumo-correto {
  background: #e3f5e9;
  color: #17663a;
}

.resumo-contagem .resumo-pendente {
  background: #fff3dd;
  color: #8a5504;
}

.resumo-contagem .resumo-divergente {
  background: #ffe6e6;
  color: #a0222a;
}

.linha-local .resumo-contagem {
  margin: 0;
  align-self: flex-end;
  gap: 6px;
}

.linha-local .resumo-contagem span {
  padding: 8px 9px;
  white-space: nowrap;
}

.linha-local .resumo-contagem strong {
  font-size: 16px;
}

/* Campo de leitura */
.linha-leitura {
  margin: 8px 0;
  flex-wrap: nowrap;
  align-items: flex-end;
  overflow-x: auto;
  gap: 10px;
}

.linha-leitura label {
  flex: 0 0 340px;
  min-width: 260px;
  max-width: 360px;
}

.linha-leitura button,
.linha-leitura h2,
.linha-leitura .meta {
  flex: none;
  white-space: nowrap;
}

.linha-leitura h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.linha-leitura .meta {
  margin-bottom: 9px;
}

.linha-leitura .mensagem-inline {
  min-height: 36px;
  padding: 9px 10px;
  flex: none;
  white-space: nowrap;
  align-self: flex-end;
}

/* Tabela de produtos */
.tabela-wrap {
  overflow: auto;
  max-height: 65vh;
  border: 1px solid #e0e6ec;
  border-radius: 6px;
  margin-top: 10px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 1200px;
  font-size: 13px;
}

th,
td {
  padding: 7px 8px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid #e0e6ec;
}

th {
  background: #eaf0f6;
  position: sticky;
  top: 0;
  white-space: nowrap;
  z-index: 1;
}

tbody tr:hover {
  background: #f5f9ff;
}

td.numero,
th.numero {
  text-align: right;
  white-space: nowrap;
}

td:nth-child(3) {
  min-width: 210px;
  white-space: nowrap;
}

td:nth-child(4),
td:nth-child(5) {
  min-width: 100px;
}

.contagem-input {
  width: 72px;
  text-align: right;
  min-height: 28px;
  margin: 0;
  padding: 4px 5px;
}

.resultado {
  font-weight: 700;
  white-space: nowrap;
}

.diferenca {
  font-weight: 700;
}

/* Cores das linhas e dos resultados */

/* Sobrou: fundo verde e texto verde */
.sobrou {
  background: #ebf9ef;
}

.sobrou .diferenca,
.sobrou .resultado {
  color: #17663a;
}

/* Faltou: fundo vermelho e texto vermelho */
.faltou {
  background: #fff0f0;
}

.faltou .diferenca,
.faltou .resultado {
  color: #b42318;
}

/* Conferido: fundo verde claro */
.conferido {
  background: #ebf9ef;
}

.conferido .resultado {
  color: #177046;
}

/* Pendente: texto cinza */
.pendente .resultado {
  color: #687786;
}

/* Seleção e tabela vazia */
.linha-atual {
  outline: 2px solid #1765be;
  outline-offset: -2px;
}

.vazio {
  text-align: center;
  color: #64758a;
  padding: 18px;
}

/* Locais da conferência */
.lista-locais {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.registro {
  background: #eef3f8;
  color: #1c426e;
  text-align: left;
  font-weight: 500;
  min-height: 32px;
}

.registro.selecionado {
  box-shadow: inset 0 0 0 2px #2173bf;
}

/* Mensagens */
.mensagem {
  min-height: 36px;
  padding: 10px;
  border-radius: 6px;
  background: #ecf3fc;
  color: #234b7b;
}

.topo .mensagem {
  flex-basis: 100%;
  margin: 0;
}

.mensagem.sucesso {
  background: #e5f5e9;
  color: #155937;
}

.mensagem.erro {
  background: #ffe9e9;
  color: #96202e;
}

/* Página de relatórios */
.relatorios-botao {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: 6px;
  background: #1559a8;
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.relatorios-botao.secundario {
  background: #e7eef7;
  color: #173b62;
}

.relatorios-botao:focus-visible {
  outline: 2px solid #1872c9;
  outline-offset: 2px;
}

.relatorios-filtros label {
  min-width: 0;
  flex: 1 1 135px;
}

.relatorios-filtros .campo-data {
  flex: 0 1 155px;
}

.relatorios-filtros label.relatorios-opcao {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 36px;
  white-space: nowrap;
}

.relatorios-opcao input {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.relatorios-tabela table {
  min-width: 720px;
}

.relatorios-tabela td:nth-child(n) {
  min-width: 0;
  white-space: normal;
}

.relatorios-pdf {
  min-height: 28px;
  padding: 4px 9px;
}

.relatorios-paginacao {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

/* Ajustes para celular */
@media (max-width: 640px) {
  .pagina {
    padding: 8px;
  }

  .painel {
    padding: 10px;
  }

  .campo-data {
    max-width: none;
  }

  .campos > * {
    flex: 1 1 100%;
  }

  .linha-titulo,
  .topo {
    align-items: flex-start;
  }

  .linha-cabecalho {
    align-items: center;
  }

  .linha-leitura {
    flex-wrap: wrap;
    overflow: visible;
  }

  .linha-leitura label {
    flex: 1 1 100%;
    min-width: 0;
  }

  .linha-leitura button,
  .linha-leitura h2,
  .linha-leitura .meta,
  .linha-leitura .mensagem-inline {
    flex: 0 1 auto;
    white-space: normal;
    margin: 0;
  }

  .linha-leitura .mensagem-inline {
    max-width: 100%;
  }

  .topo-com-relatorios {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    align-items: center;
  }

  .topo-com-relatorios > div:first-child {
    grid-column: 1 / -1;
  }

  .topo-link-relatorios {
    justify-self: start;
  }

  .relatorios-filtros .campo-data {
    flex: 1 1 135px;
    max-width: none;
  }

  .relatorios-filtros > button,
  .relatorios-filtros > .relatorios-botao {
    flex: 0 0 auto;
  }
}

/* Leitura de códigos pela câmera */
.camera-dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
  border: 1px solid #dbe3ec;
  border-radius: 10px;
  color: #172638;
  background: #fff;
  overflow: auto;
}

.camera-dialog::backdrop {
  background: #172638b3;
}

.camera-dialog .linha-titulo {
  gap: 10px;
}

.camera-dialog h2 {
  margin: 0;
}

.camera-video {
  display: block;
  width: 100%;
  height: min(42dvh, 320px);
  margin: 12px 0;
  border-radius: 8px;
  background: #111;
  object-fit: contain;
}

.camera-dialog .mensagem {
  margin: 10px 0;
  overflow-wrap: anywhere;
}

.camera-acoes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.camera-acoes button {
  flex: 1 1 160px;
}

@media (max-width: 640px) {
  .camera-dialog {
    padding: 12px;
  }

  .camera-dialog .linha-titulo {
    align-items: center;
  }
}