/* ============================================================
   CIMA CHAT — Sistema de Mensajería en Tiempo Real
   Estilo: Dark messenger con paleta navy CIMA
   ============================================================ */

/* ── VISTA CHAT ─────────────────────────────────────────── */
.view[data-view="chat"] {
  padding: 0 !important;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0a1628;
}

/* ── LAYOUT PRINCIPAL ───────────────────────────────────── */
.chat-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  overflow: hidden;
}

/* ── SIDEBAR DE CANALES ─────────────────────────────────── */
.chat-channels-panel {
  background: #0d1f3c;
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-channels-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.chat-channels-header h3 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  margin: 0 0 12px 0;
}

.chat-search-box {
  position: relative;
}

.chat-search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: rgba(255,255,255,0.8);
  font-size: 0.82rem;
  outline: none;
  transition: all 0.2s;
}

.chat-search-box input::placeholder { color: rgba(255,255,255,0.28); }
.chat-search-box input:focus {
  background: rgba(255,255,255,0.09);
  border-color: rgba(59,125,216,0.5);
}

.chat-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.4;
}

.chat-channels-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-channels-list::-webkit-scrollbar { width: 3px; }
.chat-channels-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.chat-channel-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
  padding: 12px 8px 4px;
}

.chat-channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s;
  border: 1px solid transparent;
}

.chat-channel-item:hover {
  background: rgba(255,255,255,0.05);
}

.chat-channel-item.active {
  background: rgba(59,125,216,0.18);
  border-color: rgba(59,125,216,0.25);
}

.channel-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.18s;
}

.chat-channel-item.active .channel-icon {
  background: rgba(59,125,216,0.3);
}

.channel-info {
  flex: 1;
  min-width: 0;
}

.channel-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chat-channel-item.active .channel-name {
  color: #fff;
}

.channel-last-msg {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.channel-unread {
  background: #3b7dd8;
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* ── ÁREA PRINCIPAL DE CHAT ─────────────────────────────── */
.chat-main {
  display: flex;
  flex-direction: column;
  background: #0a1628;
  overflow: hidden;
}

/* Header del chat */
.chat-header {
  padding: 14px 20px;
  background: #0d1f3c;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 14px;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3a6e, #0d2248);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
  color: #e8edf5;
  margin: 0;
}

.chat-header-subtitle {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
  margin: 0;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-header-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.18s;
}

.chat-header-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* ── MENSAJES ────────────────────────────────────────────── */
.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.chat-messages-container::-webkit-scrollbar { width: 4px; }
.chat-messages-container::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

/* Separador de fecha */
.chat-date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.chat-date-separator::before,
.chat-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.07);
}

.chat-date-text {
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255,255,255,0.25);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

/* Grupo de mensajes del mismo usuario */
.chat-msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.chat-msg-group.own {
  align-items: flex-end;
}

.chat-msg-group.other {
  align-items: flex-start;
}

/* Cabecera del grupo: avatar + nombre */
.chat-msg-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 4px;
}

.chat-msg-group.own .chat-msg-group-header {
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a6e, #0d2248);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-msg-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
}

.chat-msg-time {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.25);
}

/* ── BURBUJAS ────────────────────────────────────────────── */
.chat-bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  animation: bubbleIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

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

