/**
 * Featured / Most Recent Posts Block Styles
 *
 * Supports three layout modes:
 * - Card: Standard 3-column card grid with images
 * - Text: 3-column text-only layout (with optional icons)
 * - Masonry: 2x3 grid with alternating background colors
 *
 * @package TMW_Blocks
 * @since 1.0.0
 */

/* ==========================================================================
   Block Wrapper
   ========================================================================== */

.featured-recent-posts-wrapper {
    position: relative;
    max-width: 100%;
    overflow: hidden;
}

/* Ensure badges don't stretch to full width */
.featured-recent-posts-wrapper .badge {
    align-self: flex-start;
    margin-bottom: var(--space-md);
}

/* Badge positioning and hiding now handled globally in theme cards.css */

/* Eyebrow text styling for masonry layout (non-pill design) */
.featured-recent-posts-wrapper .eyebrow-text {
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
    text-transform: uppercase;
}

/* ==========================================================================
   Section Header
   ========================================================================== */

.featured-recent-posts-wrapper .section-header--center {
    text-align: center;
}

.featured-recent-posts-wrapper .section-header--left {
    text-align: left;
    max-width: var(--max-width-content-lg);
}

.featured-recent-posts-wrapper .section-header--right {
    max-width: var(--max-width-content-xl);
    text-align: right;
    align-items: end;

    /* flex-col utility class provides: display: flex; flex-direction: column */
    margin-left: auto;
    margin-right: 0;
}

.featured-recent-posts-wrapper .section-title {
    max-width: var(--max-width-content-lg);
}

.featured-recent-posts-wrapper.layout-masonry .section-title {
    text-wrap: auto;
}

.featured-recent-posts-wrapper .section-subtitle {
    max-width: 800px;
}

.featured-recent-posts-wrapper .section-header--center .section-title {
    margin-left: auto;
    margin-right: auto;
}

/* Right-aligned header children should also flush right */
.featured-recent-posts-wrapper .section-header--right .section-title,
.featured-recent-posts-wrapper .section-header--right .section-subtitle,
.featured-recent-posts-wrapper .section-header--right .section-cta {
    margin-left: auto;
    margin-right: 0;
}

.featured-recent-posts-wrapper .section-cta {
    margin-top: var(--space-lg);
}

/* ==========================================================================
   Grid Container Base & Element Defaults
   ========================================================================== */

.featured-recent-posts-grid {
    display: grid;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.featured-recent-posts-wrapper .post-title a:hover {
    text-decoration: underline;
    color: var(--color-tertiary);
}

/* ==========================================================================
   Card Wrapper Links (Accessibility)
   ========================================================================== */

/* Ensure entire card wrapper links display properly */
.featured-recent-posts-wrapper .card-wrapper {
    text-decoration: none;
    color: inherit;
    display: block;
}

/* Card action spans should still look clickable - styling inherited from card component */

/* Focus state for keyboard navigation */
.featured-recent-posts-wrapper .card-wrapper:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
}

/* ==========================================================================
   CARD LAYOUT (3-Column Standard Cards)
   ========================================================================== */

/* Force Flexbox layout to override .row's display:grid
   This allows incomplete rows to be centered. */
.layout-card .featured-recent-posts-grid {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
}

/* REMOVED: Desktop grid override - grid system handles responsive layout */

.layout-card .post-card {
    background: var(--color-white);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
    transition: transform 0.3s ease, box-shadow 0.3s ease;

    /* flex-col utility class provides: display: flex; flex-direction: column */
    height: 100%;
    box-sizing: border-box;
}

/* 3-column layout: all cards in flexbox need explicit width */
.layout-card .featured-recent-posts-grid .col-4 {
    width: calc(33.333% - 20px) !important;
}

.layout-card .post-card .post-thumbnail {
    order: -1;
}

.layout-card .post-card .post-content {
    order: 0;
}

.layout-card .post-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

.layout-card .post-thumbnail {
    position: relative;
    width: 100%;
    padding-top: 56.25%;

    /* 16:9 aspect ratio */
    overflow: hidden;
    background: var(--color-light-gray);
}

