:root {
  --fundo: #1b1a17;
  --painel: #262521;
  --borda: #3a3833;
  --texto: #f1ede4;
  --suave: #a8a296;
  --laranja: #d97757;
  --laranja-escuro: #b85f42;
  --usuario: #3b3a35;
  --azul: #6aa6d9;
  --verde: #7fbf7f;
  --raio: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

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

/* ---------- Login ---------- */
#tela-login { align-items: center; justify-content: center; padding: 24px; }
.login-caixa { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 84px; height: 84px; }
.login-caixa h1 { margin: 12px 0 0; font-size: 28px; }
.sub { color: var(--suave); margin: 4px 0 24px; }
#form-login { display: flex; flex-direction: column; gap: 10px; }
#form-login input, .form-texto input {
  background: var(--painel);
  border: 1px solid var(--borda);
  color: var(--texto);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  outline: none;
}
#form-login input:focus, .form-texto input:focus { border-color: var(--laranja); }
.btn-primario {
  background: var(--laranja); border: 0; border-radius: 12px; padding: 14px; font-weight: 600;
}
.btn-primario:active { background: var(--laranja-escuro); }
.btn-link { background: none; border: 0; color: var(--suave); text-decoration: underline; padding: 8px; }
.msg { min-height: 1.4em; color: var(--suave); font-size: 14px; }

/* ---------- Topo ---------- */
.topo {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--borda);
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 600; flex: 1; }
.marca img { width: 28px; height: 28px; }
.btn-icone { background: none; border: 0; font-size: 24px; padding: 4px 8px; line-height: 1; }
.menu {
  position: absolute; right: 12px; top: calc(100% - 4px); z-index: 10;
  background: var(--painel); border: 1px solid var(--borda); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden; min-width: 210px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.menu button { background: none; border: 0; text-align: left; padding: 12px 16px; }
.menu button:hover { background: var(--borda); }

/* ---------- Indicador de estado ---------- */
.estado {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--suave);
  background: var(--painel); border: 1px solid var(--borda);
  padding: 4px 10px; border-radius: 999px;
}
.estado .ponto { width: 8px; height: 8px; border-radius: 50%; background: var(--suave); }
.estado[data-estado="aguardando"] .ponto { background: var(--verde); }
.estado[data-estado="ouvindo"] .ponto { background: #e05050; animation: pulsa 1s infinite; }
.estado[data-estado="pensando"] .ponto { background: var(--laranja); animation: pulsa .6s infinite; }
.estado[data-estado="falando"] .ponto { background: var(--azul); animation: pulsa .8s infinite; }
@keyframes pulsa { 50% { opacity: .3; transform: scale(.8); } }

/* ---------- Conversa ---------- */
.conversa {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.vazio { margin: auto; text-align: center; color: var(--suave); }
.dica { font-size: 14px; }
.balao {
  max-width: 82%; padding: 10px 14px; border-radius: var(--raio);
  white-space: pre-wrap; word-wrap: break-word;
  animation: entra .2s ease-out;
}
.balao.user { align-self: flex-end; background: var(--usuario); border-bottom-right-radius: 6px; }
.balao.assistant { align-self: flex-start; background: var(--painel); border: 1px solid var(--borda); border-bottom-left-radius: 6px; }
.balao.erro { align-self: center; background: none; color: #e88; font-size: 14px; }
.balao.pensando { color: var(--suave); }
.balao.pensando::after { content: "…"; animation: pulsa 1s infinite; }
.balao .falar { background: none; border: 0; color: var(--suave); font-size: 13px; padding: 4px 0 0; display: block; }
@keyframes entra { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Rodapé ---------- */
.rodape {
  border-top: 1px solid var(--borda);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.parcial { margin: 0; min-height: 1.4em; color: var(--suave); font-style: italic; text-align: center; }

.mic {
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--laranja); border: 0;
  display: grid; place-items: center;
  box-shadow: 0 6px 24px rgba(217,119,87,.35);
  transition: transform .15s, background .15s;
}
.mic svg { width: 44px; height: 44px; fill: #fff; }
.mic:active { transform: scale(.94); }
.mic.ouvindo { background: #e05050; animation: anel 1.2s infinite; }
.mic.pensando { background: var(--borda); }
.mic.falando { background: var(--azul); }
@keyframes anel {
  0% { box-shadow: 0 0 0 0 rgba(224,80,80,.55); }
  100% { box-shadow: 0 0 0 22px rgba(224,80,80,0); }
}

.chave { display: flex; align-items: center; gap: 10px; color: var(--suave); font-size: 14px; user-select: none; }
.chave input { position: absolute; opacity: 0; pointer-events: none; }
.trilho { width: 42px; height: 24px; border-radius: 999px; background: var(--borda); position: relative; transition: background .2s; }
.bolinha { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.chave input:checked + .trilho { background: var(--verde); }
.chave input:checked + .trilho .bolinha { transform: translateX(18px); }
.chave input:focus-visible + .trilho { outline: 2px solid var(--laranja); }

.form-texto { display: flex; gap: 8px; width: 100%; max-width: 560px; }
.form-texto input { flex: 1; padding: 10px 12px; }
.form-texto button { background: var(--painel); border: 1px solid var(--borda); border-radius: 12px; padding: 0 14px; }

/* ---------- Aviso flutuante ---------- */
.aviso {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--painel); border: 1px solid var(--borda);
  padding: 10px 16px; border-radius: 12px; max-width: 90%; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

@media (min-width: 720px) {
  .conversa { padding: 24px max(14px, calc(50% - 360px)); }
}
