/* ==========================================================================
   Coletor de Romaneio — Évora · Etapa 2 (protótipo visual)
   Identidade: Montserrat · azul-marinho (base) · #00A1E4 (azul Évora, acento)
   ========================================================================== */

:root {
  --navy: #0E2A47;          /* azul-marinho — cor principal */
  --navy-deep: #081C31;
  --brand: #00A1E4;         /* azul Évora (extraído da logomarca) */
  --brand-soft: #E1F4FC;
  --bg: #F3F6F9;            /* fundo claro */
  --card: #FFFFFF;
  --ink: #14202E;
  --ink-soft: #5A6B7E;
  --line: #DDE5EC;
  --ok: #1B9E56;
  --warn: #E68A00;
  --danger: #D8434E;
  --radius: 14px;
  --tap: 56px;              /* altura mínima de toque */
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Montserrat", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* ---------- Telas (SPA) ---------- */
.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
}
.screen.active { display: flex; }

.content { flex: 1; padding: 20px 18px 28px; }

/* ---------- Cabeçalho da tela inicial ---------- */
.app-header {
  background: var(--card);
  padding: calc(env(safe-area-inset-top) + 22px) 20px 18px;
  border-bottom: 3px solid var(--brand);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.app-logo { width: 168px; max-width: 55%; height: auto; }
.app-title h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--navy);
  text-transform: uppercase;
}
.app-subtitle { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: 1.4px; text-transform: uppercase; }

.app-footer {
  padding: 14px 18px calc(env(safe-area-inset-bottom) + 14px);
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--ink-soft);
}

/* ---------- Barra superior das telas internas ---------- */
.bar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  position: sticky; top: 0; z-index: 20;
}
.bar-back {
  background: none; border: 0; color: #fff;
  font-size: 32px; line-height: 1;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 10px;
  cursor: pointer;
}
.bar-back:active { background: rgba(255,255,255,.15); }
.bar-title { font-weight: 700; font-size: 17px; display: flex; flex-direction: column; }
.bar-title small { font-weight: 600; font-size: 12px; opacity: .75; letter-spacing: .5px; }