/* Burbuja propia — azul navy */
.chat-msg-group.own .chat-bubble {
  background: linear-gradient(135deg, #1e4fa8 0%, #1639a0 100%);
  color: #ffffff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 12px rgba(30,79,168,0.4);
}

/* Primer/último burbuja del grupo own */
.chat-msg-group.own .chat-bubble:first-of-type { border-top-right-radius: 18px; }
.chat-msg-group.own .chat-bubble:last-of-type  { border-bottom-right-radius: 5px; }
.chat-msg-group.own .chat-bubble:only-child    { border-radius: 18px 18px 5px 18px; }

/* Burbuja de otros — gris azulado */
.chat-msg-group.other .chat-bubble {
  background: #132040;
  color: #d8e2f4;
  border-bottom-left-radius: 5px;
  border: 1px solid rgba(255,255,255,0.07);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.chat-msg-group.other .chat-bubble:only-child { border-radius: 18px 18px 18px 5px; }

/* Imagen en burbuja */
.chat-bubble-img {
  max-width: 260px;
  max-height: 220px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-bubble-img:hover { opacity: 0.9; }

/* Burbuja de imagen sin padding extra */
.chat-bubble.has-image {
  padding: 4px;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* ── MENCIONES ───────────────────────────────────────────── */
.chat-mention {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(59,125,216,0.25);
  border: 1px solid rgba(59,125,216,0.4);
  color: #7db3f5;
  border-radius: 5px;
  padding: 0 5px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.chat-mention:hover {
  background: rgba(59,125,216,0.4);
  color: #a8d0ff;
}

.chat-mention-activity {
  background: rgba(40,167,69,0.2);
  border-color: rgba(40,167,69,0.35);
  color: #6ee08a;
}

.chat-mention-activity:hover {
  background: rgba(40,167,69,0.35);
}

/* ── TYPING INDICATOR ────────────────────────────────────── */
.chat-typing-bar {
  min-height: 28px;
  padding: 4px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-typing-text {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  font-style: italic;
  animation: typingFade 1.4s ease-in-out infinite;
}

@keyframes typingFade {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.85; }
}

.typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  animation: dotBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-4px); background: rgba(255,255,255,0.6); }
}

/* ── INPUT DE MENSAJE ────────────────────────────────────── */
.chat-input-area {
  padding: 12px 16px 16px;
  background: #0d1f3c;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

/* Preview de imagen a subir */
.chat-img-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  margin-bottom: 10px;
  animation: fadeInUp 0.2s ease;
}

.chat-img-preview.visible { display: flex; }

.chat-img-preview img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 7px;
}

.chat-img-preview-name {
  flex: 1;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-img-preview-remove {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(220,53,69,0.2);
  border: none;
  color: #ff6b7a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.15s;
}

.chat-img-preview-remove:hover { background: rgba(220,53,69,0.4); }

/* Popup de menciones */
.chat-mention-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #0d1f3c;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
  animation: popupUp 0.15s ease;
}

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

.chat-mention-popup.visible { display: block; }

.mention-popup-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.mention-popup-item:hover,
.mention-popup-item.focused {
  background: rgba(59,125,216,0.2);
}

.mention-popup-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a6e, #0d2248);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  flex-shrink: 0;
}

.mention-popup-name {
  font-size: 0.83rem;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
}

.mention-popup-sub {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.35);
}

.mention-popup-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 5px;
  margin-left: auto;
}

.mention-popup-badge.usuario  { background: rgba(59,125,216,0.2); color: #7db3f5; }
.mention-popup-badge.actividad { background: rgba(40,167,69,0.2);  color: #6ee08a; }

/* Caja de texto */
.chat-input-box {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input-actions-left {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  padding-bottom: 3px;
}

.chat-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.18s;
  flex-shrink: 0;
}

.chat-action-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.15);
}

.chat-action-btn.active {
  background: rgba(59,125,216,0.25);
  border-color: rgba(59,125,216,0.4);
  color: #7db3f5;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-textarea {
  width: 100%;
  min-height: 42px;
  max-height: 130px;
  padding: 11px 14px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  color: rgba(255,255,255,0.9);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  transition: border-color 0.2s, background 0.2s;
  overflow-y: auto;
}

.chat-textarea::placeholder { color: rgba(255,255,255,0.28); }

.chat-textarea:focus {
  background: rgba(255,255,255,0.08);
  border-color: rgba(59,125,216,0.5);
}

.chat-textarea::-webkit-scrollbar { width: 3px; }
.chat-textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1e4fa8, #1639a0);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.18s;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(30,79,168,0.4);
}

.chat-send-btn:hover {
  background: linear-gradient(135deg, #2860c8, #1e4fa8);
  transform: scale(1.06);
  box-shadow: 0 5px 18px rgba(30,79,168,0.55);
}

.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* ── LIGHTBOX DE IMAGEN ──────────────────────────────────── */
.chat-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.chat-lightbox.visible { display: flex; }

.chat-lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0,0,0,0.8);
}

.chat-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s;
}

.chat-lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* ── EMPTY STATE ─────────────────────────────────────────── */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: rgba(255,255,255,0.2);
}

.chat-empty-icon { font-size: 48px; opacity: 0.4; }

.chat-empty-state h4 {
  font-size: 1rem;
  font-weight: 600;
  color: rgba(255,255,255,0.3);
  margin: 0;
}

.chat-empty-state p {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.18);
  margin: 0;
}

/* ── ESTADO DE CONEXIÓN ──────────────────────────────────── */
.chat-status-bar {
  padding: 4px 16px;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6c757d;
  transition: background 0.3s;
}

.chat-status-dot.connected   { background: #28a745; }
.chat-status-dot.connecting  { background: #ffc107; animation: pulse 1.5s infinite; }
.chat-status-dot.disconnected{ background: #dc3545; }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

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

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-channels-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 280px;
  }

  .chat-channels-panel.mobile-open {
    display: flex;
  }

  .chat-bubble { max-width: 85%; }
}

/* Ocultar chat en vistas que no sean chat */
.view:not([data-view="chat"]) #chatContainer {
  display: none !important;
}