:root {
  --bg: #0b0f1a;
  --bg-2: #10162a;
  --panel: #141b30;
  --panel-2: #1b2440;
  --border: #262f4d;
  --text: #f2f4fa;
  --muted: #93a0c2;
  --accent: #4f8cff;
  --accent-2: #2f6bf0;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --danger: #ff6b6b;
  --ok: #35d68a;
  --radius: 18px;
  --radius-sm: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

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

html { background: var(--bg); }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(79, 140, 255, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 32px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 10px; box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35); }
.login-card h1 { margin: 0 0 2px; font-size: 1.3rem; }
.login-card .subtitle { margin: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login-card input {
  width: 100%;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-submit { width: 100%; margin-top: 8px; }
.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.4;
}
.login-error.hidden { display: none; }

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: max(20px, env(safe-area-inset-top)) 20px 18px;
  max-width: 640px;
  margin: 0 auto;
}
.logout-btn { margin-left: auto; flex-shrink: 0; }
.topbar .logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35);
  flex-shrink: 0;
}
.topbar h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, #ffffff, #b9c8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }

/* ---------- Install banner ---------- */

.install-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--accent-2), #6a4cff);
  color: white;
  border-radius: 0 0 16px 16px;
}
.install-banner.hidden { display: none; }
.install-icon { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; }
.install-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.install-text strong { font-size: 0.92rem; }
.install-text span { font-size: 0.78rem; opacity: 0.9; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; white-space: nowrap; }
.btn-close {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- Layout ---------- */

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.step.hidden { display: none; }

.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.step-badge-ok { background: rgba(53, 214, 138, 0.18); color: var(--ok); }
.step h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }

label { font-size: 0.9rem; color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; line-height: 1.45; margin: 8px 0 0; }

select {
  width: 100%;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  margin-top: 8px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 8px 20px rgba(79, 140, 255, 0.35);
}
.btn-primary:active { filter: brightness(0.95); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.hidden { display: none; }

.capture-actions, .result-actions, .camera-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.file-btn { cursor: pointer; }

/* ---------- Camera ---------- */

.camera-wrap { margin-top: 16px; }
.camera-wrap.hidden { display: none; }

.video-box {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
#video {
  width: 100%;
  display: block;
  max-height: 70vh;
  object-fit: cover;
}
.frame-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.frame-guide path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 3px rgba(79,140,255,0.8));
}

/* ---------- Análise ao vivo da câmera ---------- */

.live-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* mesmo enquadramento do <video>, pra o contorno bater com a imagem */
  pointer-events: none;
}
.live-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  top: max(12px, env(safe-area-inset-top));
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: #fff;
  z-index: 102;
}
.live-hint.level-bad { background: rgba(220, 60, 60, 0.9); }
.live-hint.level-warn { background: rgba(255, 196, 0, 0.92); color: #2a2200; }
.live-hint.level-good { background: rgba(30, 170, 105, 0.92); }
.live-detail { font-size: 0.68rem; font-weight: 400; opacity: 0.85; margin-top: 3px; }
.live-toggle {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 0.9rem;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.live-toggle input { width: 18px; height: 18px; }

/* ---------- Modo câmera em tela cheia ---------- */
/* Quando a câmera abre, some tudo o mais e fica só o preview + os controles
   de captura, ocupando a tela inteira (sem instalar banner, header, cards). */

body.camera-mode .topbar,
body.camera-mode #installBanner,
body.camera-mode #step-profile,
body.camera-mode #step-capture .step-head,
body.camera-mode #step-capture > .hint,
body.camera-mode .capture-actions,
body.camera-mode #step-process,
body.camera-mode #step-result,
body.camera-mode #step-batch,
body.camera-mode .footer {
  display: none !important;
}

body.camera-mode { overflow: hidden; }
body.camera-mode #app { padding: 0; gap: 0; max-width: none; }
body.camera-mode #step-capture {
  background: none; border: none; box-shadow: none; padding: 0; border-radius: 0;
}

body.camera-mode .camera-wrap {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  background: #000;
  display: flex;
  flex-direction: column;
}
body.camera-mode .video-box {
  flex: 1;
  border-radius: 0;
  min-height: 0;
}
body.camera-mode #video {
  width: 100%;
  height: 100%;
  max-height: none;
}
body.camera-mode .camera-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  justify-content: center;
  margin-top: 0;
  padding: 0 16px;
  z-index: 101;
}

/* ---------- Progress / status ---------- */

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6a4cff);
  transition: width 0.2s ease;
}

.status {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  min-height: 1.2em;
}
.status.status-error { color: var(--danger); border-color: rgba(255,107,107,0.35); }
.status.status-ok { color: var(--ok); border-color: rgba(53,214,138,0.35); }

/* ---------- Calibration warning ---------- */

.calib-warning {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.45;
  margin-bottom: 14px;
  border: 1px solid;
}
.calib-warning.hidden { display: none; }
.calib-warning.level-ok {
  background: rgba(53, 214, 138, 0.1);
  border-color: rgba(53, 214, 138, 0.35);
  color: var(--ok);
}
.calib-warning.level-warn {
  background: rgba(255, 196, 0, 0.1);
  border-color: rgba(255, 196, 0, 0.4);
  color: #ffc400;
}
.calib-warning.level-error {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.4);
  color: var(--danger);
}

/* ---------- Pergunta "tem mais moldes?" e lote ---------- */

.more-question {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.more-question h3 { margin: 0; font-size: 1.02rem; }

.batch-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.batch-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}
.batch-item img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #000;
}
.batch-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Vetorização ---------- */

.result-stack { position: relative; }
.vector-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.vector-box { margin-top: 14px; }
.vector-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; }
.vector-toggle input { width: 18px; height: 18px; }
.vector-info { white-space: pre-line; }
.vector-select { width: auto; margin: 0 0 0 8px; padding: 6px 28px 6px 10px; font-size: 0.85rem; }

/* ---------- Result ---------- */

.result-wrap {
  width: 100%;
  overflow: auto;
  border-radius: var(--radius);
  background: #000;
  border: 1px solid var(--border);
}
#resultCanvas { width: 100%; display: block; }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 26px;
  padding: 0 16px;
}

.hidden { display: none !important; }

@media (min-width: 480px) {
  .step { padding: 22px; }
}

/* ---------- Envio por e-mail ---------- */
.email-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.email-label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; }
.email-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.email-input {
  flex: 1 1 220px;
  min-width: 0;
  width: 100%;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}
.email-row .email-input { width: auto; }
.email-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.email-status { white-space: pre-line; }
.email-status:empty { display: none; }
