/*
 * File:    food-menu-safari-safe.css
 * Purpose: Bulletproof override for the Food Menu cards. Replaces every modern
 *          layout primitive (CSS Grid, flex-grow, aspect-ratio, gap, :has())
 *          with universally-supported equivalents (floats, padding-bottom %,
 *          explicit min-heights). Works on every Safari since 14.0 with zero
 *          rendering quirks.
 *
 *          Scoped to .post-type-archive-moondog and .tax-md_category — affects
 *          ONLY the Food Menu archive and category pages. Safe to load globally;
 *          rules cannot match anything outside the food menu.
 *
 * Author:  Delphi Art Ltd
 * Created: 2026-04-26
 * Version: 1.0.0
 *
 * Enqueue: load AFTER kudil-child/style.css and kudil-child/responsive.css.
 *          Recommended priority in functions.php: 200 (or higher than the
 *          existing kudil_child_enqueue_responsive at 110).
 *
 *          add_action( 'wp_enqueue_scripts', function () {
 *              if ( is_post_type_archive( 'moondog' ) || is_tax( 'md_category' ) ) {
 *                  wp_enqueue_style(
 *                      'kudil-child-food-menu-safari-safe',
 *                      get_stylesheet_directory_uri() . '/food-menu-safari-safe.css',
 *                      array( 'kudil-child-responsive' ),
 *                      '1.0.0'
 *                  );
 *              }
 *          }, 200 );
 *
 * Why floats and padding-bottom:
 *   - CSS Grid auto-row sizing has historically produced inconsistent heights
 *     across Safari versions when combined with aspect-ratio children.
 *   - flex: 1 on .post-card-back relies on parent height being defined.
 *     With auto-height parents, Safari 26 can collapse the flex item.
 *   - padding-bottom: 75% creates a 4:3 ratio that has worked identically in
 *     every browser since 2010 — no edge cases.
 *   - Floats with calc() widths give a 3-up grid that Safari has rendered
 *     identically since Safari 6.
 *
 * The !important is intentional and surgical — these rules MUST win against
 * the cascade because the layout in style.css is the source of the bug.
 */


/* ─── Container: drop CSS Grid, use float layout with calc() widths ──────── */

.post-type-archive-moondog #post-grid,
.tax-md_category #post-grid {
    display: block !important;
    margin-top: 32px;
    padding-bottom: 48px;
    /* Clear the floated children */
    *zoom: 1;
}

.post-type-archive-moondog #post-grid::after,
.tax-md_category #post-grid::after {
    content: "";
    display: block;
    clear: both;
    height: 0;
    overflow: hidden;
}


/* ─── Each card: floated, 3-up at desktop, with explicit width ───────────── */

.post-type-archive-moondog #post-grid > *,
.tax-md_category #post-grid > * {
    float: left;
    width: -webkit-calc((100% - 48px) / 3);
    width: calc((100% - 48px) / 3);
    margin: 0 24px 24px 0;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Strip the right-margin on every 3rd item so the row aligns flush right */
.post-type-archive-moondog #post-grid > *:nth-child(3n),
.tax-md_category #post-grid > *:nth-child(3n) {
    margin-right: 0;
}


/* ─── Card wrapper: block layout, explicit shadow + radius ───────────────── */

.post-type-archive-moondog .post-card,
.tax-md_category .post-card {
    display: block !important;
    background: #fff;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
    -webkit-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    -webkit-transition: -webkit-box-shadow 0.25s ease;
    transition: box-shadow 0.25s ease;
}

.post-type-archive-moondog .post-card:hover,
.tax-md_category .post-card:hover {
    -webkit-box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
}


/* ─── Inner: drop flex, use plain block ──────────────────────────────────── */

.post-type-archive-moondog .post-card-inner,
.tax-md_category .post-card-inner {
    display: block !important;
    width: 100%;
}


/* ─── Image area: padding-bottom 75% = 4:3 aspect (no aspect-ratio prop) ── */

.post-type-archive-moondog .post-card-front,
.tax-md_category .post-card-front {
    display: block !important;
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 75%;     /* 3 ÷ 4 = 0.75 → 4:3 ratio */
    overflow: hidden;
}

/* Image fills the padding-bottom box */
.post-type-archive-moondog .post-card-front img,
.post-type-archive-moondog .post-card-front .post-thumbnail,
.tax-md_category .post-card-front img,
.tax-md_category .post-card-front .post-thumbnail {
    position: absolute !important;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
    object-fit: cover;
    display: block;
    -webkit-transition: -webkit-transform 0.4s ease;
    transition: transform 0.4s ease;
}

.post-type-archive-moondog .post-card:hover .post-card-front img,
.tax-md_category .post-card:hover .post-card-front img {
    -webkit-transform: scale(1.04);
    transform: scale(1.04);
}

.post-type-archive-moondog .post-thumbnail-placeholder,
.tax-md_category .post-thumbnail-placeholder {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1c1c1c;
    background-image: url('/wp-content/uploads/2025/01/moon-logo.png');
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 55% auto;
}


/* ─── Content area: explicit min-height, no flex-grow ────────────────────── */

.post-type-archive-moondog .post-card-back,
.tax-md_category .post-card-back {
    display: block !important;
    width: 100%;
    padding: 18px 16px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Force visibility of every child — guards against any cascade hiding them */
.post-type-archive-moondog .post-card-back > *,
.tax-md_category .post-card-back > * {
    visibility: visible !important;
    opacity: 1 !important;
    display: block;
}


/* ─── Tablet: 2 columns ──────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .post-type-archive-moondog #post-grid > *,
    .tax-md_category #post-grid > * {
        width: -webkit-calc((100% - 24px) / 2);
        width: calc((100% - 24px) / 2);
    }

    /* Reset the 3n rule from desktop */
    .post-type-archive-moondog #post-grid > *:nth-child(3n),
    .tax-md_category #post-grid > *:nth-child(3n) {
        margin-right: 24px;
    }

    /* New rule: clear margin on every 2nd item */
    .post-type-archive-moondog #post-grid > *:nth-child(2n),
    .tax-md_category #post-grid > *:nth-child(2n) {
        margin-right: 0;
    }
}


/* ─── Mobile: 1 column ───────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .post-type-archive-moondog #post-grid > *,
    .tax-md_category #post-grid > * {
        float: none;
        width: 100%;
        margin: 0 0 24px 0;
    }

    /* Reset all nth-child margin rules */
    .post-type-archive-moondog #post-grid > *:nth-child(2n),
    .post-type-archive-moondog #post-grid > *:nth-child(3n),
    .tax-md_category #post-grid > *:nth-child(2n),
    .tax-md_category #post-grid > *:nth-child(3n) {
        margin-right: 0;
    }

    .post-type-archive-moondog .post-card-back,
    .tax-md_category .post-card-back {
        min-height: 100px;
    }
}
