/* ==========================================================================
   SLU Bento Box Widget
   A bento grid of self-contained cells. Each cell carries its own col/row span;
   grid-auto-flow: dense packs them with no ragged holes. Pure CSS, no JS.

   Balance model:
   - --slu-bento-cols  : column count (set per breakpoint by the Columns control)
   - --slu-bento-row-h : fixed row height (grid-auto-rows) so a 2-row box is
                          exactly twice a 1-row box, gaps included
   - per cell: --slu-bento-col-span / --slu-bento-row-span (responsive, from
     Elementor-generated CSS on the repeater item), falling back to the inline
     --slu-bento-col-span-base / --slu-bento-row-span-base (desktop value)

   Span clamping: there is no native span-minmax(), so we clamp the column span
   with min(span, cols). A box can therefore never span past the current column
   count when the grid narrows — the classic "last column overflows the grid"
   bug. At 1 column everything becomes a clean stack automatically.

   Hello Elementor reset overrides: bare <a> and heading colours carry
   !important (see CLAUDE.md "Elementor / theme CSS").
   ========================================================================== */

.slu-bento {
    --slu-bento-cols: 4;
    --slu-bento-row-h: 180px;
    --slu-bento-gap: 12px;

    display: grid;
    grid-template-columns: repeat(var(--slu-bento-cols), minmax(0, 1fr));
    grid-auto-rows: var(--slu-bento-row-h);
    grid-auto-flow: dense;
    gap: var(--slu-bento-gap);
    width: 100%;
}

/* ── Cell ──────────────────────────────────────────────────────────────── */
.slu-bento__cell {
    /* NB: --slu-bento-col-span / --slu-bento-row-span are deliberately NOT given
       defaults here. They must stay undefined unless Elementor's generated CSS
       sets them, so the var() fallback below can reach the inline -base value.
       A page whose post CSS predates responsive spans (not yet regenerated or
       re-saved) therefore keeps its original desktop spans instead of
       collapsing every box to 1×1. */
    --slu-bento-cell-bg: #f4f4f4;
    --slu-bento-cell-fg: #1a1a1a;

    /* Clamp the column span to the live column count. min() is the robust
       stand-in for the not-yet-shipped span-minmax(). */
    grid-column: span min(var(--slu-bento-col-span, var(--slu-bento-col-span-base, 1)), var(--slu-bento-cols));
    grid-row: span var(--slu-bento-row-span, var(--slu-bento-row-span-base, 1));

    position: relative;
    overflow: hidden;
    background-color: var(--slu-bento-cell-bg);
    color: var(--slu-bento-cell-fg);
    border-radius: 16px;
    min-width: 0;   /* let the track shrink rather than overflow on long text */
    transition: transform .25s ease, box-shadow .25s ease;
}

/* Background image layer + legibility overlay */
.slu-bento__bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    z-index: 0;
}
.slu-bento__overlay {
    position: absolute;
    inset: 0;
    background: #000;
    opacity: .3;
    z-index: 1;
    pointer-events: none;
}
/* Cells with an image default to light text for contrast unless overridden. */
.slu-bento__cell--has-image { --slu-bento-cell-fg: #ffffff; }

/* Link wrapper fills the cell without introducing its own box. */
.slu-bento__link {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: block;
    text-decoration: none !important;
    color: inherit !important;   /* beat Hello reset + kit link colour */
}
/* Lightbox cells hint that the image enlarges on click. */
.slu-bento__link--lightbox { cursor: zoom-in; }

/* Content sits above the image/overlay. */
.slu-bento__content {
    position: relative;
    z-index: 2;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;   /* overridden per-item by content_align */
    gap: 6px;
    padding: 20px;
    pointer-events: none;        /* let clicks fall through to the link layer */
}
.slu-bento__content > * { pointer-events: auto; }

.slu-bento__title {
    margin: 0;
    color: inherit !important;   /* beat kit heading colour */
    font-weight: 600;
    line-height: 1.2;
}
.slu-bento__text {
    margin: 0;
    color: inherit !important;
    line-height: 1.45;
    opacity: .92;
}
/* Rich-text contents (v1.21.0). Spacing between blocks only, never after the
   last one, so a single paragraph sits exactly where the old plain text did. */
.slu-bento__text p,
.slu-bento__text ul,
.slu-bento__text ol { margin: 0 0 .6em; }
.slu-bento__text ul,
.slu-bento__text ol { padding-left: 1.2em; }
.slu-bento__text > :last-child { margin-bottom: 0; }
.slu-bento__text a {
    color: inherit !important;   /* beat Hello reset + kit link colour */
    text-decoration: underline;
}

/* ── Button ──────────────────────────────────────────── */
/* Rendered inside .slu-bento__content (a direct child, so pointer-events are
   re-enabled by the `.slu-bento__content > *` rule above). It sits above the
   image/overlay because content is z2. Base look is intentionally plain — the
   widget's Button style controls layer on top, all with !important to beat the
   Hello Elementor <a>/<button> reset. margin-top:auto is NOT set so the button
   hugs the rest of the content block; content_align positions the whole block. */
.slu-bento__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;      /* overridden by the Alignment control */
    margin-top: 8px;
    padding: 10px 18px;
    border: 0 solid transparent;
    border-radius: 8px;
    background-color: #1a1a1a;
    color: #fff;
    font: inherit;
    line-height: 1.1;
    text-decoration: none !important;   /* beat Hello reset */
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}
.slu-bento__button:hover {
    transform: translateY(-1px);
}

/* ── Hover lift ────────────────────────────────────────────────────────── */
.slu-bento--hover-lift .slu-bento__cell:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 34px rgba(0,0,0,.16);
}

/* ── Force single column on mobile ─────────────────────────────────────── */
/* JS-free. Gated on .slu-bento--stack-mobile (the Force Single Column on
   Mobile switch, ON by default): below 767px the grid is forced to ONE column
   and every box flattens to 1×1, overriding both the mobile Columns value and
   each box's mobile spans.
   Was unconditional until spans became responsive — an ungated flatten would
   make every per-box mobile span a dead control. Switch OFF = per-box spans
   (inherited or mobile-specific) apply on mobile, clamped to the column count.
   767px matches Elementor's default mobile breakpoint (hardcoded; the per-box
   mobile spans themselves use the site's real mobile breakpoint). */
@media (max-width: 767px) {
    /* !important is required: Elementor's Columns selector ({{WRAPPER}}
       .slu-bento) outranks this rule, so without it a mobile Columns value > 1
       silently won and the switch didn't force a single column at all.
       An important custom-property declaration beats any normal one. */
    .slu-bento.slu-bento--stack-mobile {
        --slu-bento-cols: 1 !important;
    }
    /* Override the resolved grid properties with !important rather than the
       span vars — that beats both Elementor's per-breakpoint span vars and the
       inline -base fallback regardless of specificity. */
    .slu-bento.slu-bento--stack-mobile .slu-bento__cell {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
    }
}
