/*
 * Mobile Sliding Menu
 * Off-canvas navigation drawer with app-style nested submenu panels
 * for viewports below the navbar's lg breakpoint (992px).
 */

.msm-toggle {
    /* Hidden until mobile-menu.js confirms (via body.msm-ready) that it
       actually built the drawer this button opens - see the fallback
       .navbar-toggler in header.php and the note in mobile-menu.js. If
       that script never runs, this button staying hidden is correct: the
       native fallback toggler is what's visible instead. */
    box-sizing: border-box;
    display: none;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 52px;
    line-height: 1;
    padding: 0.4rem 0.5rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

body.msm-ready .msm-toggle {
    display: inline-flex;
}

body.msm-ready .navbar-toggler.msm-fallback-toggler {
    display: none;
}

/* Fallback menu (drawer script did not run): the group buttons are not
   Bootstrap dropdowns, so nothing would open their lists and everything
   inside them - Logout included - would be out of reach. Show each group's
   links in place, under its name. */
@media (max-width: 991.98px) {
    body:not(.msm-ready) .navbar .navbar-nav .dropdown-menu {
        display: block;
        position: static;
        float: none;
        margin: 0;
        padding: 0 0 0.5rem 1rem;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    body:not(.msm-ready) .navbar .navbar-nav .dropdown-toggle {
        width: 100%;
        background: none;
        border: 0;
        text-align: left;
        cursor: default;
    }

    body:not(.msm-ready) .navbar .navbar-nav .dropdown-toggle::after {
        display: none;
    }
}

.msm-toggle-bar {
    display: block;
    flex: 0 0 auto;
    width: 24px;
    height: 3px;
    border-radius: 2px;
    /* --theme-nav-contrast: set only by a saved theme that changes the
       navigation's current text (includes/ThemeSettings.php), so the bars
       stay visible on a light bar. */
    background-color: var(--theme-nav-contrast, #fff) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.msm-toggle-label {
    display: block;
    flex: 0 0 auto;
    margin-top: 1px;
    font-size: 0.55rem !important;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--theme-nav-contrast, #fff) !important;
}

.msm-toggle.is-active .msm-toggle-bar:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.msm-toggle.is-active .msm-toggle-bar:nth-child(2) {
    opacity: 0;
}

.msm-toggle.is-active .msm-toggle-bar:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

@media (min-width: 992px) {
    .msm-toggle,
    body.msm-ready .msm-toggle {
        display: none;
    }
}

/* Backdrop */
.msm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
    z-index: 1040;
}

.msm-overlay.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0s linear 0s;
}

/* Drawer */
.msm-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(85vw, 380px);
    background: var(--theme-drawer-bg, #fff);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1050;
}

.msm-drawer.is-open {
    transform: translateX(0);
}

.msm-drawer-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    min-height: 60px;
    flex: 0 0 auto;
}

.msm-back-btn {
    display: none;
    align-items: center;
    gap: 0.35rem;
    border: 0;
    background: transparent;
    padding: 0.25rem 0.25rem 0.25rem 0;
    font-size: 0.95rem;
    font-family: var(--font-display, inherit);
    font-weight: 600;
    color: var(--theme-drawer-back, var(--green-900, #003020));
    cursor: pointer;
    white-space: nowrap;
}

.msm-drawer-header.has-back .msm-back-btn {
    display: inline-flex;
}

.msm-drawer-title {
    flex: 1;
    font-family: var(--font-display, inherit);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--theme-drawer-heading, var(--text-heading, #1c1e2d));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msm-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--theme-drawer-heading, var(--text-heading, #212529));
    font-size: 1.1rem;
}

.msm-panels {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
}

.msm-panel {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--theme-drawer-bg, #fff);
}

.msm-panel.is-current {
    transform: translateX(0);
}

.msm-panel.is-prev {
    transform: translateX(-100%);
}

.msm-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
}

.msm-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.msm-item.msm-divider {
    border-bottom: 0;
    margin: 0.5rem 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.msm-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.85rem 1.25rem;
    border: 0;
    border-left: 3px solid transparent;
    background: transparent;
    text-align: left;
    font-size: 1rem;
    color: var(--theme-drawer-text, var(--text-body, #212529));
    text-decoration: none;
    cursor: pointer;
}

.msm-link:active,
.msm-link:focus-visible {
    /* --theme-drawer-highlight is set only by a saved theme that changes
       the menu's item text: a wash of that colour, so the row still reads
       on a dark menu (includes/ThemeSettings.php). */
    background: var(--theme-drawer-highlight, var(--surface-sunken, rgba(0, 0, 0, 0.04)));
}

/* Current item: the same brand red-rule device used by the desktop
   sidebar's active state. */
.msm-link.is-current {
    background: var(--theme-drawer-highlight, var(--surface-sunken, rgba(0, 0, 0, 0.06)));
    border-left-color: var(--theme-drawer-accent, var(--rule-accent, #d90429));
    color: var(--theme-drawer-heading, var(--text-heading, #212529));
    font-weight: 600;
}

.msm-chevron {
    opacity: 0.5;
    font-size: 0.85rem;
    flex: 0 0 auto;
}

body.msm-open {
    overflow: hidden;
}

/* Account menu row (picture, name, club) copied into the drawer and the
   fallback menu from header.php: picture beside a block of text. */
.msm-link--parent > span:has(> .account-avatar) {
    display: flex;
    align-items: center;
}

.msm-link .account-avatar,
body:not(.msm-ready) .navbar .account-menu .account-avatar {
    margin-right: 0.6rem;
}

/* A drawer link that starts with an icon (account menu items, the System
   group's tools) keeps the icon beside its text rather than at the far
   end of the row. */
.msm-link:has(> i.me-2:first-child) {
    justify-content: flex-start;
}
