/*
 * GD Top Level Tiles widget — wraps a group of .gd-top-level-tile items
 * (see gd-top-level-tile.css) in a responsive row.
 *
 * Layout: flexbox instead of CSS grid so a partial row (e.g. 3 tiles) stays
 * compact and centered instead of being stretched to fill 6 columns.
 * Row size: 6 per row on desktop, fewer as the viewport shrinks, down to a
 * single column on small mobile.
 *
 * Sizing when there are fewer tiles than fit in one row: a group that fits
 * entirely in a single row (total tile count <= that breakpoint's per-row
 * count) has its tiles GROW to fill the row instead of leaving dead space
 * on the sides, capped to a max-width so 1-2 tiles don't become oversized.
 * A group with MORE tiles than fit per row (wraps to 2+ rows) keeps the
 * fixed per-row tile size instead, so every row — including a shorter
 * trailing row — stays visually aligned with the row(s) above it.
 *
 * The "is this a single row" check uses the `:has()` "quantity query" trick
 * (first child is also among the last N children => total count <= N).
 * Each breakpoint's check is scoped to its own exclusive width range so a
 * count that's a single row at a wider breakpoint (e.g. 4 tiles on desktop,
 * 6/row) isn't mistaken for a single row at a narrower one (e.g. only
 * 3/row on tablet, so those same 4 tiles actually wrap there). Browsers
 * without :has() support simply always get the fixed sizing below — a
 * harmless fallback, not a broken layout.
 *
 * Animation: opt-in via the "Load Animation" control. Tiles start hidden and
 * offset to the left, then gd-top-level-tiles.js adds "is-visible" to the
 * container the first time it scrolls into view (left-to-right stagger via
 * the --gd-tile-index custom property set per tile). Once visible, tiles
 * stay visible — the animation does not replay on subsequent scrolls.
 */

.gd-top-level-tiles {
    --gd-tiles-gap: 24px;
    --gd-tiles-per-row: 6;

    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--gd-tiles-gap);
}

.gd-top-level-tiles > .gd-top-level-tile {
    flex: 0 1 calc((100% - (var(--gd-tiles-per-row) - 1) * var(--gd-tiles-gap)) / var(--gd-tiles-per-row));
}

/* Desktop tier (per-row: 6) — only STRICTLY FEWER than a full row (1-5
   tiles) grows to fill; an exactly-full row of 6 keeps its normal fixed
   size and gap untouched. */
@media (min-width: 1025px) {
    .gd-top-level-tiles:has(> .gd-top-level-tile:nth-child(1):nth-last-child(-n+5)) > .gd-top-level-tile {
        flex-grow: 1;
        max-width: 260px;
    }

    /* Exactly 2 tiles: a bit wider and roomier than the general "fewer
       tiles" case above. */
    .gd-top-level-tiles:has(> .gd-top-level-tile:first-child:nth-last-child(2)) {
        gap: 40px;
    }

    .gd-top-level-tiles:has(> .gd-top-level-tile:first-child:nth-last-child(2)) > .gd-top-level-tile {
        max-width: 300px;
    }
}

@media (max-width: 1024px) {
    .gd-top-level-tiles {
        --gd-tiles-per-row: 3;
    }

    .gd-top-level-tiles > .gd-top-level-tile {
        max-width: 240px;
    }
}

/* Tablet tier (per-row: 3) — only strictly fewer than a full row (1-2
   tiles) grows to fill. */
@media (max-width: 1024px) and (min-width: 601px) {
    .gd-top-level-tiles:has(> .gd-top-level-tile:nth-child(1):nth-last-child(-n+2)) > .gd-top-level-tile {
        flex-grow: 1;
        max-width: 300px;
    }
}

@media (max-width: 600px) {
    .gd-top-level-tiles {
        --gd-tiles-per-row: 2;
    }

    .gd-top-level-tiles > .gd-top-level-tile {
        max-width: 260px;
    }
}

/* Mobile tier (per-row: 2) — only strictly fewer than a full row (1 tile)
   grows to fill. */
@media (max-width: 600px) and (min-width: 401px) {
    .gd-top-level-tiles:has(> .gd-top-level-tile:nth-child(1):nth-last-child(-n+1)) > .gd-top-level-tile {
        flex-grow: 1;
        max-width: 320px;
    }
}

@media (max-width: 400px) {
    .gd-top-level-tiles {
        --gd-tiles-per-row: 1;
    }

    .gd-top-level-tiles > .gd-top-level-tile {
        max-width: 320px;
    }
}

.gd-top-level-tiles--animate > .gd-top-level-tile {
    opacity: 0;
    transform: translateX(-24px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    transition-delay: calc(var(--gd-tile-index, 0) * 120ms);
}

.gd-top-level-tiles--animate.is-visible > .gd-top-level-tile {
    opacity: 1;
    transform: translateX(0);
}

/* Always show tiles in the Elementor editor — scroll-triggered reveal is a
   front-end-only effect and shouldn't hide content while editing. */
.elementor-editor-active .gd-top-level-tiles--animate > .gd-top-level-tile {
    opacity: 1;
    transform: none;
    transition: none;
}
