@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  src: url(vendor/archivo.woff2) format('woff2-variations');
}

:root {
  --tinta: #141414;
  --tinta-2: rgb(20 20 20 / 0.74);
  --neutro: #f4f2ee;
  --neutro-2: #e4e0d8;
  --neutro-tinta-2: #5c5852;
  --carimbo: #b3261e;
  --papel: var(--neutro);
  --papel-tinta: var(--tinta);
  --papel-tinta-2: var(--tinta-2);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --raio: 12px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --t-nome: 16rem;
  --t-valor: 6rem;
  --t-cifra: 2.25rem;

  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  height: 100dvh;
  font-family: 'Archivo', system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.4;
  background: var(--tinta);
  color: var(--tinta);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: 'barra' 'camera' 'papel' 'canhotos' 'leitura';
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--tinta); color: var(--neutro); }
input { caret-color: var(--neutro); }
:focus-visible { outline: 3px solid var(--tinta); outline-offset: 2px; }
.leitura :focus-visible, .barra :focus-visible { outline-color: var(--neutro); }

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Barra ---------------------------------------------------------------- */

.barra {
  grid-area: barra;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4);
  padding-top: max(var(--s3), env(safe-area-inset-top));
  background: var(--tinta); color: var(--neutro);
  font-size: 0.8125rem; font-weight: 600;
}
.barra p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-marca { order: -1; }
.barra-marca b { font-weight: 850; letter-spacing: 0.02em; }
.barra-status { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.barra-contador { color: #c9c5bd; }
.barra-contador span { color: var(--neutro); font-weight: 800; }
.luz { width: 8px; height: 8px; border-radius: 50%; background: #7a766f; flex: none; }
body[data-rede='online'] .luz { background: #7dd87d; }
body[data-rede='offline'] .luz { background: #ffa65c; }

@media (max-width: 559px) {
  .barra-contador { display: none; }
  .barra-marca b + * { display: none; }
}

/* Papel: a tela inteira é o cartaz da cor --------------------------------- */

.papel {
  grid-area: papel;
  background: var(--papel);
  color: var(--papel-tinta);
  overflow: auto;
  outline: none;
  transition: background-color 120ms linear;
}
.folha {
  container-type: inline-size;
  min-height: 100%;
  padding: var(--s4) var(--s4) var(--s5);
  display: flex; flex-direction: column;
}
.folha.troca { animation: troca 240ms var(--ease); }
@keyframes troca {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}
@media (prefers-reduced-motion: reduce) {
  .folha.troca, .folha.troca .leitura-n { animation: none; }
}

.leitura-n {
  /* Selo invertido que troca a cada leitura: duas caixas da mesma cor seguidas não parecem tela parada. */
  align-self: flex-end;
  display: inline-flex; align-items: baseline; gap: var(--s2);
  padding: var(--s1) var(--s3);
  border-radius: 6px;
  background: var(--papel-tinta); color: var(--papel);
  font-size: 0.8125rem; font-weight: 700;
}
.leitura-n b { font-size: 1.75rem; font-weight: 900; font-stretch: 75%; line-height: 1; }
.folha.troca .leitura-n { animation: selo 420ms var(--ease); }
@keyframes selo { from { transform: scale(1.35); } to { transform: none; } }

.cor-nome {
  /* AMARELO, o nome mais largo, mede 3,62em: 27cqi cabe em qualquer largura e todas as cores saem do mesmo tamanho. */
  font-size: min(var(--t-nome), 27cqi);
  line-height: 0.82;
  font-weight: 900;
  font-stretch: 62%;
  text-transform: uppercase;
  letter-spacing: -0.01em;
  margin-top: var(--s2);
  overflow-wrap: anywhere;
}
.cor-faixa { margin-top: var(--s3); font-size: 1rem; font-weight: 600; color: var(--papel-tinta-2); }

.valores { margin-top: var(--s6); }
.preco { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.preco-por { font-size: 1.25rem; font-weight: 800; text-transform: uppercase; }
.preco-valor {
  font-size: var(--t-valor); line-height: 0.9; font-weight: 900; font-stretch: 75%;
  letter-spacing: -0.02em;
}
.preco-valor small { font-size: var(--t-cifra); vertical-align: 0.95em; margin-right: 0.08em; letter-spacing: 0; }
.preco-de { margin-top: var(--s2); font-size: 1.0625rem; font-weight: 600; }
.preco-de s { font-weight: 750; text-decoration-thickness: 2px; }
.preco-avaria { margin-top: var(--s1); font-size: 0.9375rem; color: var(--papel-tinta-2); }

/* Régua proporcional das faixas */
.regua { margin-top: var(--s6); }
.regua-trilho, .regua-legenda { display: grid; column-gap: 3px; }
.regua-trilho { height: 12px; }
.regua-trilho i { position: relative; display: block; background: rgb(20 20 20 / 0.55); }
.regua-trilho i.atual { background: var(--papel-tinta); }
.regua-marca {
  position: absolute; top: -6px; width: 4px; height: 24px; margin-left: -2px;
  background: var(--papel-tinta); border-radius: 2px; box-shadow: 0 0 0 2px var(--papel);
}
.regua-legenda {
  margin-top: var(--s2);
  font-size: 0.75rem; font-weight: 600; color: var(--papel-tinta-2); white-space: nowrap;
}

.produto { margin-top: var(--s5); padding-top: var(--s3); border-top: 2px solid var(--papel-tinta); }
.produto-nome { font-size: 1rem; font-weight: 750; text-transform: uppercase; line-height: 1.25; text-wrap: balance; }
.produto-codigo { margin-top: var(--s1); font-size: 0.8125rem; font-weight: 500; color: var(--papel-tinta-2); overflow-wrap: anywhere; }

/* Estados sem cor */

body[data-estado='nao-encontrado'] { --papel: var(--tinta); --papel-tinta: var(--neutro); --papel-tinta-2: #c9c5bd; }
body[data-estado='nao-encontrado'] .produto { border-color: #4a4742; }

.titulo-estado {
  font-size: 4rem; line-height: 0.88; font-weight: 900; font-stretch: 62%;
  text-transform: uppercase; margin-top: var(--s2); text-wrap: balance;
}
.texto-estado { margin-top: var(--s4); font-size: 1.0625rem; max-width: 34ch; }
.texto-estado b { font-weight: 750; overflow-wrap: anywhere; }

.carimbo {
  align-self: flex-start;
  width: fit-content;
  transform: rotate(-2deg);
  margin-left: 8px; /* a rotação e o filete externo não passam da margem */
  outline: 2px solid var(--carimbo); outline-offset: 4px;
  margin-top: var(--s2);
  padding: var(--s2) var(--s4) var(--s1);
  border: 5px solid var(--carimbo);
  border-radius: 6px;
  color: var(--carimbo);
  font-size: min(4.75rem, 21cqi); line-height: 0.95; font-weight: 900; font-stretch: 62%;
  text-transform: uppercase; letter-spacing: 0.01em;
}
.ordem {
  margin-top: var(--s6);
  font-size: 2.5rem; line-height: 0.92; font-weight: 900; font-stretch: 62%; text-transform: uppercase;
}
.regra { margin-top: var(--s3); font-size: 0.9375rem; color: var(--neutro-tinta-2); }
.versao { margin-top: var(--s3); font-size: 0.875rem; font-weight: 700; }
.motivo { margin-top: var(--s4); font-size: 1.125rem; font-weight: 650; max-width: 32ch; text-wrap: pretty; }
.amostra { width: 28px; height: 28px; border-radius: 6px; flex: none; box-shadow: inset 0 0 0 1px rgb(20 20 20 / 0.18); }

/* Elenco fixo das faixas (tela inicial) */
.elenco { margin-top: var(--s6); list-style: none; padding: 0; display: grid; gap: 2px; }
.elenco li {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  padding: var(--s2) 0; border-bottom: 1px solid var(--neutro-2);
}
.elenco-nome { font-weight: 800; font-size: 1.0625rem; }
.elenco-faixa { display: block; font-size: 0.8125rem; color: var(--neutro-tinta-2); font-weight: 500; }
.elenco-preco { font-weight: 850; font-size: 1.25rem; font-stretch: 80%; }

/* Canhotos ------------------------------------------------------------- */

.canhotos {
  grid-area: canhotos;
  background: var(--neutro);
  border-top: 1px solid var(--neutro-2);
  padding: var(--s3) var(--s4) var(--s2);
  max-height: 34vh; overflow: auto;
}
.canhotos h2 {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--neutro-tinta-2); margin-bottom: var(--s1);
}
.canhotos ol { list-style: none; padding: 0; }
.canhotos li + li { border-top: 1px dashed #cfcac1; }
.canhoto {
  width: 100%; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  padding: var(--s2) 0; background: none; border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer;
  font-size: 0.875rem;
}
.canhoto:hover .canhoto-nome { text-decoration: underline; text-underline-offset: 3px; }
.canhoto .amostra { width: 16px; height: 16px; border-radius: 4px; }
.canhoto-nome { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canhoto-cor { font-weight: 800; }
.canhoto-cor.alerta { color: var(--carimbo); }
.canhotos-vazio { font-size: 0.875rem; color: var(--neutro-tinta-2); padding: var(--s1) 0 var(--s2); }
.canhotos ol:not(:empty) + .canhotos-vazio { display: none; }
.fonte { font-size: 0.75rem; color: var(--neutro-tinta-2); padding-top: var(--s2); }

@media (max-width: 959px) {
  .canhotos li:nth-child(n + 3) { display: none; }
  .fonte { display: none; }
}

/* Leitura -------------------------------------------------------------- */

.leitura {
  grid-area: leitura;
  display: flex; gap: var(--s2);
  padding: var(--s3) var(--s4);
  padding-bottom: max(var(--s3), env(safe-area-inset-bottom));
  background: var(--tinta);
}
.leitura-campo { flex: 1; min-width: 0; display: flex; }
.leitura input {
  width: 100%; min-height: 52px;
  border: 2px solid #8a867e; border-radius: var(--raio);
  background: transparent; color: var(--neutro);
  padding: 0 var(--s4); font: inherit; font-size: 1.125rem; font-weight: 600; letter-spacing: 0.02em;
}
.leitura input::placeholder { color: #a9a59d; font-weight: 500; letter-spacing: 0; }
.leitura input:focus { border-color: var(--neutro); outline: none; }
.leitura input:disabled { opacity: 0.5; }

.botao {
  min-height: 52px; padding: 0 var(--s4);
  border: 0; border-radius: var(--raio);
  font: inherit; font-size: 1rem; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--s2);
  transition: background-color 150ms var(--ease), transform 150ms var(--ease);
}
.botao:active { transform: scale(0.97); }
.botao:disabled { opacity: 0.5; cursor: default; }
.botao svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; }
.botao-ok { background: transparent; color: var(--neutro); box-shadow: inset 0 0 0 2px #8a867e; }
.botao-ok:hover { box-shadow: inset 0 0 0 2px var(--neutro); }
.botao-camera { background: var(--neutro); color: var(--tinta); }
.botao-camera:hover { background: #fff; }
.botao-camera[aria-pressed='true'] { background: var(--papel); box-shadow: inset 0 0 0 2px var(--neutro); }

@media (max-width: 559px) {
  .botao-ok { display: none; }
}

/* Câmera --------------------------------------------------------------- */

.camera {
  grid-area: camera;
  position: relative;
  background: #000;
  height: 34vh; min-height: 200px;
  overflow: hidden;
}
.camera[hidden] { display: none; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera::after {
  content: ''; position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; margin-top: -1px;
  background: var(--papel); box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35);
  transition: background-color 120ms linear;
}
.camera.lido::after { animation: lido 380ms var(--ease); }
@keyframes lido { from { height: 40%; margin-top: -20%; opacity: 0.55; } to { height: 2px; margin-top: -1px; opacity: 1; } }
.camera-dica {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: var(--s2) var(--s4);
  background: linear-gradient(transparent, rgb(0 0 0 / 0.7));
  color: var(--neutro); font-size: 0.875rem; font-weight: 600;
}

/* Câmera aberta no celular: só o essencial da cor cabe acima da dobra */
@media (max-width: 959px) {
  body:has(.camera:not([hidden])) .camera { height: 28vh; min-height: 170px; }
  body:has(.camera:not([hidden])) :is(.regua, .preco-avaria, .canhotos, .texto-estado + .texto-estado, .elenco) { display: none; }
  body:has(.camera:not([hidden])) .valores { margin-top: var(--s4); }
  body:has(.camera:not([hidden])) .produto { margin-top: var(--s3); }
}

/* Telas largas: cartaz à esquerda, canhotos à direita ------------------- */

@media (min-width: 960px) {
  :root { --t-valor: 9.5rem; --t-cifra: 3.25rem; }
  body {
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: 'barra barra' 'papel lateral' 'leitura leitura';
  }
  .camera, .canhotos { grid-area: auto; }
  .camera { grid-column: 2; grid-row: 2; align-self: start; height: 270px; z-index: 1; }
  .canhotos { grid-column: 2; grid-row: 2; max-height: none; border-top: 0; border-left: 1px solid var(--neutro-2); padding: var(--s5) var(--s5) var(--s4); }
  body:has(.camera:not([hidden])) .canhotos { padding-top: calc(270px + var(--s5)); }
  .folha { padding: var(--s5) var(--s7) var(--s6); }
  .folha-grade {
    flex: 1; display: grid; align-content: center; align-items: end;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'cabeca cabeca' 'valores detalhe';
    column-gap: var(--s7);
  }
  .cabeca { grid-area: cabeca; }
  .valores { grid-area: valores; }
  .detalhe { grid-area: detalhe; }
  body[data-estado='revisar'] .folha-grade { grid-template-columns: minmax(0, 44rem); grid-template-areas: none; align-items: start; }
  .produto-nome { font-size: 1.25rem; }
  .titulo-estado { font-size: 7rem; }
  .carimbo { font-size: min(8rem, 21cqi); }
  .ordem { font-size: 4rem; }
  .leitura { padding: var(--s4) var(--s7); }
  .leitura input { min-height: 60px; font-size: 1.375rem; }
  .botao { min-height: 60px; padding: 0 var(--s5); }
}

@media (min-width: 400px) and (max-width: 959px) {
  :root { --t-valor: 6.5rem; }
}
