/* ============================================================================
   Importy · Chat dock & ventanas flotantes
   Paleta: índigo corporativo / slate, sin verde brillante.
   ========================================================================== */

:root {
  --chat-bg-self: #4f46e5;
  --chat-bg-self-soft: rgba(99, 102, 241, 0.95);
  --chat-bg-other: #f1f5f9;
  --chat-text-other: #1e293b;
  --chat-text-self: #fff;
  --chat-border: rgba(15, 23, 42, 0.08);
  --chat-shadow: 0 12px 40px rgba(15, 23, 42, 0.16), 0 2px 6px rgba(15, 23, 42, 0.06);
  --chat-shadow-window: 0 18px 48px rgba(15, 23, 42, 0.22), 0 4px 10px rgba(15, 23, 42, 0.08);
  --chat-dock-w: 320px;
  --chat-window-w: 360px;
  --chat-window-h: 480px;
  --chat-window-h-min: 48px;
}

/* El layout principal NO reserva espacio para el dock: éste se abre por
   encima del contenido como un panel desplegable estilo Alibaba. */
.chat-main-pad { padding-right: 24px; }

/* ── Dock (panel derecho, oculto por default) ─────────────────────────── */
.chat-dock {
  position: fixed; top: 56px; right: 0; bottom: 0;
  width: var(--chat-dock-w);
  background: #fff; border-left: 1px solid var(--chat-border);
  box-shadow: -8px 0 24px rgba(15,23,42,0.08);
  z-index: 40;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.2,.8,.2,1);
}
.chat-dock.is-open { transform: translateX(0); }
.chat-dock-shell { display: flex; flex-direction: column; height: 100%; }
#chat-dock-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.chat-dock-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--chat-border);
  background: linear-gradient(180deg, #fafbff, #fff);
}
.chat-badge-total {
  display: inline-flex; align-items: center; justify-content: center;
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; min-width: 18px;
  box-shadow: 0 0 0 2px #fff;
}
.chat-dock-search {
  padding: 10px 12px; border-bottom: 1px solid var(--chat-border);
}
.chat-search-input {
  width: 100%; border: 1px solid #e2e8f0; border-radius: 9px;
  padding: 7px 10px; font-size: 13px; outline: none;
  background: #f8fafc;
}
.chat-search-input:focus { background: #fff; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }

.chat-dock-filters {
  display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--chat-border);
  flex-wrap: wrap;
}
.chat-filter-pill {
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  border: 1px solid #e2e8f0; background: #fff; color: #64748b;
  cursor: pointer; transition: all .15s;
}
.chat-filter-pill:hover { background: #f8fafc; }
.chat-filter-pill.is-active { background: rgba(99,102,241,0.1); color: #4f46e5; border-color: rgba(99,102,241,0.25); }
.chat-filter-pill-n {
  display: inline-flex; align-items: center; justify-content: center;
  background: #ef4444; color: #fff; font-size: 9.5px; font-weight: 700;
  padding: 0 5px; min-width: 14px; height: 14px; border-radius: 999px;
  margin-left: 3px; line-height: 14px;
}
.chat-filter-pill.is-active .chat-filter-pill-n { background: #4f46e5; }

.chat-translate-tip {
  display: flex; gap: 6px; align-items: flex-start;
  background: linear-gradient(180deg, #eef2ff, #f5f7ff);
  border-bottom: 1px solid rgba(99,102,241,0.1);
  padding: 8px 14px; font-size: 11.5px; color: #4338ca; line-height: 1.4;
}

.chat-dock-list { flex: 1; overflow-y: auto; padding: 4px 0 12px; min-height: 0; }
.chat-empty { text-align: center; padding: 36px 20px; color: #64748b; }

.chat-group { margin-top: 6px; }
.chat-group-header { display: flex; align-items: center; gap: 8px; padding: 6px 14px 4px; }
.chat-group-key {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 11px; font-weight: 700; color: #4f46e5;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.chat-group-line { flex: 1; height: 1px; background: rgba(99,102,241,0.12); }

.chat-thread-item {
  width: 100%; display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; cursor: pointer; border: none; background: transparent;
  text-align: left; transition: background .12s;
  border-left: 3px solid transparent;
}
.chat-thread-item:hover { background: rgba(99,102,241,0.04); }
.chat-thread-item.has-unread { background: rgba(99,102,241,0.05); border-left-color: #6366f1; }
.chat-thread-item.is-archived { opacity: 0.7; }

.chat-thread-icon {
  position: relative; width: 36px; height: 36px;
  border-radius: 10px; background: rgba(99,102,241,0.1);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-kind-icon { font-size: 18px; }
.chat-thread-badge {
  position: absolute; top: -4px; right: -4px;
  background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 999px; box-shadow: 0 0 0 2px #fff;
  min-width: 16px; text-align: center;
}

.chat-thread-body { flex: 1; min-width: 0; }
.chat-thread-title-row { display: flex; align-items: center; gap: 8px; }
.chat-thread-title { font-size: 13px; font-weight: 600; color: #0f172a; }
.chat-tag-archived {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: #f1f5f9; color: #64748b; font-weight: 600;
}
.chat-thread-snippet {
  font-size: 12px; color: #64748b; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-thread-meta {
  font-size: 10.5px; color: #94a3b8; margin-top: 3px;
  display: flex; align-items: center; gap: 4px;
}
.chat-online-dot {
  width: 6px; height: 6px; background: #10b981; border-radius: 50%;
  display: inline-block; box-shadow: 0 0 0 2px #fff;
}

.chat-dock-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-top: 1px solid var(--chat-border);
  font-size: 10.5px; color: #94a3b8;
}
.chat-footer-text { line-height: 1.3; }

.chat-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  border: none; background: transparent; color: #64748b; cursor: pointer;
  transition: all .12s;
}
.chat-icon-btn:hover { background: #f1f5f9; color: #4f46e5; }

/* ── Botón de chat en el navbar (estilo Alibaba) ───────────────────────── */
.chat-nav-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 34px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: #64748b;
  cursor: pointer; transition: all .15s;
}
.chat-nav-btn:hover { color: #6366f1; background: rgba(99,102,241,0.08); }
.chat-nav-btn.is-active { color: #4f46e5; background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.2); }

.chat-nav-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: #ef4444; color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 18px;
  border-radius: 999px; box-shadow: 0 0 0 2px #fff;
  display: inline-flex; align-items: center; justify-content: center;
}

/* FAB legacy: se usa solo como hook de respaldo, oculto siempre */
.chat-fab { display: none !important; }
.chat-fab-badge { display: none; }

/* Backdrop del dock cuando está abierto (click fuera para cerrar) */
.chat-dock-backdrop {
  position: fixed; inset: 56px 0 0 0;
  background: rgba(15,23,42,0.18);
  z-index: 39; opacity: 0; pointer-events: none;
  transition: opacity .18s ease;
}
.chat-dock-backdrop.is-open { opacity: 1; pointer-events: auto; }
@media (min-width: 1025px) {
  /* En desktop el backdrop es invisible pero captura clicks */
  .chat-dock-backdrop.is-open { background: transparent; }
}

/* ── Ventanas flotantes (stack inferior) ────────────────────────────────── */
.chat-windows-stack {
  position: fixed;
  right: 16px;
  bottom: 0;
  display: flex; flex-direction: row-reverse; gap: 12px;
  align-items: flex-end;          /* ancla las ventanas al borde inferior */
  z-index: 41; pointer-events: none;
  transition: right .22s cubic-bezier(.2,.8,.2,1);
}
/* Cuando el dock derecho está abierto, las ventanas se corren para no superponerse */
body:has(.chat-dock.is-open) .chat-windows-stack {
  right: calc(var(--chat-dock-w) + 16px);
}
.chat-windows-stack > * { pointer-events: auto; }

@media (max-width: 1024px) {
  .chat-windows-stack { right: 12px; bottom: 80px; }
}

.chat-window {
  width: var(--chat-window-w); height: var(--chat-window-h);
  background: #fff; border-radius: 12px 12px 0 0;
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow-window);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: chatWinIn .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes chatWinIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.chat-window.is-minimized { height: var(--chat-window-h-min); }
.chat-window.is-minimized .chat-window-body,
.chat-window.is-minimized .chat-composer,
.chat-window.is-minimized .chat-reply-preview { display: none; }

.chat-window.is-expanded {
  position: fixed !important; inset: 5% 5% 5% 5% !important;
  width: auto !important; height: auto !important;
  border-radius: 16px;
  z-index: 50;
}

@media (max-width: 768px) {
  .chat-window {
    width: 100vw; height: calc(100vh - 64px);
    border-radius: 0; bottom: 0; right: 0; position: fixed; inset: 64px 0 0 0;
  }
}

.chat-window-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--chat-border);
  background: linear-gradient(180deg, #fafbff, #fff);
}
.chat-window-titlebar {
  flex: 1; display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; cursor: pointer;
  padding: 4px 6px; border-radius: 8px; min-width: 0;
}
.chat-window-titlebar:hover { background: rgba(99,102,241,0.06); }
.chat-window-icon { font-size: 18px; }
.chat-window-title { font-size: 13px; font-weight: 600; color: #0f172a; }
.chat-window-subtitle { font-size: 11px; color: #64748b; }
.chat-window-badge {
  background: #ef4444; color: #fff; font-size: 10.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px; margin-left: auto;
}
.chat-window-actions { display: flex; gap: 2px; }

.chat-window-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.chat-archived-banner {
  background: #fef9c3; color: #854d0e;
  font-size: 12px; font-weight: 600; padding: 8px 12px; text-align: center;
  border-bottom: 1px solid #fde68a;
}
.chat-disclaimer {
  font-size: 11.5px; color: #4338ca;
  padding: 8px 12px; line-height: 1.4;
  background: linear-gradient(180deg, #eef2ff, #f5f7ff);
  border-bottom: 1px solid rgba(99,102,241,0.1);
}
.chat-disclaimer strong { color: #312e81; font-weight: 700; }

.chat-searchbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-bottom: 1px solid #f1f5f9; background: #fafbff;
}
.chat-searchbar input { flex: 1; border: none; outline: none; font-size: 12.5px; background: transparent; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  background: #fafbff;
}
.chat-no-messages { text-align: center; padding: 36px 20px; color: #94a3b8; }

.chat-date-sep {
  display: flex; align-items: center; gap: 8px;
  margin: 10px auto; max-width: 80%;
  font-size: 11px; color: #64748b; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.chat-date-sep::before, .chat-date-sep::after {
  content: ""; flex: 1; height: 1px; background: rgba(15,23,42,0.06);
}

.chat-msg { display: flex; gap: 6px; align-items: flex-end; }
.chat-msg.is-self { flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, #818cf8, #6366f1); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-msg-bubble {
  max-width: 78%; padding: 7px 11px; border-radius: 14px;
  background: var(--chat-bg-other); color: var(--chat-text-other);
  font-size: 13.5px; line-height: 1.4;
  word-wrap: break-word; position: relative;
  animation: chatBubbleIn .18s ease-out;
}
@keyframes chatBubbleIn { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.chat-msg.is-self .chat-msg-bubble {
  background: var(--chat-bg-self); color: var(--chat-text-self);
  border-bottom-right-radius: 4px;
}
.chat-msg:not(.is-self) .chat-msg-bubble { border-bottom-left-radius: 4px; }

.chat-msg-author { font-size: 11px; margin-bottom: 2px; color: #475569; }
.chat-msg.is-self .chat-msg-author { color: rgba(255,255,255,0.85); }

.chat-msg-reply {
  display: flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,0.05); border: none; border-radius: 6px;
  padding: 3px 7px; font-size: 11px; cursor: pointer; margin-bottom: 4px;
  color: inherit;
}
.chat-msg.is-self .chat-msg-reply { background: rgba(255,255,255,0.18); }

.chat-msg-body { white-space: pre-wrap; }

.chat-msg-translation {
  margin-top: 4px; padding-top: 4px;
  border-top: 1px dashed rgba(0,0,0,0.08);
}
.chat-msg.is-self .chat-msg-translation { border-top-color: rgba(255,255,255,0.2); }
.chat-toggle-original {
  display: inline-flex; align-items: center; gap: 4px;
  border: none; background: transparent; cursor: pointer;
  font-size: 10.5px; color: inherit; opacity: 0.75;
}
.chat-toggle-original:hover { opacity: 1; }
.chat-msg-original {
  margin-top: 4px; padding: 6px 8px; border-radius: 6px;
  background: rgba(0,0,0,0.04); font-size: 12px; line-height: 1.35;
}
.chat-msg.is-self .chat-msg-original { background: rgba(255,255,255,0.15); }

.chat-msg-attachments { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.chat-msg-image img {
  max-width: 220px; max-height: 200px; border-radius: 8px; display: block;
  cursor: zoom-in; object-fit: cover;
}
.chat-msg-file {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 8px;
  background: rgba(0,0,0,0.05); text-decoration: none; color: inherit;
}
.chat-msg.is-self .chat-msg-file { background: rgba(255,255,255,0.15); }
.chat-file-icon { font-size: 16px; }
.chat-file-info { display: flex; flex-direction: column; min-width: 0; }
.chat-file-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.chat-file-size { font-size: 10px; opacity: 0.8; }

.chat-msg-meta {
  display: flex; align-items: center; gap: 6px; justify-content: flex-end;
  margin-top: 2px; font-size: 10px; opacity: 0.75;
}
.chat-msg-time {}
.chat-msg-receipt { font-weight: 700; }
.chat-msg-receipt.is-read { color: #38bdf8; }
.chat-msg.is-self .chat-msg-receipt:not(.is-read) { color: rgba(255,255,255,0.85); }
.chat-msg.is-self .chat-msg-receipt.is-read { color: #67e8f9; }
.chat-msg-reply-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 11px; color: inherit; opacity: 0.6;
}
.chat-msg-reply-btn:hover { opacity: 1; }

/* ── Typing ──────────────────────────────────────────────────────────────── */
.chat-typing {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; font-size: 11px; color: #64748b;
  background: #fafbff; border-top: 1px solid #f1f5f9;
}
.chat-typing-dot {
  width: 5px; height: 5px; background: #6366f1; border-radius: 50%;
  animation: chatTyping 1.2s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: .15s; }
.chat-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes chatTyping {
  0%, 80%, 100% { transform: scale(.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Reply preview ───────────────────────────────────────────────────────── */
.chat-reply-preview {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-top: 1px solid #f1f5f9; background: #f8fafc;
}

/* ── Composer ────────────────────────────────────────────────────────────── */
.chat-composer {
  border-top: 1px solid var(--chat-border); padding: 12px; background: #fff;
  position: relative;
}
.chat-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-textarea {
  flex: 1; resize: none; border: 1px solid #e2e8f0; border-radius: 14px;
  padding: 12px 16px; font-size: 14px;
  min-height: 56px; max-height: 160px;
  outline: none; line-height: 1.5; font-family: inherit;
  background: #fafbff;
}
.chat-textarea:focus { border-color: #6366f1; background: #fff; box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.chat-textarea::placeholder { color: #94a3b8; font-size: 13.5px; }
.chat-attach-btn, .chat-emoji-btn { width: 38px; height: 38px; border-radius: 50%; cursor: pointer; }
.chat-send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff;
  border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s; flex-shrink: 0;
}
.chat-send-btn:hover { transform: scale(1.04); }
.chat-send-btn:active { transform: scale(.92); }

.chat-files-preview {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  padding: 6px; background: #f8fafc; border-radius: 8px;
}
.chat-file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; padding: 4px 10px; border-radius: 999px;
  border: 1px solid #e2e8f0; font-size: 11.5px;
}
.chat-file-chip button { border: none; background: transparent; cursor: pointer; color: #94a3b8; }

.chat-mention-pop {
  position: absolute; bottom: 100%; left: 12px; right: 12px;
  background: #fff; border: 1px solid var(--chat-border); border-radius: 10px;
  box-shadow: var(--chat-shadow);
  max-height: 200px; overflow-y: auto; z-index: 5;
  margin-bottom: 6px;
}

/* ── Emoji picker ────────────────────────────────────────────────────────── */
.chat-emoji-pop {
  position: absolute; bottom: calc(100% + 6px); right: 12px;
  width: 320px; max-height: 320px; overflow-y: auto;
  background: #fff; border: 1px solid var(--chat-border); border-radius: 12px;
  box-shadow: var(--chat-shadow);
  padding: 8px; z-index: 6;
  animation: chatBubbleIn .15s ease-out;
}
.chat-emoji-cat { margin-bottom: 8px; }
.chat-emoji-cat-title {
  font-size: 10.5px; font-weight: 700; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 4px 6px 2px;
}
.chat-emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.chat-emoji-item {
  border: none; background: transparent; cursor: pointer;
  font-size: 20px; line-height: 1;
  width: 100%; aspect-ratio: 1; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .1s, transform .1s;
}
.chat-emoji-item:hover { background: rgba(99,102,241,0.08); transform: scale(1.15); }
.chat-emoji-item:active { background: rgba(99,102,241,0.18); transform: scale(.95); }

/* Scrollbar más sutil dentro del picker */
.chat-emoji-pop::-webkit-scrollbar { width: 6px; }
.chat-emoji-pop::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.25); border-radius: 3px; }
.chat-mention-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer;
}
.chat-mention-item:hover, .chat-mention-item.is-active { background: rgba(99,102,241,0.08); }
.chat-mention-name { font-weight: 600; font-size: 13px; color: #0f172a; }
.chat-mention-meta { font-size: 11px; color: #64748b; }

/* ── Stack collapse +N ───────────────────────────────────────────────────── */
.chat-stack-more {
  position: fixed; bottom: 0;
  right: 16px;
  background: #4f46e5; color: #fff; font-weight: 700; font-size: 12px;
  border: none; cursor: pointer; padding: 8px 14px; border-radius: 8px 8px 0 0;
  box-shadow: var(--chat-shadow-window);
  z-index: 41;
  transition: right .22s cubic-bezier(.2,.8,.2,1);
}
body:has(.chat-dock.is-open) .chat-stack-more {
  right: calc(var(--chat-dock-w) + 16px);
}

/* ── Modal info ──────────────────────────────────────────────────────────── */
.chat-info-modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
}
.chat-info-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,0.5);
  backdrop-filter: blur(2px);
}
.chat-info-panel {
  position: relative; width: min(540px, 92vw); max-height: 88vh;
  background: #fff; border-radius: 14px; box-shadow: var(--chat-shadow);
  display: flex; flex-direction: column; overflow: hidden;
  animation: chatBubbleIn .2s ease-out;
}
.chat-info-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--chat-border);
}
.chat-info-content { padding: 18px; overflow-y: auto; }
.chat-info-section { margin-bottom: 14px; }
.chat-info-section h4 {
  font-size: 11px; font-weight: 700; color: #4f46e5;
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px;
}
.chat-info-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; gap: 12px; }
.chat-info-row > span:first-child { color: #64748b; }
.chat-info-row > span:last-child { font-weight: 600; color: #0f172a; text-align: right; }

/* Scrollbar styling para los mensajes */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.25); border-radius: 3px; }

/* Highlight breve cuando llega un mensaje en un thread cerrado */
.chat-thread-item.is-flash {
  animation: chatFlash 1.6s ease-out;
}
@keyframes chatFlash {
  0%   { background: rgba(99,102,241,0.18); }
  100% { background: transparent; }
}
