/* =========================================================
   Chat widget — drawer lateral + FAB
   Reutiliza tokens (--accent, --orange-1, --orange-2, --ink…)
   y comparte la animación con .drawer / .overlay del carrito.
   ========================================================= */

/* ---------- FAB (botón flotante) ---------- */
.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(var(--gradient-angle), var(--orange-1) 0%, var(--orange-2) 100%);
  box-shadow: 0 10px 28px rgba(231, 111, 81, .45),
              0 2px 6px rgba(0, 0, 0, .12);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  z-index: 90;
  transition: transform .22s var(--ease), box-shadow .22s var(--ease);
  animation: chatFabIn .5s var(--ease) both;
}
.chat-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 14px 34px rgba(231, 111, 81, .55);
}
.chat-fab:active { transform: translateY(-1px) scale(.98); }

.chat-fab .chat-fab-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(46, 204, 113, .55);
  animation: chatDotPulse 1.8s infinite;
}

@keyframes chatFabIn {
  from { opacity: 0; transform: translateY(20px) scale(.6); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes chatDotPulse {
  0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, .55); }
  70%  { box-shadow: 0 0 0 10px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

/* ---------- Drawer del chat ---------- */
/* Hereda transformaciones, posición y overlay de .drawer */
.drawer.chat-drawer {
  width: min(420px, 96vw);
  /* Altura de chat: en desktop puede ser una "ventana" flotante */
}

@media (min-width: 1024px) {
  .drawer.chat-drawer {
    top: auto;
    bottom: 22px;
    right: 22px;
    height: min(640px, calc(100dvh - 44px));
    width: 400px;
    border-radius: 18px;
    overflow: hidden;
    transform: translateY(120%);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
  }
  .drawer.chat-drawer.show { transform: translateY(0); }
}

/* Header del chat (más alto que el del carrito, con avatar) */
.chat-head {
  gap: 12px;
  padding: 0 16px;
  height: 4.6em;
}
.chat-head-ic {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  display: grid; place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.chat-head-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
  flex: 1;
}
.chat-head-text strong {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-status {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: .76rem;
  opacity: .92;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chat-dot-online {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 0 0 rgba(46, 204, 113, .55);
  animation: chatDotPulse 1.8s infinite;
}

/* ---------- Cuerpo (mensajes) ---------- */
.chat-body {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-soft);
  padding: 18px 14px 8px;
  scroll-behavior: smooth;
}
.chat-body { scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }
.chat-body::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-body::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
  background-clip: padding-box;
}

.chat-msgs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Welcome state */
.chat-welcome {
  text-align: center;
  padding: 30px 18px 18px;
  color: var(--ink-soft);
}
.chat-welcome-ic {
  width: 64px; height: 64px;
  border-radius: 50%;
  margin: 0 auto 14px;
  background: #fff;
  display: grid; place-items: center;
  color: var(--accent);
  font-size: 1.5rem;
  box-shadow: 0 6px 20px rgba(231, 111, 81, .18);
}
.chat-welcome h4 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--ink);
}
.chat-welcome p {
  margin: 0;
  font-size: .9rem;
  line-height: 1.45;
  max-width: 280px;
  margin: 0 auto;
}

/* Filas de mensaje */
.chat-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  margin-top: 8px;
}
.chat-row.user { align-self: flex-end; align-items: flex-end; }
.chat-row.bot  { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .92rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  animation: chatBubbleIn .25s var(--ease) both;
}
.chat-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-bubble.user {
  background: linear-gradient(var(--gradient-angle), var(--orange-1) 0%, var(--orange-2) 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-bubble.bot {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.chat-time {
  font-size: .68rem;
  color: var(--ink-mute);
  margin-top: 3px;
  padding: 0 6px;
}

.chat-system {
  align-self: center;
  font-size: .75rem;
  color: var(--ink-mute);
  background: rgba(0, 0, 0, .04);
  padding: 4px 12px;
  border-radius: 999px;
  margin-top: 10px;
}

@keyframes chatBubbleIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Typing */
.chat-typing {
  padding: 4px 0 6px;
  display: flex;
}
.chat-typing[hidden] {
  display: none;
}
.chat-bubble.typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 16px;
}
.chat-bubble.typing .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-mute);
  opacity: .5;
  animation: chatTypingDot 1.2s infinite ease-in-out;
}
.chat-bubble.typing .dot:nth-child(2) { animation-delay: .15s; }
.chat-bubble.typing .dot:nth-child(3) { animation-delay: .3s; }
@keyframes chatTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Sugerencias rápidas ---------- */
.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 4px;
  background: var(--bg-soft);
}
.chat-suggest:empty { display: none; }
.chat-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  padding: 7px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: .78rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.chat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff7f3;
}

/* ---------- Footer (input) ---------- */
.chat-foot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 14px;
  background: #fff;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.chat-icon-btn {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-soft);
  border: none;
  color: var(--ink-mute);
  display: grid; place-items: center;
  cursor: pointer;
  font-size: .95rem;
  transition: color .15s, background .15s;
}
.chat-icon-btn:hover { color: var(--accent); background: #fff1ea; }

.chat-input {
  flex: 1;
  min-height: 38px;
  max-height: 140px;
  resize: none;
  border: 1.5px solid var(--line);
  border-radius: 20px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: var(--bg-soft);
  outline: none;
  line-height: 1.4;
  transition: border-color .15s, background .15s;
}
.chat-input:focus {
  border-color: var(--accent);
  background: #fff;
}

.chat-send {
  width: 42px; height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(var(--gradient-angle), var(--orange-1) 0%, var(--orange-2) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: .95rem;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(231, 111, 81, .3);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.chat-send:hover { transform: scale(1.06); box-shadow: 0 6px 18px rgba(231, 111, 81, .45); }
.chat-send:active { transform: scale(.96); }

/* ---------- Responsive: mobile full-height drawer ---------- */
@media (max-width: 1023px) {
  .chat-fab {
    right: 16px;
    bottom: 16px;
    width: 54px; height: 54px;
    font-size: 1.25rem;
  }
}
@media (max-width: 480px) {
  .drawer.chat-drawer {
    width: 100vw;
  }
  .chat-row { max-width: 88%; }
}
