/* ============================================================
   AUTOWIKI — Wikinho, assistente de pesquisa (widget flutuante).
   Layout/cores 100% via custom properties do style.css — os dois
   temas (light/dark) funcionam sem regra extra. Tudo prefixado
   wk- para não colidir com as classes do style.css.
   Breakpoint mobile: <=640px (bottom-sheet ~85dvh com scrim).
   ============================================================ */

/* ------------------------------------------------ launcher (bolha 56px) */

.wk-launch {
  position: fixed; right: 20px; bottom: 20px;
  z-index: 50; /* acima do topbar (40); abaixo da cmpbar (60)/flash (70) */
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
  color: var(--btn-ink);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation; /* sem zoom por double-tap */
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.wk-launch svg { width: 26px; height: 26px; }
.wk-launch:active { transform: translateY(0); }
@media (max-width: 640px) {
  /* safe-area: não brigar com a home bar do iPhone nem com a curva da tela */
  .wk-launch {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

/* ------------------------------------------------ painel (dialog nativo) */

.wk-panel {
  position: fixed; inset: auto 20px 90px auto; /* canto inf. direito */
  z-index: 80;
  width: 380px; height: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 116px);   /* fallback p/ navegadores sem dvh */
  max-height: calc(100dvh - 116px);
  margin: 0; padding: 0;
  display: none;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
}
.wk-panel[open] { display: flex; animation: wk-in 0.22s ease; }
@keyframes wk-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
/* fechamento suave: assistant.js adiciona wk-closing e chama close() no fim */
.wk-panel.wk-closing { animation: wk-out 0.18s ease forwards; }
@keyframes wk-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(14px); }
}
.wk-panel::backdrop {
  background: rgba(4, 6, 10, 0.25);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: wk-fade 0.22s ease;
}
.wk-panel.wk-closing::backdrop {
  animation: wk-fade 0.18s ease reverse forwards;
}
@keyframes wk-fade { from { opacity: 0; } to { opacity: 1; } }

/* mobile: bottom-sheet ~85dvh ocupando a largura toda */
@media (max-width: 640px) {
  .wk-panel {
    inset: auto 0 0 0;
    width: 100%;
    height: 85vh;   /* fallback p/ navegadores sem dvh */
    height: 85dvh;
    max-height: 85vh;
    max-height: 85dvh;
    max-width: none;
    border-radius: 16px 16px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    /* paisagem em notch: conteúdo fora da curva da tela */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .wk-panel::backdrop { background: rgba(4, 6, 10, 0.55); }
}

/* ------------------------------------------------ header */

.wk-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 16px 16px 0 0;
  flex: 0 0 auto;
}
@media (max-width: 640px) { .wk-head { border-radius: 16px 16px 0 0; } }

/* restante do dia (n/20) no header — mesma cota do FAQ da home */
.wk-left {
  margin-left: auto;
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-3);
  white-space: nowrap;
}

.wk-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
  color: var(--btn-ink);
}
.wk-avatar svg { width: 20px; height: 20px; }

.wk-title {
  flex: 1 1 auto; min-width: 0;
  font-weight: 800; letter-spacing: 0.04em; font-size: 15px;
  color: var(--text);
}
.wk-title small {
  display: block; font-weight: 500; font-size: 11px;
  letter-spacing: 0.02em; color: var(--text-3);
}

.wk-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: 0 0 auto;
  background: none; border: 1px solid transparent;
  border-radius: 10px; cursor: pointer;
  color: var(--text-2);
  touch-action: manipulation;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.wk-close svg { width: 20px; height: 20px; }
.wk-close:hover { color: var(--text); background: var(--surface-3); }

/* ------------------------------------------------ área de mensagens */

.wk-msgs {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px;
  /* sem scroll-behavior:smooth — o follow do streaming (assistant.js)
     precisa de scrollTop instantâneo p/ saber se o usuário está no fim */
}

.wk-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.wk-msg.wk-bot {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  color: var(--text);
}
.wk-msg.wk-user {
  align-self: flex-end;
  background: var(--acc-dim);
  border: 1px solid var(--line-2);
  border-top-right-radius: 4px;
  color: var(--text);
}
.wk-msg.wk-err {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--bad);
  color: var(--text);
}

/* bolha vazia esperando o 1º token (só some quando o token chega — o
   evento sources NÃO a remove: a espera longa é depois dele) */
