/* Telas do cadastro. Cor, raio e fonte só por variável de tokens.css. */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--fundo);
  background-image: var(--textura-container);
  color: var(--texto);
  font-family: var(--fonte);
  font-weight: var(--peso-normal);
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--laranja); outline-offset: 2px; }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app svg, .termo svg {
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* A altura acompanha o visualViewport (teclado do iOS); sem JS vale 100dvh. */
.app {
  position: fixed;
  top: var(--topo, 0);
  left: 0;
  right: 0;
  margin-inline: auto;
  width: 100%;
  max-width: 440px;
  height: var(--altura, 100dvh);
  background-color: var(--fundo);
  overflow: hidden;
}

@media (min-width: 480px) {
  .app { border-inline: 1px solid var(--borda); }
}

.tela {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- botões ---------- */
.botao {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.25rem;
  padding: 0.75rem 1.25rem;
  border: 2px solid transparent;
  border-radius: var(--raio-p);
  font-weight: var(--peso-forte);
  font-size: 1rem;
  text-decoration: none;
  transition: transform var(--rapido) var(--curva), background-color var(--rapido);
}
.botao:active { transform: scale(0.98); }
.botao--primario { background: var(--laranja); color: var(--texto-sobre-laranja); }
.botao--primario:hover { background: var(--laranja-forte); }
.botao--primario:focus-visible { outline-color: var(--branco); }
.botao--secundario { background: transparent; color: var(--texto); border-color: var(--borda); }
.botao--secundario:hover { border-color: var(--texto-3); }
.botao--grande { min-height: 3.75rem; font-size: 1.125rem; width: 100%; }
.botao__icone { display: inline-flex; width: 1.35rem; height: 1.35rem; }
.botao__icone svg { width: 100%; height: 100%; }

.link {
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--laranja);
  font-weight: var(--peso-forte);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- abertura ---------- */
.abertura {
  justify-content: space-between;
  gap: 2rem;
  padding: calc(2.5rem + env(safe-area-inset-top)) 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  background-color: var(--fundo-2);
  background-image: var(--textura-container);
  overflow-y: auto;
}
.abertura__logo { width: min(80%, 19rem); height: auto; margin-inline: auto; }
.abertura__visor { flex: 1; display: grid; place-items: center; min-height: 7rem; }
.abertura__visor svg { height: min(100%, 15rem); width: auto; overflow: visible; }
.visor__cantos { stroke: var(--texto-3); stroke-width: 5; }
.visor__oval { stroke: var(--laranja); stroke-width: 4; }
.visor__linha {
  stroke: var(--verde);
  stroke-width: 3;
  animation: varrer 2.6s ease-in-out infinite alternate;
}
.abertura__etiqueta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.9rem;
  color: var(--verde);
  font-size: 0.8125rem;
  font-weight: var(--peso-forte);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.abertura__etiqueta::before {
  content: "";
  width: 1.75rem;
  height: 3px;
  background: var(--verde);
}
.abertura__titulo {
  margin: 0;
  font-size: clamp(2.5rem, 12vw, 3.4rem);
  font-weight: var(--peso-marca);
  line-height: 1;
  letter-spacing: -0.025em;
}
.abertura__titulo span { display: block; color: var(--laranja); }
.abertura__sub { margin: 1rem 0 0; color: var(--texto-2); font-size: 1.125rem; }

/* ---------- topo da conversa ---------- */
.topo {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.85rem;
  background-color: var(--fundo-2);
  background-image: var(--textura-container);
  border-bottom: 1px solid var(--borda);
}
.topo__avatar {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.35rem;
  border-radius: var(--raio-pilula);
  background: var(--superficie);
  border: 1px solid var(--borda);
}
.topo__nome { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topo__nome strong { font-weight: var(--peso-marca); font-size: 1.0625rem; }
.topo__nome span { color: var(--texto-3); font-size: 0.8125rem; }

.progresso {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: var(--superficie-2);
}
.progresso span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--laranja);
  transition: width var(--medio) var(--curva);
}

/* ---------- mensagens ---------- */
.mensagens {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 1.25rem 1rem 1rem;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  animation: entrar var(--medio) var(--curva) both;
}
.msg--mm + .msg--eu, .msg--eu + .msg--mm { margin-top: 0.5rem; }

.msg__avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  padding: 0.3rem;
  border-radius: var(--raio-pilula);
  background: var(--superficie);
  border: 1px solid var(--borda);
}
.msg--mm + .msg--mm .msg__avatar { visibility: hidden; }

.balao {
  max-width: 82%;
  padding: 0.7rem 0.95rem;
  border-radius: var(--raio-m);
  font-size: 1rem;
  overflow-wrap: anywhere;
}
.msg--mm .balao {
  background: var(--superficie);
  border-bottom-left-radius: 4px;
}
.msg--mm .balao:has(.resumo, .linha-tempo, .cartao-termo) { flex: 1; max-width: none; }

