/**
 * Recent Posts Block - Frontend & Editor Styles
 */

/*
 * Colours default to the active theme's palette. A sidebar colour writes the
 * matching --rp-* var inline on the block wrapper and wins; leaving it unset
 * falls through to the theme preset here, then to the literal fallback.
 * Hover/overlay states resolve from the theme's accent colour.
 */
.recent-posts-block {
    margin: 40px 0;
    width: 100%;

    --rp-read-more: var(--wp--preset--color--primary, #7bb661);
    --rp-read-more-hover: var(--wp--preset--color--accent, #5a9e8a);
    --rp-meta-icon: var(--wp--preset--color--primary, #7bb661);
    --rp-btn-bg: var(--wp--preset--color--primary, #7bb661);
    --rp-btn-hover-bg: var(--wp--preset--color--accent, #5a9e8a);
    --rp-btn-text: var(--wp--preset--color--base, #ffffff);
    --rp-overlay: color-mix(in srgb, var(--wp--preset--color--accent, #5a9e8a) 70%, transparent);
}

/* color-mix() is invalid at computed-value time where unsupported, which would
   drop the overlay entirely — restate it as a static alpha for those engines. */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {
    .recent-posts-block {
        --rp-overlay: rgba(123, 182, 97, 0.7);
    }
}

.recent-posts-grid {
    width: 100%;
}

.post-card {
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.post-image {
    position: relative;
    overflow: hidden;
    width: 100%;
    display: block;
    margin: 0;
}

.post-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.post-card:hover .post-image img {
    transform: scale(1.05);
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--rp-overlay);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.post-card:hover .image-overlay {
    opacity: 1 !important;
}

/* Read more */
.post-read-more.is-link {
    color: var(--rp-read-more);
}

.post-read-more.is-link:hover {
    color: var(--rp-read-more-hover);
}

.post-read-more.is-button {
    background-color: var(--rp-btn-bg);
    color: var(--rp-btn-text);
}

.post-read-more.is-button:hover {
    background-color: var(--rp-btn-hover-bg);
}

.post-read-more,
.post-read-more .dashicons {
    transition: color 0.3s ease, background-color 0.3s ease;
}

.post-meta .dashicons {
    color: var(--rp-meta-icon);
}

.post-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.post-meta {
    user-select: none;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.post-meta span {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.post-meta .dashicons,
.post-meta i[class*="fa"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.post-title {
    margin: 0;
    padding: 0;
    transition: color 0.3s ease;
}

.post-title a {
    transition: all 0.3s ease;
    display: block;
}

.post-title a:hover {
    opacity: 0.8;
}

.post-excerpt {
    margin: 0;
    padding: 0;
}

.post-read-more {
    user-select: none;
    transition: all 0.3s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}

.post-read-more .dashicons,
.post-read-more i[class*="fa"] {
    transition: transform 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.post-read-more:hover .dashicons,
.post-read-more:hover i[class*="fa"] {
    transform: translateX(4px);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .recent-posts-block {
        margin: 20px 0;
        padding: 0 16px;
    }

    .recent-posts-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .post-card {
        margin-bottom: 0;
    }

    .post-image {
        height: 200px !important;
    }

    .post-content {
        padding: 20px !important;
    }

    .post-title {
        font-size: 18px !important;
    }

    .post-title a {
        font-size: 18px !important;
    }

    .post-excerpt {
        font-size: 14px !important;
    }

    .post-meta {
        font-size: 12px !important;
        gap: 8px !important;
    }

    .post-meta .dashicons {
        font-size: 12px !important;
        width: 12px !important;
        height: 12px !important;
    }

    .post-read-more {
        font-size: 13px !important;
    }

    .post-read-more .dashicons {
        font-size: 13px !important;
        width: 13px !important;
        height: 13px !important;
    }
}

/* Tablet responsiveness */
@media (min-width: 769px) and (max-width: 1024px) {
    .recent-posts-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }

    .post-card {
        padding: 0 !important;
    }

    .post-content {
        padding: 20px !important;
    }

    .post-image {
        height: 220px !important;
    }

    .post-title {
        font-size: 20px !important;
    }

    .post-title a {
        font-size: 20px !important;
    }
}

/* Large screens */
@media (min-width: 1400px) {
    .recent-posts-grid {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* Landscape orientation optimization */
@media (max-height: 600px) and (orientation: landscape) {
    .recent-posts-block {
        padding: 15px 0;
    }

    .post-card {
        padding: 20px !important;
    }

    .post-content {
        padding: 20px !important;
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .post-card,
    .post-image img,
    .image-overlay,
    .post-title a,
    .post-read-more,
    .post-read-more .dashicons {
        transition: none !important;
        animation: none !important;
    }

    .post-card:hover {
        transform: none !important;
    }

    .post-card:hover .post-image img {
        transform: none !important;
    }

    .post-read-more:hover .dashicons {
        transform: none !important;
    }
}

/* Focus visible for accessibility */
.post-card:focus,
.post-title a:focus,
.post-read-more:focus {
    outline: 2px solid #7bb661;
    outline-offset: 4px;
    border-radius: 4px;
}

.post-card:focus:not(:focus-visible),
.post-title a:focus:not(:focus-visible),
.post-read-more:focus:not(:focus-visible) {
    outline: none;
}

/* Touch device optimizations */
@media (pointer: coarse) {
    /* Better touch feedback */
    .post-card {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .post-read-more:active {
        transform: scale(0.97) !important;
        opacity: 0.9;
    }

    .post-title a:active {
        opacity: 0.7;
    }
}

/* High DPI / Retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .post-image img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Loading state */
.recent-posts-block.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* List layout specific styles */
.recent-posts-grid[data-layout="list"] .post-card {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
}

.recent-posts-grid[data-layout="list"] .post-image {
    height: 100% !important;
}

@media (max-width: 768px) {
    .recent-posts-grid[data-layout="list"] .post-card {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

/* Print Styles */
@media print {
    .post-card {
        display: block !important;
        page-break-inside: avoid;
        margin-bottom: 20px;
        box-shadow: none !important;
    }

    .post-image {
        height: 200px !important;
    }

    .image-overlay {
        display: none !important;
    }

    .recent-posts-block {
        padding: 0;
    }

    .post-read-more {
        display: none !important;
    }
}

/* Empty state */
.recent-posts-grid:empty::after {
    content: "No posts to display";
    display: block;
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
    font-size: 16px;
}