.wk-typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.wk-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  animation: wk-blink 1.1s infinite ease-in-out;
}
.wk-typing i:nth-child(2) { animation-delay: 0.18s; }
.wk-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes wk-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* chips de sugestão (boas-vindas) */
.wk-sugs { display: flex; flex-direction: column; gap: 7px; align-self: stretch; }
.wk-sug {
  text-align: left; cursor: pointer;
  min-height: 40px; padding: 9px 13px;
  font: inherit; font-size: 13.5px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  touch-action: manipulation;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.wk-sug:hover { color: var(--text); border-color: var(--acc); background: var(--surface-3); }

/* ------------------------------------------------ erros acionáveis
   Link de busca (429 e "não tenho essa ficha"), contagem regressiva até
   a meia-noite local e botão de retry da lotação — dentro da bolha de
   erro do widget E da caixa .faq-err da home (assistant.css é global). */
.wk-srclk {
  color: var(--acc-text);
  font-weight: 600;
  text-decoration: underline;
  overflow-wrap: anywhere;   /* pergunta longa no ?q= não estoura a bolha */
}
.wk-srclk:hover { color: var(--acc-2); }
.wk-reset { color: var(--text-3); font-weight: 600; }
.wk-retry {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; margin-top: 8px; padding: 9px 14px;  /* toque >=40px */
  font: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--acc);
  border-radius: 11px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.wk-retry:hover { border-color: var(--acc-2); background: var(--surface-2); }
.wk-retry svg { width: 16px; height: 16px; }

/* mini-cards de fontes (chips-link para /carro/<slug>) */
.wk-srcs {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line-2);
}
.wk-src {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 8px 12px;   /* alvo de toque >=40px */
  font-size: 12.5px; font-weight: 600;
  color: var(--text-2);
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  text-decoration: none;
  touch-action: manipulation;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.wk-src:hover { color: var(--acc-text); border-color: var(--acc); }
.wk-src b { color: var(--text); font-weight: 700; }
.wk-src .wk-ano { color: var(--text-3); font-weight: 500; }

/* linha de feedback da resposta (polegares em SVG, nunca emoji):
   "Esta resposta ajudou?" + 2 botões discretos abaixo das fontes; após o
   voto a linha vira o estado "Obrigado pelo feedback!" (sem botões) */
.wk-vote {
  display: flex; align-items: center; gap: 4px;
  margin-top: 8px;
  font-size: 12px; font-weight: 600;
  color: var(--text-3);
}
.wk-vote-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;   /* alvo de toque >=40px */
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-3);
  touch-action: manipulation;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.wk-vote-btn:hover { color: var(--text); background: var(--surface-3); }
.wk-vote-btn svg { width: 18px; height: 18px; }
.wk-vote.wk-voted { color: var(--text-3); }

/* ------------------------------------------------ form de envio */

.wk-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex: 0 0 auto;
}
.wk-form input {
  flex: 1 1 auto; min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  /* 16px evita o auto-zoom do iOS Safari ao focar (<=15px dispara) */
  font: inherit; font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 11px;
}
.wk-form input::placeholder { color: var(--text-3); }
.wk-form input:focus {
  outline: none; border-color: var(--acc);
}

.wk-send {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--acc), var(--acc-2));
  color: var(--btn-ink);
  border: 1px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.wk-send svg { width: 21px; height: 21px; }
.wk-send:hover { transform: translateY(-1px); }
.wk-send:disabled { opacity: 0.5; cursor: default; transform: none; }

/* estado "parar" durante o stream */
.wk-send.wk-stop { background: var(--surface-3); color: var(--bad); border-color: var(--bad); }
.wk-send.wk-stop:hover { transform: none; filter: none; }

/* ------------------------------------------------ rodapé (sempre visível) */

.wk-foot {
  flex: 0 0 auto;
  padding: 8px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  border-radius: 0 0 16px 16px;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
}
.wk-foot a { color: var(--acc-text); font-weight: 600; text-decoration: underline; }
.wk-foot a:hover { color: var(--acc-2); }
@media (max-width: 640px) {
  .wk-foot {
    border-radius: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* respeita reduced-motion (mesmo espírito do style.css) */
@media (prefers-reduced-motion: reduce) {
  .wk-panel[open],
  .wk-panel.wk-closing,
  .wk-panel[open]::backdrop,
  .wk-panel.wk-closing::backdrop { animation: none; }
  .wk-typing i { animation: none; opacity: 0.6; }
  .wk-launch, .wk-close, .wk-send, .wk-sug, .wk-src, .wk-retry,
  .wk-vote-btn { transition: none; }
}
