/* 1. Target the direct wrapper of search results and establish an aligned 3-column grid */
body.search div:has(> .hentry),
body.search div:has(> .post),
body.search div:has(> .type-attachment) {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    column-gap: 22px !important;
    row-gap: 26px !important;
    align-items: stretch !important;
}

/* 2. CRITICAL: Remove Modularity Lite's stray <hr> and .clear dividers from taking up grid cells */
body.search div:has(> .hentry) > hr,
body.search div:has(> .hentry) > .clear,
body.search div:has(> .post) > hr,
body.search div:has(> .post) > .clear {
    display: none !important;
}

/* 3. Span the top search bar, page title, and bottom pagination across all 3 columns */
body.search .cm-top-search-bar,
body.search div:has(> .hentry) > h1,
body.search div:has(> .hentry) > h2.pagetitle,
body.search div:has(> .hentry) > h3.sub,
body.search div:has(> .hentry) > .search-header,
body.search div:has(> .hentry) > .navigation,
body.search div:has(> .hentry) > .wp-pagenavi,
body.search div:has(> .hentry) > .pagination {
    grid-column: 1 / -1 !important;
    width: 100% !important;
}

/* 4. Style each search card as a clean, equal-height vertical flex box */
body.search .hentry,
body.search .post,
body.search .type-attachment {
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    width: 100% !important;
    max-width: 100% !important;
    float: none !important;
    clear: none !important;
    margin: 0 !important;
    padding: 0 0 12px 0 !important;
    border-bottom: 1px solid #e5e5e5 !important;
    box-sizing: border-box !important;
}

/* 5. Put the image consistently at the top of the card, even if Modularity prints the title first */
body.search .hentry .entry,
body.search .hentry .entry-content,
body.search .hentry .entry-summary,
body.search .post .entry {
    order: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.search .hentry h2,
body.search .hentry h3,
body.search .post h2,
body.search .post h3,
body.search .entry-title {
    order: 2 !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
    margin: 10px 0 0 0 !important;
    padding: 0 !important;
    min-height: 38px !important; /* Reserves exact 2-line height so every row aligns */
    display: -webkit-box !important;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 6. Lock every image container and photo to an identical 3:2 ratio */
body.search .cm-search-thumb-wrap {
    width: 100% !important;
    aspect-ratio: 3 / 2 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    border-radius: 3px;
    background: #f4f4f4;
}

body.search .cm-search-thumb-wrap a,
body.search .cm-search-thumb-wrap img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    object-fit: cover !important;
    object-position: center 25% !important;
    display: block !important;
    float: none !important;
    margin: 0 !important;
}

/* 7. Hide all leftover metadata, dates, categories, and social/like elements */
body.search .postmetadata,
body.search .entry-meta,
body.search .post-meta,
body.search .sharedaddy,
body.search .sd-sharing-enabled,
body.search .sd-like,
body.search .jetpack-likes-widget-wrapper {
    display: none !important;
}

/* 8. Top search bar styling */
body.search .cm-top-search-bar {
    margin: 0 0 8px 0 !important;
}

body.search .cm-top-search-bar form {
    display: flex;
    gap: 10px;
    width: 100%;
}

body.search .cm-top-search-bar input[type="search"] {
    flex: 1;
    height: 46px;
    padding: 0 16px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

body.search .cm-top-search-bar button {
    height: 46px;
    padding: 0 24px;
    font-size: 15px;
    font-weight: 600;
    background: #222;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

body.search .cm-top-search-bar button:hover {
    background: #444;
}

/* 9. Stack cleanly to 1 column on phones */
@media (max-width: 768px) {
    body.search div:has(> .hentry),
    body.search div:has(> .post),
    body.search div:has(> .type-attachment) {
        grid-template-columns: 1fr !important;
    }
}
/* Span the top search bar across all 3 grid columns */
body.search .cm-top-search-bar {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    margin: 0 0 12px 0 !important;
}

body.search .cm-top-search-bar form {
    display: flex;
    gap: 10px;
    width: 100%;
}

body.search .cm-top-search-bar input[type="search"] {
    flex: 1;
    height: 46px;
    padding: 0 16px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

body.search .cm-top-search-bar button {
    height: 46px;
    padding: 0 24px;
    font-size: 15px;
    font-weight: 600;
    background: #222;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

body.search .cm-top-search-bar button:hover {
    background: #444;
}
