/**
 * Admin Loading System - CSS Modernizado
 * Sistema de loading centralizado y estético para AdminApp v2.1
 */

/* ========================================
   LOADING OVERLAY PRINCIPAL
   ======================================== */

/* Loading overlay del admin - compatibilidad con diseño existente */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#loading-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Contenedor de loading mejorado */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  background: white;
  border-radius: 16px;
  box-shadow: 
    0 10px 40px rgba(0, 0, 0, 0.1),
    0 4px 20px rgba(0, 0, 0, 0.05);
  max-width: 320px;
  text-align: center;
  transform: translateY(-20px);
  animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* ========================================
   LOADING DOTS MODERNOS
   ======================================== */

.loading-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.loading-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tenant-primary, #007bff);
  display: inline-block;
  animation: loading-dots-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0s;
}

@keyframes loading-dots-bounce {
  0%, 80%, 100% {
    transform: scale(0.7);
    opacity: 0.6;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

/* ========================================
   LOADING TEXT MEJORADO
   ======================================== */

.loading-text {
  font-family: var(--font-family, system-ui, -apple-system, sans-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text, #333);
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.4;
  opacity: 0;
  animation: fadeInText 0.6s ease 0.3s forwards;
}

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

/* ========================================
   LOADING SPINNER MEJORADO
   ======================================== */

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.loading-spinner-element,
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(var(--tenant-primary-rgb, 0, 123, 255), 0.2);
  border-top: 3px solid var(--tenant-primary, #007bff);
  border-radius: 50%;
  animation: modern-spin 1s linear infinite;
}

/* Variaciones de tamaño para spinner */
.loading-spinner.size-sm .spinner {
  width: 24px;
  height: 24px;
  border-width: 2px;
}

.loading-spinner.size-lg .spinner {
  width: 56px;
  height: 56px;
  border-width: 4px;
}

@keyframes modern-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* ========================================
   LOADING INLINE PARA MÓDULOS
   ======================================== */

.module-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  min-height: 200px;
  background: var(--color-surface, #f8f9fa);
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--color-border, #e9ecef);
}

.module-loading .loading-spinner {
  margin-bottom: 16px;
}

.module-loading .loading-text {
  font-size: 14px;
  color: var(--color-text-secondary, #6c757d);
}

/* ========================================
   BUTTON LOADING ESTADOS
   ======================================== */

.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: modern-spin 0.8s linear infinite;
}

.btn.loading.btn-outline::before {
  border: 2px solid rgba(var(--tenant-primary-rgb, 0, 123, 255), 0.3);
  border-top: 2px solid var(--tenant-primary, #007bff);
}

/* ========================================
   SKELETON LOADING
   ======================================== */

.skeleton-loading {
  position: relative;
  overflow: hidden;
  background: var(--color-border, #e9ecef);
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm, 4px);
}

.skeleton-line {
  height: 16px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm, 4px);
}

.skeleton-line:last-child {
  width: 60%;
}

.skeleton-title {
  height: 24px;
  width: 40%;
  margin-bottom: 16px;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 6px;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ========================================
   PROGRESS BAR LOADING
   ======================================== */

.progress-loading {
  width: 100%;
  max-width: 300px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border, #e9ecef);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  background: var(--tenant-primary, #007bff);
  border-radius: 3px;
  transition: width 0.3s ease;
  transform-origin: left;
}

.progress-text {
  font-size: 13px;
  color: var(--color-text-secondary, #6c757d);
  text-align: center;
}

/* ========================================
   TABLA LOADING ESTADOS
   ======================================== */

.table-loading {
  position: relative;
}

.table-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(2px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border, #e9ecef);
  border-top: 3px solid var(--tenant-primary, #007bff);
  border-radius: 50%;
  animation: modern-spin 1s linear infinite;
  z-index: 11;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
  .loading-container {
    padding: 24px;
    max-width: 280px;
  }
  
  .loading-text {
    font-size: 14px;
  }
  
  .loading-dots span {
    width: 10px;
    height: 10px;
  }
  
  .loading-spinner-element,
  .spinner {
    width: 32px;
    height: 32px;
    border-width: 2px;
  }
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

@media (prefers-color-scheme: dark) {
  #loading-overlay {
    background: rgba(0, 0, 0, 0.9);
  }
  
  .loading-container {
    background: var(--color-surface-dark, #2d2d2d);
    color: var(--color-text-dark, #ffffff);
  }
  
  .loading-text {
    color: var(--color-text-dark, #ffffff);
  }
  
  .module-loading {
    background: var(--color-surface-dark, #2d2d2d);
    border-color: var(--color-border-dark, #404040);
  }
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */

@media (prefers-contrast: high) {
  .loading-container {
    border: 2px solid;
  }
  
  .loading-dots span {
    border: 1px solid;
  }
}

/* ========================================
   REDUCED MOTION SUPPORT
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  .loading-dots span,
  .loading-spinner-element,
  .spinner,
  .btn.loading::before {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  
  .skeleton-loading {
    animation: none;
    background: var(--color-border, #e9ecef);
  }
  
  .loading-container {
    animation: none;
    transform: none;
  }
  
  .loading-text {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ========================================
   UTILITIES
   ======================================== */

.loading-hidden {
  display: none !important;
}

.loading-visible {
  display: flex !important;
}

.loading-fade-in {
  animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-fade-out {
  animation: fadeOut 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* ========================================
   CONVERSATION SKELETON LOADING - SUBTLE VERSION
   ======================================== */

.conversation-skeleton {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  animation: skeleton-fade-in 0.6s ease-out forwards;
}

.message-skeleton {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 80%;
  opacity: 0.7;
}

.message-skeleton.incoming {
  align-self: flex-start;
}

.message-skeleton.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar-skeleton {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(90deg, 
    rgba(0, 0, 0, 0.03) 25%, 
    rgba(0, 0, 0, 0.05) 50%, 
    rgba(0, 0, 0, 0.03) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer-subtle 2s infinite ease-in-out;
  flex-shrink: 0;
}

.message-content-skeleton {
  background: linear-gradient(90deg, 
    rgba(0, 0, 0, 0.04) 25%, 
    rgba(0, 0, 0, 0.06) 50%, 
    rgba(0, 0, 0, 0.04) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer-subtle 2s infinite ease-in-out;
  border-radius: 18px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 120px;
  border: 1px solid rgba(0, 0, 0, 0.02);
}

.message-skeleton.outgoing .message-content-skeleton {
  background: linear-gradient(90deg, 
    rgba(37, 211, 102, 0.08) 25%, 
    rgba(37, 211, 102, 0.12) 50%, 
    rgba(37, 211, 102, 0.08) 75%);
  background-size: 200% 100%;
  border: 1px solid rgba(37, 211, 102, 0.06);
}

.skeleton-line.short {
  width: 60%;
  height: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  animation: skeleton-line-pulse 1.8s infinite ease-in-out;
}

.skeleton-line.medium {
  width: 80%;
  height: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  animation: skeleton-line-pulse 1.8s infinite ease-in-out 0.2s;
}

.skeleton-line.long {
  width: 95%;
  height: 10px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  animation: skeleton-line-pulse 1.8s infinite ease-in-out 0.4s;
}

/* Animaciones suaves */
@keyframes skeleton-shimmer-subtle {
  0% {
    background-position: -200% 0;
  }
  50% {
    background-position: 0% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes skeleton-line-pulse {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.02);
  }
}

@keyframes skeleton-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Transición suave cuando aparece el contenido real */
.messages-container {
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.messages-container.loading-transition {
  opacity: 0;
  transform: translateY(5px);
}

.messages-container.content-loaded {
  opacity: 1;
  transform: translateY(0);
}