.msg--eu { justify-content: flex-end; }
.msg--eu .balao {
  background: var(--laranja);
  color: var(--texto-sobre-laranja);
  font-weight: var(--peso-forte);
  border-bottom-right-radius: 4px;
}
.balao--editavel {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  text-align: left;
}
.balao__editar { display: inline-flex; flex: none; width: 1rem; height: 1rem; opacity: 0.7; }
.balao__editar svg { width: 100%; height: 100%; }
.msg--eu .balao--editavel:disabled {
  background: var(--superficie-2);
  color: var(--texto-3);
  text-decoration: line-through;
  cursor: default;
}
.balao--editavel:disabled .balao__editar { display: none; }
.balao--editavel:has(.balao__foto) { padding: 0.35rem; flex-direction: column; }
.balao__foto {
  width: 9.5rem;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: calc(var(--raio-m) - 4px);
}
.balao--editavel:disabled .balao__foto { opacity: 0.45; }

/* indicador de digitação */
.digitando .balao { display: inline-flex; gap: 0.3rem; padding: 0.95rem 1rem; }
.digitando i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: var(--raio-pilula);
  background: var(--texto-3);
  animation: piscar 1s infinite;
}
.digitando i:nth-child(2) { animation-delay: 0.15s; }
.digitando i:nth-child(3) { animation-delay: 0.3s; }

/* cartão do consentimento */
.cartao-termo strong { display: block; margin-bottom: 0.4rem; font-weight: var(--peso-marca); }
.cartao-termo p { margin: 0 0 0.6rem; color: var(--texto-2); }

/* resumo */
.resumo { margin: -0.2rem -0.3rem; }
.resumo dl { margin: 0; }
.resumo__foto,
.resumo__linha {
  display: grid;
  align-items: center;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  border-radius: var(--raio-p);
}
.resumo__foto {
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  padding: 0.3rem;
  margin-bottom: 0.4rem;
  color: var(--laranja);
  font-weight: var(--peso-forte);
  font-size: 0.9375rem;
}
.resumo__foto img {
  width: 3.75rem;
  height: 3.75rem;
  object-fit: cover;
  border-radius: var(--raio-pilula);
  border: 2px solid var(--borda);
}
.resumo__linha {
  grid-template-columns: 6.5rem 1fr auto;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.5rem 0.3rem;
  border-top: 1px solid var(--borda);
  border-radius: 0;
}
.resumo__linha dt { color: var(--texto-3); font-size: 0.8125rem; }
.resumo__linha dd { margin: 0; font-weight: var(--peso-forte); overflow-wrap: anywhere; }
.resumo__editar { display: inline-flex; width: 1.1rem; height: 1.1rem; color: var(--texto-3); }
.resumo__editar svg { width: 100%; height: 100%; }
.resumo button:hover:not(:disabled) { background: var(--superficie-2); }
.resumo button:disabled { cursor: default; color: inherit; }
.resumo .resumo__foto:disabled { color: var(--texto-3); }
.resumo button:disabled .resumo__editar { visibility: hidden; }

/* linha do tempo da integração */
.linha-tempo strong { display: block; margin-bottom: 0.75rem; font-weight: var(--peso-marca); }
.linha-tempo ol { margin: 0; padding: 0; list-style: none; }
.linha-tempo li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.4rem;
  color: var(--texto-3);
  transition: color var(--medio);
}
.linha-tempo li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: calc(0.75rem - 1px);
  top: 1.95rem;
  height: 0.9rem;
  width: 2px;
  background: var(--borda);
}
.linha-tempo__marca {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--raio-pilula);
  border: 2px solid var(--borda);
  color: transparent;
  transition: background-color var(--medio), border-color var(--medio);
}
.linha-tempo__marca svg { width: 0.9rem; height: 0.9rem; stroke-width: 3; }
.linha-tempo li.ativo { color: var(--texto); }
.linha-tempo li.ativo .linha-tempo__marca { border-color: var(--laranja); animation: piscar 0.9s infinite; }
.linha-tempo li.feito { color: var(--texto); }
.linha-tempo li.feito .linha-tempo__marca { background: var(--verde); border-color: var(--verde); color: var(--texto-sobre-verde); }
.linha-tempo li.feito::after { background: var(--verde); }
.linha-tempo.falhou li.ativo .linha-tempo__marca { border-color: var(--erro); animation: none; }
.linha-tempo__protocolo { margin: 0.75rem 0 0; font-weight: var(--peso-forte); letter-spacing: 0.04em; }
.linha-tempo__nota { margin: 0.35rem 0 0; color: var(--texto-2); font-size: 0.875rem; }

/* ---------- rodapé: compositor e ações ---------- */
.rodape {
  padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom));
  background: var(--fundo-2);
  border-top: 1px solid var(--borda);
}
.rodape:has(> [hidden] + [hidden]) { display: none; }

