[hidden] { display: none !important; }
:root {
  --azul: #0f62fe; --azul-esc: #0043ce; --verde: #198038; --verde-cl: #defbe6; --amarelo: #fcf4d6;
  --vermelho: #da1e28; --cinza: #6f6f6f; --borda: #e0e0e0; --fundo: #f4f6f9; --card: #fff; --texto: #161616;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--fundo); color: var(--texto); }
header { display: flex; align-items: center; gap: 16px; background: #161616; color: #fff; padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 10; }
.marca { font-weight: 700; white-space: nowrap; }
nav { display: flex; gap: 4px; flex: 1; }
nav a { color: #c6c6c6; text-decoration: none; padding: 8px 12px; border-radius: 6px; white-space: nowrap; }
nav a:hover, nav a.ativo { background: #393939; color: #fff; }
.usuario { font-size: 13px; color: #c6c6c6; white-space: nowrap; }
.usuario .link { color: #78a9ff; }
.badge { display: inline-block; background: var(--vermelho); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
.sub { color: var(--cinza); margin: 0 0 20px; }
.card { background: var(--card); border: 1px solid var(--borda); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.linha { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.entre { justify-content: space-between; }
.grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
label { display: block; font-size: 13px; color: #393939; font-weight: 600; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid #c6c6c6; border-radius: 6px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul); outline-offset: -1px; border-color: var(--azul); }
textarea { min-height: 120px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
button, .btn { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 6px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--azul); color: #fff; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: var(--azul-esc); }
button.sec, .btn.sec { background: #fff; color: var(--azul); border: 1px solid var(--azul); }
button.sec:hover { background: #edf5ff; }
button.verde { background: var(--verde); } button.verde:hover { background: #0e6027; }
button.perigo { background: #fff; color: var(--vermelho); border: 1px solid var(--vermelho); }
button.link { background: none; color: var(--azul); padding: 0; font-weight: 500; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.peq, .btn.peq { padding: 5px 10px; font-size: 13px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--borda); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--cinza); background: #fafafa; position: sticky; top: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:hover td { background: #fafcff; }
.tabela-rol { overflow: auto; border: 1px solid var(--borda); border-radius: 10px; max-height: 70vh; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; background: #e0e0e0; }
.tag.aberta { background: #d0e2ff; color: #002d9c; } .tag.encerrada { background: var(--amarelo); color: #8e6a00; }
.tag.fechada { background: var(--verde-cl); color: #044317; } .tag.cancelada { background: #ffd7d9; color: #750e13; }
.tag.emitido { background: #d0e2ff; color: #002d9c; } .tag.confirmado { background: var(--verde-cl); color: #044317; }
.tag.enviado { background: var(--verde-cl); color: #044317; } .tag.falhou { background: #ffd7d9; color: #750e13; }
.tag.nao_configurado, .tag.sem_destino { background: var(--amarelo); color: #8e6a00; }
.tag.alt { background: #e8daff; color: #491d8b; }
.melhor { background: var(--verde-cl) !important; font-weight: 700; color: #044317; }
.obs { display: block; font-size: 12px; color: var(--cinza); font-weight: 400; max-width: 220px; }
.muted { color: var(--cinza); font-size: 13px; }
.abas { display: flex; gap: 4px; border-bottom: 2px solid var(--borda); margin: 16px 0; overflow-x: auto; }
.abas a { padding: 10px 16px; text-decoration: none; color: var(--cinza); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.abas a.ativo { color: var(--azul); border-color: var(--azul); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--borda); border-radius: 10px; padding: 14px 16px; }
.kpi b { display: block; font-size: 22px; }
.kpi span { color: var(--cinza); font-size: 13px; }
.aviso { background: var(--amarelo); border-left: 4px solid #f1c21b; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.sucesso { background: var(--verde-cl); border-left: 4px solid var(--verde); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.login-box { max-width: 380px; margin: 10vh auto; }
.login-box h1 { text-align: center; margin-bottom: 20px; }
.login-box form > * { margin-bottom: 14px; }
.login-box button { width: 100%; justify-content: center; padding: 12px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #161616; color: #fff; padding: 12px 20px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.on { opacity: 1; } #toast.erro { background: var(--vermelho); }
.preco-input { max-width: 130px; text-align: right; }
td input { padding: 7px 8px; }
.barra-acoes { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--borda); padding: 12px 16px; display: flex; gap: 10px;
  justify-content: flex-end; align-items: center; flex-wrap: wrap; margin: 0 -20px; box-shadow: 0 -4px 12px rgba(0,0,0,.05); }
.notif { padding: 14px 16px; border-bottom: 1px solid var(--borda); }
.notif.nova { background: #edf5ff; }
.notif pre { white-space: pre-wrap; font-family: inherit; margin: 6px 0 0; }
.so-mobile { display: none; }
@media print {
  header, .nao-imprimir, .abas, #toast { display: none !important; }
  main { padding: 0; max-width: none; } .card { border: 0; padding: 0; }
  body { background: #fff; }
}
@media (max-width: 860px) {
  header { flex-wrap: wrap; height: auto; padding: 10px 14px; }
  .so-mobile { display: inline-flex; margin-left: auto; background: #393939; }
  nav { display: none; flex-basis: 100%; flex-direction: column; order: 3; }
  nav.aberto { display: flex; }
  .usuario { order: 2; }
  main { padding: 16px 12px 80px; }
  /* tabelas responsivas viram cartões */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--borda); border-radius: 10px; margin-bottom: 10px; padding: 8px 4px; background: #fff; }
  table.cards td { border: 0; padding: 4px 10px; }
  table.cards td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; text-transform: uppercase; color: var(--cinza); font-weight: 600; }
  table.cards td.num { text-align: left; }
  .preco-input { max-width: none; }
  .tabela-rol { max-height: none; border: 0; }
  .barra-acoes { margin: 0 -12px; position: fixed; left: 0; right: 0; bottom: 0; margin: 0; }
}

/* ---------- Leitor de código de barras (câmera) ---------- */
.btn-camera { background: #161616; }
.btn-camera:hover { background: #393939; }
.scanner { position: fixed; inset: 0; z-index: 200; background: #000; color: #fff; display: flex; flex-direction: column; }
.sc-topo { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); gap: 8px; }
.sc-btn { background: #393939; color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 600; }
.sc-btn.on { background: #f1c21b; color: #000; }
.sc-video { position: relative; flex: 1; min-height: 160px; overflow: hidden; }
.sc-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.sc-mira { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.sc-mira i { width: 82%; max-width: 520px; height: 38%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); position: relative; }
.sc-mira i::after { content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; animation: sc-linha 1.6s ease-in-out infinite; }
@keyframes sc-linha { 0%,100% { transform: translateY(-40px); } 50% { transform: translateY(40px); } }
.sc-msg { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; font-size: 14px; text-shadow: 0 1px 3px #000; padding: 0 16px; }
.sc-painel:empty { display: none; }
.sc-painel { background: #fff; color: var(--texto); padding: 14px 16px; border-radius: 14px 14px 0 0; margin-top: -14px; position: relative; }
.sc-painel .sc-cod { font-size: 13px; color: var(--cinza); }
.sc-painel .sc-desc { font-size: 17px; font-weight: 700; margin: 2px 0 10px; }
.sc-qtd { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.sc-qtd button { width: 52px; height: 48px; font-size: 22px; justify-content: center; padding: 0; }
.sc-qtd input { text-align: center; font-size: 22px; font-weight: 700; height: 48px; flex: 1; }
.sc-acoes { display: flex; gap: 8px; }
.sc-acoes button { flex: 1; justify-content: center; padding: 13px; font-size: 16px; }
.sc-erro { color: var(--vermelho); font-weight: 600; }
.sc-manual { display: flex; gap: 8px; padding: 10px 12px; background: #161616; }
.sc-manual input { background: #262626; color: #fff; border-color: #525252; }
.sc-rodape { background: #161616; padding: 0 12px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); font-size: 13px; color: #c6c6c6; max-height: 22vh; overflow: auto; }
.sc-rodape div { padding: 3px 0; border-top: 1px solid #262626; display: flex; justify-content: space-between; gap: 10px; }
.lista-coleta { margin-top: 10px; }
/* iPhone dá zoom automático em campos com fonte < 16px */
@media (max-width: 860px) { input, select, textarea { font-size: 16px; } }

/* ---------- Janela de importação ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 150; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow: auto; }
.modal { width: 100%; max-width: 860px; margin: 0; }
.modal h3 { font-size: 15px; margin: 18px 0 8px; }
.btn-wa { background: #25d366; } .btn-wa:hover { background: #1da851; }
code { background: #f2f4f8; padding: 2px 6px; border-radius: 4px; font-size: 14px; }

/* ---------- Fechamento: quantidade e divisão por fornecedor ---------- */
.linha-forn { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.linha-forn .sel-forn { flex: 1; min-width: 0; }
.linha-forn .qtd-forn { width: 90px; flex: none; text-align: right; }
.linha-forn .qtd-forn:disabled { background: #f4f4f4; color: #999; }
.rem-linha { color: var(--vermelho) !important; font-size: 18px; padding: 0 4px !important; }
.qtd-ped { width: 100px; text-align: right; }
.linha-forn:not(:has(.rem-linha))::after { content: ''; width: 26px; flex: none; } /* alinha com as linhas que têm ✕ */
