:root {
  --bg: #060b17;
  --bg-2: #0b1324;
  --panel: #0e1729;
  --panel-2: #142039;
  --line: rgba(148, 163, 184, .14);
  --line-2: rgba(148, 163, 184, .24);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --faint: #64748b;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --primary-glow: rgba(59, 130, 246, .35);
  --ok: #10b981;
  --ok-glow: rgba(16, 185, 129, .3);
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 22px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }  /* senão o aviso de câmera (display:grid) cobre o vídeo */
body {
  font-family: var(--font);
  background: radial-gradient(1200px 700px at 10% -10%, #10224a 0%, transparent 60%),
              radial-gradient(900px 600px at 110% 110%, #0d2a3a 0%, transparent 55%), var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }
.ic { width: 1.15em; height: 1.15em; flex: none; }

.t-app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; padding: clamp(14px, 2.2vw, 28px); gap: clamp(12px, 2vw, 22px); }

/* ---------- cabeçalho ---------- */
.t-header { display: flex; align-items: center; gap: 16px; }
.t-brand { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.t-brand strong { display: block; font-size: 18px; letter-spacing: -.01em; }
.t-brand span { color: var(--muted); font-size: 13px; }
.t-logo { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, #3b82f6, #1d4ed8); box-shadow: 0 8px 24px -6px var(--primary-glow); }
.t-logo .ic { width: 24px; height: 24px; color: #fff; }
.t-clock { text-align: right; }
.t-clock strong { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.t-clock span { color: var(--muted); font-size: 13px; text-transform: capitalize; }
.t-fullscreen { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); border: 1px solid var(--line); }
.t-fullscreen:hover { color: var(--text); border-color: var(--line-2); }

/* ---------- layout principal ---------- */
.t-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: clamp(14px, 2vw, 24px); min-height: 0; }
.t-camera, .t-panel { min-height: 0; }

.t-stage {
  position: relative; height: 100%; border-radius: var(--radius); overflow: hidden;
  background: #02050d; border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8);
}
.t-stage video, .t-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; transform: scaleX(-1); }
.t-stage video { object-fit: cover; }
.t-guide { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.t-guide-ring {
  width: min(62%, 340px); aspect-ratio: 3 / 4; border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, .35);
  box-shadow: 0 0 0 9999px rgba(2, 5, 13, .38);
  transition: border-color .3s, box-shadow .3s, transform .3s;
}
.t-stage.st-ok .t-guide-ring { border: 3px solid var(--ok); box-shadow: 0 0 0 9999px rgba(2, 5, 13, .38), 0 0 40px var(--ok-glow); }
.t-stage.st-warn .t-guide-ring { border-color: var(--warn); }
.t-stage.st-danger .t-guide-ring { border: 3px solid var(--danger); }
.t-stage.st-busy .t-guide-ring { border-style: solid; border-color: var(--primary); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.025); box-shadow: 0 0 0 9999px rgba(2, 5, 13, .38), 0 0 36px var(--primary-glow); } }

.t-cam-status {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 500;
  background: rgba(6, 11, 23, .72); backdrop-filter: blur(10px); border: 1px solid var(--line-2);
}
.t-cam-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.t-stage.st-scan .t-cam-status .dot { background: var(--primary); animation: blink 1.2s infinite; }
.t-stage.st-ok .t-cam-status .dot { background: var(--ok); }
.t-stage.st-warn .t-cam-status .dot { background: var(--warn); }
.t-stage.st-danger .t-cam-status .dot { background: var(--danger); }
.t-stage.st-busy .t-cam-status .dot { background: var(--primary); animation: blink .6s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.t-cam-error { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 32px; background: #02050d; color: var(--muted); font-size: 16px; line-height: 1.5; }
.t-cam-error .ic { width: 44px; height: 44px; color: var(--warn); display: block; margin: 0 auto 12px; }

/* ---------- painel ---------- */
.t-panel {
  position: relative; border-radius: var(--radius); padding: clamp(22px, 3vw, 40px);
  background: linear-gradient(180deg, rgba(20, 32, 57, .85), rgba(14, 23, 41, .92));
  border: 1px solid var(--line); display: flex; flex-direction: column; overflow: auto;
}
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; animation: enter .35s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }

.eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-weight: 600; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.title { font-size: clamp(28px, 3.4vw, 42px); line-height: 1.12; letter-spacing: -.025em; margin: 10px 0 10px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: clamp(16px, 1.6vw, 19px); line-height: 1.5; margin: 0; }
.spacer { flex: 1; min-height: 16px; }

.steps { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.steps li { display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-radius: 16px; background: rgba(255, 255, 255, .03); border: 1px solid var(--line); font-size: 16px; }
.steps li .n { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: rgba(59, 130, 246, .14); color: #93c5fd; flex: none; }
.steps li small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.progress { display: flex; gap: 8px; margin-bottom: 26px; }
.progress span { height: 6px; flex: 1; border-radius: 6px; background: rgba(148, 163, 184, .18); }
.progress span.on { background: var(--primary); }
.progress span.done { background: var(--ok); }

.hello { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; background: rgba(16, 185, 129, .08); border: 1px solid rgba(16, 185, 129, .25); margin-bottom: 22px; }
.hello .badge-ok { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(16, 185, 129, .18); color: var(--ok); flex: none; }
.hello strong { display: block; font-size: 17px; }

/* foto do cadastro de quem foi reconhecido */
.hello-foto, .mini-foto, .result-foto { position: relative; flex: none; display: inline-grid; }
.hello-foto img, .mini-foto img, .result-foto img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; background: rgba(255, 255, 255, .06); }
.hello-foto i, .result-foto i { position: absolute; right: -4px; bottom: -4px; display: grid; place-items: center; border-radius: 50%; background: var(--ok); color: #fff; border: 3px solid #13203a; }
.hello-foto { width: 64px; height: 64px; border-radius: 16px; }
.hello-foto i { width: 26px; height: 26px; }
.hello-foto i .ic { width: 14px; height: 14px; }
.mini-foto { width: 34px; height: 34px; border-radius: 10px; }
.mini-foto i { display: none; }
.summary-pessoa { display: inline-flex; align-items: center; gap: 10px; }
.result-foto { width: 128px; height: 128px; border-radius: 50%; margin: 0 auto 26px; box-shadow: 0 0 0 6px rgba(16, 185, 129, .35), 0 0 0 16px rgba(16, 185, 129, .08); animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
.result-foto i { width: 40px; height: 40px; right: 0; bottom: 0; }
.result-foto i .ic { width: 22px; height: 22px; }
/* sem foto: volta para o ✓ */
.sem-foto img { display: none; }
.sem-foto { background: rgba(16, 185, 129, .18); }
.sem-foto i { position: static; border: 0; width: 100%; height: 100%; border-radius: inherit; background: transparent; color: var(--ok); }
.mini-foto.sem-foto { display: none; }
.hello span { color: var(--muted); font-size: 14px; }

/* botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 62px; padding: 0 26px; border-radius: 16px; font-size: 18px; font-weight: 600;
  transition: transform .08s, background .2s, opacity .2s; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-primary { background: linear-gradient(180deg, #3b82f6, #2563eb); color: #fff; box-shadow: 0 12px 30px -10px var(--primary-glow); }
.btn-ok { background: linear-gradient(180deg, #10b981, #059669); color: #fff; box-shadow: 0 12px 30px -10px var(--ok-glow); }
.btn-ghost { background: rgba(255, 255, 255, .05); border: 1px solid var(--line-2); color: var(--text); }
.btn-text { color: var(--muted); min-height: 52px; font-size: 16px; }
.actions { display: flex; gap: 12px; margin-top: 22px; }
.actions .btn { flex: 1; }
.actions .btn-text { flex: 0 0 auto; }

/* unidades */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 26px; }
.unit-btn {
  min-height: 84px; border-radius: 18px; background: rgba(255, 255, 255, .04); border: 1.5px solid var(--line-2);
  font-size: 26px; font-weight: 700; letter-spacing: -.01em; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.unit-btn small { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.unit-btn:active, .unit-btn.sel { border-color: var(--primary); background: rgba(59, 130, 246, .14); }
.other-unit { margin-top: 18px; display: flex; gap: 12px; }
.input {
  flex: 1; min-height: 62px; border-radius: 16px; padding: 0 20px; font-size: 22px; font-weight: 600;
  background: rgba(2, 5, 13, .5); border: 1.5px solid var(--line-2); color: var(--text); outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(59, 130, 246, .18); }
.input::placeholder { color: var(--faint); font-weight: 500; }

/* valor */
.value-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; margin-top: 22px; }
.value-display {
  border-radius: 18px; padding: 18px 20px; background: rgba(2, 5, 13, .55); border: 1.5px solid var(--line-2);
  display: flex; flex-direction: column; gap: 4px;
}
.value-display small { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.value-display strong { font-size: clamp(34px, 4vw, 50px); font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.value-display.zero strong { color: var(--faint); }
.value-hint { display: flex; gap: 10px; align-items: flex-start; margin: 14px 2px 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.value-hint .ic { margin-top: 2px; color: #93c5fd; }
.other-unit .input { min-width: 0; }
.other-unit .btn { flex: none; padding: 0 22px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  min-height: 66px; border-radius: 16px; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line); display: grid; place-items: center;
}
.key:active { background: rgba(59, 130, 246, .2); border-color: var(--primary); }
.key .ic { width: 28px; height: 28px; }

/* confirmação */
.summary { margin-top: 24px; border-radius: 18px; border: 1px solid var(--line-2); overflow: hidden; }
.summary-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 22px; font-size: 18px; }
.summary-row + .summary-row { border-top: 1px solid var(--line); }
.summary-row span { color: var(--muted); }
.summary-row strong { text-align: right; }
.summary-row.total { background: rgba(59, 130, 246, .08); }
.summary-row.total strong { font-size: 30px; letter-spacing: -.02em; }
.notice { display: flex; gap: 12px; align-items: flex-start; margin-top: 18px; padding: 14px 16px; border-radius: 14px; font-size: 15px; line-height: 1.45; background: rgba(59, 130, 246, .08); border: 1px solid rgba(59, 130, 246, .25); color: #cbd5e1; }
.notice.err { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .35); color: #fecaca; }
.notice .ic { margin-top: 2px; }

/* prova de vida */
.live-visual { margin: 34px auto 10px; width: 180px; height: 180px; position: relative; display: grid; place-items: center; }
.live-visual svg.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.live-visual .face { width: 88px; height: 88px; color: #93c5fd; animation: turn 2.2s ease-in-out infinite; }
@keyframes turn { 0%, 100% { transform: perspective(300px) rotateY(0); } 30% { transform: perspective(300px) rotateY(-38deg); } 70% { transform: perspective(300px) rotateY(38deg); } }

/* resultado */
.result { align-items: center; justify-content: center; text-align: center; }
.result-icon { width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 26px; }
.result-icon .ic { width: 60px; height: 60px; }
.result-icon.ok { background: rgba(16, 185, 129, .14); color: var(--ok); box-shadow: 0 0 0 14px rgba(16, 185, 129, .06); animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
.result-icon.warn { background: rgba(245, 158, 11, .14); color: var(--warn); box-shadow: 0 0 0 14px rgba(245, 158, 11, .06); }
.result-icon.danger { background: rgba(239, 68, 68, .14); color: var(--danger); box-shadow: 0 0 0 14px rgba(239, 68, 68, .06); }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
.result .subtitle { max-width: 460px; margin: 0 auto; }
.countdown { margin-top: 28px; color: var(--faint); font-size: 14px; }
.result .summary { width: 100%; max-width: 460px; text-align: left; }

.t-footer { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--faint); font-size: 13px; text-align: center; }

/* toasts */
.toasts { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 10px; z-index: 50; }
.toast { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-radius: 14px; font-size: 16px; background: #1e293b; border: 1px solid var(--line-2); box-shadow: 0 20px 40px -10px rgba(0, 0, 0, .6); opacity: 0; transform: translateY(-10px); transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-warn .ic { color: var(--warn); } .toast-danger .ic { color: var(--danger); } .toast-ok .ic { color: var(--ok); }

/* ---------- tablet em pé / celular ---------- */
@media (orientation: portrait), (max-width: 860px) {
  body { overflow: auto; }
  .t-app { height: auto; min-height: 100dvh; }
  .t-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .t-stage { height: 38dvh; min-height: 260px; }
  .t-guide-ring { width: auto; height: 82%; }
  .value-wrap { grid-template-columns: 1fr; }
}
/* ---------- tablet deitado de altura baixa (ex.: 1280x800) ---------- */
@media (orientation: landscape) and (max-height: 860px) and (min-width: 861px) {
  .t-panel { padding: 24px 28px; }
  .progress { margin-bottom: 16px; }
  .title { font-size: clamp(26px, 3vw, 36px); margin: 6px 0 8px; }
  .hello { margin-bottom: 14px; padding: 10px 14px; }
  .value-wrap { margin-top: 14px; gap: 18px; }
  .value-display { padding: 12px 16px; }
  .value-display strong { font-size: clamp(30px, 3.4vw, 42px); }
  .keypad { gap: 8px; }
  .key { min-height: 58px; }
  .actions { margin-top: 16px; }
  .btn { min-height: 56px; }
  .units { margin-top: 18px; }
  .unit-btn { min-height: 72px; }
  .summary { margin-top: 16px; }
  .summary-row { padding: 14px 20px; }
  .live-visual { margin-top: 20px; }
}
@media (max-width: 520px) {
  .t-clock span, .t-brand span { display: none; }
  .t-app { padding: 12px; gap: 12px; }
  .t-header { gap: 10px; }
  .t-logo { width: 40px; height: 40px; border-radius: 12px; }
  .t-brand strong { font-size: 16px; }
  .t-fullscreen { display: none; }   /* no celular a tela cheia não ajuda */

  /* câmera: grande só quando precisa ver o rosto */
  .t-stage { height: 34dvh; min-height: 220px; transition: height .3s ease; }
  body[data-etapa="unidade"] .t-stage, body[data-etapa="valor"] .t-stage,
  body[data-etapa="sucesso"] .t-stage, body[data-etapa="negado"] .t-stage { height: 76px; min-height: 0; }
  body[data-etapa="unidade"] .t-guide, body[data-etapa="valor"] .t-guide,
  body[data-etapa="sucesso"] .t-guide, body[data-etapa="negado"] .t-guide { display: none; }
  .t-cam-status { bottom: 10px; padding: 8px 14px; font-size: 14px; }
  body[data-etapa="unidade"] .t-cam-status, body[data-etapa="valor"] .t-cam-status { top: 50%; bottom: auto; transform: translate(-50%, -50%); }

  .t-panel { padding: 20px 16px; border-radius: 20px; }
  .progress { margin-bottom: 16px; }
  .title { font-size: 25px; margin: 6px 0 6px; }
  .subtitle { font-size: 15px; }
  .hello { margin-bottom: 14px; padding: 10px 12px; }
  .steps { margin-top: 18px; gap: 8px; }
  .steps li { padding: 12px 14px; font-size: 15px; }

  .units { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
  .unit-btn { min-height: 74px; font-size: 24px; }
  .other-unit { margin-top: 12px; gap: 10px; }
  .input { min-height: 56px; font-size: 19px; padding: 0 16px; }

  /* valor: visor + teclado ocupando a largura toda */
  .value-wrap { gap: 12px; margin-top: 12px; }
  .value-display { padding: 12px 16px; flex-direction: row; align-items: baseline; justify-content: space-between; gap: 10px; }
  .value-display strong { font-size: 34px; }
  .value-hint { display: none; }
  .keypad { gap: 8px; }
  .key { min-height: 60px; font-size: 26px; border-radius: 14px; }

  .summary { margin-top: 16px; }
  .summary-row { padding: 13px 16px; font-size: 16px; }
  .summary-row.total strong { font-size: 24px; }
  .result-icon { width: 96px; height: 96px; margin-bottom: 18px; }
  .result-foto { width: 104px; height: 104px; margin-bottom: 20px; }
  .hello-foto { width: 54px; height: 54px; border-radius: 14px; }

  .btn { min-height: 56px; font-size: 16px; padding: 0 16px; }
  .actions { flex-wrap: wrap; gap: 8px; margin-top: 16px; }
  .actions .btn-primary, .actions .btn-ok { flex: 1 1 100%; order: -1; }
  .actions .btn-ghost { flex: 1 1 auto; }
  .t-footer { font-size: 11.5px; }
}
