/* ═══════════════════════════════════════════════════════════════════════════
   Chatbot Widget — Popup flotante TRECK
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── FAB (Floating Action Button) ─────────────────────────────────────── */
#chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent));
  color: var(--accent-text, #1a1a1a);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(245, 180, 0, 0.35);
  transition: all 0.3s var(--ease, cubic-bezier(0.16, 1, 0.3, 1));
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fabPulse 3s ease-in-out infinite;
}
#chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(245, 180, 0, 0.5);
}
#chat-fab:active { transform: scale(0.95); }
#chat-fab.hidden { display: none; }

@keyframes fabPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(245, 180, 0, 0.35); }
  50% { box-shadow: 0 4px 28px rgba(245, 180, 0, 0.55); }
}

#chat-fab svg {
  width: 26px;
  height: 26px;
  transition: transform 0.3s ease;
}
#chat-fab.open svg { transform: rotate(90deg); }

/* ── Popup Container ──────────────────────────────────────────────────── */
#chat-popup {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9999;
  width: 400px;
  height: 560px;
  max-height: calc(100vh - 120px);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(245, 180, 0, 0.08);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease, cubic-bezier(0.16, 1, 0.3, 1));
}
#chat-popup.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}
#chat-popup.maximized {
  width: 560px;    /* 400 × 1.4 */
  height: 784px;   /* 560 × 1.4 */
  max-height: calc(100vh - 120px);
}

/* ── Header ───────────────────────────────────────────────────────────── */
.chat-popup-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-popup-header .chat-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}
.chat-popup-header .chat-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: dotPulse 2s infinite;
}
.chat-popup-header .chat-title .dot.offline { background: var(--red); animation: none; }

@keyframes dotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.chat-popup-header .header-btns {
  display: flex;
  gap: 0.35rem;
}
.chat-popup-header .header-btns button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.chat-popup-header .header-btns button:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}
.chat-popup-header .header-btns button svg {
  width: 14px;
  height: 14px;
}

/* ── Status Bar ───────────────────────────────────────────────────────── */
.chat-status-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--text2);
  padding: 0.3rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-status-bar .status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.chat-status-bar .status-dot.offline { background: var(--red); }

/* ── Messages ─────────────────────────────────────────────────────────── */
.chat-popup-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scroll-behavior: smooth;
  background: var(--bg);
}
.chat-popup-messages::-webkit-scrollbar { width: 5px; }
.chat-popup-messages::-webkit-scrollbar-track { background: transparent; }
.chat-popup-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  animation: msgSlideIn 0.25s ease-out;
}
.chat-msg.user { flex-direction: row-reverse; }

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

.chat-msg .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
}
.chat-msg .avatar.bot {
  background: linear-gradient(135deg, var(--accent), var(--accent));
  color: var(--accent-text, #1a1a1a);
}
.chat-msg .avatar.user {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.chat-msg .bubble {
  max-width: 78%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  line-height: 1.6;
  color: var(--text);
  font-size: 0.85rem;
  word-wrap: break-word;
}
.chat-msg.user .bubble {
  background: var(--accent);
  color: var(--accent-text, #1a1a1a);
  border-color: var(--accent);
}
.chat-msg .bubble strong { color: var(--accent); }
.chat-msg.user .bubble strong { color: var(--accent-text, #1a1a1a); }
.chat-msg .bubble em { color: var(--text2); font-size: 0.78rem; }
.chat-msg .bubble code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-size: 0.8rem;
  color: var(--orange);
}

/* ── Typing Indicator ─────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 0.2rem 0;
}
.chat-typing span {
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Suggestions ──────────────────────────────────────────────────────── */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-suggestions .chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.chat-suggestions .chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-card);
}

/* ── Input Bar ────────────────────────────────────────────────────────── */
.chat-popup-input {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  flex-shrink: 0;
}
.chat-input-row {
  display: flex;
  gap: 0.4rem;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 90px;
  line-height: 1.45;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.chat-input-row textarea::placeholder { color: var(--text3); }

.chat-input-row .btn-send {
  background: var(--accent);
  color: var(--accent-text, #1a1a1a);
  border: none;
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.chat-input-row .btn-send:hover { background: var(--accent); transform: scale(1.05); }
.chat-input-row .btn-send:disabled { background: var(--bg-card); color: var(--text3); cursor: not-allowed; transform: none; }
.chat-input-row .btn-send svg { width: 16px; height: 16px; }

/* ── Buzz Animation ────────────────────────────────────────────────────── */
@keyframes chatBuzz {
  0%,100% { transform: translate(0,0); }
  15% { transform: translate(-5px, 2px) rotate(-.7deg); }
  30% { transform: translate(5px,-2px) rotate(.7deg); }
  45% { transform: translate(-4px, 1px); }
  60% { transform: translate(4px,-1px); }
  80% { transform: translate(-2px, 0); }
}
#chat-popup.buzz { animation: chatBuzz .45s ease; }

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chat-popup {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }
  #chat-popup.maximized {
    width: 100%;
    height: 100%;
    max-height: 100vh;
  }
  #chat-fab {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }
  #chat-fab svg { width: 22px; height: 22px; }
  #cw-maximize { display: none; }
}

@media print {
  #chat-widget, #chat-fab, #chat-popup { display: none !important; }
}
body.reporte-body #chat-widget { display: none !important; }
