/* Coletor de Etiquetas — tema escuro, mobile-first, feito para PDA */
:root {
  --bg: #0a0f1c;
  --bg2: #0e1526;
  --surface: #121b30;
  --surface2: #17223c;
  --border: #22304f;
  --text: #e8eefb;
  --muted: #8a9abb;
  --accent: #22d3ee;
  --accent-ink: #04222a;
  --violet: #a78bfa;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --step-color: var(--accent);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(34, 211, 238, .10), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(167, 139, 250, .09), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico-accent { color: var(--accent); }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: rgba(10, 15, 28, .82);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; min-width: 0; }
.brand-mini span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.op { color: var(--muted); font-size: 13px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  color: var(--muted); border: 1px solid var(--border); background: var(--surface); text-decoration: none;
}
.icon-btn:active { transform: scale(.94); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.chip .ico { width: 14px; height: 14px; }
.chip-ok   { color: var(--ok);   background: rgba(52, 211, 153, .10); border-color: rgba(52, 211, 153, .30); }
.chip-warn { color: var(--warn); background: rgba(251, 191, 36, .10); border-color: rgba(251, 191, 36, .30); }
.chip-err  { color: var(--err);  background: rgba(248, 113, 113, .10); border-color: rgba(248, 113, 113, .30); }

/* ---------- Estrutura ---------- */
.wrap { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 14px 14px calc(88px + env(safe-area-inset-bottom)); }
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.layout { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) {
  .wrap { padding-top: 24px; }
  .layout.has-produto { grid-template-columns: 1fr 1fr; }
  .card { padding: 24px; }
}

/* ---------- Etapas ---------- */
.stepper { list-style: none; display: flex; align-items: center; margin: 4px 4px 16px; padding: 0; }
.step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; flex: none; }
.step + .step { flex: 1; }
.step + .step::before { content: ""; flex: 1; height: 2px; margin: 0 10px; background: var(--border); border-radius: 2px; transition: background .3s; min-width: 16px; }
.step.done + .step::before, .step.active + .step::before { background: var(--accent); }
.step .dot {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); font-size: 13px; transition: all .3s;
}
.step .dot .ico { width: 14px; height: 14px; stroke-width: 3; }
.step.active { color: var(--text); }
.step.active .dot { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px rgba(34, 211, 238, .15); }
.step.done .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Painel de leitura ---------- */
.scan-panel { text-align: center; }
.scan-panel[data-step="2"] { --step-color: var(--violet); }
.scan-panel h1 { font-size: 22px; margin-top: 4px; }
.scan-panel p { margin: 6px 0 16px; font-size: 14px; }

.scanner-frame {
  position: relative; width: 128px; height: 108px; margin: 2px auto 14px;
  display: grid; place-items: center; color: var(--step-color); overflow: hidden; border-radius: 10px;
}
.scanner-frame .frame-ico { width: 64px; height: 64px; fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .85; }
.scanner-frame .c { position: absolute; width: 22px; height: 22px; border: 3px solid var(--step-color); }
.c.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.c.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.c.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.c.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.laser {
  position: absolute; left: 6px; right: 6px; height: 2px; top: 6px; border-radius: 2px;
  background: var(--step-color); box-shadow: 0 0 12px 2px var(--step-color);
  animation: sweep 1.8s ease-in-out infinite alternate;
}
@keyframes sweep { to { top: calc(100% - 8px); } }

