/* Inventário Digital · responsivo, tablet primeiro (especificação, seção 5.0).
   Uso com luva e luz de galpão: botões com no mínimo 64 px de altura, texto base de 20 px, alto contraste,
   nada depende de hover.
   Quebras: até 599 px celular (uma coluna, tabelas em cartões, botões da ficha no rodapé);
   600 a 1099 px tablet; 1100 px ou mais tela larga. Notebook (tela larga com mouse): lista e ficha lado a lado,
   pelo arranjo .dividido montado em app.js. Nunca rolagem horizontal. */

:root {
  --texto: #111;
  --texto-suave: #444;
  --fundo: #eceff1;
  --painel: #fff;
  --borda: #9aa3a8;
  --foco: #0b57d0;

  --amarelo: #f2c200;
  --amarelo-fundo: #fff4bf;
  --verde: #1b7f37;
  --verde-fundo: #dff3e5;
  --azul: #1556b8;
  --azul-fundo: #dde8fb;
  --roxo: #6a1b9a;
  --roxo-fundo: #efe1f7;

  --laranja: #d84e00;
  --vermelho: #b3261e;
  --marrom: #6d4c41;
  --cinza: #5f6368;
  --principal: #0b57d0;

  --raio: 10px;
  --alto: 64px;
  --cabecalho: 142px; /* altura do topo + menu, medida em app.js */
}

* { box-sizing: border-box; }
html { font-size: 20px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--texto);
  background: var(--fundo);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
