/* Motor de idiomas: chat.css. Aba "Conversa" (engine/chat.js): cabeçalho, balões, correção, microfone, campo de texto,
   e o formulário "Tutor com chave própria" (Perfil e folha). Só tokens: funciona no claro e no escuro. */

/* barra inferior com 5 abas (Conversa ligada): rótulos um pouco menores no celular */
@media (max-width: 1023px) {
  .tabbar.t5 button { font-size: 11.5px; padding-left: 0; padding-right: 0; overflow: hidden; }
  .tabbar.t5 .ic { width: 48px; }
}

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

/* página: coluna que ocupa a tela; o campo de envio fica preso acima da barra de abas */
.page.chat {
  display: flex; flex-direction: column; gap: 0;
  min-height: calc(100vh - var(--tb-h, 56px)); min-height: calc(100dvh - var(--tb-h, 56px));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.ch-head { padding-bottom: 12px; }
.ch-title h2 { margin: 2px 0 4px; font-size: 28px; line-height: 1.1; letter-spacing: -.02em; }
.ch-title .sub { margin: 0 0 12px; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.ch-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.ch-sp { flex: 1; }
.ch-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 0;
  background: var(--card); box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-2); font-size: 13.5px; font-weight: 700;
}
.ch-pill .ico { width: 16px; height: 16px; color: var(--primary-ink); }
.ch-pill.lv { background: var(--tint-2); box-shadow: none; color: var(--primary-ink); font-variant-numeric: tabular-nums; }
button.ch-pill:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.ch-pill.own { background: var(--ok-bg); box-shadow: inset 0 0 0 1px var(--ok-line); color: var(--ok); }
.ch-pill.own .ico { color: var(--ok); }
.ch-chip {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--card); box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-2);
}
.ch-chip .ico { width: 20px; height: 20px; }
.ch-chip:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.ch-voice[aria-pressed="true"] { background: var(--tint-2); color: var(--primary-ink); box-shadow: none; }
.ch-voice[aria-pressed="false"] .ico { opacity: .45; }

