:root {
  --fundo: #f3f5f9; --cartao: #ffffff; --texto: #0f172a; --mut: #64748b; --borda: #e2e8f0;
  --prim: #0d6efd; --prim-txt: #ffffff; --cliente: #0d6efd; --cliente-txt: #ffffff;
  --ia: #eef2ff; --ia-txt: #1e1b4b; --atend: #ffffff; --atend-txt: #0f172a; --erro: #b91c1c; --aviso: #92400e;
  --sombra: 0 1px 2px rgba(15, 23, 42, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0b1220; --cartao: #111a2e; --texto: #e2e8f0; --mut: #94a3b8; --borda: #1e293b;
    --ia: #1e2448; --ia-txt: #e0e7ff; --atend: #16213a; --atend-txt: #e2e8f0; --erro: #fca5a5; --aviso: #fcd34d;
    --sombra: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--fundo); color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }

/* botões */
.botao {
  display: block; width: 100%; padding: .8rem 1rem; border-radius: 12px; border: 1px solid var(--borda);
  background: var(--cartao); cursor: pointer; font-weight: 600;
}
.botao.primario { background: var(--prim); color: var(--prim-txt); border-color: var(--prim); }
.botao:disabled { opacity: .6; }

/* identificação */
.entrar { max-width: 420px; margin: 0 auto; padding: max(2rem, env(safe-area-inset-top)) 1rem 2rem; }
.marca { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin: 1rem 0 1.5rem; }
.marca h1 { margin: 0; font-size: 1.5rem; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 16px; padding: 1.2rem; box-shadow: var(--sombra); }
.cartao label { display: block; font-size: .85rem; color: var(--mut); margin-bottom: .9rem; }
.cartao input {
  display: block; width: 100%; margin-top: .3rem; padding: .75rem .85rem; border-radius: 10px;
  border: 1px solid var(--borda); background: var(--fundo); font-size: 1rem;
}
.cartao input:focus, .composer textarea:focus { outline: 2px solid var(--prim); outline-offset: 0; border-color: transparent; }
.opcional { opacity: .7; }
.alerta { border-radius: 10px; padding: .7rem .85rem; margin-bottom: 1rem; font-size: .9rem; }
.alerta.erro { background: rgba(185, 28, 28, .1); color: var(--erro); }
.alerta.aviso { background: rgba(217, 119, 6, .12); color: var(--aviso); }

/* chat */
.tela-chat { display: flex; flex-direction: column; height: 100dvh; }
.topo {
  position: relative; display: flex; align-items: center; gap: .7rem;
  padding: calc(.6rem + env(safe-area-inset-top)) .9rem .6rem; background: var(--cartao); border-bottom: 1px solid var(--borda);
}
.topo-texto { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.status { font-size: .8rem; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icone { background: none; border: 0; font-size: 1.4rem; padding: .2rem .5rem; cursor: pointer; }
.menu {
  position: absolute; right: .6rem; top: calc(100% - .2rem); z-index: 10; min-width: 230px;
  background: var(--cartao); border: 1px solid var(--borda); border-radius: 12px; padding: .3rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: .7rem .8rem; border: 0; background: none;
  border-radius: 8px; cursor: pointer; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--fundo); }
.menu form { margin: 0; }

.mensagens { flex: 1; overflow-y: auto; padding: 1rem .8rem; display: flex; flex-direction: column; gap: .5rem; }
.inicio { margin: auto; text-align: center; max-width: 360px; width: 100%; display: flex; flex-direction: column; gap: .7rem; }
.inicio h2 { margin: 0; }
.inicio p { margin: 0 0 .6rem; color: var(--mut); }
.msg { max-width: 82%; padding: .55rem .8rem; border-radius: 16px; box-shadow: var(--sombra); word-wrap: break-word; }
.msg .texto { white-space: pre-wrap; }
.msg .autor { font-size: .72rem; font-weight: 600; opacity: .75; margin-bottom: .15rem; }
.msg .hora { font-size: .68rem; opacity: .6; text-align: right; margin-top: .15rem; }
.msg.cliente { align-self: flex-end; background: var(--cliente); color: var(--cliente-txt); border-bottom-right-radius: 4px; }
.msg.cliente.pendente { opacity: .7; }
.msg.ia { align-self: flex-start; background: var(--ia); color: var(--ia-txt); border-bottom-left-radius: 4px; }
.msg.atendente { align-self: flex-start; background: var(--atend); color: var(--atend-txt); border: 1px solid var(--borda); border-bottom-left-radius: 4px; }
.msg.sistema { align-self: center; background: none; box-shadow: none; color: var(--mut); font-size: .8rem; text-align: center; max-width: 92%; }
.digitando .texto { display: flex; gap: 4px; padding: .2rem 0; }
.digitando .texto span { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .4; animation: pulo 1.2s infinite; }
.digitando .texto span:nth-child(2) { animation-delay: .2s; }
.digitando .texto span:nth-child(3) { animation-delay: .4s; }
@keyframes pulo { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .digitando .texto span { animation: none; } }

.composer {
  display: flex; gap: .5rem; align-items: flex-end;
  padding: .6rem .7rem calc(.6rem + env(safe-area-inset-bottom)); background: var(--cartao); border-top: 1px solid var(--borda);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--borda); border-radius: 20px; padding: .65rem .9rem;
  background: var(--fundo); max-height: 140px;
}
.enviar { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--prim); color: var(--prim-txt); font-size: 1.1rem; cursor: pointer; }
.mic { min-width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--borda); background: var(--fundo); font-size: 1.1rem;
  cursor: pointer; padding: 0 .6rem; font-variant-numeric: tabular-nums; }
.mic.gravando { background: #dc2626; color: #fff; border-color: #dc2626; font-size: .9rem; animation: gravando 1.4s infinite; }
@keyframes gravando { 50% { opacity: .75; } }
@media (prefers-reduced-motion: reduce) { .mic.gravando { animation: none; } }

.dialogo { border: 1px solid var(--borda); border-radius: 16px; background: var(--cartao); color: var(--texto); padding: 1.1rem; width: min(92vw, 460px); }
.dialogo::backdrop { background: rgba(2, 6, 23, .55); }
.dialogo h3 { margin: 0 0 .7rem; }
.dialogo textarea { width: 100%; border: 1px solid var(--borda); border-radius: 10px; padding: .7rem; background: var(--fundo); }
.dialogo .acoes { display: flex; gap: .5rem; margin-top: .8rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(5rem + env(safe-area-inset-bottom)); z-index: 20;
  background: #14532d; color: #fff; padding: .7rem 1rem; border-radius: 12px; max-width: 92vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast.erro { background: #991b1b; }
