/* Credenciamento Mobile — mobile-first, tela cheia, alvos de toque grandes.
   As variáveis de cor são injetadas pelo index.php a partir da config do evento. */

:root {
  --primaria: #0d6efd;
  --fundo: #0b1220;
  --texto: #f8fafc;
  --btn-texto: #ffffff;

  --painel: rgba(255, 255, 255, .06);
  --borda: rgba(255, 255, 255, .14);
  --suave: rgba(255, 255, 255, .55);
  --erro: #fda4af;
  --ok: #4ade80;

  --raio: 14px;
  --gap: 14px;
  /* Área segura de aparelhos com notch */
  --topo-seguro: env(safe-area-inset-top, 0px);
  --base-segura: env(safe-area-inset-bottom, 0px);
}

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

/* O atributo hidden vale mais que qualquer display do autor.
   Sem isto, regras como `.btn { display: flex }` sobrescrevem o
   `display: none` que o navegador aplica em [hidden] — a folha do
   user-agent perde para qualquer regra de autor — e o elemento fica
   visível mesmo marcado como oculto. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { padding-top: var(--topo-seguro); padding-bottom: var(--base-segura); }

/* ── Telas ─────────────────────────────────────────────────────────────── */

.tela {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--topo-seguro);
  padding-bottom: var(--base-segura);
  background: var(--fundo);
  animation: entra .18s ease-out;
}
/* .tela[hidden] já é coberto pela regra global [hidden] no topo. */

@keyframes entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tela { animation: none; } }

.centro {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
  text-align: center;
  overflow-y: auto;
}

.conteudo {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Topo ──────────────────────────────────────────────────────────────── */

.topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--borda);
  background: var(--painel);
  min-height: 54px;
}
.topo strong { font-size: 16px; font-weight: 600; }

.icone {
  background: none;
  border: 0;
  color: var(--texto);
  font-size: 22px;
  line-height: 1;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
}
.icone:active { background: var(--painel); }

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--primaria);
  color: var(--btn-texto);
}

/* ── Tipografia ────────────────────────────────────────────────────────── */

h1 { font-size: 24px; margin: 0 0 6px; font-weight: 700; }
h2 { font-size: 22px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; }

.sub { color: var(--suave); margin: 0 0 18px; font-size: 14px; }
.dica { color: var(--suave); font-size: 14px; text-align: center; margin: 4px 0; }
.vazio { color: var(--suave); text-align: center; padding: 24px 0; }
.erro { color: var(--erro); font-size: 14px; margin: 4px 0 0; }

.logo { max-width: 180px; max-height: 100px; margin-bottom: 18px; object-fit: contain; }

/* ── Botões ────────────────────────────────────────────────────────────── */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  background: var(--painel);
  color: var(--texto);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn.primario { background: var(--primaria); color: var(--btn-texto); border-color: transparent; }
.btn.grande { min-height: 64px; font-size: 17px; }
.btn .ico { font-size: 22px; }

.link {
  background: none;
  border: 0;
  color: var(--primaria);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 2px;
}

.acoes { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 420px; }

/* ── Formulários ───────────────────────────────────────────────────────── */

.painel {
  width: 100%;
  max-width: 380px;
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 20px;
  text-align: left;
}

label { display: block; font-size: 13px; color: var(--suave); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="email"],
input[type="tel"], input[type="search"], select, textarea {
  width: 100%;
  /* 16px evita o zoom automático do iOS ao focar o campo */
  font-size: 16px;
  padding: 14px;
  border-radius: 11px;
  border: 1px solid var(--borda);
  background: rgba(0, 0, 0, .25);
  color: var(--texto);
  margin-bottom: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primaria);
  outline-offset: 1px;
}
input::placeholder { color: var(--suave); }

.campo-obrigatorio::after { content: " *"; color: var(--erro); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--texto);
  cursor: pointer;
  margin: 0;
}
.check input { width: 24px; height: 24px; flex: 0 0 24px; margin: 0; accent-color: var(--primaria); }

/* ── Abas ──────────────────────────────────────────────────────────────── */

.abas { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 4px; }
.aba {
  flex: 0 0 auto;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--borda);
  background: transparent;
  color: var(--suave);
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
}
.aba.ativa { background: var(--primaria); color: var(--btn-texto); border-color: transparent; font-weight: 600; }

/* ── Resultados da busca ───────────────────────────────────────────────── */