/* conversa */
.ch-log { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 10px 0 16px; }
.ch-empty { margin: auto 0; padding: 24px 12px; text-align: center; color: var(--ink-2); }
.ch-empty .ch-art { display: block; margin: 0 auto 10px; }
.ch-empty p { margin: 0 auto 8px; max-width: 30ch; font-size: 15.5px; line-height: 1.5; }
.ch-tip { color: var(--muted); font-size: 13.5px; }
.ch-msg { max-width: 86%; animation: chin .2s ease-out; }
.ch-msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ch-msg.me {
  align-self: flex-end; padding: 10px 14px; border-radius: 18px 18px 6px 18px;
  background: var(--primary); color: #fff; font-size: 16px; line-height: 1.45;
}
.ch-msg.tutor { align-self: flex-start; display: flex; flex-direction: column; gap: 6px; }
.ch-bub {
  position: relative; display: flex; align-items: flex-start; gap: 6px; padding: 10px 8px 10px 14px; border-radius: 18px 18px 18px 6px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-1); font-size: 16px; line-height: 1.45; color: var(--ink);
}
.ch-bub p { flex: 1; padding-top: 2px; }
.ch-bub .say.ch-say {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; margin: -4px 0 -4px; border: 0; border-radius: 10px;
  background: var(--tint); color: var(--primary-ink);
}
.ch-bub .say.ch-say .ico { width: 19px; height: 19px; }
.ch-cor {
  padding: 9px 12px 10px; border-radius: 14px; background: var(--accent-wash); border: 1px solid var(--accent-soft);
  color: var(--ink); font-size: 14.5px; line-height: 1.45;
}
.ch-cor b { display: flex; align-items: center; gap: 5px; margin-bottom: 2px; color: var(--accent-ink); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.ch-cor b .ico { width: 15px; height: 15px; }
.ch-msg.err {
  align-self: stretch; max-width: none; padding: 12px 14px; border-radius: 16px;
  background: var(--bad-bg); border: 1px solid var(--bad-line); color: var(--ink); font-size: 15px; line-height: 1.45;
}
.ch-msg.err .ch-tip { margin-top: 4px; color: var(--ink-2); }
.ch-err-act { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ch-err-act:empty { display: none; }
.ch-err-act .btn .ico { width: 17px; height: 17px; }
.ch-dots { display: inline-flex; gap: 5px; padding: 6px 4px; }
.ch-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: chdot 1.1s infinite ease-in-out; }
.ch-dots i:nth-child(2) { animation-delay: .15s; }
.ch-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chdot { 0%, 80%, 100% { opacity: .3; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes chin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* envio: microfone grande + campo de texto, presos acima da barra de abas */
.ch-compose {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 0 -16px; padding: 8px 16px 12px; background: var(--bg); border-top: 1px solid var(--line);
}
.ch-status { min-height: 18px; margin: 0; color: var(--ink-2); font-size: 13.5px; text-align: center; }
.ch-status:empty { display: none; }
.ch-status.bad { color: var(--bad); font-weight: 600; }
.ch-mic {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 6px 22px 6px 6px; border: 0; border-radius: 999px;
  background: var(--primary); color: #fff; box-shadow: inset 0 -4px 0 var(--primary-edge);
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
}
.ch-mic-ic { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: rgb(255 255 255 / .18); }
.ch-mic-ic .ico { width: 26px; height: 26px; }
.ch-mic:hover { filter: brightness(1.06); }
.ch-mic:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--primary-edge); }
.ch-mic[disabled] { background: var(--line); color: var(--muted); box-shadow: inset 0 -4px 0 var(--line-strong); cursor: default; }
.ch-mic.on { background: var(--bad-solid); box-shadow: inset 0 -4px 0 var(--bad-edge); }
.ch-mic.on .ch-mic-ic { animation: chpulse 1.4s infinite; }
@keyframes chpulse { 0% { box-shadow: 0 0 0 0 rgb(255 255 255 / .55); } 100% { box-shadow: 0 0 0 14px rgb(255 255 255 / 0); } }
.ch-form { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.ch-in {
  flex: 1; min-width: 0; min-height: 48px; max-height: 132px; padding: 12px 14px; resize: none; border-radius: 16px;
  border: 1.5px solid var(--line-strong); background: var(--card); color: var(--ink); font-size: 16px; line-height: 1.4;
}
.ch-in::placeholder { color: var(--muted); }
.ch-in:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.ch-send {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 14px;
  background: var(--primary); color: #fff; box-shadow: inset 0 -3px 0 var(--primary-edge);
}
.ch-send .ico { width: 21px; height: 21px; }
.ch-send[disabled] { background: var(--line); color: var(--muted); box-shadow: none; cursor: default; }

/* tutor com chave própria (Perfil > Configurações e folha da aba) */
.ck { padding-bottom: 12px; }
.ck .hint { margin: -2px 0 10px; }
.ck-f { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.ck-f label { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.ck-in {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1.5px solid var(--line-strong); border-radius: 12px;
  background: var(--card); color: var(--ink); font-size: 15px;
}
select.ck-in { padding-right: 34px; background: var(--card) var(--ic-chev) right 10px center / 16px no-repeat; -webkit-appearance: none; appearance: none; }
.ck-in[disabled] { opacity: .5; }
.ck-kw { display: flex; gap: 8px; }
.ck-kw .ck-in { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, Menlo, monospace; }
.ck-show { flex: none; display: grid; place-items: center; width: 46px; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--card); color: var(--ink-2); }
.ck-show[aria-pressed="true"] { background: var(--tint-2); color: var(--primary-ink); border-color: transparent; }
.ck-show .ico { width: 20px; height: 20px; }
.ck-hint { color: var(--muted); font-size: 13px; }
.ck-warn { display: flex; gap: 8px; margin: 4px 0 14px; padding: 10px 12px; border-radius: 12px; background: var(--tint); color: var(--ink-2); font-size: 13.5px; line-height: 1.45; }
.ck-warn .ico { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--primary-ink); }
.ck-act { display: flex; flex-wrap: wrap; gap: 8px; }
.ck-act .btn .ico { width: 17px; height: 17px; }
.ck-msg { min-height: 0; margin: 10px 0 0; font-size: 14px; line-height: 1.45; color: var(--ink-2); overflow-wrap: anywhere; }
.ck-msg:empty { display: none; }
.ck-msg.ok { color: var(--ok); font-weight: 600; }
.ck-msg.bad { color: var(--bad); font-weight: 600; }
.modal.ck-sheet { max-height: 92vh; max-height: 92dvh; overflow-y: auto; }
.modal.ck-sheet .ck-warn { margin-bottom: 14px; }
.modal.ck-sheet .gate-x { position: absolute; top: 12px; right: 12px; }

@media (min-width: 1024px) {
  #app:has(> .tabbar) > .page.chat { min-height: 100vh; min-height: 100dvh; padding-bottom: 0; }
  .ch-compose { bottom: 0; margin: 0 -40px; padding: 10px 40px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .ch-msg, .ch-dots i, .ch-mic.on .ch-mic-ic { animation: none; }
}
