/* Custom Article Grid Styles */

/* Target ALL post templates on the homepage, archives, and search results */
.home .wp-block-post-template.is-layout-grid .wp-block-post,
.archive .wp-block-post-template.is-layout-grid .wp-block-post,
.search .wp-block-post-template.is-layout-grid .wp-block-post {
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
}

/* Hover Effect */
.home .wp-block-post-template.is-layout-grid .wp-block-post:hover,
.archive .wp-block-post-template.is-layout-grid .wp-block-post:hover,
.search .wp-block-post-template.is-layout-grid .wp-block-post:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

/* Featured Image - Force Height and Fit */
.home .wp-block-post-template.is-layout-grid .wp-block-post-featured-image,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-featured-image,
.search .wp-block-post-template.is-layout-grid .wp-block-post-featured-image {
    margin-bottom: 0 !important;
    margin-top: 0 !important;
    width: 100%;
    background-color: #f7f7f7;
    /* Placeholder background */
}

.home .wp-block-post-template.is-layout-grid .wp-block-post-featured-image img,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-featured-image img,
.search .wp-block-post-template.is-layout-grid .wp-block-post-featured-image img {
    border-radius: 0 !important;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 16/9 !important;
    /* Force 16:9 ratio for uniformity */
    object-fit: cover !important;
    /* Force cover to avoid grey bars */
    display: block;
}

/* Content Container & Text Elements */
/* 1. If there is a Group wrapper (standard), give it full padding */
.home .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group,
.archive .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group,
.search .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group {
    padding: 2rem !important;
    /* Generous padding */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
}

/* 2. Fallback: If text elements are direct children (no Group), give them side padding */
.home .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group),
.archive .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group),
.search .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group) {
    padding-left: 2rem !important;
    padding-right: 2rem !important;
    background-color: #ffffff;
    /* Ensure background is white */
}

/* 3. Ensure space at the bottom of the card if no group is used */
.home .wp-block-post-template.is-layout-grid .wp-block-post,
.archive .wp-block-post-template.is-layout-grid .wp-block-post,
.search .wp-block-post-template.is-layout-grid .wp-block-post {
    padding-bottom: 0 !important;
    /* Reset, let children handle spacing */
}

/* Mobile Responsiveness */
@media (max-width: 600px) {

    .home .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group,
    .archive .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group,
    .search .wp-block-post-template.is-layout-grid .wp-block-post>.wp-block-group {
        padding: 1.5rem !important;
    }

    .home .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group),
    .archive .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group),
    .search .wp-block-post-template.is-layout-grid .wp-block-post> :not(.wp-block-post-featured-image):not(.wp-block-group) {
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }
}

/* Title */
.home .wp-block-post-template.is-layout-grid .wp-block-post-title,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-title,
.search .wp-block-post-template.is-layout-grid .wp-block-post-title {
    font-family: var(--wp--preset--font-family--heading);
    font-weight: 700;
    font-size: 1.25rem !important;
    margin-top: 0;
    margin-bottom: 0.75rem;
    line-height: 1.35;
}

.home .wp-block-post-template.is-layout-grid .wp-block-post-title a,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-title a,
.search .wp-block-post-template.is-layout-grid .wp-block-post-title a {
    text-decoration: none;
    color: #111827;
}

.home .wp-block-post-template.is-layout-grid .wp-block-post-title a:hover,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-title a:hover,
.search .wp-block-post-template.is-layout-grid .wp-block-post-title a:hover {
    color: var(--wp--preset--color--accent);
}

