/* Central de Ajuda Inteligente — Chat IA (T-600, refino premium T-602)
   Herda os design tokens de ajuda.css (:root). Sem framework, sem dependências. */

/* T-602: token local de texto auxiliar com contraste >= WCAG AA (~6.5:1 sobre --bg).
   Escopo local (não altera o --text-faint global de ajuda.css). */
:root { --aux-text: rgba(255, 255, 255, 0.62); }

/* T-602 (P1-6): trava o scroll do fundo enquanto o chat está aberto. */
html.ai-chat-open, body.ai-chat-open { overflow: hidden; }

/* --- Pesquisa (hero) ------------------------------------------------------- */
.ajuda-search {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 640px;
  margin: 28px auto 4px;
  padding: 6px 6px 6px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.ajuda-search:focus-within { border-color: var(--border-strong); }
.ajuda-search__icon { color: var(--text-faint); font-size: 15px; }
.ajuda-search__input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  color: var(--text); font-size: 16px; padding: 10px 4px;
}
.ajuda-search__input::placeholder { color: var(--aux-text); }
.ajuda-search__submit {
  flex-shrink: 0; border: 0; cursor: pointer; border-radius: 999px;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  background: var(--accent); color: #0a0a0b;
}
.ajuda-search__submit:hover { opacity: 0.9; }
/* T-602 (P1-5): em telas estreitas o botão vai para a 2ª linha e o campo ocupa
   a largura inteira — o placeholder deixa de truncar. */
@media (max-width: 480px) {
  .ajuda-search { flex-wrap: wrap; border-radius: var(--radius-md); padding: 10px 14px; }
  .ajuda-search__input { padding: 8px 4px; }
  .ajuda-search__submit { flex-basis: 100%; margin-top: 8px; padding: 12px; }
}

/* --- Cards de categoria (reusa .ajuda-card) -------------------------------- */
.ajuda-cards--categories { grid-template-columns: repeat(4, 1fr); }
button.ajuda-card--category {
  font: inherit; text-align: left; cursor: pointer; color: inherit;
  background: var(--bg-elevated); border: 1px solid var(--border);
}
.ajuda-card--category:hover { border-color: var(--border-strong); transform: translateY(-2px); }
@media (max-width: 960px) { .ajuda-cards--categories { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .ajuda-cards--categories { grid-template-columns: 1fr; } }

/* --- Painel do Chat -------------------------------------------------------- */
.ai-chat[hidden] { display: none; }
.ai-chat__backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  opacity: 0; transition: opacity 0.2s ease; z-index: 60;
}
.ai-chat.is-open .ai-chat__backdrop { opacity: 1; }
.ai-chat__panel {
  position: fixed; top: 0; right: 0; z-index: 61;
  width: 440px; max-width: 100vw; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-chat.is-open .ai-chat__panel { transform: translateX(0); }

.ai-chat__header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.ai-chat__title { font-size: 15px; font-weight: 600; flex: 1; display: flex; align-items: center; gap: 8px; }
.ai-chat__title-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 8px #34d399; }
.ai-chat__icon-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; cursor: pointer;
}
.ai-chat__icon-btn:hover { border-color: var(--border-strong); color: var(--text); }

.ai-chat__messages {
  flex: 1; overflow-y: auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
.ai-chat__empty { margin: auto; text-align: center; color: var(--aux-text); font-size: 14px; max-width: 280px; }
.ai-chat__empty strong { color: var(--text); display: block; margin-bottom: 6px; font-size: 15px; }

.ai-msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.ai-msg__bubble {
  padding: 12px 14px; border-radius: var(--radius-md); font-size: 14.5px; line-height: 1.55;
  white-space: normal; word-wrap: break-word; overflow-wrap: anywhere;
}
.ai-msg--user { align-items: flex-end; }
.ai-msg--user .ai-msg__bubble { background: var(--accent); color: #0a0a0b; border-bottom-right-radius: 4px; max-width: 85%; }
.ai-msg--ai .ai-msg__bubble { background: var(--bg-elevated); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ai-msg__bubble p { margin: 0 0 8px; }
.ai-msg__bubble p:last-child { margin-bottom: 0; }
.ai-msg__bubble ul, .ai-msg__bubble ol { margin: 6px 0; padding-left: 20px; }
.ai-msg__bubble code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.ai-msg__bubble pre { background: #000; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; margin: 8px 0; }
.ai-msg__bubble pre code { background: none; padding: 0; }
.ai-msg__bubble a { color: #7dd3fc; text-decoration: underline; }
.ai-msg__actions { display: flex; gap: 6px; }
.ai-msg__act {
  border: 1px solid var(--border); background: transparent; color: var(--text-faint);
  border-radius: var(--radius-sm); padding: 4px 8px; font-size: 12px; cursor: pointer;
}
.ai-msg__act:hover { border-color: var(--border-strong); color: var(--text-muted); }
.ai-msg__act.is-active { color: var(--text); border-color: var(--border-strong); }
.ai-msg__feedback { display: flex; gap: 6px; align-items: center; }
.ai-msg__feedback-label { font-size: 12px; color: var(--text-faint); margin-right: 2px; }

.ai-typing { display: inline-flex; gap: 4px; align-items: center; color: var(--text-faint); font-size: 13px; }
.ai-typing__dots { display: inline-flex; gap: 3px; }
.ai-typing__dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: ai-blink 1.2s infinite; }
.ai-typing__dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing__dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.ai-chat__composer { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.ai-chat__textarea {
  flex: 1; resize: none; max-height: 120px; border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; font-size: 14.5px; outline: none;
}
.ai-chat__textarea:focus { border-color: var(--border-strong); }
.ai-chat__textarea::placeholder { color: var(--aux-text); }
.ai-chat__send {
  flex-shrink: 0; border: 0; cursor: pointer; border-radius: var(--radius-sm); width: 42px; height: 42px;
  background: var(--accent); color: #0a0a0b; font-size: 18px;
}
.ai-chat__send:disabled { opacity: 0.4; cursor: not-allowed; }
/* T-602 (P1-4 contraste + P1-7 safe-area): rodapé informativo. */
.ai-chat__hint { font-size: 11px; color: var(--aux-text); text-align: center; padding: 0 12px calc(10px + env(safe-area-inset-bottom, 0px)); }

/* --- Modo desenvolvedor (só em dev) ---------------------------------------- */
.ai-chat__dev {
  border-top: 1px dashed var(--border-strong); padding: 10px 14px; font-size: 12px;
  color: var(--text-muted); background: rgba(255,255,255,0.02);
}
.ai-chat__dev-title { color: var(--aux-text); text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px; margin-bottom: 6px; }
.ai-chat__dev-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.ai-chat__dev-row span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }

/* --- Responsivo ------------------------------------------------------------ */
@media (max-width: 560px) {
  .ai-chat__panel { width: 100vw; border-left: 0; }
  .ai-chat__header { padding: 14px; }
}

/* --- Acessibilidade -------------------------------------------------------- */
.ai-chat__icon-btn:focus-visible, .ai-chat__send:focus-visible, .ai-chat__textarea:focus-visible,
.ajuda-card--category:focus-visible, .ai-msg__act:focus-visible {
  outline: 2px solid #7dd3fc; outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .ai-chat__panel, .ai-chat__backdrop { transition: none; }
  .ai-typing__dots span { animation: none; }
}
