:root{
  --bg:#f6f7fb;
  --card:#ffffff;
  --text:#101828;
  --muted:#667085;
  --line:#e6e8ee;
  --primary:#2563eb;
  --warn:#f59e0b;
  --danger:#ef4444;
  --shadow:0 10px 25px rgba(16,24,40,.08);
  --radius:16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:var(--bg);
  color:var(--text);
}

.topbar{
  position:sticky; top:0; z-index:10;
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 18px;
  background:rgba(246,247,251,.8);
  backdrop-filter: blur(10px);
  border-bottom:1px solid var(--line);
}

.brand{ display:flex; gap:12px; align-items:center; }
.logo{
  width:38px; height:38px; border-radius:12px;
  background:var(--text); color:white;
  display:flex; align-items:center; justify-content:center;
  font-weight:800;
}
.name{ font-weight:800; letter-spacing:.2px; }
.sub{ color:var(--muted); font-size:12px; margin-top:2px; }

.nav{ display:flex; gap:8px; flex-wrap:wrap; }
.navbtn{
  border:1px solid var(--line);
  background:var(--card);
  padding:10px 12px;
  border-radius:999px;
  cursor:pointer;
  font-weight:600;
}
.navbtn.active{ border-color:rgba(37,99,235,.35); box-shadow:0 6px 18px rgba(37,99,235,.12); }

.container{ padding:18px; max-width:1200px; margin:0 auto; }

.view{ display:none; }
.view.active{ display:block; }

.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:16px;
}

.hero h2{ margin:0 0 6px 0; font-size:22px; }
.hero p{ margin:0 0 14px 0; color:var(--muted); }

.grid2{ display:grid; grid-template-columns: 1.1fr .9fr; gap:14px; }
.grid3{ display:grid; grid-template-columns: repeat(3, 1fr); gap:14px; }

@media (max-width: 980px){
  .grid2{ grid-template-columns:1fr; }
  .grid3{ grid-template-columns:1fr; }
  .topbar{ position:static; }
}

.actions{ display:flex; gap:10px; flex-wrap:wrap; margin-top:10px; }
.btn{
  border:1px solid var(--line);
  background:var(--card);
  padding:10px 14px;
  border-radius:12px;
  cursor:pointer;
  font-weight:700;
}
.btn.primary{
  background:var(--primary);
  border-color:transparent;
  color:white;
}
.btn.warn{ background:rgba(245,158,11,.12); border-color:rgba(245,158,11,.35); }
.btn.danger{ background:rgba(239,68,68,.12); border-color:rgba(239,68,68,.35); }

.label{ display:block; font-weight:700; margin:10px 0 6px; }
.input{
  width:100%;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 12px;
  background:#fff;
  outline:none;
}
.input:focus{ border-color:rgba(37,99,235,.45); box-shadow:0 0 0 4px rgba(37,99,235,.10); }
.input.big{ font-size:16px; padding:12px 14px; }
.input.scan{ font-size:20px; padding:14px 14px; letter-spacing:.5px; }

/* =========================
   Modo Operador (Painel completo)
   ========================= */
