/**
 * Skeleton Loading para Móviles - Carga Ultra Rápida
 * Muestra placeholders mientras cargan los anuncios reales
 * @version 1.0.0
 * @date 2026-01-10
 */

/* ===================================
   SKELETON BASE - Solo móviles
   =================================== */

@media (max-width: 768px) {
  
  /* Skeleton base animation */
  @keyframes skeleton-shimmer {
    0% {
      background-position: -200% 0;
    }
    100% {
      background-position: 200% 0;
    }
  }
  
  .skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
  }
  
  /* Card skeleton completa */
  .ad-card-skeleton {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
    margin-bottom: 12px;
    height: 380px;
    display: flex;
    flex-direction: column;
  }
  
  /* Imagen skeleton */
  .ad-card-skeleton .skeleton-image {
    width: 100%;
    height: 180px;
    background: linear-gradient(90deg, #e8e8e8 25%, #d8d8d8 50%, #e8e8e8 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
  }
  
  /* Contenido skeleton */
  .ad-card-skeleton .skeleton-content {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  /* Título skeleton */
  .ad-card-skeleton .skeleton-title {
    height: 20px;
    width: 85%;
  }
  
  /* Categoría skeleton */
  .ad-card-skeleton .skeleton-category {
    height: 14px;
    width: 60%;
  }
  
  /* Ubicación skeleton */
  .ad-card-skeleton .skeleton-location {
    height: 12px;
    width: 70%;
  }
  
  /* Precio skeleton */
  .ad-card-skeleton .skeleton-price {
    height: 24px;
    width: 40%;
    margin-top: 8px;
  }
  
  /* Usuario skeleton */
  .ad-card-skeleton .skeleton-user {
    height: 14px;
    width: 50%;
    margin-top: auto;
  }
  
  /* ===================================
     SKELETON PARA LISTA
     =================================== */
  
  .skeleton-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 8px;
  }
  
  /* ===================================
     SKELETON PARA GRID
     =================================== */
  
  .skeleton-grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 8px;
  }
  
  .skeleton-grid-container .ad-card-skeleton {
    height: 280px;
  }
  
  .skeleton-grid-container .skeleton-image {
    height: 120px;
  }
  
  /* ===================================
     LOADING INDICATOR MEJORADO
     =================================== */
  
  .mobile-loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 12px;
  }
  
  .mobile-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: #005F00;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .mobile-loading-text {
    font-size: 14px;
    color: #666;
    text-align: center;
  }
  
  /* ===================================
     LAZY IMAGE PLACEHOLDER
     =================================== */
  
  .lazy-image-placeholder {
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    color: #ccc;
  }
  
  .lazy-image-placeholder::before {
    content: "📷";
    font-size: 32px;
    opacity: 0.5;
  }
  
  /* ===================================
     OPTIMIZACIÓN DE TARJETAS EN MÓVIL
     =================================== */
  
  /* Simplificar bordes y sombras en móvil */
  .card-ospl.ads-thumb-view {
    border-radius: 8px !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
  }
  
  /* Reducir padding en contenido */
  .card-ospl .card-body {
    padding: 10px !important;
  }
  
  /* Optimizar fuentes */
  .card-ospl .task-listing-title {
    font-size: 0.95rem !important;
    line-height: 1.3 !important;
  }
  
  /* ===================================
     CONTENIDO VISIBLE/OCULTO POR CARGA
     =================================== */
  
  /* Ocultar contenido real mientras skeleton visible */
  .ads-loading .ads-real-content {
    opacity: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
  }
  
  .ads-loading .skeleton-container {
    display: block;
  }
  
  /* Mostrar contenido real cuando cargó */
  .ads-loaded .ads-real-content {
    opacity: 1;
    height: auto;
    transition: opacity 0.2s ease-out;
  }
  
  .ads-loaded .skeleton-container {
    display: none;
  }
  
  /* ===================================
     IMAGEN LAZY STATES
     =================================== */
  
  img.mobile-lazy {
    opacity: 0;
    transition: opacity 0.15s ease-out;
    background: #f0f0f0;
  }
  
  img.mobile-lazy.loaded {
    opacity: 1;
    background: transparent;
  }
  
  img.mobile-lazy.error {
    opacity: 0.5;
  }
  
  /* ===================================
     BOTÓN CARGAR MÁS MEJORADO
     =================================== */
  
  #load_more {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    margin: 16px 0;
  }
  
  /* Estado de carga del botón */
  #load_more.loading {
    pointer-events: none;
    opacity: 0.7;
  }
  
  #load_more.loading::after {
    content: " ⏳";
  }
  
  /* ===================================
     NO-SCROLL MIENTRAS CARGA
     =================================== */
  
  body.mobile-loading-ads {
    overflow-y: hidden;
  }
  
  /* ===================================
     PULL TO REFRESH INDICATOR
     =================================== */
  
  .pull-refresh-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: linear-gradient(to bottom, rgba(0,95,0,0.1), transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
  }
  
  .pull-refresh-indicator.visible {
    transform: translateY(0);
  }
  
}

/* ===================================
   DESKTOP: Sin cambios
   =================================== */
@media (min-width: 769px) {
  .ad-card-skeleton,
  .skeleton-container,
  .mobile-loading-indicator {
    display: none !important;
  }
}
