/* ══════════════════════════════════════════════════════════
   CHAT.CSS — Panel de chat deslizante (CoreFlow)
══════════════════════════════════════════════════════════ */

/* ── Utilidad ── */
#chatHubView.hidden,
#chatDirectView.hidden,
#chatBtnVolver.hidden,
#chatBtnFinalizar.hidden,
#chatSolBanner.hidden,
#chatFinalizadoBar.hidden,
#chatInputArea.hidden { display: none !important; }

/* ── Panel principal ── */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.chat-panel--abierto {
  transform: translateX(0);
}

.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 1499;
}
.chat-overlay--visible {
  display: block;
}

/* ── Header ── */
.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}
.chat-panel-titulo {
  flex: 1;
  font-weight: 700;
  font-size: .95rem;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-btn-volver,
.chat-btn-cerrar {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  color: #64748b;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}
.chat-btn-volver:hover,
.chat-btn-cerrar:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* ── Botón finalizar conversación ── */
.chat-btn-finalizar {
  background: transparent;
  border: 1px solid #dc2626;
  color: #dc2626;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.chat-btn-finalizar:hover:not(:disabled) { background: #fee2e2; }
.chat-btn-finalizar--confirmando {
  background: #dc2626 !important;
  color: #fff !important;
  border-color: #b91c1c !important;
}
.chat-btn-finalizar:disabled { opacity: .5; cursor: not-allowed; }

/* ── Hub: lista de conversaciones ── */
.chat-hub-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.chat-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.chat-search-icon { font-size: 14px; color: #94a3b8; }
.chat-search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: .875rem;
  color: #334155;
  background: transparent;
}
.chat-hub-list {
  flex: 1;
  overflow-y: auto;
}
.chat-hub-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .15s;
}
.chat-hub-item:hover               { background: #f8fafc; }
.chat-hub-item--unread             { background: #eff6ff; }
.chat-hub-item--unread:hover       { background: #dbeafe; }
.chat-hub-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.chat-hub-docnum {
  font-weight: 700;
  font-size: .875rem;
  color: #1e293b;
}
.chat-hub-badge {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 7px;
  flex-shrink: 0;
}
.chat-hub-ts {
  margin-left: auto;
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
}
.chat-hub-ultimo {
  font-size: .8rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-hub-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  color: #94a3b8;
  font-size: .875rem;
  text-align: center;
}
.chat-hub-empty span { font-size: 2.5rem; }

/* ── Paginación ── */
.chat-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.chat-page-btn {
  background: #f1f5f9;
  border: none;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 1rem;
  color: #475569;
  line-height: 1;
}
.chat-page-btn:hover:not(:disabled) { background: #e2e8f0; }
.chat-page-btn:disabled             { opacity: .4; cursor: default; }
.chat-page-label { font-size: .8rem; color: #64748b; min-width: 40px; text-align: center; }

/* ── Vista directa ── */
.chat-direct-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ── Banner de contexto de solicitud ── */
.chat-sol-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-sol-banner-num {
  font-weight: 700;
  font-size: .9rem;
  color: #1e293b;
}
.chat-sol-banner-tipo {
  font-size: 11px;
  font-weight: 600;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 99px;
  padding: 1px 8px;
}

/* ── Mensajes ── */
.chat-mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-loading {
  text-align: center;
  color: #94a3b8;
  font-size: .875rem;
  padding: 30px 20px;
}
.chat-sin-mensajes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  color: #94a3b8;
  font-size: .875rem;
  text-align: center;
}
.chat-sin-mensajes span { font-size: 2.5rem; }

/* ── Burbujas ── */
.chat-burbuja {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
}
.chat-burbuja--otro {
  background: #f1f5f9;
  color: #1e293b;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-burbuja--mia {
  background: #1d4ed8;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* ── Colores por rol — lado izquierdo (otros) ── */
.chat-burbuja--otro.chat-burbuja--rol-solicitante { background: #dcfce7; color: #14532d; }
.chat-burbuja--otro.chat-burbuja--rol-autorizador { background: #dbeafe; color: #1e3a8a; }
.chat-burbuja--otro.chat-burbuja--rol-encargado   { background: #ede9fe; color: #3b0764; }
.chat-burbuja--otro.chat-burbuja--rol-finanzas    { background: #fef3c7; color: #78350f; }

/* ── Colores por rol — lado derecho (míos) ── */
.chat-burbuja--mia.chat-burbuja--rol-solicitante  { background: #16a34a; }
.chat-burbuja--mia.chat-burbuja--rol-autorizador  { background: #1d4ed8; }
.chat-burbuja--mia.chat-burbuja--rol-encargado    { background: #7c3aed; }
.chat-burbuja--mia.chat-burbuja--rol-finanzas     { background: #d97706; }
.chat-nombre {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 3px;
}
.chat-msg-texto {
  margin: 0;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg-ts {
  display: block;
  font-size: 10px;
  opacity: .65;
  margin-top: 4px;
  text-align: right;
}

/* ── Mensaje de acción (sistema) ── */
.chat-msg-accion {
  align-self: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  max-width: 92%;
}
.chat-msg-accion .chat-msg-texto {
  font-size: .8rem;
  color: #64748b;
  margin-top: 5px;
  font-style: italic;
}
.chat-msg-meta {
  display: block;
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
}

/* ── Badge de estado (reutilizado en acción) ── */
.chat-accion-badge {
  display: inline-block;
  font-size: .8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1.5px solid;
}

/* ── Banda de acción pendiente ── */
.chat-accion-wrap {
  padding: 10px 14px;
  background: #fafafa;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-accion-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-accion-desc {
  font-size: .8rem;
  color: #64748b;
}

/* ── Banner conversación finalizada ── */
.chat-finalizado-bar {
  padding: 12px 16px;
  background: #fef2f2;
  border-top: 1px solid #fecaca;
  color: #991b1b;
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
}

/* ── Input ── */
.chat-input-area {
  padding: 12px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}
.chat-input-msg {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .875rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  box-sizing: border-box;
  color: #1e293b;
  background: #fff;
}
.chat-input-msg:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,.15);
}
.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.chat-input-count {
  font-size: 11px;
  color: #94a3b8;
  flex-shrink: 0;
}
.chat-accion-btns {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
}

/* ── Tag de rol en burbuja ── */
.chat-rol-tag {
  font-size: 10px;
  font-weight: 600;
  border-radius: 99px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}
.chat-rol-tag--solicitante    { background: #dcfce7; color: #166534; }
.chat-rol-tag--autorizador    { background: #dbeafe; color: #1e40af; }
.chat-rol-tag--encargado      { background: #ede9fe; color: #5b21b6; }
.chat-rol-tag--finanzas       { background: #fef3c7; color: #92400e; }

/* ── Widget sidebar: badge de mensajes no leídos ── */
.chat-widget-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  line-height: 14px;
  border: 2px solid #fff;
}
