/* Меню в шапке (bitrix:menu, шаблон header).
   Файл подключается ядром автоматически вместе с шаблоном компонента
   (CBitrixComponentTemplate::__IncludeCSSFile). */

.nav{
  justify-self: end;
  min-width: 0;
}
.nav__list {
    display: grid;
    grid-template-columns: repeat(5, auto);
    align-items: center;
    justify-content: center;
    gap: 4px 20px;
}

.nav__list > li {
    position: relative;
}

.nav__list > li > a {
    display: inline-block;
    position: relative;
    padding: 8px 0;
    
    font-size: clamp(15px, 1.4vw, 1.25rem);
    font-weight: 500;
    color: var(--color-text-muted);
    white-space: nowrap;
    transition: color 0.2s ease;
}

/*.nav__list > li:first-child > a,*/
.nav__list > li > a.active {
    color: var(--color-primary);
    font-weight: 600;
}

.nav__list > li > a:hover,
.nav__list > li > a:focus-visible {
    color: var(--color-accent);
}
.nav__list > li > a:after{
 content:'\20';
 position: absolute;
 left: 0;
 bottom: 0;
 width: 0;
 height: 2px;
 background: var(--color-accent);
 transition: all ease 0.3s;
 width: 0%; 
}
.nav__list > li > a:hover:after{
  width: 100%;
}

/* ===== Подменю второго уровня (десктоп) ===== */

.nav__caret {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-left: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.25s ease;
}

.nav__item--parent:hover > a .nav__caret,
.nav__item--parent:focus-within > a .nav__caret {
    transform: translateY(1px) rotate(-135deg);
}

.nav__submenu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 240px;
    padding: 8px 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
    z-index: 20;
}

/* Прозрачный мост над зазором, чтобы подменю не закрывалось при
   переходе курсора от родителя к списку. */
.nav__submenu::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}

.nav__item--parent:hover > .nav__submenu,
.nav__item--parent:focus-within > .nav__submenu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav__submenu li {
    width: 100%;
}

.nav__submenu a {
    display: block;
    padding: 10px 16px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-muted);
    white-space: normal;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.nav__submenu a:hover,
.nav__submenu a:focus-visible {
    color: var(--color-primary);
    background: var(--color-bg-light);
}

.nav__submenu a.active {
    color: var(--color-primary);
    font-weight: 600;
}

.nav__submenu-toggle {
    display: none;
}

/* ===== Мобильная версия (аккордеон) ===== */

@media (max-width: 900px) {
    .nav {
        position: fixed;
        top: 100px;
        left: 0;
        right: 0;
        max-height: 0;
        overflow: hidden;
        background: var(--color-bg);
        box-shadow: 0 12px 24px rgba(27, 58, 107, 0.12);
        transition: max-height 1s ease;
        z-index: 10;
        width: 95%;
        margin: 0 auto;
    }

    .nav--open {
        max-height: calc(100vh - 56px);
        overflow-y: auto;
    }

    .nav__list {
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: 0;
        padding: 8px 20px 20px;
    }

    .nav__list > li {
        border-bottom: 1px solid var(--color-border);
    }

    .nav__list > li:last-child {
        border-bottom: none;
    }

    .nav__list > li > a {
        display: block;
        padding: 14px 0;
        white-space: normal;
        color: var(--color-text-muted);
    }

    .nav__list > li:first-child > a {
        color: var(--color-primary);
        font-weight: 600;
    }

    /* Второй уровень на мобильных — аккордеон, раскрывается вниз */
    .nav__caret {
        display: none;
    }

    .nav__list > .nav__item--parent > a {
        padding-right: 44px;
    }

    .nav__submenu-toggle {
        display: flex;
        position: absolute;
        top: 0;
        right: 0;
        width: 40px;
        height: 48px;
        align-items: center;
        justify-content: center;
        color: var(--color-primary);
    }

    .nav__submenu-toggle::before {
        content: '';
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(45deg);
        transition: transform 0.25s ease;
    }

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

    .nav__submenu {
        position: static;
        min-width: 0;
        padding: 0;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .nav__submenu.is-open {
        max-height: 500px;
    }

    .nav__submenu a {
        padding: 12px 0 12px 16px;
        color: var(--color-text-muted);
    }

    .nav__submenu a:hover,
    .nav__submenu a:focus-visible {
        background: transparent;
    }
}
