/* Chat RAG no e-commerce (Fase 2 — SDD-ecommerce-chat §5.2) */

:root {
  --rag-blue: #2f6fed;
  --rag-radius: 14px;
}

/* garante que o atributo [hidden] esconda mesmo com display custom */
#rag-panel[hidden],
#rag-overlay[hidden] { display: none !important; }

/* trava o scroll do site enquanto a modal está aberta */
body.rag-modal-open { overflow: hidden; }

/* #rag-chat-root é sempre full-width (col-xs-12). float:none + clear:both evita que, na
   listagem (mesmo .row dos produtos), a grade sobreponha o campo e bloqueie o clique. */
#rag-chat-root { float: none; clear: both; }

/* ---------- estado idle: campo de busca (em fluxo na página) ---------- */
#rag-searchbox {
  position: relative;
  max-width: 720px;
  margin: 24px auto;
}
#rag-searchbox .rag-search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--rag-blue);
  font-size: 1.8rem;
  pointer-events: none;
}
#rag-input {
  width: 100%;
  padding: 18px 24px 18px 58px;
  font-size: 1.6rem;     /* = 16px: mesmo tamanho dos nomes das categorias (.find-your-area__list li>a) */
  border: 1px solid #d9d9d9;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
  outline: none;
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s;
}
#rag-input::placeholder { color: #8a8a8a; }
#rag-input:focus { border-color: var(--rag-blue); box-shadow: 0 4px 20px rgba(47, 111, 237, .18); }

/* ---------- variante HOME (is-home): faixa cinza de destaque no topo ---------- */
/* só aplica quando o include recebe home=True; a listagem mantém o visual simples acima */
#rag-chat-root.is-home {
  padding: 5% 0 6%;
  background-color: #fafafa;
  border-bottom: 2px solid #e8e8e8;
  box-shadow: 0 3px 9px #9999991c;
}
#rag-chat-root.is-home .rag-home-title { margin-bottom: 0 !important; }
#rag-chat-root.is-home #rag-searchbox { margin-top: 10px; }
/* input com borda em gradiente azul (truque do double-background) — só na home */
#rag-chat-root.is-home #rag-input {
  font-size: 1.8rem;
  border: 3px solid transparent;
  box-shadow: 0 2px 9px 3px rgba(0, 0, 0, .08);
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(to right, #133bd2, #3a4e99) border-box;
}

/* ---------- overlay (cobre o site inteiro: branco 90% + blur) ---------- */
#rag-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, .49);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 1040;
}

/* ---------- modal de chat (centralizada, máx. 700px) ---------- */
#rag-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(700px, 94vw);
  max-height: 85vh;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  overflow: hidden;
}
.rag-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #fff;
  border-bottom: 1px solid #ececec;
  flex: 0 0 auto;
}
.rag-panel-title { font-weight: 600; color: #222; }
.rag-panel-title .bi { color: var(--rag-blue); }
#rag-close {
  border: 0;
  background: transparent;
  font-size: 1.8rem;
  line-height: 1;
  color: #888;
  cursor: pointer;
}
#rag-close:hover { color: #222; }

/* área das mensagens — rola por dentro (min-height:0 é o que destrava o scroll no flex) */
#rag-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.rag-panel-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  background: #fff;
  border-top: 1px solid #ececec;
}
.rag-panel-footer #rag-input-bottom {
  flex: 1 1 auto;
  padding: 12px 16px;
  font-size: 1.6rem;     /* = 16px: mesmo padrão de texto do site */
  border: 1px solid #d9d9d9;
  border-radius: 999px;
  outline: none;
}
.rag-panel-footer #rag-input-bottom:focus { border-color: var(--rag-blue); }
#rag-send {
  flex: 0 0 auto;
  border: 0;
  background: var(--rag-blue);
  color: #fff;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  cursor: pointer;
}

/* ---------- balões ---------- */
.rag-msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: var(--rag-radius);
  margin: 4px 0;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
