/* Related Posts Grid Styles */

.newsx-related-posts-section {
    margin: 40px 0;
    padding: 30px 0;
    border-top: 2px solid #e5e5e5;
    clear: both; /* Clear any floats */
}

.newsx-related-posts-header {
    margin-bottom: 25px;
}

.newsx-related-posts-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 20px 0;
    text-transform: uppercase;
    letter-spacing: -0.5px;
}

/* Grid Layout */
.newsx-related-posts-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
}

/* Reset any conflicting styles for cards */
.newsx-related-posts-grid > .newsx-related-post-card {
    width: auto !important;
    max-width: none !important;
    float: none !important;
    margin: 0 !important;
}

/* Card Styles */
.newsx-related-post-card {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    overflow: hidden;
    transition: all 0.3s ease;
    height: 100%;
    width: 100% !important; /* Force full width of grid cell */
    min-width: 0 !important; /* Prevent cards from overflowing grid */
    max-width: 100% !important; /* Ensure it doesn't exceed grid cell */
    display: block !important;
}

.newsx-related-post-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.newsx-related-post-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
}

/* Image */
.newsx-related-post-image {
    width: 100%;
    height: 150px;
    overflow: hidden;
    background: #f5f5f5;
}

.newsx-related-post-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.newsx-related-post-card:hover .newsx-related-post-image img {
    transform: scale(1.05);
}

/* Content */
.newsx-related-post-content {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Category Badge */
.newsx-related-post-category {
    margin-bottom: 8px;
}

.category-badge {
    display: inline-block;
    padding: 3px 8px;
    background: #d32f2f;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 2px;
    letter-spacing: 0.5px;
}

/* Title */
.newsx-related-post-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    margin: 0 0 10px 0;
    color: #1a1a1a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 2.6em;
}

.newsx-related-post-card:hover .newsx-related-post-title {
    color: #d32f2f;
}

/* Excerpt */
.newsx-related-post-excerpt {
    font-size: 0.875rem;
    line-height: 1.4;
    color: #666;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Meta */
.newsx-related-post-meta {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
}

.newsx-related-post-date {
    font-size: 0.8rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tablet View (2x2 grid) */
@media (max-width: 1024px) and (min-width: 641px) {
    .newsx-related-posts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }
    
    .newsx-related-post-image {
        height: 180px;
    }
}

/* Mobile View (2x2 grid or single column) */
@media (max-width: 640px) {
    .newsx-related-posts-section {
        margin: 30px 0;
        padding: 20px 0;
    }
    
    .newsx-related-posts-title {
        font-size: 1.25rem;
    }
    
    .newsx-related-posts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 15px;
    }
    
    .newsx-related-post-image {
        height: 120px;
    }
    
    .newsx-related-post-content {
        padding: 10px;
    }
    
    .newsx-related-post-title {
        font-size: 0.9rem;
    }
    
    .newsx-related-post-excerpt {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
    }
    
    .category-badge {
        font-size: 0.7rem;
        padding: 2px 6px;
    }
}

/* Very small mobile (single column) */
@media (max-width: 480px) {
    .newsx-related-posts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .newsx-related-post-image {
        height: 200px;
    }
}

/* Dark Mode Support */
.newsx-dark-mode .newsx-related-posts-section {
    border-top-color: #333;
}

.newsx-dark-mode .newsx-related-posts-title {
    color: #fff;
}

.newsx-dark-mode .newsx-related-post-card {
    background: #1a1a1a;
    border-color: #333;
}

.newsx-dark-mode .newsx-related-post-title {
    color: #fff;
}

.newsx-dark-mode .newsx-related-post-card:hover .newsx-related-post-title {
    color: #ff5252;
}

.newsx-dark-mode .newsx-related-post-excerpt {
    color: #aaa;
}

.newsx-dark-mode .newsx-related-post-meta {
    border-top-color: #333;
}

.newsx-dark-mode .newsx-related-post-date {
    color: #777;
}

/* No posts fallback */
.newsx-related-posts-section:empty {
    display: none;
}