.compositor { display: flex; gap: 0.5rem; }
.compositor__campo {
  flex: 1;
  min-width: 0;
  min-height: 3rem;
  padding: 0 1.1rem;
  border: 2px solid var(--borda);
  border-radius: var(--raio-pilula);
  background: var(--superficie);
  font-size: 1.0625rem; /* 17px: abaixo de 16px o iOS dá zoom no foco */
}
.compositor__campo::placeholder { color: var(--texto-3); }
.compositor__campo:focus { outline: none; border-color: var(--laranja); }
.compositor__campo[aria-invalid="true"] { border-color: var(--erro); }
.compositor__enviar {
  flex: none;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 0;
  border-radius: var(--raio-pilula);
  background: var(--laranja);
  color: var(--texto-sobre-laranja);
  transition: background-color var(--rapido);
}
.compositor__enviar svg { width: 1.4rem; height: 1.4rem; stroke-width: 2.5; }
.compositor__enviar:disabled { background: var(--superficie-2); color: var(--texto-3); cursor: default; }

.acoes { display: flex; gap: 0.6rem; }
.acoes .botao { flex: 1; }

/* ---------- porta (terminal de acesso) ---------- */
.porta {
  overflow-y: auto;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  background-color: var(--fundo-2);
  background-image: var(--textura-container);
}
.selo {
  position: sticky;
  top: 0;
  z-index: 1;
  align-self: center;
  margin: 0 0 1.5rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--laranja);
  border-radius: var(--raio-pilula);
  background: var(--fundo);
  color: var(--laranja);
  font-size: 0.75rem;
  font-weight: var(--peso-forte);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.terminal {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: auto 0 1.25rem;
  padding: 2rem 1rem 1.75rem;
  border-radius: var(--raio-g);
  background: var(--fundo);
  border: 1px solid var(--borda);
  text-align: center;
}
.terminal__foto {
  position: relative;
  width: 10rem;
  height: 10rem;
  border-radius: var(--raio-pilula);
  border: 6px solid var(--verde);
}
.terminal__foto::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  border: 3px solid var(--verde);
  animation: anel 1.6s var(--curva) 0.2s 2 both;
}
.terminal__foto img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.terminal__titulo {
  margin: 1.25rem 0 0.75rem;
  font-size: 1.75rem;
  font-weight: var(--peso-marca);
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.terminal__titulo:focus { outline: none; }
.terminal__status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.5rem 1rem;
  border-radius: var(--raio-pilula);
  background: var(--verde);
  color: var(--texto-sobre-verde);
  font-weight: var(--peso-marca);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.terminal__status svg { width: 1.2rem; height: 1.2rem; stroke-width: 3; }

.porta__info { display: flex; flex-direction: column; gap: 0.9rem; margin-bottom: auto; }
.porta__tempo { margin: 0; font-size: 1.0625rem; font-weight: var(--peso-forte); }
.porta__tempo strong { color: var(--verde); font-weight: var(--peso-marca); }
.porta__protocolo { margin: -0.4rem 0 0; color: var(--texto-3); font-size: 0.875rem; }
.porta__json {
  border: 1px solid var(--borda);
  border-radius: var(--raio-m);
  background: var(--fundo);
}
.porta__json summary {
  padding: 0.9rem 1rem;
  font-weight: var(--peso-forte);
  cursor: pointer;
}
.porta__json pre {
  margin: 0;
  padding: 0 1rem 1rem;
  overflow-x: auto;
  color: var(--texto-2);
  font-size: 0.75rem;
  line-height: 1.5;
}
.porta__botoes { display: flex; flex-direction: column; gap: 0.6rem; }

/* ---------- termo ---------- */
.termo {
  width: min(32rem, calc(100% - 2rem));
  max-height: 85dvh;
  padding: 0;
  border: 1px solid var(--borda);
  border-radius: var(--raio-g);
  background: var(--superficie);
  color: var(--texto);
}
.termo[open] { display: flex; flex-direction: column; }
.termo::backdrop { background: rgb(0 0 0 / 0.65); }
.termo__corpo { padding: 1.5rem 1.25rem 0.5rem; overflow-y: auto; }
.termo h2 { margin: 0; font-size: 1.25rem; font-weight: var(--peso-marca); }
.termo h3 { margin: 1.1rem 0 0.25rem; font-size: 0.9375rem; color: var(--laranja); }
.termo p { margin: 0; color: var(--texto-2); font-size: 0.9375rem; }
.termo .termo__versao { margin-top: 0.25rem; color: var(--texto-3); font-size: 0.8125rem; }
.termo .termo__nota { margin-top: 1.25rem; color: var(--texto-3); }
.termo__rodape { padding: 1rem 1.25rem 1.25rem; border-top: 1px solid var(--borda); }
.termo__rodape .botao { width: 100%; }

/* ---------- movimento ---------- */
@keyframes entrar {
  from { opacity: 0; transform: translateY(6px); }
}
@keyframes piscar {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@keyframes varrer {
  from { transform: translateY(-48px); }
  to { transform: translateY(48px); }
}
@keyframes anel {
  from { opacity: 0.9; transform: scale(1); }
  to { opacity: 0; transform: scale(1.35); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