/* Meta Data (Date, Categories) */
.home .wp-block-post-template.is-layout-grid .wp-block-post-date,
.home .wp-block-post-template.is-layout-grid .wp-block-post-terms,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-date,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-terms,
.search .wp-block-post-template.is-layout-grid .wp-block-post-date,
.search .wp-block-post-template.is-layout-grid .wp-block-post-terms {
    font-size: 0.75rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

/* Term Badges in cards */
.wp-block-post-terms a {
    background-color: transparent;
    padding: 0;
    color: var(--wp--preset--color--accent);
    font-weight: 600;
}

/* Excerpt (if present) */
.home .wp-block-post-template.is-layout-grid .wp-block-post-excerpt,
.archive .wp-block-post-template.is-layout-grid .wp-block-post-excerpt,
.search .wp-block-post-template.is-layout-grid .wp-block-post-excerpt {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #4b5563;
    margin-top: auto;
}

/* --- SIDEBAR STYLES --- */

/* 1. Make the sidebar column sticky and reset its background */
/* We target the last column. We MUST use !important to override inline styles set by the Block Editor */
main .wp-block-columns .wp-block-column:last-child {
    position: sticky;
    top: 2rem;
    align-self: start;
    background-color: transparent !important;
    /* Override inline grey background */
    border: none !important;
    box-shadow: none !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

/* 2. Style ALL widgets in the sidebar as cards */
main .wp-block-columns .wp-block-column>* {
    background-color: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    border-radius: 12px !important;
    padding: 1.5rem !important;
    margin-bottom: 1.5rem !important;
    margin-top: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
    box-sizing: border-box;
    width: 100%;
}

/* B) Exception for Nested Pattern Structure (Column > Aside > Group > Widgets) */
/* Reset the outer wrapper if it exists */
main .wp-block-columns .wp-block-column:last-child>.wp-block-group,
main .wp-block-columns .wp-block-column:last-child aside>.wp-block-group {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin-bottom: 0 !important;
}

/* Style the inner widgets of the nested group */
main .wp-block-columns .wp-block-column:last-child>.wp-block-group>*,
main .wp-block-columns .wp-block-column:last-child aside>.wp-block-group>* {
    background-color: #ffffff !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
    padding: 1.5rem !important;
    margin-bottom: 1.5rem !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
    box-sizing: border-box;
}

/* Hide separators in the sidebar */
main .wp-block-columns .wp-block-column:last-child .wp-block-separator,
main .wp-block-columns .wp-block-column:last-child aside .wp-block-separator {
    display: none !important;
}

/* Author Card specific refinements */
.is-author-card {
    border: none !important;
}

.is-author-card .wp-block-button__link {
    transition: background 0.2s ease;
}

.is-author-card .wp-block-button__link:hover {
    background-color: var(--wp--preset--color--accent) !important;
    color: white !important;
}

/* Category Pill List */
.is-pill-list ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.is-pill-list ul li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px !important;
    background: #f9fafb;
    border: 1px solid #f3f4f6;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #4b5563;
    transition: all 0.2s ease;
}

.is-pill-list ul li:hover {
    background: #ffffff;
    border-color: var(--wp--preset--color--accent);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.is-pill-list .wp-block-categories__post-count {
    background: #e5e7eb;
    color: #6b7280;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Most Read Thumbnails Style */
.wp-block-latest-posts.is-grid.has-dates li {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.wp-block-latest-posts li {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 1rem !important;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.75rem !important;
}

.wp-block-latest-posts li .wp-block-latest-posts__featured-image {
    flex-shrink: 0;
    width: 60px;
}

.wp-block-latest-posts li .wp-block-latest-posts__featured-image img {
    border-radius: 6px;
    aspect-ratio: 1;
    object-fit: cover;
}

/* Featured Recap Banner */
.is-featured-recap-banner {
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
}

.is-featured-recap-banner h2 {
    color: #ffffff !important;
    border-bottom: none !important;
}

/* Table of Contents */
.is-style-no-bullets {
    list-style: none !important;
    padding-left: 0 !important;
}

.is-style-no-bullets li {
    margin-bottom: 0.75rem;
}

.is-style-no-bullets a {
    text-decoration: none;
    color: #4b5563;
    transition: color 0.2s ease;
}

.is-style-no-bullets a:hover {
    color: var(--wp--preset--color--accent);
}

/* Breadcrumbs */
.wp-block-group p.has-contrast-3-color {
    font-size: 0.8rem;
    font-weight: 500;
}

/* Social Sharing Icons refinement */
.wp-block-social-links.is-style-logos-only .wp-social-link {
    transition: opacity 0.2s ease;
}

.wp-block-social-links.is-style-logos-only .wp-social-link:hover {
    opacity: 0.7;
}

/* Featured Recap Image */
.is-featured-recap-banner figure.wp-block-image img {
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Newsletter Input refinement */
input[type="email"] {
    border: 1px solid #e5e7eb;
    transition: border-color 0.2s ease;
}

/* --- Layout Stability & Grid Fixes --- */

/* Force 3 columns on desktop for the main article grid */
@media (min-width: 1024px) {
    .wp-block-query .wp-block-post-template.is-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: var(--wp--preset--spacing--30) !important;
    }
}

/* Ensure the main container is never too narrow */
main.alignfull {
    width: 100% !important;
}

.alignwide {
    max-width: 1320px !important;
    width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Fix for the compressed look in the screenshot */
.wp-block-columns {
    display: flex !important;
    flex-wrap: wrap !important;
}

@media (min-width: 782px) {
    .wp-block-columns {
        flex-wrap: nowrap !important;
    }
}