/**
 * Blog Featured Images CSS
 * 
 * Modern, responsive styles for blog featured images with 4:3 aspect ratio.
 * Handles various source image ratios gracefully across all devices.
 * 
 * @version 1.0.0
 */

/* ============================================
   RESET OLD STYLES FROM style.css
   ============================================ */

/* AGGRESSIVE RESET: Override all old styles that cause text overlay issues */

/* Reset article-card structure */
.blog-preview .article-card {
  position: relative !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 0 !important;
  padding-top: 0 !important;
  gap: 0 !important;
  margin: 0 !important;
}

/* Reset article-image completely */
.blog-preview .article-card .article-image {
  position: relative !important;
  height: auto !important;
  display: block !important;
  flex: none !important;
  align-items: initial !important;
  justify-content: initial !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 12px 12px 0 0 !important;
}

/* Reset article-content */
.blog-preview .article-card .article-content {
  position: relative !important;
  display: block !important;
  flex: none !important;
  margin: 0 !important;
}

/* Hide old article-icon */
.blog-preview .article-card .article-icon {
  display: none !important;
}

/* General fallback for any article-card */
.article-card .article-image {
  height: auto !important;
  display: block !important;
}

.article-card {
  padding-top: 0 !important;
  gap: 0 !important;
}

/* ============================================
   ASPECT RATIO CONTAINERS
   ============================================ */

/**
 * Base aspect ratio container
 * Uses modern aspect-ratio property with fallback for older browsers
 */
.blog-image-container {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f5f5f5;
  border-radius: 8px;
  
  /* Modern browsers: native aspect-ratio - 4:3 */
  aspect-ratio: 4 / 3;
}

/* Fallback for browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 4 / 3) {
  .blog-image-container {
    padding-bottom: 75%; /* 4:3 ratio */
  }
  
  .blog-image-container img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

/**
 * Featured image styling
 * Uses object-fit to handle various aspect ratios gracefully
 */
.blog-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  
  /* Smooth rendering */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  
  /* Performance optimization */
  transform: translateZ(0);
  will-change: transform;
  
  /* Smooth transitions */
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.3s ease;
}

/* ============================================
   HOVER EFFECTS
   ============================================ */

.blog-image-container:hover img {
  transform: scale(1.05);
}

/* Optional overlay on hover */
.blog-image-container::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.1) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  border-radius: 8px;
}

.blog-image-container:hover::after {
  opacity: 1;
}

/* ============================================
   HOME PAGE - BLOG PREVIEW SECTION
   ============================================ */

.blog-preview .article-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  
  /* Override old padding from style.css */
  padding-top: 0 !important;
  gap: 0 !important;
}

.blog-preview .article-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* Remove old article-icon styling */
.blog-preview .article-icon {
  display: none;
}

/* Article image container in blog preview */
.blog-preview .article-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f5f5f5;
  
  /* 4:3 aspect ratio */
  aspect-ratio: 4 / 3;
  
  /* Override old fixed height from style.css */
  height: auto !important;
  
  /* Reset old styles */
  display: block !important;
  padding-top: 0 !important;
}