.resultados { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  background: var(--painel);
  color: var(--texto);
  text-align: left;
  cursor: pointer;
  min-height: 62px;
}
.item:active { background: rgba(255, 255, 255, .1); }
.item .info { min-width: 0; }
.item .nome { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .selo { flex: 0 0 auto; font-size: 11px; padding: 4px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.selo.feito { background: rgba(74, 222, 128, .16); color: var(--ok); }
.selo.pendente { background: rgba(255, 255, 255, .1); color: var(--suave); }

/* ── Cartão de confirmação ─────────────────────────────────────────────── */

.cartao {
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 18px;
}
.cartao .nome-grande { font-size: 21px; font-weight: 700; margin: 0 0 12px; }
.cartao dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.cartao dt { color: var(--suave); }
.cartao dd { margin: 0; word-break: break-word; }
.cartao .aviso {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(74, 222, 128, .12);
  color: var(--ok);
  font-size: 13.5px;
}

/* ── Assinatura ────────────────────────────────────────────────────────── */

.assinatura {
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 12px;
}
.assinatura-topo { display: flex; align-items: center; justify-content: space-between; }
.assinatura label { margin: 0; }
#canvasAssinatura, #canvasAssinaturaCad {
  display: block;
  width: 100%;
  height: 170px;
  margin-top: 8px;
  border-radius: 10px;
  background: #ffffff;
  /* Impede o scroll da página enquanto o dedo desenha */
  touch-action: none;
}

/* ── QR ────────────────────────────────────────────────────────────────── */

#leitorQr {
  width: 100%;
  border-radius: var(--raio);
  overflow: hidden;
  background: #000;
  min-height: 260px;
}
#leitorQr video { width: 100% !important; height: auto !important; display: block; }
#leitorQr img[alt="Info icon"] { display: none; }

/* ── Sucesso ───────────────────────────────────────────────────────────── */

.sucesso .centro { gap: 6px; }
.visto {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(74, 222, 128, .16);
  color: var(--ok);
  font-size: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.nome-grande { font-size: 22px; font-weight: 700; margin: 0; }
.sucesso .btn { max-width: 380px; margin-top: 14px; }
.sucesso #btnNovo { margin-top: 26px; }

.impressao-status {
  margin: 14px 0 0;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  background: var(--painel);
  border: 1px solid var(--borda);
}
.impressao-status.ok { background: rgba(74, 222, 128, .14); border-color: transparent; color: var(--ok); }
.impressao-status.falha { background: rgba(248, 113, 113, .14); border-color: transparent; color: var(--erro); }

/* ── Dashboard ─────────────────────────────────────────────────────────── */

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi {
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 14px;
}
.kpi .valor { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .rotulo { font-size: 12px; color: var(--suave); margin-top: 3px; text-transform: uppercase; letter-spacing: .04em; }
.kpi.destaque .valor { color: var(--primaria); }

.grafico-caixa, .lista-caixa {
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 16px;
}

.ultimos, .participantes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ultimos li, .participantes li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--borda);
  font-size: 14.5px;
}
.ultimos li:last-child, .participantes li:last-child { border-bottom: 0; }
.ultimos .hora { color: var(--suave); font-size: 13px; flex: 0 0 auto; }
.participantes .nome { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Menu ──────────────────────────────────────────────────────────────── */

.menu {
  position: absolute;
  top: calc(56px + var(--topo-seguro));
  right: 12px;
  background: #16213a;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  overflow: hidden;
  min-width: 190px;
  z-index: 30;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.menu button {
  display: block;
  width: 100%;
  padding: 15px 18px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--borda);
  color: var(--texto);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.menu button:last-child { border-bottom: 0; }
.menu button:active { background: var(--painel); }

/* ── Modal ─────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .65);
}
.modal-caixa {
  width: 100%;
  max-width: 440px;
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px;
  border-radius: var(--raio);
  background: #16213a;
  border: 1px solid var(--borda);
}
.modal-caixa h2 { font-size: 19px; margin: 0 0 6px; }
.modal-caixa .sub { margin-bottom: 16px; }

.lista-impressoras { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.lista-impressoras .item .ip { font-size: 13px; color: var(--suave); }
.lista-impressoras .item.escolhida { border-color: var(--primaria); }

/* ── Carregando / toast ────────────────────────────────────────────────── */

.carregando {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, .2);
  border-top-color: var(--primaria);
  border-radius: 50%;
  animation: girar .7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--base-segura));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 13px 18px;
  border-radius: 12px;
  background: #1e293b;
  border: 1px solid var(--borda);
  font-size: 14.5px;
  text-align: center;
  z-index: 60;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
}
.toast.erro-toast { background: #3b1220; border-color: #7f1d33; color: var(--erro); }
.toast.ok-toast { background: #0d2a1c; border-color: #14532d; color: var(--ok); }

/* ── Telas maiores ─────────────────────────────────────────────────────── */

@media (min-width: 640px) {
  .conteudo { max-width: 640px; width: 100%; margin: 0 auto; padding: 22px; }
  .topo { padding: 14px 22px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
