/* ==========================================================================
   CHAT FLOTANTE (estilo LinkedIn) — barra acoplada abajo, expandible
   ========================================================================== */

/* Paleta ajustada a los colores del formulario de login (navy + naranja).
   Si el hex exacto de tu marca es distinto, solo hay que cambiar estas
   variables — el resto del archivo las usa, no valores sueltos. */
:root {
  --chat-primary: #1B2A4A;
  --chat-primary-hover: #14213A;
  --chat-accent: #F97316;
  --chat-accent-hover: #EA6A0C;
}

.floating-chat {
  position: fixed;
  bottom: 0;
  right: 24px;
  z-index: 1000;
  font-family: system-ui, -apple-system, sans-serif;
}

/* ==========================================================================
   FIX: el atributo `hidden` de HTML debe ganar SIEMPRE, sin importar qué
   otras reglas de `display` tengan los elementos (ej. display:flex de las
   vistas), porque si no, algunas clases pisan el hidden por igual
   especificidad + orden de cascada.
   ========================================================================== */
.floating-chat [hidden] {
  display: none !important;
}

/* ================= PANEL (barra + cuerpo) ================= */
.floating-chat-panel {
  width: 320px;
  background-color: #ffffff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08), 0 8px 30px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================= BARRA SUPERIOR (siempre visible) ================= */
.floating-chat-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 6px 10px 14px;
  cursor: pointer;
  user-select: none;
  background-color: #ffffff;
}

.floating-chat-bar:hover {
  background-color: #f8fafc;
}

.floating-chat-bar-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.floating-chat-bar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.floating-chat-bar-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

/* Avatar del usuario logueado (iniciales) mostrado en la barra */
.floating-chat-my-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--chat-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.floating-chat-status-dot--bar {
  width: 9px;
  height: 9px;
}

.floating-chat-badge--inline {
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  flex-shrink: 0;
}

.floating-chat-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #56687a;
  cursor: pointer;
  transition: background-color .15s ease;
}

.floating-chat-icon-btn:hover {
  background-color: #e2e8f0;
}

/* ================= CUERPO EXPANDIBLE ================= */
.floating-chat-body {
  width: 320px;
  height: 420px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #e2e8f0;
}

.floating-chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Sub-header con flecha de "volver" (vistas de hilo y redactar) */
.floating-chat-subheader {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.floating-chat-subtitle {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f172a;
}

/* ================= BUSCADOR ================= */
.floating-chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 14px;
  padding: 6px 10px;
  border-radius: 999px;
  background-color: #f1f5f9;
  color: #64748b;
  flex-shrink: 0;
}

.floating-chat-search input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.85rem;
  width: 100%;
  color: #0f172a;
}

.floating-chat-filter-icon {
  font-size: 0.9rem;
  color: #64748b;
  flex-shrink: 0;
}

/* ================= TABS: Prioritarios / Otros ================= */
.floating-chat-tabs {
  display: flex;
  gap: 20px;
  padding: 0 14px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.floating-chat-tab {
  background: none;
  border: none;
  padding: 8px 2px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}

.floating-chat-tab:hover {
  color: #334155;
}

.floating-chat-tab.active {
  color: var(--chat-primary);
  border-bottom-color: var(--chat-accent);
}

/* ================= LISTA DE CONVERSACIONES ================= */
.floating-chat-conversation-list {
  list-style: none;
  margin: 0;
  padding: 6px 6px 10px;
  overflow-y: auto;
  flex: 1;
}

.floating-chat-conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background-color .15s ease;
}

.floating-chat-conversation-item:hover {
  background-color: #f1f5f9;
}

.floating-chat-conversation-item.unread .floating-chat-conversation-name,
.floating-chat-conversation-item.unread .floating-chat-conversation-preview {
  font-weight: 700;
  color: #0f172a;
}

/* ================= AVATAR + INDICADOR DE ESTADO (genérico) ================= */
.floating-chat-avatar-wrapper {
  position: relative;
  flex-shrink: 0;
}

.floating-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background-color: #e2e8f0;
}

/* Respaldo cuando la imagen del avatar falla al cargar (ej. URLs
   externas con hotlink bloqueado). Comparte tamaño/forma con
   .floating-chat-avatar; solo agrega el centrado de texto y color. */
.floating-chat-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--chat-primary);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
}

.floating-chat-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background-color: #94a3b8; /* offline por defecto */
}

.floating-chat-status-dot.online {
  background-color: #22c55e;
}

.floating-chat-conversation-text {
  flex: 1;
  min-width: 0;
}

.floating-chat-conversation-name {
  margin: 0;
  font-size: 0.9rem;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.floating-chat-conversation-preview {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.floating-chat-conversation-time {
  font-size: 0.7rem;
  color: #94a3b8;
  flex-shrink: 0;
  align-self: flex-start;
}

.floating-chat-empty-state {
  padding: 24px 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.85rem;
}

/* ================= VISTA DE CONVERSACIÓN (HILO) ================= */
.floating-chat-thread-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.floating-chat-thread-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.floating-chat-thread-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: #64748b;
}

.floating-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: #f8fafc;
}

.floating-chat-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.35;
  word-wrap: break-word;
}

.floating-chat-bubble--received {
  align-self: flex-start;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

.floating-chat-bubble--sent {
  align-self: flex-end;
  background-color: var(--chat-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.floating-chat-bubble-time {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  opacity: 0.7;
}

/* ================= INPUT DE ENVÍO ================= */
.floating-chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  background-color: #ffffff;
}

.floating-chat-input-bar input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  outline: none;
}

.floating-chat-input-bar input:focus {
  border-color: var(--chat-primary);
}

.floating-chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background-color: var(--chat-accent);
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color .15s ease;
}

.floating-chat-send-btn:hover {
  background-color: var(--chat-accent-hover);
}

.floating-chat-send-btn:disabled {
  background-color: #cbd5e1;
  cursor: not-allowed;
}

/* ================= RESPONSIVE (MÓVIL) ================= */
@media (max-width: 480px) {
  .floating-chat {
    right: 12px;
  }

  .floating-chat-panel,
  .floating-chat-body {
    width: calc(100vw - 24px);
  }

  .floating-chat-body {
    height: 70vh;
  }
}