/*
Theme Name: GeneratePress Child
Template: generatepress
Version: 1.0.1
*/

@import url("../generatepress/style.css");

/* Performance Optimizations */
* {
    box-sizing: border-box;
}

/* Use CSS containment for better performance */
.post-grid-container {
    contain: layout style;
}

.post-card {
    contain: layout style paint;
}

/* Grid Layout Styles - Optimized */
.post-grid-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.post-grid-header {
    text-align: center;
    margin-bottom: 3rem;
}

.post-grid-title {
    font-size: clamp(1.875rem, 4vw, 2.5rem); /* Responsive font size */
    font-weight: bold;
    color: #1a202c;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.post-grid-description {
    font-size: clamp(1rem, 2vw, 1.125rem);
    color: #718096;
    max-width: 32rem;
    margin: 0 auto;
    line-height: 1.6;
}

/* Category Filters - Optimized */
.category-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.category-filter-btn {
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease; /* Faster transition */
    background-color: #e2e8f0;
    color: #4a5568;
    will-change: background-color, color; /* Optimize for animations */
}

.category-filter-btn:hover {
    background-color: #cbd5e0;
    transform: translateY(-1px);
}

.category-filter-btn.active {
    background-color: #3182ce;
    color: white;
}

/* Posts Grid - Performance Optimized */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    contain: layout; /* CSS containment */
}

.post-card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.2s ease; /* Faster transition */
    transform: translateY(0);
    display: flex;
    flex-direction: column;
    height: 100%;
    will-change: transform, box-shadow; /* Optimize for animations */
}

.post-card:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px);
}

/* Image Optimization */
.post-card-image {
    position: relative;
    overflow: hidden;
    height: 12rem;
    flex-shrink: 0;
    background-color: #f7fafc; /* Placeholder color */
}

.post-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
    cursor: pointer;
    will-change: transform;
}

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

.post-category-badge {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background-color: #3182ce;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.2s ease;
    z-index: 2;
}

.post-category-badge:hover {
    background-color: #2c5aa0;
    color: white;
    text-decoration: none;
}

/* Content Optimization */
.post-card-content {
    padding: 1.5rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.post-card-title {
    font-size: 1.25rem;
    font-weight: bold;
    color: #1a202c;
    margin-bottom: 0.75rem;
    line-height: 1.4;
    transition: color 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-card-title:hover {
    color: #3182ce;
}

.post-card-excerpt {
    color: #718096;
    margin-bottom: 1rem;
    line-height: 1.6;
    flex-grow: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 4.8rem;
}

.post-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    color: #a0aec0;
    padding: 0 1.5rem 1.5rem 1.5rem;
    flex-shrink: 0;
}

.post-meta-left {
    display: flex;
    gap: 1rem;
}

.post-meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.post-meta-item a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.post-meta-item a:hover {
    color: #3182ce;
    text-decoration: underline;
}

.meta-icon {
    font-size: 0.875rem;
}

/* Modal Styles - Performance Optimized */
.post-modal-overlay {
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease; /* Faster transition */
    backdrop-filter: blur(2px); /* Modern blur effect */
}

.post-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.post-modal {
    background: white;
    border-radius: 0.5rem;
    max-width: 56rem;
    max-height: 90vh;
    overflow: hidden;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.2s ease;
    width: 100%;
    contain: layout style; /* CSS containment */
}

.post-modal-overlay.active .post-modal {
    transform: scale(1);
}

.post-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
    background: white;
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s ease;
    font-size: 1.5rem;
    color: #666;
}

.post-modal-close:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.post-modal-content {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scroll-behavior: smooth; /* Smooth scrolling */
}

/* Optimize scrollbar */
.post-modal-content::-webkit-scrollbar {
    width: 8px;
}

.post-modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.post-modal-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.post-modal-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.post-category-badge-header {
    display: inline-block;
    background-color: #3182ce;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1rem;
}

.post-modal-header {
    padding: 2rem 2rem 1rem 2rem;
}

.post-modal-title {
    font-size: clamp(1.5rem, 3vw, 1.875rem);
    font-weight: bold;
    color: #1a202c;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.post-modal-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: #a0aec0;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
}

.post-modal-body {
    padding: 0 2rem 2rem 2rem;
    color: #4a5568;
    line-height: 1.7;
}

/* Typography Optimization */
.post-modal-body h2 {
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
    font-weight: bold;
    color: #1a202c;
    margin: 2rem 0 1rem 0;
}

.post-modal-body h3 {
    font-size: clamp(1.125rem, 2vw, 1.25rem);
    font-weight: 600;
    color: #2d3748;
    margin: 1.5rem 0 0.75rem 0;
}

.post-modal-body p {
    margin-bottom: 1rem;
}

.post-modal-body ul,
.post-modal-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.post-modal-body li {
    margin-bottom: 0.5rem;
}

.post-modal-body blockquote {
    border-left: 4px solid #3182ce;
    padding-left: 1rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: #4a5568;
    background-color: #f7fafc;
    padding: 1rem;
    border-radius: 0.25rem;
}

.post-modal-body code {
    background-color: #f7fafc;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.post-modal-body pre {
    background-color: #f7fafc;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.post-modal-body pre code {
    background-color: transparent;
    padding: 0;
}

.post-modal-body a {
    color: #3182ce;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.post-modal-body a:hover {
    color: #2c5aa0;
}

.post-modal-body img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1rem 0;
    loading: lazy; /* Native lazy loading */
}

body.modal-open {
    overflow: hidden;
}

/* Loading and Error States - Optimized */
.modal-loading,
.modal-error,
.grid-loading,
.grid-error {
    padding: 2rem;
    text-align: center;
    color: #4a5568;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.modal-error,
.grid-error {
    color: #e53e3e;
}

/* Add loading animation */
.modal-loading::after,
.grid-loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #3182ce;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Load More Button - Optimized */
.load-more-container {
    text-align: center;
    margin-top: 3rem;
    margin-bottom: 2rem;
}

.load-more-btn {
    background-color: #3182ce;
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    will-change: transform, box-shadow;
}

.load-more-btn:hover:not(:disabled) {
    background-color: #2c5aa0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.load-more-btn:disabled {
    background-color: #a0aec0;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Fade in animation for new posts */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.post-card.fade-in {
    animation: fadeInUp 0.3s ease forwards;
}

/* Responsive Design - Optimized */
@media (max-width: 768px) {
    .post-modal-overlay {
        top: 60px;
        padding: 0.5rem;
    }
    
    .post-modal-content {
        max-height: calc(100vh - 100px);
    }
    
    .posts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .category-filters {
        justify-content: flex-start;
        gap: 0.25rem;
    }
    
    .category-filter-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
    
    .post-card-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .post-modal {
        margin: 0.5rem;
        max-height: 95vh;
    }
    
    .post-modal-header {
        padding: 1.5rem 1.5rem 1rem 1.5rem;
    }
    
    .post-modal-body {
        padding: 0 1.5rem 1.5rem 1.5rem;
    }
    
    .post-modal-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .load-more-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.875rem;
    }
    
    .post-card-image {
        height: 10rem;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .post-card {
        border: 2px solid #000;
    }
    
    .category-filter-btn {
        border: 1px solid #000;
    }
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: dark) {
    .post-grid-container {
        color: #e2e8f0;
    }
    
    .post-card {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .post-modal {
        background: #2d3748;
        color: #e2e8f0;
    }
}