/**
 * ViaLocal Business Nexus - front-end.
 *
 * Equal-height listing cards.
 *
 * Findus renders grid cards through at least two structurally different
 * containers:
 *
 *   WP Job Manager archive (job_manager/job-listings-start.php):
 *     .job_listings.job_listings_cards.row
 *       .col-lg-* .col-md-* .col-sm-* .col-xs-12
 *         .job_listing.job-grid-style
 *
 *   Elementor "APUS Listings" widget, grid layout
 *   (inc/vendors/elementor/listing_widgets/listings.php), confirmed against
 *   the live page in Chrome DevTools:
 *     .widget-listing.style-grid .widget-content
 *       .row                                    <- no job_listings_cards
 *         .full-smallest.col-xs-12.col-sm-6.col-md-4
 *           .job_listing.job-grid-style
 *
 * A first pass anchored every rule on `.job_listings_cards`, which only the
 * first container carries. It had no effect on the Elementor path because
 * that ancestor does not exist there.
 *
 * This version anchors on the card class itself - `.job-grid-style`,
 * `.job-grid-v2`, `.job-grid-v3` - which both containers emit identically,
 * and on the `col-*` column that is their immediate parent in both. Bootstrap
 * float layout is what prevents equal heights in either container, so the
 * fix (flex the row, flex the column, flex the card, let one region absorb
 * the vertical slack) is unchanged from the first pass; only the selectors
 * that reach it have changed.
 *
 * The half-map layout (`.apus-listing-map .job-grid-style`,
 * template.css:12674+) uses the same card class, so it must be excluded
 * explicitly rather than left out by accident of a narrower ancestor.
 *
 * No Findus template or stylesheet is modified. No JavaScript. No subgrid.
 * Phone/location internal layout is unchanged - a separate piece of work,
 * blocked by an !important rule scoped to job-grid-v3.
 */

/* --- 1. Rows containing grid cards become flex containers ---------- */
/* Scoped to a row that actually contains a card: `.row` alone is
   Bootstrap's generic grid class, used throughout the theme for layout
   unrelated to listings, and must not be touched wholesale. */

.row:has(> [class*="col-"] > .job-grid-style):not(.apus-listing-map .row),
.row:has(> [class*="col-"] > .job-grid-v2):not(.apus-listing-map .row),
.row:has(> [class*="col-"] > .job-grid-v3):not(.apus-listing-map .row) {
    display: flex;
    flex-wrap: wrap;
}

/* Bootstrap 3's clearfix pseudo-elements become flex items under the rule
   above and would render as phantom zero-width columns. */
.row:has(> [class*="col-"] > .job-grid-style):not(.apus-listing-map .row)::before,
.row:has(> [class*="col-"] > .job-grid-style):not(.apus-listing-map .row)::after,
.row:has(> [class*="col-"] > .job-grid-v2):not(.apus-listing-map .row)::before,
.row:has(> [class*="col-"] > .job-grid-v2):not(.apus-listing-map .row)::after,
.row:has(> [class*="col-"] > .job-grid-v3):not(.apus-listing-map .row)::before,
.row:has(> [class*="col-"] > .job-grid-v3):not(.apus-listing-map .row)::after {
    display: none;
}

/* --- 2. The column stretches, and stops clearing ------------------- */

.row > [class*="col-"]:has(> .job-grid-style):not(.apus-listing-map *),
.row > [class*="col-"]:has(> .job-grid-v2):not(.apus-listing-map *),
.row > [class*="col-"]:has(> .job-grid-v3):not(.apus-listing-map *) {
    display: flex;
    float: none;
    clear: none;
}

/* --- 3. The card fills its column ---------------------------------- */