.layout-card .post-thumbnail img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

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

.layout-card .post-content {
    padding: var(--space-lg);
    flex: 1;

    /* flex-col utility class provides: display: flex; flex-direction: column */
}

.layout-card .post-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.layout-card .post-meta {
    font-size: var(--font-size-small);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.layout-card .post-excerpt {
    font-size: var(--font-size-body);
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-md);
    flex: 1;
}

.layout-card .btn-arrow,
.layout-card .card-action {
    margin-top: auto !important;

    /* Force CTA to bottom of flexbox */
}

/* Prevent parent block text color from affecting cards - reset to default card styles */
.has-text-color .layout-card .post-title,
.has-text-color .layout-card .post-title a,
.has-text-color .layout-card .post-meta,
.has-text-color .layout-card .post-excerpt,
.has-text-color .layout-card .btn-arrow,
.has-text-color .layout-card .card-action {
    color: revert;
}

/* ==========================================================================
   TEXT LAYOUT (3-Column Text with Optional Icons)
   ========================================================================== */

.layout-text .featured-recent-posts-grid {
    /* REMOVED: grid-template-columns - grid system (.col-4) handles 3-column layout */
    position: relative;
}

@media (width >=768px) {
    .layout-text .featured-recent-posts-grid {
        gap: var(--space-xl);

        /* REMOVED: grid-template-columns: repeat(3, 1fr) - grid system handles responsive layout */
    }
}

.layout-text .post-card {
    background: transparent;
    padding: 10px 0;

    /* flex-col utility class provides: display: flex; flex-direction: column */
    height: 100%;
    position: relative;
}

.layout-text .post-icon {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-md);
    flex-shrink: 0;
}

.layout-text .post-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.layout-text .post-content {
    /* flex-col utility class provides: display: flex; flex-direction: column */
    height: 100%;
}

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

.layout-text .post-excerpt {
    margin-bottom: var(--space-md);
    color: var(--color-text-secondary);
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.layout-text .btn-arrow,
.layout-text .card-action {
    margin-top: auto !important;

    /* Force CTA to bottom of flexbox */
}

/* Prevent parent block text color from affecting text layout - reset to default text layout styles */
.has-text-color .layout-text .post-title,
.has-text-color .layout-text .post-title a,
.has-text-color .layout-text .post-excerpt,
.has-text-color .layout-text .btn-arrow,
.has-text-color .layout-text .card-action {
    color: revert;
}

/* ==========================================================================
   MASONRY LAYOUT (3-Column x 2-Row Grid)
   Layout Structure:
   [Post #1] [Post #2] [Post #3 - Tall]
   [Post #4 - Wide   ] [Post #3 cont'd]
   ========================================================================== */

.layout-masonry .featured-recent-posts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, minmax(250px, auto));
    gap: var(--space-lg);
}

/* Post #3, #7, #11... spans 2 rows (tall card on the right) */
.layout-masonry .post-card:nth-child(4n-1) {
    grid-row: span 2;
    height: 100%;
}

/* Post #4, #8, #12... spans 2 columns (wide card on the bottom left) */
.layout-masonry .post-card:nth-child(4n) {
    grid-column: span 2;
}

.layout-masonry .post-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: var(--space-lg);

    /* flex-col utility class provides: display: flex; flex-direction: column */
    justify-content: flex-start;

    /* Changed from space-between to flex-start - button uses margin-top: auto */

    position: relative;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
    text-decoration: none;
    color: inherit;
    box-sizing: border-box;
}

/* Focus state for keyboard navigation accessibility */
.layout-masonry .post-card:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
}

.layout-masonry .post-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

/* For cards with images */
.layout-masonry .post-card.has-image {
    display: grid;
    padding: 0;
}

.layout-masonry .post-card.has-image .post-content {
    padding: var(--space-lg);
    order: 1;
}

.layout-masonry .post-card.has-image .post-thumbnail {
    order: -1;
}

