/* ========================================
Page Submenu — section sibling navigation
Mobile: horizontal chips · Desktop: stacked soft / brand pills
Dropdown: expandable nested links under a parent item
======================================== */

/* Shared shell: submenu + page content */
.page-submenu-layout {
    max-width: 100%;
    min-width: 0;
    background-color: var(--color-background);
    color: var(--color-text);
}

.page-submenu-layout__inner {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-inline: auto;
    padding-block-start: 0;
}

.page-submenu-layout__content {
    min-width: 0;
    width: var(--layout-col-10);
    margin-inline: auto;
}

@media (min-width: 1024px) {
    .page-submenu-layout__inner {
        display: grid;
        grid-template-columns: var(--layout-col-3) minmax(0, 1fr);
        column-gap: clamp(1.5rem, 3vw, 3rem);
        align-items: start;
        width: var(--layout-col-10);
        padding-block-start: clamp(5rem, 8vw, 8rem);
    }

    .page-submenu-layout__content {
        width: auto;
        margin-inline: 0;
    }
}

.page-submenu {
    position: relative;
    width: 100%;
    min-width: 0;
    padding: 0.75rem var(--layout-gutter-x);
    background-color: var(--color-surface);
    border-radius: 0;
}

.page-submenu__nav {
    min-width: 0;
}

.page-submenu__list {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.page-submenu__list::-webkit-scrollbar {
    display: none;
}

.page-submenu__item {
    flex: 0 0 auto;
}

.page-submenu__link-icon {
    display: none;
}

.page-submenu__link:focus-visible {
    outline: 2px solid var(--color-brand-red);
    outline-offset: 3px;
}

/* ---------- Dropdown (shared) ---------- */

.page-submenu__item--dropdown {
    position: relative;
}

.page-submenu__toggle {
    cursor: pointer;
}

.page-submenu__toggle .page-submenu__link-icon--chevron,
.page-submenu__toggle .page-submenu__link-icon--arrow {
    flex-shrink: 0;
    color: currentColor;
}

/* Mobile default: angle chevron · Desktop: long arrow like sibling items */
.page-submenu__toggle .page-submenu__link-icon--chevron {
    display: block;
    width: 1.25rem;
    height: 1.25rem;
}

.page-submenu__toggle .page-submenu__link-icon--arrow {
    display: none;
    width: 1.25rem;
    height: 1.25rem;
    transform: rotate(0deg);
    transform-origin: center;
    transition: transform var(--transition-base);
}

/* Open parent matches brand-red pill from the design, even if section is inactive */
.page-submenu__item--dropdown.is-open .page-submenu__toggle.btn.btn-custom {
    --btn-custom-color: #fff;
    --btn-custom-bg: var(--button-custom-brand-red);
    --btn-custom-border: var(--button-custom-brand-red);
    --btn-custom-hover-color: #fff;
    --btn-custom-hover-bg: var(--button-custom-brand-red-hover);
    --btn-custom-hover-border: var(--button-custom-brand-red-hover);
    --btn-custom-active-color: #fff;
    --btn-custom-active-bg: var(--button-custom-brand-red-active);
    --btn-custom-active-border: var(--button-custom-brand-red-active);
}

.page-submenu__dropdown {
    overflow: hidden;
    max-height: 0;
    visibility: hidden;
    pointer-events: none;
    margin-block-start: 0;
    /* max-height px values come from page-submenu.js (content height ↔ 0).
       Do not use var(--transition-base) as a delay — it includes `ease` and
       invalidates the whole transition list (close would snap with no animation). */
    transition:
        max-height var(--transition-base),
        margin-block-start var(--transition-base),
        visibility 0s linear 0.3s;
}

.page-submenu__item--dropdown.is-open .page-submenu__dropdown {
    visibility: visible;
    pointer-events: auto;
    transition:
        max-height var(--transition-base),
        margin-block-start var(--transition-base),
        visibility 0s linear 0s;
}

.page-submenu__dropdown-list {
    margin: 0;
    padding: 0.25rem 0 0.15rem;
    list-style: none;
}

.page-submenu__dropdown-item + .page-submenu__dropdown-item {
    margin-block-start: 0.125rem;
}

.page-submenu__dropdown-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 0.875rem;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    line-height: 1.35;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition:
        color var(--transition-fast),
        background-color var(--transition-fast);
}

.page-submenu__dropdown-link:hover {
    color: var(--color-brand-red);
    background-color: transparent;
}

.page-submenu__dropdown-link.is-active {
    color: var(--color-brand-red);
}

.page-submenu__dropdown-icon {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    color: currentColor;
}

.page-submenu__dropdown-label {
    min-width: 0;
}

.page-submenu__dropdown-link:focus-visible {
    outline: 2px solid var(--color-brand-red);
    outline-offset: 2px;
}