/* respiro entre os turnos: nova pergunta e resposta ganham espaço acima */
.rag-msg.user { align-self: flex-end; background: var(--rag-blue); color: #fff; margin-top: 16px; }
.rag-msg.bot { align-self: flex-start; background: #f4f4f6; color: #222; margin-top: 12px; white-space: normal; }

/* markdown renderizado dentro da bolha do bot */
.rag-msg.bot > :first-child { margin-top: 0; }
.rag-msg.bot > :last-child { margin-bottom: 0; }
.rag-msg.bot p { margin: 0 0 .6em; }
/* restaura os marcadores (o tema tem reset global ul,ol{list-style:none}) */
.rag-msg.bot ul { list-style: disc; margin: .3em 0 .6em; padding-left: 1.5em; }
.rag-msg.bot ol { list-style: decimal; margin: .3em 0 .6em; padding-left: 1.5em; }
.rag-msg.bot li { margin: .15em 0; display: list-item; }
.rag-msg.bot a { color: var(--rag-blue); text-decoration: underline; }
.rag-msg.bot strong, .rag-msg.bot b { font-weight: 700; }
.rag-msg.bot code { background: #e7e9ee; padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.rag-msg.bot pre { background: #e7e9ee; padding: 8px 10px; border-radius: 6px; overflow-x: auto; }
.rag-msg.bot pre code { background: none; padding: 0; }
.rag-msg.bot blockquote { margin: .3em 0; padding-left: .8em; border-left: 3px solid #d9d9d9; color: #555; }
.rag-msg.error { align-self: flex-start; background: #fde8e8; border: 1px solid #f5c2c2; color: #9b1c1c; }

/* ---------- loader (três pontinhos) ---------- */
.rag-loader { align-self: flex-start; display: inline-flex; gap: 5px; padding: .7rem .9rem; }
.rag-loader span {
  width: 7px; height: 7px; border-radius: 50%; background: #bbb;
  animation: rag-bounce 1.2s infinite ease-in-out both;
}
.rag-loader span:nth-child(2) { animation-delay: .15s; }
.rag-loader span:nth-child(3) { animation-delay: .3s; }
@keyframes rag-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

/* ---------- botão "Ver conversas anteriores" (paginação do histórico) ---------- */
.rag-load-older {
  align-self: center;
  margin: 2px 0 12px;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 999px;
  color: var(--rag-blue);
  font-size: 1.3rem;
  font-weight: 600;
  padding: 7px 18px;
  cursor: pointer;
  transition: background .15s;
}
.rag-load-older:hover { background: #f0f4ff; }
.rag-load-older:disabled { opacity: .6; cursor: default; }

/* ---------- cards de livros (sources) — seguem as classes do list_loop_card ---------- */
.rag-cards { align-self: stretch; display: flex; flex-wrap: wrap; gap: 12px; margin: 2px 0 14px; }
.rag-cards:empty { display: none; }
.rag-card {
  width: 168px; border: 1px solid #e7e7e7; border-radius: 10px;
  background: #fff; padding: 12px;
  display: flex; flex-direction: column;
  transition: box-shadow .2s, transform .2s;
}
.rag-card:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, .1); transform: translateY(-2px); }
.rag-card .rag-card-link { display: flex; flex-direction: column; text-decoration: none; color: #222; }
.rag-card .figure-first { margin: 0 0 10px; text-align: center; }
.rag-card .figure-first img { max-width: 100%; height: 210px; object-fit: contain; }
/* texto dos cards compatível com o resto da modal (=15px; lembrar: 1rem=10px no tema) */
.rag-card .product-name { font-size: 1.5rem; line-height: 1.3; margin: 0 0 5px; font-weight: 600; }
.rag-card .product-price { font-size: 1.5rem; color: var(--rag-blue); font-weight: 600; margin-top: auto; }
/* CTA: adicionar ao carrinho direto do card */
.rag-card-cart {
  margin-top: 10px; width: 100%; border: 0; border-radius: 8px;
  background: var(--rag-blue); color: #fff;
  font-size: 1.25rem; font-weight: 600; line-height: 1.25;
  padding: 9px 8px; cursor: pointer; text-align: center;
  transition: background .15s;
}
.rag-card-cart .bi { margin-right: 4px; }
.rag-card-cart:hover { background: #1f57c8; }
.rag-card-cart:disabled { opacity: .6; cursor: default; }

/* ---------- mobile ---------- */
@media (max-width: 576px) {
  #rag-panel { width: 94vw; max-height: 88vh; }
  .rag-msg { max-width: 90%; }
  .rag-card { width: 44%; }
  .rag-card .figure-first img { height: 180px; }
  /* respiro lateral no campo de busca (mobile) */
  #rag-searchbox { padding-left: 10px; padding-right: 10px; }
  /* mesmo font-size no mobile p/ home E listagem (placeholder legível) */
  #rag-input,
  #rag-chat-root.is-home #rag-input { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  #rag-input, .rag-card { transition: none; }
  .rag-loader span { animation: none; }
}
