/* ===== 广告展示组件统一样式 ===== */

/* === 新版广告横幅布局样式 (固定布局+自动换行) === */
.ad-banner-container {
  width: 100%;
  margin: 20px 0; /* 减少外边距 */
  padding: 0;
  /* CLS保护：预设最小高度 */
  min-height: 64px; /* 优化最小高度 */
}

.ad-grid-container {
  width: 100%;
  max-width: 1400px; /* 支持1400px宽度 */
  margin: 0 auto;
  padding: 0 15px;
}

.ad-items-wrapper {
  display: grid;
  /* 默认PC端2列布局，JS会根据设备调整 */
  grid-template-columns: repeat(2, 1fr);
  /* 自动换行的关键：grid-auto-rows */
  grid-auto-rows: auto;
  gap: 12px; /* 进一步减小间距 */
  width: 100%;
  /* CLS保护：预设最小高度 */
  min-height: 64px; /* 优化最小高度 */
  transition: grid-template-columns 0.3s ease;
}

/* 广告项目样式 - 支持1400*150比例，但控制实际高度 */
.ad-item {
  position: relative;
  width: 100%;
  background: transparent;
  border-radius: 6px; /* 进一步减小圆角 */
  overflow: hidden;
  transition: all 0.3s ease;
  /* CLS保护：使用aspect-ratio确保稳定的宽高比 */
  aspect-ratio: 1400 / 150; /* 1400*150的比例 */
  height: 64px; /* 优化实际显示高度：桌面端64px */
  max-height: 64px;
}

.ad-item.ad-loaded {
  animation: adFadeIn 0.5s ease-out;
}

/* 广告包装器 */
.ad-item .ad-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.ad-item .ad-wrapper:hover {
  transform: translateY(-1px); /* 减小悬停偏移 */
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08); /* 优化阴影 */
}

/* 广告图片样式 - 优化为1400*150比例 */
.ad-item .ad-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 保持比例并裁剪 */
  display: block;
  border-radius: 6px;
  transition: transform 0.3s ease;
  /* CLS保护：防止图片加载导致的布局偏移 */
  background-color: rgba(255,255,255,0.05); /* 加载时的背景色 */
}

.ad-item .ad-wrapper:hover img {
  transform: scale(1.02);
}

/* 广告遮罩层 */
.ad-item .ad-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.1) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 6px;
  pointer-events: none;
}

.ad-item .ad-wrapper:hover .ad-overlay {
  opacity: 1;
}

/* 加载状态样式 */
.ad-loading-state {
  grid-column: 1 / -1; /* 占满整行 */
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px; /* 优化加载状态高度 */
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  border: 2px dashed rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  font-size: 14px;
}

.loading-spinner i {
  margin-right: 8px;
  animation: adSpin 1s linear infinite;
}

/* 隐藏加载状态（当广告加载完成后） */
.ad-items-wrapper.ads-loaded .ad-loading-state {
  display: none;
}

/* === 图集内页广告强制1列布局 === */
.detail-top-banner .ad-items-wrapper,
.detail-bottom-banner .ad-items-wrapper {
  /* 图集内页：PC端和移动端都使用1列布局 */
  grid-template-columns: 1fr !important;
}

/* === 移动端响应式布局 - 1列+垂直堆叠 === */
@media (max-width: 768px) {
  .ad-banner-container {
    margin: 12px 0; /* 移动端进一步减小外边距 */
    min-height: 48px;
  }
  
  .ad-grid-container {
    padding: 0 8px;
    max-width: 100%;
  }
  
  .ad-items-wrapper {
    /* 移动端：强制1列布局 */
    grid-template-columns: 1fr !important;
    gap: 10px; /* 移动端进一步减小间距 */
    min-height: 48px;
  }
  
  .ad-item {
    height: 48px; /* 移动端优化高度：48px */
    max-height: 48px;
    /* 移动端保持1400*150比例 */
    aspect-ratio: 1400 / 150;
  }
  
  .ad-item .ad-wrapper img {
    height: 48px; /* 移动端图片高度 */
  }
  
  .ad-loading-state {
    height: 48px; /* 移动端加载状态高度 */
    font-size: 12px;
  }
}

/* === 平板端适配 - 保持2列布局 === */
@media (min-width: 769px) and (max-width: 1024px) {
  .ad-grid-container {
    max-width: 1024px;
  }
  
  .ad-items-wrapper {
    /* 平板端：2列布局 */
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }
  
  /* 图集内页在平板端也使用1列布局 */
  .detail-top-banner .ad-items-wrapper,
  .detail-bottom-banner .ad-items-wrapper {
    grid-template-columns: 1fr !important;
  }
  
  .ad-item {
    height: 56px; /* 平板端优化高度：56px */
    max-height: 56px;
  }
  
  .ad-item .ad-wrapper img {
    height: 56px;
  }
}

