/* =========================================================================
   Atendimento ao cliente — folha de estilo

   Direção: sóbria e institucional. Uma única cor de acento (azul), verde
   reservado para estado "conectado", superfícies planas com borda de 1px.
   Sem gradiente decorativo, sem emoji e sem raio grande: a tela precisa
   passar seriedade, não entusiasmo.

   Os NOMES das variáveis são os mesmos que o admin.css consome — mudar os
   valores aqui repinta o painel de controle junto.
   ========================================================================= */
:root {
  --bg: #0b0f16;
  --bg2: #121824;
  --card: #151c28;
  --card2: #1b2432;
  --texto: #e7ecf3;
  --texto2: #8a99ad;
  --texto3: #64748b;
  --borda: #222c3a;
  --borda2: #2c3848;

  --verde: #2f9e68;
  --verde2: #268055;
  --azul: #3d7ebd;
  --azul2: #336ba3;
  --vermelho: #c9453f;
  --amarelo: #c08a24;

  --raio: 10px;
  --raio-sm: 7px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
.oculta { display: none !important; }
.svg-defs { position: absolute; width: 0; height: 0; }

.tela { min-height: 100%; min-height: 100dvh; }

/* ========================= Tela inicial ========================= */
#tela-inicio {
  display: flex; align-items: center; justify-content: center;
  padding: calc(32px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}
.inicio-conteudo { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }

/* --- Modos da tela inicial ---------------------------------------------
   Cada bloco declara para quem existe; o modo atual esconde o resto. A ordem
   também muda: para o atendente, a área dele vem antes da caixa de código. */
#tela-inicio:not([data-modo="visitante"]) .so-visitante,
#tela-inicio:not([data-modo="login"]) .so-login,
#tela-inicio:not([data-modo="atendente"]) .so-atendente { display: none; }

.marca { order: 0; }
.cabecalho { order: 1; }
#card-master, #card-login { order: 2; }
.card-codigo { order: 3; }
.seguranca { order: 4; }
.link-login { order: 5; }
.rodape { order: 6; }
/* a caixa de código serve ao visitante e ao atendente, nunca à tela de login */
#tela-inicio[data-modo="login"] .card-codigo { display: none; }
/* o atendente só entra em código por exceção: fica depois e discreto */
#tela-inicio[data-modo="atendente"] .card-codigo { background: none; border-style: dashed; }

.marca { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.marca-icone {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 9px; background: var(--azul);
  display: flex; align-items: center; justify-content: center;
}
.marca-icone svg { width: 22px; height: 22px; color: #fff; }
.marca h1 {
  font-size: 1.15rem; margin: 0; font-weight: 600; letter-spacing: -0.01em;
}
.marca .marca-sub {
  display: block; font-size: .78rem; font-weight: 400; color: var(--texto2);
  letter-spacing: .02em; margin-top: 1px;
}

.cabecalho { margin-bottom: 4px; }
.titulo { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 5px; }
.sub { color: var(--texto2); margin: 0; font-size: .95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 20px;
}
.card-rotulo {
  display: block; font-size: .72rem; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--texto3); margin-bottom: 10px;
}

.btn {
  appearance: none; border: 1px solid var(--borda2); background: var(--card2); color: var(--texto);
  border-radius: var(--raio-sm); padding: 11px 16px; cursor: pointer; font-weight: 500;
  transition: background .15s ease, border-color .15s ease;
}
a.btn { text-decoration: none; display: inline-block; }
.btn:hover { background: #222c3c; }
.btn:active { background: #1a2331; }
.btn:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }
.btn.primario { background: var(--azul); border-color: var(--azul); color: #fff; font-weight: 600; }
.btn.primario:hover { background: var(--azul2); border-color: var(--azul2); }
.btn.grande { width: 100%; padding: 13px 16px; font-size: 1rem; }
.btn.mini { padding: 7px 12px; font-size: .86rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

#form-entrar { display: flex; gap: 8px; }
#codigo {
  flex: 1; min-width: 0; background: var(--bg); color: var(--texto);
  border: 1px solid var(--borda2); border-radius: var(--raio-sm);
  padding: 12px 14px; font-size: 1.2rem; letter-spacing: .28em; text-transform: uppercase;
  text-align: center; font-weight: 600; font-variant-numeric: tabular-nums;
}
#codigo::placeholder { letter-spacing: .12em; font-weight: 500; color: var(--texto3); }
#codigo:focus { outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(61,126,189,.18); }

.aviso { min-height: 1.3em; color: var(--amarelo); margin: 12px 0 0; font-size: .9rem; }
.aviso:empty { margin: 0; min-height: 0; }
.aviso.carregando { color: var(--texto2); }
.aviso.carregando::before {
  content: ""; display: inline-block; width: .8em; height: .8em; margin-right: 7px;
  border: 2px solid var(--borda2); border-top-color: var(--azul);
  border-radius: 50%; vertical-align: -0.05em;
  animation: girar .7s linear infinite;
}
.aviso.erro { color: #e0736d; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---- Garantias de segurança (tela inicial) ---- */
/* Informação de apoio: fica mais leve que o card do código de propósito,
   para não disputar atenção com a ação principal da tela. */
.seguranca {
  list-style: none; margin: 6px 0 0; padding: 0 2px;
}
.seguranca li {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: .84rem; color: var(--texto2); line-height: 1.45;
}
.seguranca li + li { margin-top: 9px; }
.seguranca svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 3px; color: var(--verde); }
.seguranca b { color: var(--texto); font-weight: 600; }

.link-login {
  display: block; margin: 6px auto 0; background: none; border: none;
  color: var(--texto2); font-size: .9rem; cursor: pointer; padding: 8px 12px;
  border-radius: var(--raio-sm);
}
.link-login:hover { color: var(--texto); background: var(--bg2); }

.rodape { margin-top: 12px; border-top: 1px solid var(--borda); padding-top: 14px; }
.rodape-nota {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 0; font-size: .76rem; color: var(--texto3); line-height: 1.5;
}
.rodape-nota svg { width: 12px; height: 12px; flex-shrink: 0; margin-top: 3px; }
.versao {
  text-align: center; color: var(--texto3); font-size: .72rem;
  margin: 12px 0 0; font-variant-numeric: tabular-nums; letter-spacing: .04em;
}

/* ---- Login / área do atendente ---- */
#form-login { display: flex; flex-direction: column; gap: 9px; }
#form-login input {
  background: var(--bg); color: var(--texto); border: 1px solid var(--borda2);
  border-radius: var(--raio-sm); padding: 11px 13px; font-size: .98rem;
}
#form-login input:focus { outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(61,126,189,.18); }
#btn-login-voltar { display: block; margin: 12px auto 0; }

/* ---- Área do atendente ---- */
.atendente-topo {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 14px; margin-bottom: 16px; border-bottom: 1px solid var(--borda);
}
.atendente-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--azul); color: #fff; font-weight: 600; font-size: .92rem;
  display: flex; align-items: center; justify-content: center;
}
.atendente-id { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.atendente-id b {
  font-size: .95rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.atendente-linha { display: flex; align-items: center; gap: 7px; min-width: 0; }
.papel-tag {
  flex-shrink: 0; font-size: .64rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 4px;
  background: rgba(61,126,189,.16); color: #7fb0e0; border: 1px solid rgba(61,126,189,.3);
}
.atendente-usuario { font-size: .74rem; color: var(--texto2); }
.dica { margin: 9px 0 0; font-size: .78rem; color: var(--texto3); text-align: center; }

/* ---- Escolha da foto do atendente ---- */
.foto-escolha {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 16px;
  background: var(--bg2); border: 1px solid var(--borda); border-radius: var(--raio-sm);
}
.foto-preview {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: var(--card2); border: 1px solid var(--borda2);
  display: flex; align-items: center; justify-content: center;
  font-size: .58rem; color: var(--texto3); text-align: center; line-height: 1.2;
}
.foto-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto-texto { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.foto-texto b { font-size: .88rem; font-weight: 600; }
.foto-texto span { font-size: .74rem; color: var(--texto2); }
.foto-acoes { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.foto-acoes .btn { white-space: nowrap; }

/* ---- Foto no lugar do vídeo ---- */
.avatar-remoto {
  width: 132px; height: 132px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--borda2); background: var(--card);
}
.avatar-local {
  position: absolute; right: 12px; top: calc(76px + var(--safe-top));
  width: 26vw; max-width: 148px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.22); background: #10151d;
  box-shadow: 0 4px 16px rgba(0,0,0,.55); z-index: 3;
}

/* ---- Diálogo de confirmação ---- */
.dlg {
  border: 1px solid var(--borda2); border-radius: var(--raio);
  background: var(--card); color: var(--texto);
  padding: 22px; max-width: 340px; width: calc(100vw - 40px);
  box-shadow: 0 16px 48px rgba(0,0,0,.6);
}
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg h3 { margin: 0 0 8px; font-size: 1.05rem; font-weight: 600; }
.dlg p { margin: 0 0 20px; font-size: .9rem; color: var(--texto2); line-height: 1.5; }
.dlg-acoes { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-acoes .btn { flex: 1; }
@media (min-width: 420px) { .dlg-acoes .btn { flex: 0 1 auto; min-width: 118px; } }
#card-master .btn.grande + .btn.grande,
#card-master .dica + .btn.grande { margin-top: 12px; }

/* ========================= Tela da chamada ========================= */
#tela-chamada { position: fixed; inset: 0; background: #000; overflow: hidden; }
#video-remoto {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000;
}
#tela-remota {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000; z-index: 2;
}
.sem-video {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  color: var(--texto3); background: #0a0e14;
}
.sem-video svg { width: 88px; height: 88px; color: #1e2836; }
.sem-video span { font-size: .95rem; }

#video-local {
  position: absolute; right: 12px; top: calc(76px + var(--safe-top));
  width: 26vw; max-width: 148px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.22); background: #10151d;
  box-shadow: 0 4px 16px rgba(0,0,0,.55); z-index: 3;
}
#video-local.espelho { transform: scaleX(-1); }

.topo {
  position: absolute; left: 0; right: 0; top: 0; z-index: 4;
  padding: calc(12px + var(--safe-top)) 14px 14px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  background: linear-gradient(180deg, rgba(0,0,0,.7), rgba(0,0,0,0));
  pointer-events: none;
}
.topo-esq { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.status {
  display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
.ponto { width: 8px; height: 8px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.ponto.ok { background: var(--verde); }
.ponto.alerta { background: var(--amarelo); animation: pulsar 1s infinite; }
.ponto.espera { background: var(--azul); animation: pulsar 1.4s infinite; }
@keyframes pulsar { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Selo discreto de criptografia — informativo, não decorativo */
.selo-cripto {
  /* o .topo é pointer-events:none para não cobrir o vídeo; o selo reativa
     só para si, senão o title= nunca apareceria no hover */
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(10,15,22,.72); border: 1px solid rgba(255,255,255,.13);
  border-radius: 5px; padding: 3px 8px;
  font-size: .7rem; font-weight: 500; letter-spacing: .02em; color: #b9c6d6;
}
.selo-cripto svg { width: 11px; height: 11px; color: var(--verde); }

.sala {
  text-align: right; font-size: .82rem; color: #b9c6d6;
  text-shadow: 0 1px 3px rgba(0,0,0,.8); display: flex; flex-direction: column; gap: 3px;
}
.sala b { letter-spacing: .16em; color: #fff; font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; color: #97a6b8; }

.overlay {
  position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.72); padding: 24px;
}
.overlay .btn { max-width: 340px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; }
.overlay .btn svg { width: 18px; height: 18px; }

.banner {
  position: absolute; left: 12px; right: 12px; bottom: calc(108px + var(--safe-bottom)); z-index: 5;
  background: rgba(18,24,36,.95); border: 1px solid var(--borda2); border-radius: var(--raio-sm);
  padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: .88rem;
}

.controles {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center; gap: 6px;
  padding: 14px 8px calc(16px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(0,0,0,.78), rgba(0,0,0,0));
}
.ctl {
  appearance: none; border: 1px solid rgba(255,255,255,.1); background: rgba(24,31,42,.8); color: #e7ecf3;
  width: 54px; height: 60px; border-radius: 9px; cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .15s ease, border-color .15s ease;
}
.ctl:hover { background: rgba(34,44,60,.9); }
.ctl:active { background: rgba(18,24,36,.9); }
.ctl:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }
.ctl svg { width: 21px; height: 21px; }
.ctl span { font-size: .64rem; letter-spacing: .01em; color: #b9c6d6; }
.ctl.off { background: rgba(233,238,245,.92); color: #0b0f16; border-color: transparent; }
.ctl.off span { color: #38445a; }
.ctl.off::after {
  content: ""; position: absolute; width: 28px; height: 2px; background: var(--vermelho); border-radius: 1px;
  transform: rotate(-45deg); top: 19px;
}
.ctl.sair { background: var(--vermelho); border-color: transparent; }
.ctl.sair span { color: rgba(255,255,255,.9); }
.ctl.sair:hover { background: #b13b36; }
.ctl:disabled { opacity: .35; cursor: not-allowed; }
.badge {
  position: absolute; top: 5px; right: 5px; min-width: 17px; height: 17px; border-radius: 9px;
  background: var(--vermelho); color: #fff; font-size: .66rem; font-style: normal; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
@media (min-width: 480px) {
  .ctl { width: 68px; }
  .controles { gap: 9px; }
}

/* ========================= Chat ========================= */
.chat {
  position: absolute; z-index: 7; left: 0; right: 0; bottom: 0;
  height: min(60vh, 470px); background: rgba(11,15,22,.97);
  border-top-left-radius: 12px; border-top-right-radius: 12px;
  border: 1px solid var(--borda2); border-bottom: none;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
@media (min-width: 768px) {
  .chat {
    left: auto; width: 344px; right: 12px; bottom: 96px; height: 420px;
    border-radius: 12px; border-bottom: 1px solid var(--borda2);
  }
}
.chat-topo {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--borda);
}
.chat-titulo { display: flex; flex-direction: column; gap: 2px; }
.chat-titulo b { font-size: .92rem; font-weight: 600; }
.chat-cripto { display: flex; align-items: center; gap: 4px; font-size: .68rem; color: var(--texto3); }
.chat-cripto svg { width: 10px; height: 10px; color: var(--verde); }
.chat-topo button {
  background: none; border: none; color: var(--texto2); font-size: 1.05rem;
  cursor: pointer; padding: 4px 8px; border-radius: 5px;
}
.chat-topo button:hover { background: var(--bg2); color: var(--texto); }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg {
  max-width: 80%; padding: 8px 12px; border-radius: 10px; font-size: .92rem;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.eu { align-self: flex-end; background: var(--azul2); color: #fff; border-bottom-right-radius: 3px; }
.msg.dela { align-self: flex-start; background: var(--card2); border: 1px solid var(--borda); border-bottom-left-radius: 3px; }
#chat-form { display: flex; gap: 8px; padding: 11px 12px; border-top: 1px solid var(--borda); }
#chat-input {
  flex: 1; min-width: 0; background: var(--bg2); color: var(--texto);
  border: 1px solid var(--borda2); border-radius: var(--raio-sm); padding: 10px 12px; font-size: .95rem;
}
#chat-input:focus { outline: none; border-color: var(--azul); }

/* ========================= Toast ========================= */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(116px + var(--safe-bottom)); z-index: 20;
  background: #e7ecf3; color: #0b0f16; padding: 10px 16px; border-radius: 6px;
  font-size: .88rem; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.5);
  max-width: 90vw; text-align: center;
}