.job-grid-style:not(.apus-listing-map *),
.job-grid-v2:not(.apus-listing-map *),
.job-grid-v3:not(.apus-listing-map *) {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* --- 4. One region absorbs the slack -------------------------------- */
/* The image keeps its natural height; .bottom-grid takes the remainder so
   the metas row sits flush at the base of every card in a row, whatever
   number of lines the title or address wrapped to. */

.job-grid-style:not(.apus-listing-map *) > .listing-image,
.job-grid-v2:not(.apus-listing-map *) > .listing-image,
.job-grid-v3:not(.apus-listing-map *) > .listing-image {
    flex: 0 0 auto;
}

.job-grid-style:not(.apus-listing-map *) > .bottom-grid,
.job-grid-v2:not(.apus-listing-map *) > .bottom-grid,
.job-grid-v3:not(.apus-listing-map *) > .bottom-grid {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

/* grid and grid-v3 carry a title block; letting it take the slack keeps
   contact and metas bottom-aligned. grid-v2 has no .listing-content - its
   .listing-content-bottom absorbs the space instead. Neither sets a fixed
   height, a line-clamp or overflow:hidden with an ellipsis, so titles and
   addresses continue to wrap to as many lines as they need. */
.job-grid-style:not(.apus-listing-map *) .listing-content,
.job-grid-v3:not(.apus-listing-map *) .listing-content {
    flex: 1 1 auto;
}

.job-grid-v2:not(.apus-listing-map *) .listing-content-bottom {
    margin-top: auto;
}

.job-grid-style:not(.apus-listing-map *) > .bottom-grid > .listing-content-bottom,
.job-grid-v3:not(.apus-listing-map *) > .bottom-grid > .listing-content-bottom {
    flex: 0 0 auto;
}

/* --- 5. Small screens ------------------------------------------------ */
/* At col-xs-12 each card is its own row, so stretching is a no-op; the
   float/clear reset must not outlive the layout it exists to correct. */

@media (max-width: 767px) {
    .row > [class*="col-"]:has(> .job-grid-style):not(.apus-listing-map *),
    .row > [class*="col-"]:has(> .job-grid-v2):not(.apus-listing-map *),
    .row > [class*="col-"]:has(> .job-grid-v3):not(.apus-listing-map *) {
        display: block;
    }

    .job-grid-style:not(.apus-listing-map *),
    .job-grid-v2:not(.apus-listing-map *),
    .job-grid-v3:not(.apus-listing-map *) {
        width: auto;
    }
}

/* ===================================================================
 * Card contact area, Format 2: location alone, then a footer row
 * pairing whatever Findus already renders there (category on grid/v2,
 * its review widget on grid-v3) with Phone + Show.
 *
 * Appended after the equal-height section above, which is frozen and
 * unmodified. Nothing here changes display/flex-direction/width on
 * .job-grid-style, .job-grid-v2, .job-grid-v3, .bottom-grid or
 * .listing-image - it only lays out .listing-contact and
 * .listing-content-bottom, which the equal-height rules already size.
 *
 * No fixed heights and no truncation are introduced: business names and
 * addresses continue to wrap to as many lines as their content needs.
 * =================================================================== */

/* --- Location, alone on its row -------------------------------------
 * Phone no longer renders here (FindusCardRegions moved it to the footer
 * row below), so this is a single block, not a flex stack.
 *
 * .grid-contact-inner is the actual wrapper around this hook's output on
 * every variant - opened/closed by findus_listings_grid_contact_before()/
 * _after() at priorities 1/30 in functions-display.php:611-614,655-658,
 * around our own displaced render() at priority 5 - not .listing-contact
 * itself, which merely contains it. */

.job-grid-style:not(.apus-listing-map *) .listing-contact,
.job-grid-v3:not(.apus-listing-map *) .listing-contact {
    display: block;
}

/* job-grid-v3's own stylesheet sets display:block !important on this
 * element (template.css:14635-14637), which already matches the layout
 * above. No Findus file is edited to remove it; this rule exists so a
 * change to that theme rule cannot silently reopen a flex layout here. */
.job-grid-v3:not(.apus-listing-map *) .grid-contact-inner {
    display: block !important;
}

/* v2 has no .listing-contact wrapper - FindusCardRegions prints location
 * directly into .bottom-grid on that variant. */
.job-grid-v2:not(.apus-listing-map *) > .bottom-grid > .listing-location {
    display: block;
}

/* --- Footer row: existing content on the left, Phone + Show on the right */

.job-grid-style:not(.apus-listing-map *) .listing-content-bottom,
.job-grid-v2:not(.apus-listing-map *) .listing-content-bottom,
.job-grid-v3:not(.apus-listing-map *) .listing-content-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* .vbn-card-phone wraps findus_display_listing_phone()'s own markup
 * (FindusCardRegions::render_phone()) so it can be targeted as a flex
 * sibling without touching the theme's .phone-wrapper/.phone-show classes -
 * the masked-number and "show" toggle behaviour inside it is untouched. */
.job-grid-style:not(.apus-listing-map *) .vbn-card-phone,
.job-grid-v2:not(.apus-listing-map *) .vbn-card-phone,
.job-grid-v3:not(.apus-listing-map *) .vbn-card-phone {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    white-space: nowrap;
}