/* CMS Page Manager - front office */

/*
 * Mobile first. The multi-column layout is applied ONLY inside min-width
 * media queries.
 *
 * This matters: media queries do not add specificity. An unconditional
 * `.cmspm-wrapper[data-columns="4"] .cmspm-grid` rule (0,3,0) would beat a
 * `@media (max-width:767px) .cmspm-grid` rule (0,1,0) and the columns would
 * stay side by side on phones. Scoping the column counts to min-width instead
 * means they simply never apply on small screens.
 */

.cmspm-wrapper {
    width: 100%;
}

/* ---------------------------------------------------------------
 * Base = mobile: one full width section per line
 * ------------------------------------------------------------ */

.cmspm-grid {
    display: block;
}

.cmspm-block {
    display: block;
    width: 100%;
    min-width: 0;
    border-bottom: 1px solid rgba(0, 0, 0, .1);
}

.cmspm-block-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    margin: 0;
    padding: .9rem 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.cmspm-icon {
    flex: 0 0 auto;
    font-size: 1.25em;
    line-height: 1;
}

.cmspm-icon-img {
    width: 1.25em;
    height: 1.25em;
    object-fit: contain;
}

.cmspm-block-label {
    flex: 1 1 auto;
    min-width: 0;
}

.cmspm-caret {
    flex: 0 0 auto;
    margin-left: auto;
    width: .5rem;
    height: .5rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform .2s ease;
}

.cmspm-list {
    margin: 0;
    padding: 0 0 .9rem;
    list-style: none;
}

.cmspm-item + .cmspm-item {
    margin-top: .5rem;
}

.cmspm-link {
    display: inline-block;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color .15s ease;
}

.cmspm-link:hover,
.cmspm-link:focus {
    text-decoration: none;
}

.cmspm-link:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Accordion behaviour, mobile only (see min-width block below for the reset) */
.cmspm-toggle {
    cursor: pointer;
    user-select: none;
}

.cmspm-toggle + .cmspm-list {
    display: none;
}

.cmspm-toggle[aria-expanded="true"] + .cmspm-list {
    display: block;
}

.cmspm-toggle[aria-expanded="true"] .cmspm-caret {
    transform: rotate(-135deg);
}

/* ---------------------------------------------------------------
 * Tablet: at most two columns, whatever the configured count
 * ------------------------------------------------------------ */

@media (min-width: 768px) {
    .cmspm-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1.5rem 2rem;
    }

    .cmspm-wrapper[data-columns="1"] .cmspm-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .cmspm-block {
        border-bottom: 0;
    }

    .cmspm-block-title {
        padding: 0;
        margin-bottom: .75rem;
        font-size: 1.05rem;
        cursor: auto;
    }

    /* No accordion above mobile: always expanded, no caret. */
    .cmspm-caret {
        display: none;
    }

    .cmspm-toggle + .cmspm-list,
    .cmspm-toggle[aria-expanded="false"] + .cmspm-list {
        display: block;
    }

    .cmspm-list {
        padding-bottom: 0;
    }
}

/* ---------------------------------------------------------------
 * Desktop: the column count chosen in the module settings
 * ------------------------------------------------------------ */

@media (min-width: 992px) {
    .cmspm-wrapper[data-columns="1"] .cmspm-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
    .cmspm-wrapper[data-columns="2"] .cmspm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cmspm-wrapper[data-columns="3"] .cmspm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .cmspm-wrapper[data-columns="4"] .cmspm-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .cmspm-wrapper[data-columns="5"] .cmspm-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .cmspm-wrapper[data-columns="6"] .cmspm-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