.scan-input-wrap { position: relative; }
#scanInput {
  width: 100%; height: 60px; padding: 0 16px; text-align: center;
  font: 600 22px/1 var(--mono); letter-spacing: 1px; text-transform: uppercase;
  color: var(--text); background: #0a1326;
  border: 2px solid var(--border); border-radius: 14px; outline: none; caret-color: var(--step-color);
  transition: border-color .2s, box-shadow .2s;
}
#scanInput::placeholder { color: #4a5b7d; font-size: 16px; letter-spacing: 0; text-transform: none; font-family: inherit; font-weight: 500; }
#scanInput:focus { border-color: var(--step-color); box-shadow: 0 0 0 4px rgba(34, 211, 238, .2); }
.scan-panel[data-step="2"] #scanInput:focus { box-shadow: 0 0 0 4px rgba(167, 139, 250, .25); }
.spinner {
  position: absolute; right: 14px; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border: 3px solid var(--border); border-top-color: var(--step-color); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions .btn { flex: 1; }
.scan-panel.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.scan-panel.flash-err #scanInput { border-color: var(--err); box-shadow: 0 0 0 4px rgba(248, 113, 113, .22); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  font: 600 15px/1 inherit; font-family: inherit; color: var(--text);
  border: 1px solid var(--border); background: var(--surface2); transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, #2ee0fb, #16b8d4); color: var(--accent-ink); border-color: transparent; }
.btn-ghost:hover { filter: brightness(1.15); }
.btn-link { background: none; border: 0; color: var(--muted); margin: 12px auto 0; min-height: 44px; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn-lg { min-height: 56px; width: 100%; font-size: 17px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Produto ---------- */
.produto { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.produto-top { display: flex; gap: 14px; align-items: flex-start; }
.produto-foto { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: #0a1326; flex: none; }
.produto-id { min-width: 0; }
.code {
  display: inline-block; font: 600 13px/1 var(--mono); color: var(--accent);
  padding: 5px 8px; border-radius: 8px; background: rgba(34, 211, 238, .10); border: 1px solid rgba(34, 211, 238, .25);
  word-break: break-all;
}
.produto h2 { font-size: 18px; margin-top: 8px; word-break: break-word; }
.meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; }
.meta > div { background: #0d1730; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.meta small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.meta b { display: block; font-size: 15px; margin-top: 2px; word-break: break-word; }
.meta .wide { grid-column: 1 / -1; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin-top: 12px; font-size: 14px; }
.alert .ico { margin-top: 2px; }
.alert span { white-space: pre-line; word-break: break-word; }
.alert-warn { color: #ffe08a; background: rgba(251, 191, 36, .10); border: 1px solid rgba(251, 191, 36, .35); }
.alert-err  { color: #ffb4b4; background: rgba(248, 113, 113, .10); border: 1px solid rgba(248, 113, 113, .35); margin: 0 0 14px; }

.adjust { margin-top: 12px; border: 1px dashed var(--border); border-radius: 12px; }
.adjust summary { cursor: pointer; padding: 12px 14px; color: var(--muted); font-size: 14px; font-weight: 600; list-style: none; }
.adjust summary::-webkit-details-marker { display: none; }
.adjust summary::after { content: "+"; float: right; color: var(--accent); font-size: 18px; line-height: 1; }
.adjust[open] summary::after { content: "–"; }
.adjust-body { display: grid; gap: 12px; padding: 0 14px 14px; }

.field { display: grid; gap: 6px; text-align: left; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .qty input {
  height: 48px; padding: 0 12px; font: 600 17px/1 inherit; font-family: inherit; color: var(--text);
  background: #0a1326; border: 1px solid var(--border); border-radius: 12px; outline: none; width: 100%;
}
.field input:focus, .qty input:focus { border-color: var(--accent); }
.qty { display: flex; gap: 8px; }
.qty input { text-align: center; font-family: var(--mono); }
.qty-btn { width: 48px; height: 48px; flex: none; border-radius: 12px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); display: grid; place-items: center; cursor: pointer; }
.qty-btn:active { transform: scale(.94); }

/* ---------- Sucesso / aviso / modais ---------- */
.overlay-ok {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 60; display: grid; place-items: center; padding: 24px; cursor: pointer;
  background: radial-gradient(700px 500px at 50% 30%, #0f6b4b, #052a1f);
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.ok-box { text-align: center; max-width: 420px; width: 100%; }
.ok-circle {
  width: 96px; height: 96px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok); color: #05261b; animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}
.ok-check { width: 54px; height: 54px; stroke-width: 3; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.ok-box h2 { font-size: 30px; }
.ok-code { margin-top: 10px; font: 600 15px var(--mono); color: #b8f5dc; word-break: break-all; }
.ok-desc { margin-top: 4px; color: #d3fbe9; font-size: 14px; }
.ok-rack {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 18px; padding: 14px 22px; border-radius: 16px;
  background: rgba(0, 0, 0, .35); border: 1px solid rgba(255, 255, 255, .18); font: 700 34px/1 var(--mono); color: #fff;
}
.ok-rack .ico { width: 30px; height: 30px; color: var(--ok); }
.ok-qty { margin-top: 10px; color: #d3fbe9; font-weight: 600; }
.ok-note { margin: 16px 0 0; font-size: 13px; color: #9fe6c8; }

.toast {
  position: fixed; left: 12px; right: 12px; top: calc(64px + env(safe-area-inset-top)); z-index: 70;
  max-width: 560px; margin: 0 auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px; border-radius: 14px; font-weight: 600;
  color: #fff; background: #b91c1c; border: 1px solid #ef4444; box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
  animation: rise .2s ease-out;
}
.toast.info { background: #0e7490; border-color: #22d3ee; }
.toast.good { background: #047857; border-color: #34d399; }
.toast .ico { margin-top: 1px; }

.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 18, .8); backdrop-filter: blur(4px); }
.modal-box { width: 100%; max-width: 480px; max-height: 85vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.escolha-lista { display: grid; gap: 8px; }
.escolha-item { text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); font: inherit; cursor: pointer; }
.escolha-item:active { border-color: var(--accent); }
.escolha-item b { display: block; font: 600 13px var(--mono); color: var(--accent); }

.modal-cam { padding: 0; background: #000; }
.modal-cam video { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-guide { position: absolute; left: 10%; right: 10%; top: 50%; height: 28%; transform: translateY(-50%); border: 2px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
.cam-close { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: rgba(18, 27, 48, .9); }

/* ---------- Navegação inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: rgba(10, 15, 28, .9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0;
  background: none; border: 0; color: var(--muted); font: 600 12px inherit; font-family: inherit; cursor: pointer; border-radius: 12px;
}
.tab.active { color: var(--accent); background: rgba(34, 211, 238, .08); }
.tab .ico { width: 24px; height: 24px; }
.badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #2b1d00; font-size: 11px; line-height: 18px; text-align: center; }

/* ---------- Histórico ---------- */
.hist-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; }
.hist-head h1 { font-size: 22px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; text-align: center; }
.kpi b { display: block; font: 700 26px/1.1 var(--mono); }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.warn b { color: var(--warn); } .kpi.err b { color: var(--err); } .kpi.ok b { color: var(--accent); }

.hist-lista { display: grid; gap: 10px; }
@media (min-width: 900px) { .hist-lista { grid-template-columns: 1fr 1fr; } }
.h-item { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: grid; gap: 6px; }
.h-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.h-cod { font: 600 13px var(--mono); color: var(--accent); word-break: break-all; }
.h-desc { font-size: 14px; word-break: break-word; }
.h-rack { font: 700 15px var(--mono); padding: 3px 9px; border-radius: 8px; background: rgba(167, 139, 250, .14); color: #c9b8ff; border: 1px solid rgba(167, 139, 250, .3); white-space: nowrap; }
.h-meta { color: var(--muted); font-size: 12px; }
.h-err { color: #ffb4b4; font-size: 12px; word-break: break-word; }
.h-empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- Login ---------- */
.login-body { justify-content: center; align-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: linear-gradient(180deg, var(--surface), var(--bg2)); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .4); }
.login-card form { display: grid; gap: 14px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand-ico { width: 44px; height: 44px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.brand h1 { font-size: 22px; margin-top: 8px; }
.brand p { margin: 6px 0 0; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Ajustes para telas pequenas (PDA) ---------- */
@media (max-width: 899px) {
  /* Na etapa 2 o campo de leitura vem primeiro: nunca fica escondido atrás do cartão do produto. */
  .layout.has-produto .scan-panel { order: -1; }
  .scan-panel[data-step="2"] .scanner-frame { display: none; }
  .scan-panel[data-step="2"] h1 { font-size: 20px; }
  .scan-panel[data-step="2"] p { margin-bottom: 12px; }
}
@media (max-width: 420px) {
  .brand-mini span { display: none; }
  .op { max-width: 96px; }
}

/* Lista resumida das etiquetas lidas (até 2 por endereço): código do produto, lote e nº da etiqueta */
.etq-lista { display: grid; gap: 6px; margin-bottom: 12px; }
.etq-lista:empty { display: none; }
.etq-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: #0d1730; cursor: pointer; }
.etq-row.sel { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(34, 211, 238, .35) inset; }
.etq-i { flex-shrink: 0; width: 24px; height: 24px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; background: rgba(34, 211, 238, .15); color: var(--accent); }
.etq-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.etq-cod { font-family: var(--mono); font-size: 14px; word-break: break-all; }
.etq-meta { font-size: 12px; color: var(--muted); }
.etq-x { flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.etq-x:hover { color: var(--err); border-color: var(--err); }
