:root {
  --paper: #eef2ed;
  --surface: #ffffff;
  --ink: #17241c;
  --ink-soft: #4a564e;
  --muted: #6e7a70;
  --line: #d7ded4;
  --brand: #0e5c39;
  --brand-dark: #093f27;
  --accent: #e4a11b;
  --accent-ink: #6a4a06;
  --teal: #2c6e76;
  --shadow: 0 1px 2px rgba(23, 36, 28, 0.06), 0 8px 24px rgba(23, 36, 28, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Cabeçalho ---------- */
.topo {
  background: var(--brand);
  color: #eaf3ee;
  border-bottom: 3px solid var(--brand-dark);
}
.topo-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 20px;
}
.marca { display: flex; align-items: center; gap: 14px; }
.marca-tag {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 10px;
  border-radius: 8px;
  line-height: 1;
}
.marca-nome {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0;
  color: #ffffff;
}
.marca-sub { margin: 2px 0 0; font-size: 13px; color: #bcd7c8; }

/* ---------- Layout ---------- */
.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 22px 20px 40px;
}

/* ---------- Painel de busca ---------- */
.painel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.linha { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.linha-filtros { align-items: flex-end; }

.campo { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.campo-cresce { flex: 1 1 260px; }
.campo-estreito { min-width: 120px; flex: 0 0 auto; }

.rotulo {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select {
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #fbfdfb;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 92, 57, 0.14);
}

/* ---------- Botões ---------- */
.btn-primario {
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  background: var(--brand);
  border: 1px solid var(--brand-dark);
  border-radius: 9px;
  padding: 11px 20px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn-primario:hover { background: var(--brand-dark); }
.btn-primario:active { transform: translateY(1px); }
.btn-primario:disabled { opacity: 0.55; cursor: progress; }

.btn-ghost {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--brand);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  height: fit-content;
}
.btn-ghost:hover { border-color: var(--brand); background: #f0f6f2; }

.aviso {
  margin: 0;
  font-size: 13px;
  color: var(--teal);
}

/* ---------- Resultados ---------- */
.resultados { margin-top: 22px; display: flex; flex-direction: column; gap: 12px; }

.status {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  color: var(--ink-soft);
}
.status strong { color: var(--ink); }
.status.erro { border-color: #d98b8b; color: #8a3b3b; background: #fcf3f3; }

.contagem {
  font-size: 13px;
  color: var(--muted);
  padding: 2px 2px 4px;
}

/* Cartão de resultado (linha de recibo) */
.item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.item-foto {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: contain;
  background: #f3f6f2;
  border: 1px solid var(--line);
}
.item-info { min-width: 0; }
.item-desc {
  font-weight: 600;
  font-size: 15px;
  margin: 0 0 3px;
  color: var(--ink);
}
.item-estab { font-size: 13.5px; color: var(--ink-soft); margin: 0; }
.item-meta { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.item-meta span { margin-right: 12px; white-space: nowrap; }

.item-preco {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 21px;
  color: var(--brand-dark);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.item-preco small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }

/* Destaque do melhor preço */
.item-melhor {
  border: 1px solid var(--accent);
  border-top: none;
  position: relative;
  background: #fffdf6;
}
.item-melhor::before {
  content: "";
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 6px;
  border-radius: var(--radius) var(--radius) 0 0;
  background:
    radial-gradient(circle at 6px -2px, transparent 4px, var(--accent) 4px) 0 0 / 12px 6px repeat-x;
}
.selo {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: #fbeecb;
  border-radius: 5px;
  padding: 2px 7px;
}
.item-melhor .item-preco { color: var(--accent-ink); }

.item-selos { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.item-selos:empty { display: none; }
.chip {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
  background: #e7f0f1;
  border-radius: 5px;
  padding: 2px 7px;
}

.mais-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px 4px;
}
.btn-mais { flex: 0 0 auto; }
.mais-nota { font-size: 12.5px; color: var(--muted); }

/* JSON bruto */
.bruto { margin-top: 8px; }
.bruto summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 2px;
  user-select: none;
}
.bruto summary:hover { color: var(--brand); }
.bruto pre {
  background: #10231a;
  color: #d6e7dc;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 14px;
  border-radius: 10px;
  overflow: auto;
  max-height: 360px;
}

/* ---------- Rodapé ---------- */
.rodape {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px 36px;
}
.rodape p {
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin: 0;
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .item {
    grid-template-columns: 48px 1fr;
    grid-template-rows: auto auto;
  }
  .item-foto { width: 48px; height: 48px; }
  .item-preco {
    grid-column: 1 / -1;
    text-align: left;
    border-top: 1px dashed var(--line);
    padding-top: 8px;
  }
  .item-preco small { display: inline; margin-left: 8px; }
  .btn-primario, .btn-ghost { width: 100%; }
  .campo-estreito { flex: 1 1 44%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Botão escanear ---------- */
.btn-escanear {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  background: var(--accent-ink);
  border: 1px solid var(--accent-ink);
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
  white-space: nowrap;
  height: fit-content;
}
.btn-escanear:hover { background: #563c05; }
.btn-escanear svg { flex: 0 0 auto; }

/* ---------- Sobreposição do scanner ---------- */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0b120e;
  display: flex;
  flex-direction: column;
}
.scanner[hidden] { display: none; }

.scanner-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  color: #eaf3ee;
}
.scanner-titulo { font-weight: 600; font-size: 15px; }
.scanner-fechar {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.scanner-fechar:hover { background: rgba(255, 255, 255, 0.22); }

.scanner-palco {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-palco video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-mira {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(78%, 320px);
  height: 150px;
  border: 3px solid rgba(228, 161, 27, 0.95);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}
.scanner-status {
  color: #cfe0d6;
  font-size: 14px;
  text-align: center;
  padding: 14px 18px 22px;
  margin: 0;
  min-height: 1.4em;
}