/*
  Mobile: keep chip-row overflow-x:auto so the page does not grow sideways.
  Dropdown panels use position:fixed (coords from page-submenu.js) so they are
  not clipped by the scrollport — do not set overflow:visible on the list.
*/
@media (max-width: 1023.98px) {
    .page-submenu {
        max-width: 100%;
        box-sizing: border-box;
    }

    .page-submenu__nav {
        max-width: 100%;
        min-width: 0;
    }

    .page-submenu__list {
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }

    .page-submenu__toggle .page-submenu__link-icon--chevron {
        width: 1.75rem;
        height: 1.75rem;
    }

    /*
      Mobile uses scaleY + opacity (not max-height). max-height + ease left a
      white stub under the chip for ~0.5s at the end of close (see screen recording).
      top/left/min-width are set inline by JS while open.
    */
    .page-submenu__item--dropdown .page-submenu__dropdown {
        position: fixed;
        top: 0;
        left: 0;
        z-index: calc(var(--z-header) - 1);
        box-sizing: border-box;
        width: max-content;
        min-width: 0;
        max-width: min(18rem, calc(100vw - (var(--layout-gutter-x) * 2)));
        max-height: none;
        padding: 0;
        background-color: transparent;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
        transform: scaleY(0);
        transform-origin: top center;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition:
            transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.2s ease,
            visibility 0s linear 0.25s;
    }

    .page-submenu__item--dropdown.is-open .page-submenu__dropdown {
        transform: scaleY(1);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition:
            transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.2s ease,
            visibility 0s linear 0s;
    }

    .page-submenu__item--dropdown .page-submenu__dropdown-list {
        padding: 0.35rem;
        background-color: var(--color-background);
        border-radius: var(--radius-lg);
        box-shadow: 0 0.5rem 1.25rem rgb(0 0 0 / 0.08);
    }
}

@media (min-width: 1024px) {
    .page-submenu {
        position: sticky;
        top: calc(var(--header-height) + 1rem);
        align-self: start;
        box-sizing: border-box;
        width: calc(100% - var(--layout-col-2));
        max-width: 100%;
        min-width: 0;
        margin-inline-end: var(--layout-col-2);
        padding: 0.75rem;
        overflow: visible;
        border-radius: var(--radius-xl);
    }

    .page-submenu__list {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 0.5rem;
        overflow: visible;
    }

    .page-submenu__item {
        flex: none;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    /* Desktop: full-width pills — inactive white, active brand-red from btn variant */
    .page-submenu__link.btn.btn-custom {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        justify-content: space-between;
        gap: 0.75rem;
        height: auto;
        min-height: 2.5rem;
        padding-block: 0.625rem;
        font-size: var(--font-size-sm);
        white-space: normal;
        border-radius: var(--radius-lg);
        box-shadow: none;
    }

    .page-submenu__link.btn.btn-custom:not(.is-active):not(.page-submenu__toggle) {
        --btn-custom-color: var(--color-text-muted);
        --btn-custom-bg: var(--color-background);
        --btn-custom-border: var(--color-background);
        --btn-custom-hover-color: var(--color-text);
        --btn-custom-hover-bg: var(--color-background);
        --btn-custom-hover-border: var(--color-background);
        --btn-custom-active-color: var(--color-text);
        --btn-custom-active-bg: var(--color-background);
        --btn-custom-active-border: var(--color-background);
    }

    /* Soft toggle (inactive section) matches sibling soft pills */
    .page-submenu__toggle.btn.btn-custom-soft-secondary {
        --btn-custom-color: var(--color-text-muted);
        --btn-custom-bg: var(--color-background);
        --btn-custom-border: var(--color-background);
        --btn-custom-hover-color: var(--color-text);
        --btn-custom-hover-bg: var(--color-background);
        --btn-custom-hover-border: var(--color-background);
        --btn-custom-active-color: var(--color-text);
        --btn-custom-active-bg: var(--color-background);
        --btn-custom-active-border: var(--color-background);
    }

    .page-submenu__link-label {
        min-width: 0;
        flex: 1 1 auto;
        overflow-wrap: break-word;
        text-align: start;
    }

    .page-submenu__link-icon {
        display: block;
        flex-shrink: 0;
        width: 1.25rem;
        height: 1.25rem;
        color: currentColor;
    }

    .page-submenu__toggle .page-submenu__link-icon--chevron {
        display: none;
    }

    .page-submenu__toggle .page-submenu__link-icon--arrow {
        display: block;
        transform: rotate(0deg);
        transition: transform var(--transition-base);
    }

    .page-submenu__item--dropdown.is-open .page-submenu__link-icon--arrow {
        transform: rotate(90deg);
    }

    .page-submenu__item--dropdown.is-open .page-submenu__dropdown {
        width: 100%;
        margin-block-start: 0.15rem;
        background-color: transparent;
    }

    .page-submenu__dropdown-link {
        padding-block: 0.7rem;
        padding-inline: 0.875rem;
    }

    .page-submenu__dropdown-link:hover {
        color: var(--color-brand-red);
        background-color: transparent;
    }
}
