/* =============================================================================
   Sponsor / beneficiary logo blocks — the [dd_logos] shortcode (DD_Logos::render_block).

   Two layouts, both responsive:
   • rows — logos in the order given, centred, wrapping onto new rows as the width runs out. Each logo's
            height is at most --dd-logo-h (smaller on phones) and its width follows its proportions
            (--ar), so a wide logo is wide and a tall one is narrow — but no logo is wider than
            --dd-maxr times that height, so a very wide logo comes out shorter instead (this balances wide
            and compact logos). A logo that is too wide for the column shrinks to fit. With "fill" (.dd-logos--fill) the logos in a row also grow, by at most
            35%, so each full row reaches both edges ("justified") — heights then match within a row.
   • grid — uniform cells: each logo sits centred inside an equal box. --dd-cell is the box width,
            --dd-cols a fixed column count (0 = as many as fit), --dd-mcols the columns on phones.
   --s is a per-logo size adjustment (1 = as set), --dd-gap the space between logos (per block).
   --dd-h is the logo height actually in force: the block's, or the phone one at ≤600px.
   .dd-logos--phone forces the phone rules (the editor's phone preview).
   ============================================================================= */

.dd-logos {
    --dd-h: var(--dd-logo-h, 60px);
    margin: 1em 0;
    clear: both;
}
.dd-logos .dd-logo {
    display: block;
    text-decoration: none;
    border: 0;
    box-shadow: none;
}
.dd-logos .dd-logo img {
    display: block;
    border: 0;
    box-shadow: none;
    margin: 0;
}

/* ---- Rows ---- */
.dd-logos--rows {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: var(--dd-gap, 16px);
}
.dd-logos--rows .dd-logo {
    --dd-wr: min(var(--ar, 2), var(--dd-maxr, 99));                    /* width as a multiple of the height */
    --dd-w:  calc(var(--dd-wr) * var(--s, 1) * var(--dd-h));
    flex: 0 1 var(--dd-w);
    max-width: var(--dd-w);
    min-width: 0;
}
.dd-logos--rows .dd-logo img {
    width: 100%;
    height: auto;
}
.dd-logos--rows.dd-logos--fill .dd-logo {
    flex-grow: calc(var(--dd-wr) * var(--s, 1) * 100);
    max-width: calc(var(--dd-w) * 1.35);
}

/* ---- Uniform grid ---- */
.dd-logos--grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--dd-cell, 120px), 1fr));
    gap: var(--dd-gap, 16px);
    align-items: center;
    justify-items: center;
}
.dd-logos--grid.dd-logos--fixed-cols {
    grid-template-columns: repeat(var(--dd-cols, 3), minmax(0, 1fr));
}
.dd-logos--grid .dd-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 5 / 3;
}
.dd-logos--grid .dd-logo img {
    max-width: min(100%, calc(90% * var(--s, 1)));
    max-height: min(100%, calc(90% * var(--s, 1)));
    width: auto;
    height: auto;
    object-fit: contain;
}

/* ---- Phones ---- */
@media (max-width: 600px) {
    .dd-logos { --dd-h: var(--dd-logo-hm, 42px); }
    .dd-logos--grid,
    .dd-logos--grid.dd-logos--fixed-cols {
        grid-template-columns: repeat(var(--dd-mcols, 2), minmax(0, 1fr));
    }
}
/* The editor's phone preview applies the same rules without needing a narrow screen. */
.dd-logos--phone { --dd-h: var(--dd-logo-hm, 42px); }
.dd-logos--grid.dd-logos--phone,
.dd-logos--grid.dd-logos--fixed-cols.dd-logos--phone {
    grid-template-columns: repeat(var(--dd-mcols, 2), minmax(0, 1fr));
}
