:root {
  --bg: #140b22;
  --bg-2: #1c1030;
  --card: #241640;
  --card-2: #2e1c52;
  --line: #3d2a66;
  --text: #f3eefc;
  --muted: #a99bc7;
  --roxo: #7b3fe4;
  --roxo-2: #9a6bff;
  --amarelo: #ffcc1a;
  --amarelo-ink: #241640;
  --verde: #3ddc84;
  --vermelho: #ff5c7a;
  --laranja: #ffa23d;
  --raio: 14px;
  --raio-s: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; min-height: 100dvh; }
a { color: var(--amarelo); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.wordmark { font-family: 'Anton', sans-serif; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: rgba(20, 11, 34, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .back { background: none; border: 0; padding: 6px; margin-left: -6px; cursor: pointer; color: var(--text); display: grid; place-items: center; }
.topbar .back svg { width: 24px; height: 24px; }
.topbar h1 { font-size: 18px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .marca { font-size: 22px; color: var(--amarelo); flex: 1; }
.topbar .marca small { font-family: 'Poppins'; font-size: 11px; color: var(--muted); letter-spacing: .08em; margin-left: 6px; }
.status-rede { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: var(--card); color: var(--muted); white-space: nowrap; }
.status-rede.off { background: rgba(255, 92, 122, .18); color: var(--vermelho); }

main { padding: 16px 16px calc(96px + var(--safe-b)); max-width: 880px; margin: 0 auto; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(28, 16, 48, .96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: 11px; color: var(--muted); text-decoration: none; border-radius: 10px;
}
.bottomnav a.ativo { color: var(--amarelo); }
.bottomnav svg { width: 22px; height: 22px; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--raio); padding: 16px; }
.card + .card { margin-top: 12px; }
.secao { margin-top: 22px; }
.secao > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--raio-s);
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.primario { background: var(--amarelo); color: var(--amarelo-ink); border-color: var(--amarelo); }
.btn.roxo { background: var(--roxo); border-color: var(--roxo); }
.btn.perigo { background: transparent; color: var(--vermelho); border-color: rgba(255, 92, 122, .5); }
.btn.fantasma { background: transparent; }
.btn.bloco { width: 100%; }
.btn.peq { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-icone { width: 46px; padding: 0; }
.linha-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.linha-btns > .btn { flex: 1; }

label.campo { display: block; margin-bottom: 14px; }
label.campo > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--raio-s);
  border: 1px solid var(--line); background: var(--bg-2); outline: none;
}
.input:focus { border-color: var(--roxo-2); box-shadow: 0 0 0 3px rgba(123, 63, 228, .25); }
textarea.input { min-height: 80px; resize: vertical; }
.input-grupo { display: flex; gap: 8px; }
.input-grupo .input { flex: 1; min-width: 0; }
.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.ajuda { font-size: 12px; color: var(--muted); margin-top: -8px; margin-bottom: 14px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer;
}
.chip.ativo { background: var(--roxo); border-color: var(--roxo); color: #fff; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.tag.amarelo { background: rgba(255, 204, 26, .15); color: var(--amarelo); }
.tag.vermelho { background: rgba(255, 92, 122, .16); color: var(--vermelho); }
.tag.laranja { background: rgba(255, 162, 61, .16); color: var(--laranja); }
.tag.verde { background: rgba(61, 220, 132, .14); color: var(--verde); }
.tag.roxo { background: rgba(154, 107, 255, .18); color: var(--roxo-2); }

/* Lista de itens */
.lista { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--raio);
  text-decoration: none; color: inherit; cursor: pointer;
}
.item:active { background: var(--card-2); }
.item .info { flex: 1; min-width: 0; }
.item .titulo { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.item .lado { text-align: right; flex: none; }
.item .preco { font-weight: 700; color: var(--amarelo); }
.item .estoque { font-size: 12px; color: var(--muted); }
.vazio { text-align: center; color: var(--muted); padding: 40px 16px; }
.vazio strong { display: block; color: var(--text); margin-bottom: 4px; }

/* Início */
.saudacao { margin: 4px 0 18px; }
.saudacao h2 { font-size: 22px; font-weight: 700; }
.saudacao p { margin: 4px 0 0; color: var(--muted); }
.modulos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.modulo {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 16px; min-height: 118px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--raio);
  text-decoration: none; color: inherit;
}
.modulo.destaque { background: linear-gradient(160deg, var(--roxo) 0%, #4b23a0 100%); border-color: var(--roxo-2); }
.modulo .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 204, 26, .14); color: var(--amarelo); }
.modulo.destaque .ic { background: var(--amarelo); color: var(--amarelo-ink); }
.modulo .ic svg { width: 22px; height: 22px; }
.modulo strong { font-size: 15px; }
.modulo small { color: var(--muted); font-size: 12px; margin-top: -6px; }
.modulo.destaque small { color: rgba(255, 255, 255, .75); }
.modulo.breve { opacity: .55; pointer-events: none; }
.modulo .selo { position: absolute; top: 12px; right: 12px; }

.alertas .item { border-left: 3px solid var(--laranja); }

/* Detalhe */
.det-topo { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.det-topo h2 { font-size: 20px; }
.det-preco { font-size: 26px; font-weight: 700; color: var(--amarelo); }
.det-grade { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.det-grade div { background: var(--bg-2); border-radius: var(--raio-s); padding: 10px 12px; }
.det-grade small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.det-grade b { font-size: 16px; }
.codigo-barras-preview { background: #fff; border-radius: var(--raio-s); padding: 10px; margin-top: 14px; text-align: center; }
.codigo-barras-preview svg { max-width: 100%; height: 70px; }

table.tab { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tab th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.tab td { padding: 9px 6px; border-bottom: 1px solid var(--line); }
table.tab td.num, table.tab th.num { text-align: right; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login .caixa { width: 100%; max-width: 380px; }
.login .logo { text-align: center; margin-bottom: 28px; }
.login .logo .wordmark { font-size: 44px; color: var(--amarelo); display: block; line-height: 1; }
.login .logo span { color: var(--muted); font-size: 13px; letter-spacing: .2em; text-transform: uppercase; }
.erro { background: rgba(255, 92, 122, .14); color: var(--vermelho); border-radius: var(--raio-s); padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* Botão flutuante */
.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-b)); z-index: 15;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--amarelo); color: var(--amarelo-ink); display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.fab svg { width: 26px; height: 26px; }

/* Modal */
.modal-fundo { position: fixed; inset: 0; z-index: 50; background: rgba(8, 4, 15, .72); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
}
@media (min-width: 640px) { .modal-fundo { align-items: center; } .modal { border-radius: 20px; } }
.modal-cab { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-cab h3 { font-size: 17px; }
.fechar { background: none; border: 0; color: var(--muted); padding: 6px; cursor: pointer; }

/* Scanner */
.scanner-area { position: relative; border-radius: var(--raio); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scanner-area #leitor { width: 100%; height: 100%; }
.scanner-area #leitor video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner-mira { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.scanner-mira::before { content: ''; width: 78%; height: 34%; border: 3px solid var(--amarelo); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.scanner-msg { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0; }

/* Toast */
#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%) translateY(-20px);
  z-index: 80; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #fff; color: #1a1028; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none;
  transition: .25s; box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.erro { background: var(--vermelho); color: #fff; }

.carregando { display: grid; place-items: center; padding: 48px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--amarelo); animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

/* Etiquetas — fila */
.fila-item { display: flex; align-items: center; gap: 10px; }
.qtd { display: flex; align-items: center; gap: 6px; }
.qtd button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font-size: 18px; }
.qtd b { min-width: 22px; text-align: center; }

/* ---------- Impressão de etiquetas ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; }
  #app, #toast, #modal-root { display: none !important; }
  #print-root { display: block; }
}
.folha { position: relative; width: 210mm; height: 297mm; overflow: hidden; page-break-after: always; break-after: page; background: #fff; }
.folha:last-child { page-break-after: auto; break-after: auto; }
.etq {
  position: absolute; overflow: hidden; color: #000; font-family: 'Poppins', Arial, sans-serif;
  display: flex; flex-direction: column; justify-content: space-between; padding: 2.2mm 3mm;
}
.etq .e-topo { display: flex; justify-content: space-between; align-items: baseline; gap: 2mm; }
.etq .e-marca { font-family: 'Anton', Impact, sans-serif; font-size: 8pt; letter-spacing: .05em; }
.etq .e-preco { font-size: 12pt; font-weight: 700; }
.etq .e-nome { font-size: 7.5pt; font-weight: 600; line-height: 1.15; max-height: 2.3em; overflow: hidden; }
.etq .e-det { font-size: 6.5pt; color: #333; }
.etq svg { width: 100%; height: 11mm; display: block; }
.etq.contorno { outline: .2mm dashed #bbb; }

/* ---------- Comprovante (impressão) ---------- */
.cupom { width: 72mm; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 9pt; color: #000; background: #fff; line-height: 1.35; }
.cupom hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.cupom .cl { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- Gráfico de barras simples ---------- */
.barras { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.barras .b { flex: 1; min-width: 6px; background: var(--roxo); border-radius: 4px 4px 0 0; position: relative; }
.barras .b:hover, .barras .b.ativo { background: var(--amarelo); }
.barras-rotulos { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--raio); padding: 12px 14px; }
.kpi small { display: block; color: var(--muted); font-size: 12px; }
.kpi b { font-size: 19px; display: block; margin-top: 2px; }
.kpi.destaque { background: linear-gradient(160deg, var(--roxo) 0%, #4b23a0 100%); border-color: var(--roxo-2); }
.kpi.destaque small { color: rgba(255,255,255,.75); }
.barra-h { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 6px; }
.barra-h span { display: block; height: 100%; background: var(--amarelo); border-radius: 99px; }
details > summary::-webkit-details-marker { display: none; }

.item svg { width: 22px; height: 22px; flex: none; }
.item .fechar svg { width: 18px; height: 18px; }
