/* components.css */
/* Buttons */
.btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: none;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: var(--glow-green);
}

.btn-danger {
  background-color: var(--danger-color);
  color: #fff;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background-color: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

/* Badges */
.badge {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge-online { background-color: rgba(34, 197, 94, 0.2); color: var(--success-color); }
.badge-offline { background-color: rgba(239, 68, 68, 0.2); color: var(--danger-color); }
.badge-connecting { background-color: rgba(245, 158, 11, 0.2); color: var(--warning-color); }

/* Inputs */
.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background-color: rgba(0,0,0,0.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: border-color var(--transition-fast);
}
.input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.input-search {
  padding-left: 2.5rem;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>');
  background-repeat: no-repeat;
  background-position: 0.75rem center;
}

/* Chat Messages */
.message-bubble {
  max-width: 75%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  position: relative;
  word-wrap: break-word;
}
.message-sent {
  align-self: flex-end;
  background-color: var(--sent-bubble);
  border-bottom-right-radius: 4px;
}
.message-received {
  align-self: flex-start;
  background-color: var(--received-bubble);
  border-bottom-left-radius: 4px;
}
.message-meta {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.6);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.message-image img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Contacts */
.contact-item {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  transition: background-color var(--transition-fast);
}
.contact-item:hover, .contact-item.active {
  background-color: rgba(255,255,255,0.05);
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--secondary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  margin-right: var(--space-3);
  position: relative;
}
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: 600; margin-bottom: 2px; }
.contact-preview { font-size: var(--text-sm); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--sidebar-bg);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-elevated);
  max-width: 500px;
  width: 90%;
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}
.modal-overlay.active .modal { transform: translateY(0); }

/* QR Container */
.qr-container {
  background: #fff;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  display: inline-block;
  margin: var(--space-4) 0;
}
.qr-container img { width: 250px; height: 250px; }

/* Diagnostics */
.metric-card {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}
.metric-header { display: flex; justify-content: space-between; margin-bottom: var(--space-2); color: var(--text-secondary); font-size: var(--text-sm); }
.metric-value { font-size: var(--text-xl); font-weight: 700; }
.log-entry { font-family: var(--font-mono); font-size: var(--text-xs); padding: 4px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.log-info { color: #60a5fa; }
.log-warn { color: var(--warning-color); }
.log-error { color: var(--danger-color); }

/* Toasts */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--sidebar-bg); border-left: 4px solid var(--primary-color); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); color: var(--text-primary); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-secondary);
}
.empty-state svg { width: 64px; height: 64px; margin-bottom: var(--space-4); opacity: 0.5; }

/* Typing indicator */
.typing-indicator span {
  display: inline-block; width: 6px; height: 6px; background-color: var(--text-secondary); border-radius: 50%; animation: typing 1.4s infinite ease-in-out both; margin: 0 2px;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ── Multimedia en el chat ────────────────────────────────────────────────
 * Los adjuntos se descargan por fetch autenticado y se insertan como object
 * URL (ver public/js/media.js), así que hay un lapso entre que se dibuja la
 * burbuja y que aparece el contenido: estos estilos cubren ese estado.
 */
.media-loading {
  min-width: 180px;
  min-height: 120px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md, 10px);
  animation: media-pulse 1.4s ease-in-out infinite;
}

audio.media-loading,
video.media-loading {
  min-height: 40px;
}

@keyframes media-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.8; }
}

.media-error-text {
  display: inline-block;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: rgba(255, 190, 190, 0.9);
  background: rgba(240, 85, 95, 0.12);
  border: 1px solid rgba(240, 85, 95, 0.3);
  border-radius: var(--radius-md, 10px);
}

@media (prefers-reduced-motion: reduce) {
  .media-loading { animation: none; }
}

/* ── Tamaño de los adjuntos en la burbuja ─────────────────────────────────
 * El estilo anterior solo limitaba el ancho. Una foto vertical se renderizaba
 * a su altura completa, empujaba el cuadro de respuesta fuera de la pantalla
 * y dejaba el chat sin forma de escribir.
 */
.chat-media-img {
  display: block;
  max-width: 260px;
  max-height: 260px;
  width: auto;
  height: auto;
  object-fit: cover;
  border-radius: var(--radius-md, 10px);
  margin-bottom: var(--space-2, 8px);
}

.chat-media-video {
  display: block;
  max-width: 280px;
  max-height: 280px;
  border-radius: var(--radius-md, 10px);
  margin-bottom: var(--space-2, 8px);
}

.chat-media-audio {
  display: block;
  width: 240px;
  max-width: 100%;
  margin-bottom: var(--space-2, 8px);
}

/* ── Visor de imagen ──────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 20px;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(3px);
  animation: lightbox-in 0.18s ease-out;
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox-img {
  max-width: min(92vw, 1100px);
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease;
}

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

.lightbox-hint {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
}

/* Congela el scroll del chat mientras el visor está abierto. */
body.lightbox-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .lightbox { animation: none; }
}