/* Fallback for older browsers */
@supports not (aspect-ratio: 4 / 3) {
  .blog-preview .article-image {
    padding-bottom: 75%;
  }
  
  .blog-preview .article-image img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.blog-preview .article-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.blog-preview .article-card:hover .article-image img {
  transform: scale(1.05);
}

/* Placeholder for articles without images */
.blog-preview .article-image--placeholder {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.blog-preview .article-image--placeholder::before {
  content: '📝';
  font-size: 3rem;
  opacity: 0.5;
}

/* Article content styling */
.blog-preview .article-content {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.blog-preview .article-content h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  color: #1a1a1a;
}

.blog-preview .article-content p {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #666;
  flex: 1;
}

.blog-preview .article-link {
  display: inline-flex;
  align-items: center;
  color: #e74c3c;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.2s ease;
}

.blog-preview .article-link:hover {
  color: #c0392b;
}

.blog-preview .article-link::after {
  content: '→';
  margin-left: 0.5rem;
  transition: transform 0.2s ease;
}

.blog-preview .article-link:hover::after {
  transform: translateX(4px);
}

/* ============================================
   BLOG LIST PAGE - BLOG CARDS
   ============================================ */

.blog-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  height: 100%;
}

.blog-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.blog-card-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f5f5f5;
  
  /* 4:3 aspect ratio */
  aspect-ratio: 4 / 3;
  
  /* Override any fixed height from other stylesheets */
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

/* Fallback for older browsers */
@supports not (aspect-ratio: 4 / 3) {
  .blog-card-image {
    padding-bottom: 75%;
    height: 0 !important;
  }
  
  .blog-card-image img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.blog-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.blog-card:hover .blog-card-image img {
  transform: scale(1.05);
}

.blog-card-content {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.blog-card-header {
  margin-bottom: 1rem;
}

.blog-card-title {
  margin: 0 0 0.75rem 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
}

.blog-card-title a {
  color: #1a1a1a;
  text-decoration: none;
  transition: color 0.2s ease;
}

.blog-card-title a:hover {
  color: #e74c3c;
}

.blog-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.875rem;
  color: #666;
}

.blog-card-meta time {
  display: inline-flex;
  align-items: center;
}

.blog-card-category a {
  color: #e74c3c;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.blog-card-category a:hover {
  color: #c0392b;
}

.blog-card-excerpt {
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #444;
  flex: 1;
}

.blog-card-footer {
  margin-top: auto;
}

.blog-card-link {
  display: inline-flex;
  align-items: center;
  color: #e74c3c;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.2s ease;
}

.blog-card-link:hover {
  color: #c0392b;
}

.blog-card-link::after {
  content: '';
  margin-left: 0.5rem;
  transition: transform 0.2s ease;
}

.blog-card-link:hover::after {
  transform: translateX(4px);
}

/* ============================================
   BLOG ARTICLE PAGE - FEATURED IMAGE
   ============================================ */

.article-featured-image {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  
  /* 4:3 aspect ratio for article hero */
  aspect-ratio: 4 / 3;
}

/* Fallback for older browsers */
@supports not (aspect-ratio: 4 / 3) {
  .article-featured-image {
    padding-bottom: 75%;
  }
  
  .article-featured-image img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.article-featured-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* ============================================
   RELATED ARTICLES
   ============================================ */

.related-image {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f5f5f5;
  border-radius: 8px;
  
  /* 4:3 aspect ratio */
  aspect-ratio: 4 / 3;
}

/* Fallback for older browsers */
@supports not (aspect-ratio: 4 / 3) {
  .related-image {
    padding-bottom: 75%;
  }
  
  .related-image img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.related-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.3s ease;
}

.related-card:hover .related-image img {
  transform: scale(1.05);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet */
@media (max-width: 768px) {
  .blog-card-title {
    font-size: 1.25rem;
  }
  
  .blog-preview .article-content h3 {
    font-size: 1.125rem;
  }
  
  .blog-card-content,
  .blog-preview .article-content {
    padding: 1.25rem;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .blog-card-title {
    font-size: 1.125rem;
  }
  
  .blog-preview .article-content h3 {
    font-size: 1rem;
  }
  
  .blog-card-content,
  .blog-preview .article-content {
    padding: 1rem;
  }
  
  .blog-card-meta {
    font-size: 0.8125rem;
  }
  
  /* Keep 4:3 aspect ratio on mobile (same as desktop) */
  .blog-preview .article-image,
  .blog-card-image {
    aspect-ratio: 4 / 3;
    height: auto !important; /* Override any fixed heights */
  }
  
  @supports not (aspect-ratio: 4 / 3) {
    .blog-preview .article-image,
    .blog-card-image {
      padding-bottom: 75%; /* 4:3 ratio */
      height: 0 !important;
    }
  }
  
  /* Ensure article card structure is correct on mobile */
  .blog-preview .article-card {
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
  }
  
  /* Ensure image is first, content is second */
  .blog-preview .article-image {
    order: 1;
    position: relative !important;
    margin: 0 !important;
  }
  
  .blog-preview .article-content {
    order: 2;
    position: relative !important;
    margin: 0 !important;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus styles for keyboard navigation */
.blog-card:focus-within {
  outline: 3px solid #e74c3c;
  outline-offset: 2px;
}

.blog-card-title a:focus,
.blog-card-link:focus,
.article-link:focus {
  outline: 2px solid #e74c3c;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .blog-image-container img,
  .blog-card,
  .blog-preview .article-card,
  .blog-card-image img,
  .blog-preview .article-image img,
  .related-image img {
    transition: none;
  }
  
  .blog-card:hover,
  .blog-preview .article-card:hover {
    transform: none;
  }
  
  .blog-card:hover .blog-card-image img,
  .blog-preview .article-card:hover .article-image img,
  .related-card:hover .related-image img {
    transform: none;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .blog-image-container,
  .blog-card-image,
  .article-featured-image,
  .related-image {
    page-break-inside: avoid;
    box-shadow: none;
  }
  
  .blog-card:hover,
  .blog-preview .article-card:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
}

/* ============================================
   LOADING STATES
   ============================================ */

/* Skeleton loading animation for images */
.blog-image-container.loading,
.blog-card-image.loading,
.article-image.loading {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Hide img during loading */
.blog-image-container.loading img,
.blog-card-image.loading img,
.article-image.loading img {
  opacity: 0;
}


/* ============================================
   CRITICAL MOBILE FIX - MUST BE LAST
   ============================================ */

/* Ultra-specific mobile fix to prevent text overlay */
@media (max-width: 768px) {
  /* Force correct card structure */
  .blog-preview .article-card,
  section.blog-preview .article-card,
  .blog-preview .articles-grid .article-card {
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  /* Force image to be block element at top */
  .blog-preview .article-card .article-image,
  section.blog-preview .article-card .article-image,
  .blog-preview .articles-grid .article-card .article-image {
    position: relative !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    flex: none !important;
    order: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
  }
  
  /* Force content to be below image */
  .blog-preview .article-card .article-content,
  section.blog-preview .article-card .article-content,
  .blog-preview .articles-grid .article-card .article-content {
    position: relative !important;
    display: block !important;
    width: 100% !important;
    flex: none !important;
    order: 2 !important;
    margin: 0 !important;
    padding: 1.5rem !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
  }
  
  /* Ensure h3 and links are not absolutely positioned */
  .blog-preview .article-content h3,
  .blog-preview .article-content h3 a,
  .blog-preview .article-content p,
  .blog-preview .article-content .article-link {
    position: relative !important;
    display: block !important;
    margin-bottom: 0.75rem !important;
  }
  
  /* Ensure image img tag is properly sized */
  .blog-preview .article-image img {
    position: relative !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
  }
}


/* ============================================
   RESPONSIVE FIXES - PREVENT TITLE OVERLAP
   ============================================ */

/* Ensure proper card structure and spacing */
.blog-preview .article-card,
.blog-card {
  display: flex !important;
  flex-direction: column !important;
  position: relative !important;
}

/* Ensure image container doesn't collapse */
.blog-preview .article-image,
.blog-card-image {
  flex-shrink: 0 !important;
  position: relative !important;
  z-index: 1 !important;
}

/* Ensure content stays below image */
.blog-preview .article-content,
.blog-card-content {
  position: relative !important;
  z-index: 2 !important;
  margin-top: 0 !important;
  padding-top: 1.5rem !important;
}

/* Additional responsive breakpoints for title spacing */
@media (max-width: 1024px) {
  .blog-preview .article-content h3,
  .blog-card-title {
    font-size: 1.125rem !important;
    line-height: 1.4 !important;
    margin-bottom: 0.75rem !important;
  }
  
  .blog-preview .article-content,
  .blog-card-content {
    padding: 1.25rem !important;
  }
}

@media (max-width: 768px) {
  .blog-preview .article-content h3,
  .blog-card-title {
    font-size: 1rem !important;
    line-height: 1.4 !important;
    margin-bottom: 0.5rem !important;
  }
  
  .blog-preview .article-content,
  .blog-card-content {
    padding: 1rem !important;
  }
}

@media (max-width: 480px) {
  .blog-preview .article-content h3,
  .blog-card-title {
    font-size: 0.95rem !important;
    line-height: 1.3 !important;
    margin-bottom: 0.5rem !important;
  }
  
  .blog-preview .article-content,
  .blog-card-content {
    padding: 0.875rem !important;
  }
}

/* Fix for specific responsive views (tablets in portrait) */
@media (min-width: 481px) and (max-width: 900px) {
  .blog-preview .article-image,
  .blog-card-image {
    aspect-ratio: 4 / 3 !important;
  }
  
  @supports not (aspect-ratio: 4 / 3) {
    .blog-preview .article-image,
    .blog-card-image {
      padding-bottom: 75% !important;
      height: 0 !important;
    }
  }
  
  .blog-preview .article-content h3,
  .blog-card-title {
    margin-top: 0 !important;
    padding-top: 0 !important;
  }
}

/* Ensure no absolute positioning conflicts */
.blog-preview .article-content h3,
.blog-preview .article-content h3 a,
.blog-card-title,
.blog-card-title a {
  position: relative !important;
  display: block !important;
}

/* Clear any floats that might cause overlap */
.blog-preview .article-image::after,
.blog-card-image::after {
  content: '';
  display: table;
  clear: both;
}
