:root {
  --fundo: #eef1f6;
  --cartao: #ffffff;
  --texto: #1d2433;
  --suave: #667085;
  --borda: #e3e7ee;
  --bot: #f3f5f9;
  --usuario: #3156d3;
  --usuario-texto: #ffffff;
  --destaque: #3156d3;
  --ok: #16a34a;
  --aviso: #d97706;
  --sombra: 0 10px 40px rgba(17, 24, 39, 0.08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0f131a;
    --cartao: #161b24;
    --texto: #e6e9ef;
    --suave: #98a2b3;
    --borda: #262d3a;
    --bot: #1e2531;
    --usuario: #4a6cf0;
    --destaque: #7c97ff;
    --sombra: 0 10px 40px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--fundo);
  color: var(--texto);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 24px 16px;
}

.chat {
  width: 100%;
  max-width: 720px;
  background: var(--cartao);
  border: 1px solid var(--borda);
  border-radius: 20px;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ---------- topo ---------- */
.topo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--borda);
}
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  background: var(--bot);
  flex-shrink: 0;
}
.identidade { flex: 1; min-width: 0; }
.identidade h1 { font-size: 16px; margin: 0; }
.identidade p { font-size: 13px; margin: 0; color: var(--suave); }

.acoes { display: flex; gap: 6px; }
.acao-topo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--borda);
  background: var(--bot);
  color: var(--texto);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.acao-topo:hover:not(:disabled) { color: var(--destaque); border-color: var(--destaque); }
.acao-topo:disabled { opacity: .4; cursor: default; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12px;
  color: var(--suave);
  background: var(--bot);
  border: 1px solid var(--borda);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: default;
  white-space: nowrap;
}
.status[data-clicavel="1"] { cursor: pointer; color: var(--destaque); }
.status .ponto { width: 8px; height: 8px; border-radius: 50%; background: var(--suave); }
.status[data-modo="carregando"] .ponto { background: var(--aviso); animation: pulsar 1.2s infinite; }
.status[data-modo="embeddings"] .ponto { background: var(--ok); }

/* ---------- mensagens ---------- */
.mensagens {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.linha { display: flex; gap: 8px; align-items: flex-end; animation: entrar .25s ease-out; }
.linha.usuario { justify-content: flex-end; }

.balao {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
}
.linha.bot .balao { background: var(--bot); border-bottom-left-radius: 4px; }
.linha.usuario .balao { background: var(--usuario); color: var(--usuario-texto); border-bottom-right-radius: 4px; }

.balao p { margin: 0 0 6px; }
.balao p:last-child { margin-bottom: 0; }
.balao ol, .balao ul { margin: 4px 0 6px; padding-left: 20px; }
.balao li { margin: 2px 0; }
.balao a { color: var(--destaque); font-weight: 500; }
.balao code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  background: color-mix(in srgb, var(--destaque) 12%, transparent);
  padding: 1px 5px;
  border-radius: 5px;
}

.balao mark.preencher {
  background: #fde68a;
  color: #713f12;
  padding: 0 4px;
  border-radius: 4px;
  font-size: 13px;
}

.debug-linha {
  font: 11px/1.3 ui-monospace, Consolas, monospace;
  color: var(--suave);
  margin: -4px 0 0 4px;
}

/* digitando… */
.digitando { display: inline-flex; gap: 4px; padding: 14px 16px; }
.digitando span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--suave);
  animation: quicar 1.2s infinite ease-in-out;
}
.digitando span:nth-child(2) { animation-delay: .15s; }
.digitando span:nth-child(3) { animation-delay: .3s; }

/* botões de resposta rápida */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 6px; animation: entrar .25s ease-out; }
.chip {
  font: inherit; font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--destaque) 45%, var(--borda));
  background: transparent;
  color: var(--destaque);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.chip:hover:not(:disabled) { background: color-mix(in srgb, var(--destaque) 10%, transparent); }
.chip:active:not(:disabled) { transform: scale(.97); }
.chip:disabled { opacity: .45; cursor: default; }

/* ---------- entrada ---------- */
.entrada {
  display: flex; gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--borda);
}
.entrada input {
  flex: 1;
  font: inherit;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--borda);
  background: var(--fundo);
  color: var(--texto);
  outline: none;
}
.entrada input:focus { border-color: var(--destaque); }
.entrada button {
  width: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--destaque);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
}
.entrada button:disabled { opacity: .5; cursor: default; }

/* ---------- modo debug ---------- */
.debug {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--suave);
  border-top: 1px dashed var(--borda);
}
.debug[hidden] { display: none; }
.debug span { flex: 1; }
.debug button {
  font: inherit; font-size: 12px;
  background: none; border: 1px solid var(--borda); border-radius: 6px;
  color: var(--texto); padding: 3px 8px; cursor: pointer;
}

@keyframes entrar { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes quicar { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes pulsar { 50% { opacity: .35; } }

@media (max-width: 600px) {
  body { padding: 0; }
  .topo { gap: 8px; padding: 12px 14px; }
  #status-texto { display: none; } /* no celular fica só a bolinha do status */
  .chat { border-radius: 0; border: 0; }
  .balao { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}