h1 { font-size: 1.6rem; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
a { color: var(--principal); }
small { font-size: .8rem; }
kbd { font: inherit; font-size: .8rem; padding: 0 .35rem; border: 2px solid var(--borda); border-radius: 6px; background: #fff; }
img, svg { max-width: 100%; }
:focus-visible { outline: 4px solid var(--foco); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sub { color: var(--texto-suave); margin: 0 0 1rem; }
.pequeno { font-size: .8rem; }
.vazio { padding: 1.2rem; color: var(--texto-suave); text-align: center; background: var(--painel); border-radius: var(--raio); }
.carregando { padding: 2rem; text-align: center; }

/* ------------------------------------------------------------------ botões */
.botao {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--alto); padding: 0 1.4rem;
  font: inherit; font-weight: 700; text-decoration: none; text-align: center;
  border: 3px solid transparent; border-radius: var(--raio);
  cursor: pointer; user-select: none; touch-action: manipulation;
  color: #fff; background: var(--principal);
}
.botao:active { transform: translateY(2px); filter: brightness(.92); }
.botao:disabled { opacity: .5; cursor: not-allowed; }
.botao-principal { background: var(--principal); }
.botao-secundario { background: #fff; color: var(--texto); border-color: var(--texto); }
.botao-verde { background: var(--verde); }
.botao-laranja { background: var(--laranja); }
.botao-cinza { background: var(--cinza); }
.botao-marrom { background: var(--marrom); }
.botao-roxo { background: var(--roxo); }
.botao-perigo { background: var(--vermelho); }
.botao-largo { width: 100%; }
.botao-sair { background: var(--vermelho); min-width: 140px; font-size: 1.1rem; }
.botao-finalizar { min-width: 260px; font-size: 1.25rem; }
.botao-icone {
  min-width: var(--alto); min-height: var(--alto); font-size: 1.6rem; font-weight: 700;
  border: 3px solid var(--texto); border-radius: var(--raio); background: #fff; color: var(--texto); cursor: pointer;
}
.botao-flutuante { position: fixed; right: 24px; bottom: 24px; z-index: 20; box-shadow: 0 4px 14px rgba(0,0,0,.35); min-width: 200px; }
.botao-arquivo { position: relative; }

/* ------------------------------------------------------------------ campos */
.campo { display: flex; flex-direction: column; gap: .3rem; margin: 0 0 .8rem; min-width: 0; border: 0; padding: 0; }
.campo > span, .campo label > span, .campo legend { font-weight: 700; }
input, select, textarea {
  font: inherit; color: var(--texto); background: #fff;
  min-height: var(--alto); padding: .4rem .8rem;
  border: 3px solid var(--borda); border-radius: var(--raio); width: 100%; max-width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--foco); outline: none; }
input[type="checkbox"] { width: 40px; height: 40px; min-height: 0; accent-color: var(--verde); flex: none; }
.erro-campo { color: var(--vermelho); font-weight: 700; min-height: 1.3rem; margin: .2rem 0; }
.campo-busca-pequena { min-height: 52px; }
.grade-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grade-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.campo-duplo { grid-column: span 2; }
.campo-largo { grid-column: 1 / -1; }
.acoes { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .6rem; }

/* ------------------------------------------------------------------ topo e menu */
.topo {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem; background: #1b1b1b; color: #fff; min-height: 76px;
}
.topo-onde, .topo-quem { display: flex; flex-direction: column; min-width: 0; }
.topo-onde { flex: 1; }
.topo-onde span, .topo-quem span { color: #cfd8dc; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topo-onde strong, .topo-quem strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topo-quem { text-align: right; }
.topo-conexao { display: flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 700; padding: .3rem .6rem; border-radius: 999px; background: #333; }
.topo-conexao .ponto { width: 14px; height: 14px; border-radius: 50%; background: #4caf50; flex: none; }
.topo-conexao.off .ponto { background: #ff9800; }
.faixa-conexao { background: var(--laranja); color: #fff; font-weight: 700; padding: .6rem 1rem; text-align: center; }
.menu { display: flex; gap: .4rem; padding: .4rem 1rem; background: #fff; border-bottom: 3px solid #cfd8dc; overflow-x: auto; position: sticky; top: 76px; z-index: 25; }
.menu-item {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 56px; padding: 0 1.1rem;
  border-radius: var(--raio); font-weight: 700; color: var(--texto); text-decoration: none; white-space: nowrap; border: 3px solid transparent;
}
.menu-item.ativo { background: #1b1b1b; color: #fff; }
.contador { background: var(--azul); color: #fff; border-radius: 999px; padding: 0 .55rem; font-size: .85rem; }
.menu-item.ativo .contador { background: #fff; color: var(--azul); }

/* ------------------------------------------------------------------ telas e blocos */
.tela, #tela { outline: none; }
.pagina { padding: 1rem 1.2rem 6rem; }
.pagina-estreita { max-width: 900px; }
.bloco { background: var(--painel); border-radius: var(--raio); padding: 1rem 1.2rem; margin: 0 0 1rem; border: 2px solid #d5dbdf; min-width: 0; }
fieldset.bloco { margin: 0 0 1rem; }
fieldset.bloco legend { font-weight: 700; font-size: 1.1rem; padding: 0 .3rem; }
.faixa-info, .faixa-ok, .faixa-erro, .faixa-motivos {
  padding: .8rem 1rem; border-radius: var(--raio); font-weight: 700; margin: 0 0 1rem;
}
.faixa-info { background: #fff3cd; border: 2px solid #c79b00; }
.faixa-trava { background: var(--amarelo-fundo); border-color: var(--amarelo); font-size: 1.2rem; }
.faixa-ok { background: var(--verde-fundo); border: 2px solid var(--verde); }
.faixa-erro { background: #fde7e6; border: 2px solid var(--vermelho); }
.faixa-motivos { background: var(--roxo-fundo); border: 2px solid var(--roxo); font-size: 1.15rem; }
.lista-erros { max-height: 300px; overflow: auto; margin: .5rem 0 0; font-weight: 400; font-size: .85rem; }

/* ------------------------------------------------------------------ login */
.tela-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.caixa-login { width: min(520px, 100%); background: #fff; border-radius: 16px; padding: 2rem; border: 3px solid #1b1b1b; display: flex; flex-direction: column; gap: .4rem; }
.caixa-login h1 { margin: 0; }
.caixa-login .botao { margin-top: .5rem; }

/* ------------------------------------------------------------------ início e inventários */
.lista-cartoes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 1rem; }
.cartao {
  display: flex; flex-direction: column; gap: .3rem; padding: 1.2rem; min-height: 140px;
  background: #fff; border-radius: var(--raio); border: 3px solid #cfd8dc; color: var(--texto); text-decoration: none; border-left-width: 14px;
}
.cartao strong { font-size: 1.3rem; }
.cartao-status { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.cartao-em_andamento { border-left-color: var(--verde); }
.cartao-preparacao { border-left-color: var(--amarelo); }
.cartao-fechado { border-left-color: var(--cinza); }
.inventario-item { border-left: 14px solid #cfd8dc; }
.inventario-item header h2 { margin: .2rem 0; }
.inventario-item header p { margin: 0 0 .2rem; }
.form-linha .grade-3 { align-items: end; }

/* ------------------------------------------------------------------ lista de lotes */
.tela-lotes {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: auto auto 1fr;
  grid-template-areas: "familias familias" "rosca busca" "rosca lista";
  gap: .8rem 1rem; padding: .8rem 1rem 1rem; align-items: start;
}
.progresso-resumo { display: none; }
.area-busca { grid-area: busca; min-width: 0; }
.area-busca .faixa-info { margin-bottom: .6rem; }
.barra-familias { grid-area: familias; }
.barra-familias .chips { margin: 0; }
.painel-filtros { grid-area: rosca; position: sticky; top: calc(var(--cabecalho) + 12px); display: flex; flex-direction: column; gap: 1rem; max-height: calc(100vh - var(--cabecalho) - 24px); overflow: auto; }
.painel-lista { grid-area: lista; min-width: 0; }
/* espaço livre no fim da lista: o botão Criar lote não cobre a última linha */
.area-criar-lote { height: calc(var(--alto) + 56px); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .8rem; }
.chip {
  min-height: var(--alto); min-width: 80px; padding: 0 1rem; font: inherit; font-weight: 700;
  border: 3px solid var(--texto); border-radius: 999px; background: #fff; color: var(--texto); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.chip small { font-weight: 400; }
.chip.marcado { background: #1b1b1b; color: #fff; }
.chip-check input { width: 28px; height: 28px; }
.rosca-caixa { background: #fff; border-radius: var(--raio); padding: .8rem; border: 2px solid #d5dbdf; }
.alternar { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-bottom: .6rem; }
.alternar-botao { min-height: var(--alto); font: inherit; font-weight: 700; border: 3px solid var(--texto); border-radius: var(--raio); background: #fff; color: var(--texto); cursor: pointer; }
.alternar-botao.marcado { background: #1b1b1b; color: #fff; }
.rosca { width: 100%; max-width: 230px; display: block; margin: 0 auto; }
.fatia { fill: none; stroke-width: 30; }
.fatia.verde { stroke: var(--verde); }
.fatia.roxo { stroke: var(--roxo); }
.fatia.azul { stroke: var(--azul); }
.fatia.amarelo { stroke: var(--amarelo); }
.fatia.vazia { stroke: #cfd8dc; }
.rosca-centro { font-size: 30px; font-weight: 800; text-anchor: middle; fill: var(--texto); }
.rosca-sub { font-size: 15px; text-anchor: middle; fill: var(--texto-suave); }
.legenda { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-direction: column; gap: .4rem; font-size: .9rem; }
.legenda li { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: .35rem; }
.legenda li strong { text-align: right; }
.legenda .detalhe { display: block; padding-left: 57px; margin-top: -.3rem; color: var(--texto-suave); font-size: .8rem; }
.marcas { display: inline-flex; gap: 4px; }
.marca { width: 22px; height: 22px; border-radius: 4px; display: inline-block; }
.marca.verde { background: var(--verde); } .marca.roxo { background: var(--roxo); }
.marca.azul { background: var(--azul); } .marca.amarelo { background: var(--amarelo); }

/* barra de progresso (rosca recolhida, no celular) */
.progresso-barra svg { display: block; width: 100%; height: 22px; border-radius: 6px; overflow: hidden; }
.progresso-barra .fundo { fill: #cfd8dc; }
.progresso-barra .verde { fill: var(--verde); } .progresso-barra .roxo { fill: var(--roxo); }
.progresso-barra .azul { fill: var(--azul); } .progresso-barra .amarelo { fill: var(--amarelo); }

.busca { font-size: 1.1rem; min-height: 72px; border-width: 3px; border-color: var(--texto); }
.contagem { margin: .5rem 0; font-weight: 700; }
.lista-lotes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
/* cartão do lote: linha 1 lote, item e medida; linha 2 a qualidade completa, na largura toda */
.lote {
  display: grid; grid-template-columns: 22px minmax(140px, 1fr) minmax(0, 1.5fr) auto;
  grid-template-areas: "ind num item medida" "ind qual qual qual" "ind estado estado estado";
  column-gap: .8rem; row-gap: .15rem; align-items: center; min-height: 76px; padding: .6rem .8rem;
  background: #fff; border-radius: var(--raio); border: 3px solid #cfd8dc; color: var(--texto); text-decoration: none;
}
.lote .indicador { grid-area: ind; align-self: stretch; border-radius: 6px; }
.lote-num { grid-area: num; display: flex; flex-direction: column; min-width: 0; }
.lote-num strong { font-size: 1.15rem; overflow-wrap: anywhere; }
.lote-item { grid-area: item; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.lote-medida { grid-area: medida; font-weight: 700; white-space: nowrap; text-align: right; }
.lote-qualidade { grid-area: qual; font-size: .85rem; color: var(--texto-suave); overflow-wrap: break-word; }
.lote-estado { grid-area: estado; }
.cor-amarelo .indicador { background: var(--amarelo); } .cor-amarelo { border-color: var(--amarelo); }
.cor-azul .indicador { background: var(--azul); } .cor-azul { border-color: var(--azul); background: var(--azul-fundo); }
.cor-roxo .indicador { background: var(--roxo); } .cor-roxo { border-color: var(--roxo); background: var(--roxo-fundo); }
.cor-verde .indicador { background: var(--verde); } .cor-verde { border-color: var(--verde); background: var(--verde-fundo); }
.cor-verde .lote-num, .cor-verde .lote-item, .cor-verde .lote-medida, .cor-verde .lote-qualidade { text-decoration: line-through; text-decoration-thickness: 2px; }
.lote.travado { border-style: dashed; opacity: .85; }
.lote.selecionado { outline: 5px solid var(--foco); outline-offset: 1px; }
.selo-trava { display: inline-block; background: var(--amarelo-fundo); border: 2px solid var(--amarelo); padding: .1rem .6rem; border-radius: 6px; font-style: normal; font-weight: 700; }

/* ------------------------------------------------------------------ ficha */
.tela-ficha { padding: 0 1rem 7rem; border-top: 10px solid transparent; }
.quadro-laranja { border-top-color: var(--laranja); }
.quadro-vermelho { border-top-color: var(--vermelho); }
.quadro-marrom { border-top-color: var(--marrom); }
.quadro-roxo { border-top: 10px solid var(--roxo); }
.quadro-leitura { border-top-color: var(--cinza); }
.ficha-cabecalho { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; }
.ficha-titulo { display: flex; flex-direction: column; min-width: 0; }
.ficha-titulo h1 { margin: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.quadro-laranja .ficha-titulo h1 { color: var(--laranja); }
.quadro-vermelho .ficha-titulo h1 { color: var(--vermelho); }
.quadro-marrom .ficha-titulo h1 { color: var(--marrom); }
.quadro-roxo .ficha-titulo h1 { color: var(--roxo); }
.ficha-corpo { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 1rem; align-items: start; }
.info { margin: 0 0 1rem; display: grid; gap: .1rem; }
.info > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: .6rem; padding: .45rem .3rem; border-bottom: 1px solid #e0e4e7; }
.info dt { font-weight: 700; color: var(--texto-suave); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.info .alterado { background: #ffe6e3; border-left: 6px solid var(--vermelho); }
.info .original, .campo .original { color: var(--vermelho); font-weight: 700; font-size: .8rem; }
.info-compacta > div { grid-template-columns: 170px minmax(0, 1fr); }
.aviso-correcao { background: #ffe6e3; border: 2px solid var(--vermelho); padding: .6rem; border-radius: var(--raio); font-weight: 700; }
.caixa-conferi {
  display: flex; align-items: center; gap: 1rem; min-height: 84px; padding: .6rem 1rem;
  border: 4px solid var(--verde); border-radius: var(--raio); background: var(--verde-fundo); font-size: 1.3rem; font-weight: 800; cursor: pointer;
}
.bloco-peso { border: 3px solid var(--laranja); }
.pesagens { display: flex; flex-direction: column; gap: .5rem; }
.pesagem { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: .6rem; align-items: center; }
.pesagem-num { font-weight: 800; text-align: center; }
.campo-peso { font-size: 1.5rem; font-weight: 800; min-height: 72px; text-align: right; }
.peso-rodape { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .8rem; flex-wrap: wrap; }
.peso-total { font-size: 1.3rem; }
.peso-total strong { font-size: 2rem; }
.campo-foto .foto-area { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.foto-miniatura { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 2px solid var(--borda); }
.foto-botoes { display: flex; flex-direction: column; gap: .4rem; }
.foto-grande { width: 100%; max-height: 70vh; object-fit: contain; border-radius: var(--raio); background: #000; margin: .5rem 0; }
.barra-acoes {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: flex-end; gap: 1rem; padding: .7rem 1rem;
  background: #fff; border-top: 3px solid #cfd8dc; box-shadow: 0 -4px 12px rgba(0,0,0,.12);
}
.barra-acoes .botao-finalizar { margin-left: auto; }
.grade-corrigir { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grade-corrigir .campo.alterado input, .grade-corrigir .campo.alterado select { border-color: var(--vermelho); background: #fff1ef; }
.ficha-lida { border: 2px solid #cfd8dc; border-radius: var(--raio); padding: .8rem; margin: 0 0 .8rem; }
.ficha-lida header { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.ficha-lida header small { flex-basis: 100%; color: var(--texto-suave); }
.ficha-lida.status-cancelada { opacity: .75; background: #f5f5f5; }
.linha-do-tempo ol { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: .35rem; }
.linha-do-tempo li { overflow-wrap: anywhere; }
.aviso-lote { background: var(--amarelo-fundo); border: 3px solid var(--amarelo); border-radius: var(--raio); padding: .7rem 1rem; margin: 0 0 1rem; }
.aviso-lote ul { margin: .4rem 0 0; }
.aviso-lote a { display: inline-block; padding: .4rem 0; font-weight: 700; }

/* selos de situação */
.selo { display: inline-block; padding: .1rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 800; color: #fff; vertical-align: middle; }
.selo-finalizada_ok { background: var(--verde); }
.selo-divergente { background: var(--azul); }
.selo-validada { background: var(--roxo); }
.selo-cancelada { background: var(--cinza); }

/* ------------------------------------------------------------------ fichas (gestão) */
.filtros { margin-bottom: .6rem; }
.tabela-fichas { display: flex; flex-direction: column; gap: .4rem; }
.linha-tabela {
  display: grid; grid-template-columns: 60px 1.3fr 1.3fr .9fr .9fr .8fr .7fr 1.5fr 1.2fr; gap: .5rem; align-items: center;
  min-height: 72px; padding: .5rem .7rem; background: #fff; border-radius: var(--raio); border: 2px solid #d5dbdf;
  color: var(--texto); text-decoration: none; font-size: .85rem;
}
.linha-tabela > span { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; overflow-wrap: anywhere; }
.linha-tabela.cabecalho { min-height: 0; background: transparent; border: 0; font-weight: 700; color: var(--texto-suave); }
.linha-tabela .n strong { font-size: 1.2rem; }
.linha-tabela .num { text-align: right; align-items: flex-end; }
.falta { color: var(--vermelho); font-weight: 700; }
.sobra { color: var(--verde); font-weight: 700; }
.status-divergente { border-left: 8px solid var(--azul); }
.status-validada { border-left: 8px solid var(--roxo); }
.status-finalizada_ok { border-left: 8px solid var(--verde); }
.status-cancelada { border-left: 8px solid var(--cinza); }
.links { padding-left: 1.2rem; }
.links a { display: inline-block; padding: .4rem 0; font-weight: 700; }

/* ------------------------------------------------------------------ cadastros */
.abas { display: flex; gap: .4rem; margin: 0 0 1rem; flex-wrap: wrap; }
.aba { min-height: var(--alto); display: inline-flex; align-items: center; padding: 0 1.2rem; border-radius: var(--raio); border: 3px solid var(--texto); color: var(--texto); font-weight: 700; text-decoration: none; background: #fff; }
.aba.ativa { background: #1b1b1b; color: #fff; }
.tabela-simples { display: flex; flex-direction: column; gap: .3rem; margin-top: 1rem; }
.linha-simples {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; align-items: center; text-align: left;
  min-height: 64px; padding: .4rem .8rem; font: inherit; font-size: .9rem; color: var(--texto);
  background: #fff; border: 2px solid #d5dbdf; border-radius: var(--raio); width: 100%;
}
.linha-simples > span { min-width: 0; overflow-wrap: anywhere; }
button.linha-simples { cursor: pointer; }
.linha-simples.cabecalho { min-height: 0; background: transparent; border: 0; font-weight: 700; color: var(--texto-suave); }
.linha-simples.inativo { opacity: .55; }

/* ------------------------------------------------------------------ aviso e janela */
.aviso {
  position: fixed; left: 50%; top: 90px; transform: translate(-50%, -200%); z-index: 60;
  width: max-content; max-width: min(90vw, 760px); padding: 1rem 1.6rem; border-radius: var(--raio);
  font-size: 1.15rem; font-weight: 800; color: #fff; background: var(--verde); box-shadow: 0 6px 20px rgba(0,0,0,.35);
  transition: transform .2s ease, opacity .2s ease; pointer-events: none; opacity: 0; visibility: hidden;
}
.aviso.visivel { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.aviso-erro { background: var(--vermelho); }
.modal-fundo { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-caixa { width: min(640px, 100%); max-height: calc(100vh - 2rem); overflow: auto; background: #fff; border-radius: 16px; padding: 1.6rem; border: 4px solid #1b1b1b; }
.modal-perigo { border-color: var(--vermelho); }
.modal-caixa h2 { font-size: 1.6rem; }
.modal-texto { font-size: 1.1rem; }
.modal-botoes { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.2rem; }

/* ------------------------------------------------------------------ notebook: lista e ficha lado a lado */
.dividido { display: grid; grid-template-columns: minmax(420px, 36%) minmax(0, 1fr); height: calc(100vh - var(--cabecalho)); }
.lado-detalhe .info > div { grid-template-columns: 110px minmax(0, 1fr); }
.lado-lista { overflow-y: auto; border-right: 3px solid #cfd8dc; background: var(--fundo); }
.lado-detalhe { overflow-y: auto; background: var(--fundo); }
.lado-lista .tela-lotes { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "busca" "familias" "rosca" "lista"; }
.lado-lista .painel-filtros { position: static; max-height: none; overflow: visible; }
.lado-lista .rosca-caixa { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 0 1rem; align-items: center; }
.lado-lista .alternar { grid-column: 1 / -1; }
.lado-lista .legenda { margin: 0; }
.lado-lista .lote { grid-template-columns: 18px minmax(0, 1fr) auto; grid-template-areas: "ind num medida" "ind item item" "ind qual qual" "ind estado estado"; }
.lado-lista .lote-medida { align-self: start; }
/* o Criar lote fica no fim da coluna da lista, sem cobrir a ficha ao lado */
.lado-lista .area-criar-lote { height: auto; position: sticky; bottom: 0; display: flex; justify-content: flex-end; padding: 1rem 0 .4rem; }
.lado-lista .botao-flutuante { position: static; }
.lado-detalhe .tela-ficha { padding-bottom: 0; }
.lado-detalhe .barra-acoes { position: sticky; left: auto; right: auto; margin: 1rem -1rem 0; }
.detalhe-vazio { height: 100%; min-height: 50vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; color: var(--texto-suave); font-size: 1.2rem; }
body.modo-dividido { overflow: hidden; }

/* ------------------------------------------------------------------ tablet (600 a 1099 px) */
@media (max-width: 1099.98px) {
  .tela-lotes { grid-template-columns: 260px minmax(0, 1fr); }
  .lote { grid-template-columns: 18px minmax(120px, 1fr) minmax(0, 1.3fr) auto; }
  .ficha-corpo { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
  .info > div { grid-template-columns: 120px minmax(0, 1fr); }
  .linha-tabela { grid-template-columns: 50px 1.2fr 1.2fr .8fr .8fr .7fr .6fr 1.3fr 1.1fr; font-size: .8rem; }
  .botao-finalizar { min-width: 220px; }
}

/* ------------------------------------------------------------------ celular (até 599 px) */
@media (max-width: 599.98px) {
  .topo { position: static; flex-wrap: wrap; gap: .4rem .6rem; padding: .5rem .7rem; }
  .topo-onde { flex: 1 1 calc(100% - 140px); }
  .botao-sair { min-width: 110px; }
  .topo-quem { order: 3; flex: 1 1 auto; text-align: left; }
  .topo-conexao { order: 4; }
  .menu { position: static; flex-wrap: wrap; overflow: visible; gap: .2rem; padding: .3rem .5rem; }
  .menu-item { padding: 0 .55rem; font-size: .9rem; min-height: 52px; }
  .pagina { padding: .8rem .7rem 6rem; }
  h1 { font-size: 1.4rem; }

  .tela-lotes { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "progresso" "busca" "familias" "rosca" "lista"; padding: .6rem .7rem 1rem; gap: .6rem; }
  .busca { min-height: var(--alto); font-size: 1rem; }
  .progresso-resumo {
    grid-area: progresso; display: flex; flex-direction: column; gap: .4rem; width: 100%; min-height: var(--alto);
    padding: .6rem .8rem; font: inherit; font-weight: 700; text-align: left; color: var(--texto);
    background: #fff; border: 3px solid var(--texto); border-radius: var(--raio); cursor: pointer;
  }
  .painel-filtros { display: none; position: static; max-height: none; overflow: visible; }
  .painel-filtros.aberta { display: flex; }
  .chip { min-width: 0; padding: 0 .7rem; font-size: .95rem; }
  .chips { gap: .4rem; }
  .lote { grid-template-columns: 16px minmax(0, 1fr) auto; grid-template-areas: "ind num medida" "ind item item" "ind qual qual" "ind estado estado"; padding: .5rem .6rem; column-gap: .6rem; }
  .lote-medida { align-self: start; }
  .lote-qualidade { font-size: .78rem; }
  .botao-flutuante { right: .7rem; bottom: .7rem; min-width: 0; }

  .tela-ficha { padding: 0 .7rem calc(2 * var(--alto) + 3rem); }
  .ficha-cabecalho { flex-wrap: wrap; gap: .6rem; }
  .ficha-corpo, .grade-2, .grade-3, .grade-corrigir { grid-template-columns: minmax(0, 1fr); }
  .campo-duplo { grid-column: auto; }
  .info > div, .info-compacta > div { grid-template-columns: 105px minmax(0, 1fr); }
  .bloco { padding: .8rem; }
  /* botões fixos no rodapé, 64 px, na largura toda. Na ficha: Corrigir e Não localizado lado a lado,
     Finalizar embaixo; nas outras telas, um botão por linha com a ação principal por último */
  .barra-acoes { display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; padding: .5rem .7rem; }
  .barra-acoes.barra-ficha { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .barra-acoes .botao { width: 100%; min-width: 0; padding: 0 .5rem; }
  .barra-acoes .botao-finalizar { grid-column: 1 / -1; order: 9; margin-left: 0; }

  /* tabelas viram cartões empilhados, nunca rolagem horizontal */
  .linha-tabela.cabecalho, .linha-simples.cabecalho { display: none; }
  .linha-tabela { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem .8rem; padding: .7rem; font-size: .9rem; }
  .linha-tabela > span::before, .linha-simples > span::before {
    content: attr(data-rotulo); display: block; font-size: .7rem; font-weight: 700; color: var(--texto-suave); text-transform: uppercase;
  }
  .linha-tabela .num { text-align: left; align-items: flex-start; }
  .linha-tabela .c-largo { grid-column: 1 / -1; }
  .linha-simples { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem .8rem; padding: .7rem; }
  .linha-simples > span.pequeno { grid-column: 1 / -1; }
  /* filtros das fichas: os três na mesma linha, situação em chips menores */
  .filtros .grade-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 .4rem; }
  .filtros select { padding: .3rem .4rem; font-size: .9rem; }
  .filtros .campo > span { font-size: .85rem; }
  .filtros .chip { font-size: .85rem; padding: 0 .6rem; }

  .modal-caixa { padding: 1.1rem; }
  .modal-botoes { grid-template-columns: minmax(0, 1fr); }
  .modal-botoes [data-r="sim"] { order: -1; }
  .caixa-login { padding: 1.2rem; }
  .aviso { top: 12px; }
}

/* celular e tablet deitados (pouca altura): topo e menu rolam junto com a página */
@media (max-height: 520px) {
  .topo, .menu { position: static; }
  .painel-filtros { position: static; max-height: none; }
}
