/* --- Reset / base --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0F2E1E;
  color: #F5F5F5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
input, button { font: inherit; color: inherit; }
button { border: none; background: none; cursor: pointer; }

/* --- Screens --- */
.screen {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  min-height: 56px;
}
.topbar h3 { margin: 0; font-size: 16px; font-weight: 600; }
.topbar > span { min-width: 40px; }

/* --- Buttons --- */
.btn {
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  transition: transform .05s ease, opacity .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: #22c55e; color: #0F2E1E; }
.btn.danger  { background: #ef4444; color: white; }
.btn.ghost   { background: transparent; color: #F5F5F5; border: 1px solid rgba(255,255,255,0.2); }
.btn.big     { padding: 18px; font-size: 18px; width: 100%; }
.btn.small   { padding: 8px 12px; font-size: 13px; }
.btn.back    { padding: 8px 12px; }

/* --- Entrada (sem login) --- */
#scr-login {
  justify-content: center;
  align-items: center;
  padding: 32px 20px;
  background: linear-gradient(180deg, #0F2E1E 0%, #052012 100%);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand img { width: min(72vw, 320px); max-height: 130px; object-fit: contain; }
.tagline { margin: 8px 0 0; color: #F29CBE; font-size: 16px; letter-spacing: .5px; font-weight: 600; }
.entry-card {
  text-align: center;
}
.entry-desc {
  color: #9ca3af;
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}
.card {
  width: 100%;
  max-width: 380px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 20px;
  display: grid;
  gap: 14px;
}
label { display: grid; gap: 6px; font-size: 13px; color: #d1d5db; }
input[type=text], input[type=password] {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: #fff;
  font-size: 16px;
}
input:focus { outline: 2px solid #22c55e; outline-offset: 1px; }

/* --- Coleta --- */
#scr-collect { padding: 0; }
#scr-collect.active { flex-direction: column; }
#scr-collect .topbar { flex-shrink: 0; z-index: 3; }

#scanner-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 55vh;
  background: #000;
  overflow: hidden;
}
#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.scan-frame {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 82%; height: 24%;
  border: 3px solid rgba(34,197,94,0.95);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
  pointer-events: none;
  z-index: 2;
}
.scan-frame::after {
  content: '';
  position: absolute;
  left: 6%; right: 6%; top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #22c55e, transparent);
  box-shadow: 0 0 10px #22c55e;
  animation: scan-sweep 1.6s ease-in-out infinite;
}
@keyframes scan-sweep {
  0%   { transform: translateY(-40px); opacity: .3; }
  50%  { transform: translateY(0);     opacity: 1;  }
  100% { transform: translateY(40px);  opacity: .3; }
}
.scan-hint {
  position: absolute;
  bottom: 66px; left: 0; right: 0;
  text-align: center; color: #fff; margin: 0;
  font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.9);
  z-index: 2;
}
.scanner-toolbar {
  position: absolute;
  bottom: 10px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; gap: 8px;
  z-index: 2;
}
.torch-btn {
  position: absolute;
  top: 12px; right: 12px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 20px;
  display: none;
  align-items: center; justify-content: center;
  z-index: 3;
  border: 1px solid rgba(255,255,255,0.25);
}
.torch-btn.available { display: inline-flex !important; }
.torch-btn.on { background: #fde047; color: #000; }

.scan-debug {
  display: none;
  position: absolute;
  top: 12px; left: 12px;
  max-width: 62%;
  z-index: 3;
  background: rgba(0,0,0,0.65);
  color: #86efac;
  font: 500 11px/1.35 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(134,239,172,0.25);
  white-space: pre-wrap;
  word-break: break-all;
  pointer-events: none;
}
body.debug .scan-debug { display: block; }

.col-stats {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: #86efac;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.items {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.items li {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.items li .info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.items li .code { font-weight: 700; color: #86efac; font-size: 15px; }
.items li .meta { color: #9ca3af; font-size: 12px; }
.items li .del { color: #f87171; padding: 8px; font-size: 20px; }

.fab {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #22c55e;
  color: #0F2E1E;
  font-size: 32px;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  display: none;
}
.fab.show { display: block; }

/* --- Teclado numérico --- */
.numpad-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 20px;
}
.numpad-label {
  margin: 0;
  color: #9ca3af;
  font-size: 15px;
  text-align: center;
}
.numpad-input {
  width: 180px;
  text-align: center;
  font-size: 48px;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid rgba(34,197,94,0.4);
  background: rgba(0,0,0,0.3);
  color: #22c55e;
  caret-color: transparent;
}
.numpad-input:focus { outline: 2px solid #22c55e; }
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 300px;
  width: 100%;
}
.nk {
  padding: 18px;
  border-radius: 12px;
  background: #1a4a30;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.08);
  transition: transform .05s;
}
.nk:active { transform: scale(0.95); background: #22553a; }
.nk-del { color: #f87171; }
.nk-ok  { background: #22c55e; color: #0F2E1E; }
.nk-ok:active { background: #16a34a; }

/* --- Resumo --- */
#scr-resumo { padding: 0; overflow-y: auto; }
.resumo-wrap {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.resumo-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 20px;
  display: grid;
  gap: 16px;
}
.resumo-header {
  text-align: center;
  display: grid;
  gap: 4px;
}
.resumo-header strong {
  font-size: 18px;
  color: #F29CBE;
  letter-spacing: 1px;
}
.resumo-header span {
  font-size: 13px;
  color: #9ca3af;
}
.resumo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.resumo-stat {
  text-align: center;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 12px;
  padding: 14px 8px;
  display: grid;
  gap: 4px;
}
.resumo-num {
  font-size: 32px;
  font-weight: 800;
  color: #22c55e;
}
.resumo-label {
  font-size: 11px;
  color: #86efac;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}
.resumo-list {
  font-size: 13px;
  color: #d1d5db;
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.resumo-list .car-tag {
  display: inline-block;
  background: rgba(34,197,94,0.15);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 6px;
  padding: 3px 8px;
  margin: 3px 4px;
  font-size: 12px;
  font-weight: 600;
  color: #86efac;
}
.resumo-list .car-tag.sn-tag {
  background: rgba(251,191,36,0.15);
  border-color: rgba(251,191,36,0.4);
  color: #fbbf24;
}
.btn-sn {
  background: rgba(251,191,36,0.2) !important;
  border: 1px solid rgba(251,191,36,0.5) !important;
  color: #fbbf24 !important;
  font-weight: 700 !important;
}
.sn-code {
  color: #fbbf24 !important;
}
.resumo-actions {
  display: grid;
  gap: 10px;
}
.resumo-email {
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
  margin: 0;
}
.resumo-email.ok { color: #86efac; }
.resumo-email.err { color: #fca5a5; }

/* --- Input com prefixo CAR --- */
.manual-input-row {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
}
.manual-prefix {
  padding: 14px 12px;
  font-size: 16px;
  font-weight: 700;
  color: #22c55e;
  background: rgba(34,197,94,0.15);
  border-right: 1px solid rgba(255,255,255,0.1);
  user-select: none;
  flex-shrink: 0;
}
.manual-input-row input {
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  flex: 1;
  min-width: 0;
}

/* --- Modais --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: #163e28;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 14px;
}
.modal-card h3 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  z-index: 200;
  animation: fadein .2s ease;
  max-width: 90vw;
  text-align: center;
  font-size: 14px;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