.operatorPanel{ margin-top:12px; border:1px solid rgba(0,0,0,.08); border-radius:14px; padding:14px; background:#fff; }

.opTopGrid{
  display:grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr;
  gap:12px;
  align-items:stretch;
}
.opTopGrid .opCard{ min-width:0; }

.opCard{ border:1px solid rgba(0,0,0,.08); border-radius:14px; padding:12px; background:#fafbfc; }
.opCard.wide{ background:#fff; }
.opCard.clickable{ cursor:pointer; }
button.opCard{ appearance:none; -webkit-appearance:none; background:inherit; text-align:left; width:100%; }
button.opCard:focus{ outline:2px solid rgba(59,130,246,.35); outline-offset:2px; }
.opCardLabel{ font-size:12px; letter-spacing:.6px; text-transform:uppercase; color:#6b7280; }
.opCardValue{ font-size:22px; font-weight:800; margin-top:4px; }
.opCardMeta{ margin-top:4px; color:#6b7280; font-size:13px; }

.opLast{ margin-top:12px; border:1px solid rgba(0,0,0,.08); border-radius:14px; padding:12px; background:#fff; }
.opLastTitle{ font-size:12px; letter-spacing:.6px; text-transform:uppercase; color:#6b7280; }
.opLastValue{ font-size:18px; font-weight:800; margin-top:6px; }
.opLastMeta{ margin-top:2px; color:#374151; }
.opLastHint{ margin-top:6px; color:#6b7280; font-size:12px; }

.opLastRow{ display:flex; gap:12px; flex-wrap:wrap; margin-top:6px; }
.opLastBox{ flex:1 1 260px; min-width:260px; }

.opQueue{ margin-top:12px; border:1px solid rgba(0,0,0,.08); border-radius:14px; padding:12px; background:#fff; }
.opQueueTop{ display:flex; align-items:flex-end; justify-content:space-between; gap:12px; margin-bottom:8px; }
.opQueueTitle{ font-size:16px; font-weight:800; }
.opTable .num{ text-align:right; }
.opStatus{ display:inline-flex; align-items:center; gap:8px; font-weight:700; }
.opDot{ width:10px; height:10px; border-radius:999px; display:inline-block; }
.opDot.ok{ background:#16a34a; }
.opDot.pendente{ background:#f59e0b; }
.opDot.div{ background:#dc2626; }
.opDot.final{ background:#64748b; }

/* Tuning para modo operador */
body.operator-mode .top{ position:sticky; top:0; z-index:10; }
body.operator-mode #view-operacao .grid2{ grid-template-columns:1fr; }
body.operator-mode #view-operacao .opHeader{ display:none; }
body.operator-mode .input.scan{ font-size:28px; padding:18px; }
body.operator-mode .table{ font-size:15px; }
body.operator-mode .btn{ font-size:15px; padding:10px 14px; }
body.operator-mode #btnUndoLast{ display:inline-flex !important; }

.row{ display:flex; align-items:center; }
.gap{ gap:10px; }
.row > * { flex:1; }
.row > button { flex:0 0 auto; }

.muted{ color:var(--muted); font-size:13px; margin-top:8px; }
.note{
  margin-top:12px;
  padding:10px 12px;
  border-radius:12px;
  background:rgba(37,99,235,.06);
  border:1px solid rgba(37,99,235,.18);
  color:#1b3a93;
}

.kpis{ display:grid; grid-template-columns:repeat(2, 1fr); gap:10px; margin-top:12px; }
.kpi{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
}
.kpiLabel{ color:var(--muted); font-size:12px; }
.kpiValue{ font-size:22px; font-weight:900; margin-top:4px; }

.pill{
  display:inline-flex;
  align-items:center;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:#fff;
  font-weight:800;
  font-size:12px;
}

.hr{ border:none; border-top:1px solid var(--line); margin:14px 0; }

/* =========================
   TABELA / HISTÓRICO
   ========================= */
.tableWrap{
  width:100%;
  overflow-x:auto;
  overflow-y:auto;
  border:1px solid var(--line);
  border-radius:14px;
  margin-top:12px;
  background:var(--card);
  -webkit-overflow-scrolling: touch;
}
.table{
  width:100%;
  border-collapse:collapse;
  min-width:1100px;
}
.table th, .table td{
  padding:10px 10px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align:top;
  font-size:13px;
  white-space:nowrap;
}
.table thead th{
  background:#fbfbfd;
  position:sticky;
  top:0;
  z-index:2;
}
.table .num{ text-align:right; font-variant-numeric: tabular-nums; }

.badge{
  display:inline-flex; align-items:center;
  padding:4px 8px; border-radius:999px;
  font-weight:800; font-size:12px;
  border:1px solid var(--line);
}
.badge.ok{ background:rgba(34,197,94,.10); border-color:rgba(34,197,94,.28); }
.badge.warn{ background:rgba(245,158,11,.10); border-color:rgba(245,158,11,.28); }
.badge.bad{ background:rgba(239,68,68,.10); border-color:rgba(239,68,68,.28); }
.badge.neutral{ background:rgba(148,163,184,.12); border-color:rgba(148,163,184,.30); }

.opHeader{ display:flex; justify-content:space-between; align-items:flex-start; gap:12px; }
.opActions{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; }

.mini{ border:1px solid var(--line); border-radius:14px; padding:14px; background:#fff; }
.miniTitle{ font-weight:900; }
.miniDesc{ color:var(--muted); font-size:13px; margin-top:6px; }

.alert{
  margin-top:12px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid rgba(239,68,68,.25);
  background:rgba(239,68,68,.08);
  color:#7a1c1c;
  font-weight:700;
  white-space:pre-wrap;
}
.alert.good{
  border-color:rgba(34,197,94,.28);
  background:rgba(34,197,94,.10);
  color:#165a2a;
}

.hidden{ display:none !important; }

/* Ações: alinhado e compacto */
.actionsCell{
  display:flex;
  gap:8px;
  justify-content:flex-end;
  align-items:center;
}

/* Coluna Ações sticky na direita */
.table th.actionsSticky,
.table td.actionsSticky{
  position:sticky;
  right:0;
  z-index:3;
  background:#fff;
  box-shadow:-10px 0 18px rgba(16,24,40,.06);
  border-left:1px solid var(--line);
}
.table thead th.actionsSticky{
  z-index:4;
  background:#fbfbfd;
}

/* Modal */
.modal{
  position:fixed; inset:0;
  background:rgba(16,24,40,.45);
  display:flex; align-items:center; justify-content:center;
  padding:18px;
}
.modalBox{
  width:min(980px, 100%);
  max-height:92vh;
  overflow:hidden;
  background:var(--card);
  border-radius:18px;
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  display:flex; flex-direction:column;
}
.modalTop{
  padding:14px 16px;
  display:flex; justify-content:space-between; align-items:flex-start;
  border-bottom:1px solid var(--line);
}
.modalTitle{ font-weight:900; font-size:16px; }
.modalBody{ padding:16px; overflow:auto; }
.iconBtn{
  border:1px solid var(--line);
  background:#fff;
  width:36px; height:36px;
  border-radius:12px;
  cursor:pointer;
  font-weight:900;
}

.help li{ margin:10px 0; }
code{ font-family:var(--mono); font-size:12px; background:#f1f3f8; padding:2px 6px; border-radius:8px; border:1px solid var(--line); }

/* =========================
   Modo Operador (tela cheia)
   ========================= */
body.operator-mode{ background:#fff; }
body.operator-mode .topbar{ display:none !important; }
body.operator-mode .container{ max-width:none; padding:14px; }
body.operator-mode #view-operacao .grid2{ grid-template-columns: 1fr !important; }
body.operator-mode #view-operacao .card{ border-radius: 20px; }
body.operator-mode #scanInput{ font-size: 32px; padding: 18px 16px; height: auto; }
body.operator-mode #scanQtd{ display:none !important; }
body.operator-mode #btnScan{ display:none !important; }
body.operator-mode #startBlock{ display:none !important; }
body.operator-mode #manualScanRow .muted{ display:none !important; }
body.operator-mode .opQueue{ display:none !important; }
body.operator-mode #view-operacao .kpis{ display:none !important; }
body.operator-mode #view-operacao .muted{ margin-top:6px; }
body.operator-mode #itemsTable{ min-width: 0 !important; }
body.operator-mode #itemsTable th, body.operator-mode #itemsTable td{ font-size:16px; padding:12px 10px; }
body.operator-mode #itemsTable td:nth-child(2){ font-size:18px; font-weight:900; }
body.operator-mode .btn{ font-size: 18px; padding: 12px 14px; }
body.operator-mode .kpis .kpiValue{ font-size: 34px; }
body.operator-mode .kpis .kpiLabel{ font-size: 14px; }

/* Destaque azul para volumes (VL) */
.vl-badge{background:#1e88e5;color:#fff;padding:2px 8px;border-radius:10px;font-weight:600;font-size:12px;margin-left:4px;line-height:1;}
.unvl{margin-top:4px;font-size:12px;color:#6b7280;white-space:nowrap;}

/* auth / userbar */
.userchip{
  display:flex;
  align-items:center;
  gap:10px;
  margin-left:10px;
  padding-left:10px;
  border-left:1px solid var(--line);
}
.userchip .who{
  font-size:13px;
  color:var(--muted);
  white-space:nowrap;
}

/* duplicado no seu base, mantido */
.grid2{
  display:flex;
  flex-direction:column;
  gap:16px;
}

/* Produto/Volume UX */
.pvCell{ display:flex; flex-direction:column; gap:6px; align-items:flex-end; }
.pvPair{ font-variant-numeric: tabular-nums; font-weight:800; }
.pvPair span{ color:var(--muted); font-weight:700; }
.pvBar{ height:8px; background:rgba(148,163,184,.25); border-radius:999px; overflow:hidden; width:120px; margin-left:auto; }
.pvBar > i{ display:block; height:100%; background:rgba(34,197,94,.55); width:0%; }
.pvBar.warn > i{ background:rgba(245,158,11,.70); }
.pvBar.bad > i{ background:rgba(239,68,68,.70); }
.detailsBtn{ padding:8px 10px; font-size:13px; }
.pvSummary{
  background: rgba(148,163,184,.10);
  border:1px solid rgba(148,163,184,.22);
  padding:10px 12px;
  border-radius:12px;
  margin-bottom:12px;
  line-height:1.35;
}
.tabRow{ display:flex; gap:8px; margin:10px 0 12px; }
.tabBtn{
  border:1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding:8px 12px;
  border-radius:999px;
  font-weight:700;
  cursor:pointer;
}
.tabBtn.active{ background: rgba(30,136,229,.12); border-color: rgba(30,136,229,.35); }
.chips{ display:flex; flex-wrap:wrap; gap:8px; }
.chip{
  border:1px solid rgba(148,163,184,.25);
  background: rgba(15,23,42,.03);
  border-radius:999px;
  padding:8px 10px;
  font-size:13px;
  font-family: var(--mono);
}
.chip.ok{ border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.08); }
.chip.bad{ border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.08); }
.chip.neutral{ border-color: rgba(148,163,184,.35); background: rgba(148,163,184,.08); }

/* flash */
.flash{
  position:fixed;
  inset:0;
  pointer-events:none;
  z-index:9999;
  opacity:0;
  transition:opacity .12s ease;
}
.flash.ok{ background:rgba(16,185,129,.35); }
.flash.err{ background:rgba(239,68,68,.45); }
.flash.show{ opacity:1; }

/* modal overlay */
.modal{ z-index:99999; background:rgba(0,0,0,.78); }
body.modal-open{ overflow:hidden !important; }

/* Clique em linhas */
.opRowClickable{ cursor:pointer; }
.opRowClickable:hover{ background: rgba(37,99,235,.06); }

/* itens NF no modal */
.opNfItemsPane{ margin-top:12px; padding-top:10px; border-top:1px solid var(--line); }
.opNfItemsTop{ display:flex; align-items:flex-start; justify-content:space-between; gap:10px; margin-bottom:10px; }
.opNfItemsTitle{ font-weight:800; font-size:16px; }

/* =========================================
   ÚLTIMA LEITURA + TRANSPORTADORA lado a lado
   ========================================= */
.opLastRow{
  display:flex !important;
  gap:12px !important;
  align-items:stretch !important;
  flex-wrap:nowrap !important;
}
.opLastBox{
  flex:1 1 0 !important;
  min-width:0 !important;
}
@media (max-width: 520px){
  .opLastRow{ flex-wrap:wrap !important; }
  .opLastBox{ flex:1 1 100% !important; }
}

.small{ font-size:12px; color: var(--muted); white-space:normal; }


/* === Erros KPI (barras simples) === */
.barwrap{
  width:160px;
  height:10px;
  background:var(--line);
  border-radius:999px;
  overflow:hidden;
}
.bar{
  height:100%;
  background:var(--primary);
}

.score{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:3px 8px;
  border-radius:999px;
  font-weight:800;
  font-size:12px;
  border:1px solid var(--line);
  white-space:nowrap;
}
.score.good{ background:rgba(16,185,129,.12); color:#065f46; border-color:rgba(16,185,129,.22); }
.score.warn{ background:rgba(245,158,11,.14); color:#7c2d12; border-color:rgba(245,158,11,.25); }
.score.bad{  background:rgba(239,68,68,.12); color:#7f1d1d; border-color:rgba(239,68,68,.22); }
.kpiGrid{
  display:grid;
  grid-template-columns:repeat(4, minmax(0,1fr));
  gap:12px;
}
@media (max-width: 980px){
  .kpiGrid{ grid-template-columns:repeat(2, minmax(0,1fr)); }
}
@media (max-width: 520px){
  .kpiGrid{ grid-template-columns:1fr; }
  .barwrap{ width:120px; }
}
