/* --- Estilos modernos para chat flotante --- */
.chat-popup-window.chat-modern {
  position: fixed;
  bottom: 100px;
  right: 390px; /* FIX: a la izquierda del panel (340px + margen) */
  width: 340px;
  max-width: 90vw;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 2px 16px #0003;
  display: flex;
  flex-direction: column;
  z-index: 10000;
  font-family: inherit;
  transition: height 0.2s ease;
}

/* Minimizado */
.chat-popup-window.chat-modern.chat-minimized .chat-popup-body,
.chat-popup-window.chat-modern.chat-minimized .chat-popup-footer {
  display: none;
}
.chat-popup-window.chat-modern.chat-minimized {
  border-radius: 16px;
}

.chat-popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #2563eb;
  color: #fff;
  padding: 10px 16px;
  border-radius: 16px 16px 0 0;
  font-weight: 600;
  cursor: pointer; /* clickeable para minimizar */
}
.chat-popup-window.chat-modern.chat-minimized .chat-popup-header {
  border-radius: 16px;
}
.chat-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1em;
  font-weight: bold;
}
.chat-user-name {
  flex: 1;
}
.chat-minimize-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2em;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.chat-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5em;
  cursor: pointer;
}

/* Badge contador de mensajes no leídos en el header */
.chat-header-badge {
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  font-size: 0.75em;
  padding: 2px 7px;
  font-weight: bold;
  display: none;
}
.chat-header-badge.visible {
  display: inline-block;
}

.chat-popup-body {
  flex: 1;
  padding: 12px;
  background: #f3f4f6;
  overflow-y: auto;
  min-height: 180px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
}
.chat-popup-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}
.chat-popup-footer input[type="text"] {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 1em;
  outline: none;
}
.chat-send-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-send-btn:hover {
  background: #174bbd;
}

/* Mensajes */
.chat-popup-message {
  display: flex;
  margin-bottom: 8px;
}
.chat-msg-own {
  justify-content: flex-end;
}
.chat-msg-other {
  justify-content: flex-start;
}
.chat-msg-bubble {
  padding: 8px 14px;
  border-radius: 16px;
  max-width: 75%;
  box-shadow: 0 1px 4px #0001;
  word-break: break-word;
}
.chat-msg-own .chat-msg-bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-other .chat-msg-bubble {
  background: #e5e7eb;
  color: #222;
  border-bottom-left-radius: 4px;
}
.chat-msg-content {
  font-size: 1em;
  margin-bottom: 2px;
}
.chat-msg-time {
  font-size: 0.75em;
  opacity: 0.6;
  text-align: right;
  margin-top: 2px;
}
.chat-msg-own .chat-msg-time { color: #dbeafe; }
.chat-msg-other .chat-msg-time { color: #888; }

/* Sidebar items */
.chat-sidebar-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}
.chat-sidebar-item:hover { background: #f3f4f6; }
.chat-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-title {
  font-weight: 600;
  font-size: 0.95em;
  color: #1e3a8a;
}
.chat-last-msg {
  font-size: 0.87em;
  color: #555;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.chat-last-time {
  font-size: 0.8em;
  color: #aaa;
  float: right;
}
.chat-unread-badge {
  background: #2563eb;
  color: #fff;
  border-radius: 50%;
  font-size: 0.75em;
  padding: 2px 7px;
  font-weight: bold;
}
.chat-typing-indicator {
  font-size: 0.85em;
  color: #888;
  font-style: italic;
}
.chat-popup-highlight {
  box-shadow: 0 0 0 3px #2563eb88;
  transition: box-shadow 0.3s;
}
.empty {
  color: #aaa;
  text-align: center;
  padding: 24px;
  font-size: 0.95em;
}