/* ============================================
   CORREÇÃO DE IMAGENS PARA HOME
   Versão: 2.0
   ============================================ */

/* ============================================
   BASE - RESET DAS IMAGENS
   ============================================ */

/* Todas as imagens da home */
.home-image,
.ad-image,
.anuncio-imagem,
.listing-image,
.card-image,
.product-image {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

/* Imagens dentro de containers */
.ad-image-container img,
.anuncio-imagem img,
.listing-image img,
.card-image img,
.product-image img,
.ad-card img,
.product-card img,
.listing-card img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

/* ============================================
   WRAPPER COM ASPECT RATIO FIXO
   ============================================ */

.ad-image-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 75%; /* 4:3 por padrão */
  overflow: hidden;
  background: #1a1a1a;
  border-radius: 8px;
}

.ad-image-wrapper img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.ad-image-wrapper:hover img {
  transform: scale(1.05);
}

/* ============================================
   GRID DE ANÚNCIOS - RESPONSIVO
   ============================================ */

/* Grid base - 2 colunas no mobile */
.ads-grid,
.listing-grid,
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 8px;
}

/* Cards individuais */
.ad-card,
.product-card,
.listing-card {
  background: #1a1a1a;
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid #2a2a2a;
}

.ad-card:hover,
.product-card:hover,
.listing-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border-color: #e6b94d;
}

/* ============================================
   CONTEÚDO DOS CARDS
   ============================================ */

.ad-card-content,
.product-card-content,
.listing-card-content {
  padding: 12px;
}

.ad-card-title,
.product-card-title,
.listing-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 4px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.ad-card-price,
.product-card-price,
.listing-card-price {
  font-size: 16px;
  font-weight: 700;
  color: #e6b94d;
  margin: 4px 0;
}

.ad-card-location,
.product-card-location,
.listing-card-location {
  font-size: 12px;
  color: #888;
  margin: 2px 0;
}

.ad-card-date,
.product-card-date,
.listing-card-date {
  font-size: 11px;
  color: #666;
}

/* ============================================
   RESPONSIVIDADE - TABLET
   ============================================ */

@media (min-width: 481px) and (max-width: 768px) {
  .ads-grid,
  .listing-grid,
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 12px;
  }
  
  .ad-image-wrapper {
    padding-bottom: 70%;
  }
  
  .ad-card-title,
  .product-card-title,
  .listing-card-title {
    font-size: 15px;
  }
  
  .ad-card-price,
  .product-card-price,
  .listing-card-price {
    font-size: 17px;
  }
}

/* ============================================
   RESPONSIVIDADE - DESKTOP
   ============================================ */

@media (min-width: 769px) {
  .ads-grid,
  .listing-grid,
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
  }
  
  .ad-image-wrapper {
    padding-bottom: 65%;
    border-radius: 10px;
  }
  
  .ad-card-content,
  .product-card-content,
  .listing-card-content {
    padding: 16px;
  }
  
  .ad-card-title,
  .product-card-title,
  .listing-card-title {
    font-size: 16px;
  }
  
  .ad-card-price,
  .product-card-price,
  .listing-card-price {
    font-size: 20px;
  }
  
  .ad-card-location,
  .product-card-location,
  .listing-card-location {
    font-size: 13px;
  }
}

/* ============================================
   RESPONSIVIDADE - DESKTOP GRANDE
   ============================================ */

@media (min-width: 1024px) {
  .ads-grid,
  .listing-grid,
  .product-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }
  
  .ad-image-wrapper {
    padding-bottom: 60%;
  }
}

/* ============================================
   RESPONSIVIDADE - MOBILE PEQUENO
   ============================================ */

@media (max-width: 360px) {
  .ads-grid,
  .listing-grid,
  .product-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 6px;
  }
  
  .ad-image-wrapper {
    padding-bottom: 80%;
  }
  
  .ad-card-title,
  .product-card-title,
  .listing-card-title {
    font-size: 13px;
  }
  
  .ad-card-price,
  .product-card-price,
  .listing-card-price {
    font-size: 15px;
  }
}

/* ============================================
   ESTILOS ADICIONAIS
   ============================================ */

/* Placeholder de carregamento */
.image-loading {
  position: relative;
  background: linear-gradient(90deg, #1a1a1a 25%, #2a2a2a 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  min-height: 150px;
}

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

/* Imagem carregada com fade */
.ad-image-wrapper img.loaded,
.ad-image-wrapper img:not([src=""]) {
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Corrigir imagens sem altura definida */
img[src$=".webp"],
img[src$=".jpg"],
img[src$=".jpeg"],
img[src$=".png"] {
  height: auto !important;
  max-width: 100% !important;
  display: block !important;
}

/* Botão de favorito */
.favorite-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.favorite-btn:hover {
  background: #e6b94d;
  color: #000;
  transform: scale(1.1);
}

.favorite-btn.active {
  background: #e6b94d;
  color: #000;
}

/* Badge de destaque */
.featured-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #e6b94d;
  color: #000;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  z-index: 2;
}

/* Badge de urgência */
.urgent-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #ff4444;
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  z-index: 2;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ============================================
   CORREÇÃO PARA ANÚNCIOS ANTIGOS
   ============================================ */

/* Forçar responsividade em imagens antigas */
img[width],
img[height] {
  max-width: 100% !important;
  height: auto !important;
}

/* Remover atributos de tamanho fixo */
img[width]:not([style*="width"]),
img[height]:not([style*="height"]) {
  width: auto;
  height: auto;
}

/* Container para imagens antigas */
.old-ad-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: #1a1a1a;
}

.old-ad-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

/* Fallback para imagens quebradas */
img[src=""]:after,
img[src*="undefined"]:after,
img.error:after {
  content: "📷";
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #1a1a1a;
  color: #444;
  font-size: 48px;
}

/* ============================================
   PERFORMANCE - REDUZIR REPAINT
   ============================================ */

.ad-card,
.product-card,
.listing-card {
  will-change: transform;
  backface-visibility: hidden;
}

.ad-image-wrapper img {
  will-change: transform;
  backface-visibility: hidden;
}

/* ============================================
   DARK MODE COMPATÍVEL
   ============================================ */

@media (prefers-color-scheme: light) {
  .ad-card,
  .product-card,
  .listing-card {
    background: #ffffff;
    border-color: #e0e0e0;
  }
  
  .ad-card-title,
  .product-card-title,
  .listing-card-title {
    color: #1a1a1a;
  }
  
  .ad-card-location,
  .product-card-location,
  .listing-card-location {
    color: #666;
  }
  
  .ad-image-wrapper {
    background: #f0f0f0;
  }
}

/* ============================================
   IMPRESSÃO
   ============================================ */

@media print {
  .ad-image-wrapper img {
    position: relative !important;
    max-width: 100% !important;
    height: auto !important;
  }
  
  .ad-image-wrapper {
    padding-bottom: 0 !important;
    height: auto !important;
  }
}