/* Posts #1, #2, #5, #6, #9, #10... - Default (no image in typical use) */
.layout-masonry .post-card.has-image:nth-child(4n+1),
.layout-masonry .post-card.has-image:nth-child(4n+2) {
    grid-template-columns: 1fr;
}

/* Posts #3, #7, #11... (tall card) - Image at top */
.layout-masonry .post-card.has-image:nth-child(4n-1) {
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr;
}

.layout-masonry .post-card.has-image:nth-child(4n-1) .post-thumbnail {
    order: -1;

    /* Move thumbnail before content */
    width: 100%;
    height: auto;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.layout-masonry .post-card.has-image:nth-child(4n-1) .post-content {
    order: 1;
}

/* Posts #4, #8, #12... (wide card) - Image at left */
.layout-masonry .post-card.has-image:nth-child(4n) {
    grid-template-columns: 45% 1fr;
}

.layout-masonry .post-card.has-image:nth-child(4n) .post-thumbnail {
    order: -1;

    /* Move thumbnail before content */
    height: 100%;
    border-radius: var(--radius-card) 0 0 var(--radius-card);
}

.layout-masonry .post-card.has-image:nth-child(4n) .post-content {
    order: 1;
}

.layout-masonry .post-thumbnail {
    width: 100%;
    height: 200px;
    border-radius: var(--radius-card);
    overflow: hidden;
    background: var(--color-light-gray);
}

.layout-masonry .post-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.layout-masonry .post-content {
    /* flex-col utility class provides: display: flex; flex-direction: column */
    gap: var(--space-sm);
    min-width: 0;
    flex: 1;
}

.layout-masonry .post-title {
    color: var(--color-primary);
    margin-bottom: var(--space-xs);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.layout-masonry .post-excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--color-text-secondary);
    margin-bottom: 0;
}

.layout-masonry .btn-arrow,
.layout-masonry .card-action {
    margin-top: auto !important;

    /* Force CTA to bottom of flexbox */
}

/* Prevent parent block text color from affecting masonry layout - reset to default masonry styles */
.has-text-color .layout-masonry .post-title,
.has-text-color .layout-masonry .post-excerpt,
.has-text-color .layout-masonry .btn-arrow,
.has-text-color .layout-masonry .card-action {
    color: revert;
}

.layout-masonry .post-card:nth-child(4n-1) .post-excerpt,
.layout-masonry .post-card:nth-child(4n) .post-excerpt {
    -webkit-line-clamp: 3;
}

/* ==========================================================================
   Bottom CTA
   ========================================================================== */

.featured-recent-posts-wrapper .bottom-cta {
    margin-top: var(--space-2xl);
    text-align: center;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (width <=1024px) {
    .layout-masonry .featured-recent-posts-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
    }

    /* Reset spans on tablet - stack normally */
    .layout-masonry .post-card:nth-child(4n-1),
    .layout-masonry .post-card:nth-child(4n) {
        grid-row: auto;
        grid-column: auto;
    }

    /* Hide images on tablet and below for cleaner layout */
    .layout-masonry .post-thumbnail {
        display: none;
    }

    /* Reset grid layout for cards without visible images */
    .layout-masonry .post-card.has-image {
        display: flex;
    }

    /* Reset 4n card grid - no longer has image on left */
    .layout-masonry .post-card.has-image:nth-child(4n) {
        grid-template-columns: 1fr;
    }
}

/* Tablet: 2 columns for Card layout */
@media (width <=1024px) {
    .layout-card .featured-recent-posts-grid .col-4 {
        width: calc(33.333% - var(--space-md)) !important;
    }
}

@media (width <=991px) {
    .layout-card .featured-recent-posts-grid .col-4 {
        width: calc(50% - var(--space-md)) !important;
    }
}

@media (width <=767px) {
    .featured-recent-posts-wrapper .section-title {
        font-size: var(--font-size-h3);
    }

    /* Mobile: 1 column for Card layout */
    .layout-card .featured-recent-posts-grid .col-4 {
        width: 100% !important;
    }

    /* Mobile: 1 column for masonry layout */
    .layout-masonry .featured-recent-posts-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.text-center {
    text-align: center;
}