/* === 大屏幕优化 - 保持2列布局 === */
@media (min-width: 1200px) {
  .ad-grid-container {
    max-width: 1400px; /* 支持1400px宽度 */
  }
  
  .ad-items-wrapper {
    /* 大屏幕：2列布局 */
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px;
  }
  
  /* 图集内页在大屏幕也使用1列布局 */
  .detail-top-banner .ad-items-wrapper,
  .detail-bottom-banner .ad-items-wrapper {
    grid-template-columns: 1fr !important;
  }
  
  .ad-item {
    height: 72px; /* 大屏幕优化高度：72px */
    max-height: 72px;
  }
  
  .ad-item .ad-wrapper img {
    height: 72px; /* 大屏幕使用优化高度 */
  }
}

/* === 超大屏幕支持 - 保持2列布局 === */
@media (min-width: 1600px) {
  .ad-grid-container {
    max-width: 1600px;
  }
  
  .ad-items-wrapper {
    /* 超大屏幕：仍然2列布局 */
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px;
  }
  
  /* 图集内页在超大屏幕也使用1列布局 */
  .detail-top-banner .ad-items-wrapper,
  .detail-bottom-banner .ad-items-wrapper {
    grid-template-columns: 1fr !important;
  }
  
  .ad-item {
    height: 80px; /* 超大屏幕优化高度：80px */
    max-height: 80px;
  }
  
  .ad-item .ad-wrapper img {
    height: 80px;
  }
}

/* === 兼容原有单广告组件样式 === */
.ad_card {
  width: 100%;
  display: block;
  position: relative;
  background: transparent;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.3s ease;
  /* CLS保护 */
  min-height: 64px;
}

.ad_card.ad-container-active {
  animation: adFadeIn 0.5s ease-out;
}

.ad-wrapper {
  position: relative;
  width: 100%;
  display: block;
  background: transparent;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

.ad-wrapper img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  transition: transform 0.3s ease;
  /* CLS保护 */
  background-color: rgba(255,255,255,0.05);
}

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

.ad-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.1) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 6px;
  pointer-events: none;
}

.ad-wrapper:hover .ad-overlay {
  opacity: 1;
}

/* 加载状态样式 */
.ad-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  border: 2px dashed rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.4);
  font-size: 14px;
}

.ad-loading i {
  margin-right: 8px;
  animation: adSpin 1s linear infinite;
}

/* 广告展示动画效果 */
@keyframes adFadeIn {
  from {
    opacity: 0;
    transform: translateY(5px); /* 减小动画偏移 */
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 广告加载动画 */
@keyframes adSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 广告响应式设计 */
@media (max-width: 768px) {
  .ad_card {
    margin: 10px 0; /* 优化外边距 */
    min-height: 48px;
  }
}

/* 广告容器位置特定样式 */
.home-top-banner,
.home-bottom-banner {
  margin: 16px 0; /* 优化外边距 */
}

.detail-top-banner,
.detail-bottom-banner {
  margin: 14px 0;
}

.search-top-banner,
.search-bottom-banner,
.category-top-banner,
.category-bottom-banner,
.tag-top-banner,
.tag-bottom-banner,
.ranking-top-banner,
.ranking-bottom-banner {
  margin: 12px 0;
}

/* 移动端广告间距调整 */
@media (max-width: 768px) {
  .home-top-banner,
  .home-bottom-banner {
    margin: 12px 0;
  }
  
  .detail-top-banner,
  .detail-bottom-banner,
  .search-top-banner,
  .search-bottom-banner,
  .category-top-banner,
  .category-bottom-banner,
  .tag-top-banner,
  .tag-bottom-banner,
  .ranking-top-banner,
  .ranking-bottom-banner {
    margin: 10px 0;
  }
}

/* === CLS优化：预加载占位符 === */
.ad-placeholder {
  width: 100%;
  height: 64px; /* 优化占位符高度 */
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.05) 0%, 
    rgba(255,255,255,0.1) 50%, 
    rgba(255,255,255,0.05) 100%);
  background-size: 200% 100%;
  animation: adSkeleton 1.5s ease-in-out infinite;
  border-radius: 6px;
}

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

@media (max-width: 768px) {
  .ad-placeholder {
    height: 48px; /* 移动端占位符高度 */
  }
} 