/* ---------- Botões ---------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  border: 0;
  border-radius: var(--radius);
  min-height: var(--tap);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  width: 100%;
  transition: transform .06s ease, filter .12s ease;
}
.btn:active { transform: scale(.985); filter: brightness(.94); }

.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(0,161,228,.35); }
.btn-navy    { background: var(--navy);  color: #fff; }
.btn-outline { background: var(--card); color: var(--navy); border: 2px solid var(--line); }
.btn-ghost   { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; font-size: 14px; min-height: 48px; }
.btn-close   { background: none; color: rgba(255,255,255,.7); font-weight: 600; min-height: 48px; }

.btn-xl { min-height: 66px; font-size: 17.5px; }
.btn-icon { font-size: 22px; font-weight: 800; }
.btn-sub { display: block; width: 100%; font-size: 12px; font-weight: 600; color: var(--ink-soft); }

#btn-new { margin-bottom: 12px; }
#btn-continue { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }

/* Botão principal de escanear */
.btn-scan {
  background: linear-gradient(160deg, var(--brand) 0%, #0083C4 100%);
  color: #fff;
  min-height: 92px;
  font-size: 19px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  box-shadow: 0 6px 20px rgba(0,161,228,.4);
}

/* ---------- Histórico (tela inicial) ---------- */
.section-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 26px 0 10px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.history-item.open { border-left-color: var(--warn); }
.hi-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hi-rom { font-weight: 700; font-size: 14.5px; color: var(--navy); }
.hi-meta { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.hi-right { text-align: right; flex-shrink: 0; }
.hi-count { font-weight: 800; font-size: 18px; color: var(--brand); }
.hi-status { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ok); }
.history-item.open .hi-status { color: var(--warn); }
.hi-count small { font-size: 10px; color: var(--ink-soft); font-weight: 600; }

.last-use { margin-top: 22px; font-size: 12.5px; color: var(--ink-soft); text-align: center; font-weight: 500; }

/* ---------- Formulário Novo Romaneio ---------- */
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--navy); margin-bottom: 6px; }
.field-label em { font-weight: 500; color: var(--ink-soft); font-style: normal; }
.field input, .field select {
  width: 100%;
  font-family: inherit;
  font-size: 16.5px;
  font-weight: 500;
  padding: 0 14px;
  height: var(--tap);
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%230E2A47' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); }

.rom-preview {
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 6px 0 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rom-preview strong { font-family: var(--mono); font-size: 17px; color: var(--navy); letter-spacing: .5px; }

/* ---------- Faixa do contador (coleta) ---------- */
.counter-band {
  background: var(--navy);
  color: #fff;
  padding: 4px 18px 16px;
  position: sticky;
  top: calc(env(safe-area-inset-top) + 64px);
  z-index: 15;
}
.counter-meta {
  display: flex; justify-content: space-between;
  font-size: 12.5px; font-weight: 500; opacity: .8;
  margin-bottom: 6px;
}
.counter-main { display: flex; align-items: baseline; justify-content: space-between; }
.counter-label { font-size: 13px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; opacity: .9; }
.counter-value {
  font-size: 44px;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: transform .12s ease;
}
.counter-value.bump { transform: scale(1.18); }

/* ---------- Área de coleta ---------- */
.collect-content { padding-top: 16px; }
.manual-row { display: flex; gap: 8px; margin-top: 12px; }
.manual-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: 16.5px;
  padding: 0 14px;
  height: var(--tap);
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.manual-row input:focus { outline: none; border-color: var(--brand); }
.btn-add { width: var(--tap); flex-shrink: 0; font-size: 26px; padding: 0; }

/* Feedback de leitura */
.feedback {
  margin-top: 12px;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
  display: none;
  line-height: 1.5;
}
.feedback.show { display: block; }
.feedback.ok     { background: #E4F6EC; color: #116B3A; border: 1.5px solid #9ED9B8; }
.feedback.dup    { background: #FDECEE; color: #A02833; border: 1.5px solid #F0B4BA; }
.feedback.nfe    { background: #FDF3E3; color: #8A5200; border: 1.5px solid #F0CE94; }
.feedback.err    { background: #FDECEE; color: #A02833; border: 1.5px solid #F0B4BA; }
.feedback code { font-family: var(--mono); font-weight: 700; }

/* Lista de itens coletados */
.item-list { list-style: none; margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slide-in .18s ease;
}
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } }
.item.flash { animation: flash-dup .5s ease; }
@keyframes flash-dup { 0%,100% { box-shadow: none; } 30% { box-shadow: 0 0 0 3px var(--danger); } }
.item-seq {
  font-weight: 800; font-size: 13px; color: var(--brand);
  background: var(--brand-soft);
  border-radius: 8px;
  min-width: 38px; height: 38px;
  display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}
.item-code { flex: 1; font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: .4px; word-break: break-all; }
.item-time { font-size: 12px; color: var(--ink-soft); font-weight: 600; font-variant-numeric: tabular-nums; }
.item-del {
  background: none; border: 0; cursor: pointer;
  color: var(--ink-soft); font-size: 18px;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
}
.item-del:active { background: #FDECEE; color: var(--danger); }

.empty-hint { margin-top: 34px; text-align: center; color: var(--ink-soft); font-size: 14.5px; font-weight: 500; line-height: 1.7; }

.collect-footer {
  position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 12px 18px calc(env(safe-area-inset-bottom) + 14px);
}

/* ---------- Conferência ---------- */
.review-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 16px;
}
.review-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.review-head img { width: 108px; height: auto; }
.review-head strong { font-family: var(--mono); font-size: 14px; color: var(--navy); }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.review-grid dt { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-soft); }
.review-grid dd { font-size: 15px; font-weight: 600; color: var(--ink); }
.review-grid .r-total { font-size: 24px; font-weight: 800; color: var(--brand); }
.review-note { margin-top: 12px; font-size: 13.5px; color: var(--ink-soft); }

.review-codes { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.review-codes li {
  display: flex; gap: 10px; align-items: baseline;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 14.5px;
}
.review-codes .seq { color: var(--brand); font-weight: 700; min-width: 26px; }
.review-codes .t { margin-left: auto; color: var(--ink-soft); font-size: 12px; }

.review-actions { display: flex; flex-direction: column; gap: 8px; }
.pdf-row { display: flex; gap: 8px; }
.pdf-row .btn { flex: 1; }
.review-actions .btn small { font-weight: 600; opacity: .7; }

/* ---------- Scanner simulado ---------- */
.scanner {
  position: fixed; inset: 0; z-index: 100;
  background: #0A1420;
  display: flex; flex-direction: column;
}
.scanner-viewport {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(0,161,228,.12), transparent 60%),
    #0A1420;
}
#qr-region {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}
#qr-region video {
  width: 100% !important;
  border-radius: 14px;
  object-fit: cover;
}
/* moldura de mira desenhada pela própria biblioteca (qrbox) */
#qr-region canvas { display: none; }

.scan-error {
  margin: 14px 18px 0;
  background: #2A1218;
  border: 1.5px solid var(--danger);
  color: #FFD9DC;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.55;
  max-width: 460px;
}
.scan-error strong { color: #FF8B94; }

.scan-lastread {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: #fff;
}
.scan-lastread code { font-family: var(--mono); font-weight: 600; font-size: 14px; }
.scan-lastread b { margin-left: auto; }
.scan-lastread.ok  { background: rgba(27,158,86,.25); border: 1.5px solid var(--ok); }
.scan-lastread.dup, .scan-lastread.err { background: rgba(216,67,78,.25); border: 1.5px solid var(--danger); }
.scan-lastread.nfe { background: rgba(230,138,0,.25); border: 1.5px solid var(--warn); }
.scan-lastread.hidden { display: none; }

.scanner-actions {
  padding: 14px 18px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; flex-direction: column; gap: 8px;
}
.sim-row { display: flex; gap: 8px; }
.sim-row .btn { flex: 1; }

/* Flash de confirmação de leitura */
.scanner.flash-ok  .scanner-viewport { animation: fok .35s ease; }
.scanner.flash-bad .scanner-viewport { animation: fbad .45s ease; }
@keyframes fok  { 0% { box-shadow: inset 0 0 0 100vmax rgba(27,158,86,.55); } 100% { box-shadow: none; } }
@keyframes fbad { 0%,40% { box-shadow: inset 0 0 0 100vmax rgba(216,67,78,.5); } 100% { box-shadow: none; } }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,28,49,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--card);
  border-radius: 16px;
  padding: 22px 18px 16px;
  width: 100%; max-width: 380px;
}
.modal-box p { font-size: 16.5px; font-weight: 600; text-align: center; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; }

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