/* =========================================================
   Rivadex — asistente con IA (globo flotante)
   ========================================================= */
.chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 18px 12px 14px; border: 0; border-radius: 100px; cursor: pointer;
  background: var(--ink); color: var(--ivory);
  font-family: var(--font-sans); font-weight: 500; font-size: 14px; line-height: 1;
  box-shadow: 0 10px 30px rgba(20, 20, 19, .22);
  transition: transform .15s var(--ease), opacity .2s var(--ease);
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--clay); box-shadow: 0 0 0 4px rgba(217, 119, 87, .25); }
.chat-fab[aria-expanded="true"] { opacity: 0; pointer-events: none; }

.chat {
  position: fixed; right: 20px; bottom: 20px; z-index: 61;
  width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  background: var(--ivory); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-card);
  box-shadow: 0 24px 60px rgba(20, 20, 19, .22);
  overflow: hidden;
}
.chat[hidden] { display: none; }

.chat__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 14px 18px; background: var(--ink); color: var(--ivory);
}
.chat__title { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.2; }
.chat__sub { font-size: 12px; color: var(--on-dark-muted); line-height: 1.3; }
.chat__head-text { flex: 1; min-width: 0; }
.chat__icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; min-width: 32px; padding: 0 10px; border: 0; border-radius: 100px; cursor: pointer;
  background: var(--darkline); color: var(--ivory); font-size: 12px; line-height: 1;
}
.chat__icon-btn:hover { opacity: .85; }

.chat__log {
  flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.chat__msg {
  max-width: 86%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat__msg--assistant { align-self: flex-start; background: var(--pampas); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat__msg--user { align-self: flex-end; background: var(--ink); color: var(--ivory); border-bottom-right-radius: 4px; }
.chat__msg--error { align-self: flex-start; background: #FBEDE7; border: 1px solid #F0C9BA; color: #7A2E16; }
.chat__msg a { text-decoration: underline; }

.chat__typing { display: inline-flex; gap: 4px; align-items: center; }
.chat__typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: chat-dot 1s infinite ease-in-out; }
.chat__typing span:nth-child(2) { animation-delay: .15s; }
.chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chat__chips[hidden] { display: none; }
.chat__chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chat__chips .chip { cursor: pointer; font-family: var(--font-sans); }

.chat__gate { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line); background: #fff; }
.chat__gate[hidden], .chat__form[hidden] { display: none; }
.chat__gate-text { font-size: 13px; font-weight: 500; color: var(--ink); }
.chat__check { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; line-height: 1.45; color: var(--body); cursor: pointer; }
.chat__check input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--ink); cursor: pointer; }
.chat__check a { text-decoration: underline; text-underline-offset: 2px; }
.chat__gate-err { font-size: 12px; color: #B54A2F; min-height: 0; }
.chat__gate-err:empty { display: none; }
.chat__start { height: 42px; border-radius: 12px; }
.chat__start:disabled { opacity: .6; }

.chat__form { display: flex; gap: 8px; align-items: flex-end; padding: 12px; border-top: 1px solid var(--line); background: #fff; }
.chat__input {
  flex: 1; resize: none; max-height: 120px; min-height: 42px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--ivory);
  font: inherit; font-size: 14px; line-height: 1.4; color: var(--ink);
}
.chat__input:focus { outline: none; border-color: var(--ink); }
.chat__send { height: 42px; padding: 0 16px; border-radius: 12px; }
.chat__note { padding: 0 14px 10px; background: #fff; font-size: 11px; color: var(--muted); text-align: center; }

@media (max-width: 809px) {
  .chat-fab { right: 16px; bottom: 16px; }
  .chat { right: 0; bottom: 0; width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .chat__typing span { animation: none; }
  .chat__log { scroll-behavior: auto; }
}
