/**
 * mod_buttonmenu - responsive horizontal button menu
 * All colours / sizes come from CSS custom properties written per module instance.
 */

.bm {
    /* Fallbacks - overwritten by the per-instance inline block. */
    --bm-bg: rgba(255, 255, 255, 0);
    --bm-color: #243447;
    --bm-border-color: #243447;
    --bm-bg-hover: #243447;
    --bm-color-hover: #ffffff;
    --bm-border-color-hover: #243447;
    --bm-bg-active: #0f6fc6;
    --bm-color-active: #ffffff;
    --bm-border-color-active: #0f6fc6;
    --bm-border-width: 1px;
    --bm-border-style: solid;
    --bm-radius: 6px;
    --bm-panel-radius: 8px;
    --bm-pad-v: 10px;
    --bm-pad-h: 18px;
    --bm-gap: 8px;
    --bm-font-size: 15px;
    --bm-font-weight: 500;
    --bm-transform: none;
    --bm-transition: 200ms;
    --bm-sub-bg: #ffffff;
    --bm-sub-color: var(--bm-color);
    --bm-sub-min-width: 200px;
    --bm-mobile-bg: #f4f6f8;
    --bm-mobile-pad: 12px;
    --bm-toggle-bg: var(--bm-bg);
    --bm-toggle-color: var(--bm-color);
    --bm-toggle-border: var(--bm-border-color);

    position: relative;
    box-sizing: border-box;
}

.bm *,
.bm *::before,
.bm *::after {
    box-sizing: inherit;
}

/* ---------- Lists ---------- */

.bm__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bm__list--root {
    display: flex;
    flex-wrap: wrap;
    gap: var(--bm-gap);
    align-items: center;
}

.bm--align-center .bm__list--root {
    justify-content: center;
}

.bm--align-right .bm__list--root {
    justify-content: flex-end;
}

.bm--align-justify .bm__list--root > .bm__item {
    flex: 1 1 0;
}

.bm--align-justify .bm__btn {
    width: 100%;
    justify-content: center;
}

.bm__item {
    position: relative;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

/* ---------- The button itself ---------- */

.bm__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4em;
    padding: var(--bm-pad-v) var(--bm-pad-h);
    background: var(--bm-bg);
    color: var(--bm-color);
    border: var(--bm-border-width) var(--bm-border-style) var(--bm-border-color);
    border-radius: var(--bm-radius);
    font-size: var(--bm-font-size);
    font-weight: var(--bm-font-weight);
    text-transform: var(--bm-transform);
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--bm-transition) ease,
                color var(--bm-transition) ease,
                border-color var(--bm-transition) ease;
}

.bm__btn:hover,
.bm__btn:focus-visible {
    background: var(--bm-bg-hover);
    color: var(--bm-color-hover);
    border-color: var(--bm-border-color-hover);
    text-decoration: none;
}

.bm__btn:focus-visible {
    outline: 2px solid var(--bm-border-color-active);
    outline-offset: 2px;
}

.bm__btn.is-active,
.bm__item--active > .bm__btn {
    background: var(--bm-bg-active);
    color: var(--bm-color-active);
    border-color: var(--bm-border-color-active);
}

.bm__btn--static {
    cursor: default;
}

/* ---------- Second level (desktop dropdown) ---------- */

.bm__list--sub {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    display: none;
    min-width: var(--bm-sub-min-width);
    padding: var(--bm-gap);
    margin-top: 4px;
    flex: 0 0 100%;
    background: var(--bm-sub-bg);
    border-radius: var(--bm-panel-radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}

.bm__list--sub .bm__item + .bm__item {
    margin-top: calc(var(--bm-gap) / 2);
}

.bm__list--sub .bm__btn {
    width: 100%;
    justify-content: flex-start;
    white-space: normal;
    color: var(--bm-sub-color);
}

.bm__list--sub .bm__btn:hover,
.bm__list--sub .bm__btn:focus-visible {
    color: var(--bm-color-hover);
}

.bm__list--sub .bm__item--active > .bm__btn,
.bm__list--sub .bm__btn.is-active {
    color: var(--bm-color-active);
}

.bm__item--parent:hover > .bm__list--sub,
.bm__item--parent:focus-within > .bm__list--sub,
.bm__item.is-open > .bm__list--sub {
    display: block;
}

/*
 * Invisible bridge across the gap between the button and the drop-down, so the
 * pointer can travel down without losing :hover. It only exists while the item is
 * actually open - otherwise it would swallow clicks on whatever sits underneath
 * (e.g. the second row of a wrapped menu).
 */
.bm__item--parent::after {
    content: none;
}

.bm__item--parent:hover::after,
.bm__item--parent:focus-within::after,
.bm__item--parent.is-open::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: calc(var(--bm-gap) + 6px);
}

/* Sub-level toggle button - only used on mobile. */
.bm__sub-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.4em;
    align-self: stretch;
    padding: 0;
    background: none;
    border: 0;
    color: var(--bm-color);
    cursor: pointer;
}

.bm__caret {
    width: .5em;
    height: .5em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform var(--bm-transition) ease;
}

.bm__item.is-open > .bm__sub-toggle .bm__caret {
    transform: rotate(-135deg) translate(-2px, -2px);
}

/* ---------- Hamburger toggle ---------- */

.bm__toggle {
    display: none;
    align-items: center;
    gap: .6em;
    padding: var(--bm-pad-v) var(--bm-pad-h);
    background: var(--bm-toggle-bg);
    color: var(--bm-toggle-color);
    border: var(--bm-border-width) var(--bm-border-style) var(--bm-toggle-border);
    border-radius: var(--bm-radius);
    font-size: var(--bm-font-size);
    font-weight: var(--bm-font-weight);
    text-transform: var(--bm-transform);
    line-height: 1.25;
    cursor: pointer;
    transition: background-color var(--bm-transition) ease,
                color var(--bm-transition) ease,
                border-color var(--bm-transition) ease;
}

.bm__toggle:hover,
.bm__toggle:focus-visible {
    background: var(--bm-bg-hover);
    color: var(--bm-color-hover);
    border-color: var(--bm-border-color-hover);
}

.bm--toggle-right .bm__toggle {
    flex-direction: row-reverse;
}

.bm--align-center .bm__toggle {
    margin-inline: auto;
}

.bm--align-right .bm__toggle {
    margin-inline-start: auto;
}

.bm__burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    width: 20px;
    height: 14px;
    flex: 0 0 auto;
}

.bm__burger > span {
    display: block;
    height: 2px;
    width: 100%;
    background: currentColor;
    border-radius: 2px;
    transition: transform var(--bm-transition) ease,
                opacity var(--bm-transition) ease;
}

.bm__toggle[aria-expanded="true"] .bm__burger > span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.bm__toggle[aria-expanded="true"] .bm__burger > span:nth-child(2) {
    opacity: 0;
}

.bm__toggle[aria-expanded="true"] .bm__burger > span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

@media (prefers-reduced-motion: reduce) {
    .bm__btn,
    .bm__toggle,
    .bm__burger > span,
    .bm__caret {
        transition: none;
    }
}
