
/* ════════════════════════════════════════════
   NAVBAR
════════════════════════════════════════════ */
.navbar-nav { gap: 8px; }

/* z-index: 0 (any explicit value, not just "auto") makes each item its
   own stacking context - without it, an open dropdown's z-index: 9999
   (below) escapes past its own <li> and renders above *every* sibling
   button, including ones wrapped onto a second row directly beneath it,
   making them unclickable. With it, a dropdown only ever outranks
   page content below the header, never a sibling category button. */
.navbar-nav > li {
    position: relative;
    z-index: 0;
}

/* Bootstrap's reboot sets border-box globally, but the table-style
   dropdown rows below size themselves to exactly 100% of their row
   and would overflow it under padding on a content-box default -
   don't depend on that being loaded. */
.dropdown-menu,
.dropdown-menu * {
    box-sizing: border-box;
}

/* ════════════════════════════════════════════
   ROOT BUTTON
════════════════════════════════════════════ */
.mymenu {
    min-width: 130px;
    height: 50px;
    padding: 0 22px;
    background: var(--color-menu-surface);
    color: var(--color-menu-text);
    border: 1.5px solid var(--color-menu-border);
    border-radius: var(--radius-sm);
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast),
                border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.mymenu:hover {
    background: var(--color-menu-hover);
    color: var(--color-bootstrap-primary);
    border-color: var(--color-bootstrap-primary);
}
.mymenu:focus-visible {
    outline: 2px solid var(--color-bootstrap-primary);
    outline-offset: 2px;
}
.mymenu[aria-expanded="true"] {
    background: var(--color-menu-active);
    color: var(--color-bootstrap-primary);
    border-color: var(--color-bootstrap-primary);
    box-shadow: var(--shadow-dropdown);
}

/* Bootstrap's own caret is a plain CSS triangle with no transition hook,
   so it snaps instantly on open/close. Replace it with a text glyph we
   can rotate smoothly to match the panel's own fade-in. */
.mymenu.dropdown-toggle::after {
    display: inline-block;
    content: "\25BE";
    border: none;
    font-size: 13px;
    line-height: 1;
    margin-left: 2px;
    transition: transform var(--transition-base);
}
.mymenu.dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

/* ════════════════════════════════════════════
   DROPDOWN PANEL — a bordered table, not a
   floating card: flat edges, a solid rule, no
   drop shadow. Always in the layout, faded/
   scaled out until .show is applied, so opening
   it is an animation rather than an instant swap.
════════════════════════════════════════════ */
.dropdown-menu {
    display: block;
    position: absolute;
    padding: 0;
    min-width: 210px;
    max-width: 280px;
    width: max-content;
    border: 1.5px solid var(--color-menu-border);
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
    z-index: 9999;
    /* visible, not hidden: a flyout submenu is an absolutely-positioned
       descendant anchored outside this panel's own box (see "FLYOUT
       PANEL" below) - clipping overflow here would cut it off. Rows have
       no border-radius of their own, so the only place this matters is
       the panel's own rounded corners, handled on the first/last row
       below instead. */
    overflow: visible;
    background: var(--color-menu-surface);

    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(.98);
    transform-origin: top left;
    pointer-events: none;
    transition: opacity var(--transition-base), transform var(--transition-base),
                visibility 0s linear var(--transition-base);
}
.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition: opacity var(--transition-base), transform var(--transition-base),
                visibility 0s linear 0s;
}

/* ════════════════════════════════════════════
   ALL LI — table rows, ruled off from each other
════════════════════════════════════════════ */
.dropdown-menu li {
    position: relative;
    padding: 0;
    margin: 0;
    border-bottom: 1px solid var(--color-menu-border);
}
.dropdown-menu li:last-child {
    border-bottom: none;
}
/* Round the panel's own corners via its first/last row instead of
   clipping (see overflow: visible above). */
.dropdown-menu li:first-child > a {
    border-radius: 4.5px 4.5px 0 0;
}
.dropdown-menu li:last-child > a {
    border-radius: 0 0 4.5px 4.5px;
}

/* ════════════════════════════════════════════
   LEAF LINKS
════════════════════════════════════════════ */
.dropdown-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 0;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--color-menu-text) !important;
    white-space: normal;
    word-break: break-word;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.dropdown-item:hover,
.dropdown-item:focus-visible {
    background: var(--color-menu-hover);
    color: var(--color-bootstrap-primary) !important;
}
.dropdown-item:focus-visible {
    outline: 2px solid var(--color-bootstrap-primary);
    outline-offset: -2px;
}

/* Grade a leaf's page is for (templatetag menu_item_grade): a quiet chip
   at the right end of the row, so teachers see «5-кл.» before clicking. */
.menu-grade {
    flex: none;
    margin-left: auto;
    padding: 1px 7px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    color: var(--text-muted);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
}
.dropdown-item:has(.menu-grade) { gap: 10px; }

/* ════════════════════════════════════════════
   SUBMENU TOGGLE — same shape as a leaf link
════════════════════════════════════════════ */
.dropdown-submenu { position: relative; }

.dropdown-submenu > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 0;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--color-menu-text);
    white-space: normal;
    word-break: break-word;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.dropdown-submenu > a:hover,
.dropdown-submenu > a:focus-visible {
    background: var(--color-menu-hover);
    color: var(--color-bootstrap-primary);
}

/* Right arrow — only submenu toggles get one, matching the reference's
   "chevron means this row opens a further level" convention. */
.dropdown-submenu > a::after {
    content: "\203A";
    border: none;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    color: var(--color-bootstrap-primary);
    transition: transform var(--transition-base);
}
.dropdown-submenu > a:hover::after {
    transform: translateX(2px);
}

/* Shown in a category panel that was opened before /menu/ finished. */
.menu-loading {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-muted);
    cursor: default;
}

/* ════════════════════════════════════════════
   FLYOUT PANEL — sits flush against the parent
   panel's edge (shared border line) like an
   adjoining table column, not a separate
   floating card off to the side.
════════════════════════════════════════════ */
.dropdown-submenu > .dropdown-menu {
    position: absolute;
    top: -1.5px;
    left: calc(100% - 1.5px);
    margin: 0;
    transform-origin: top left;
}

.dropdown-submenu.dropstart > .dropdown-menu {
    left: auto;
    right: calc(100% - 1.5px);
    transform-origin: top right;
}

/* ════════════════════════════════════════════
   MOBILE — below the navbar-expand-lg breakpoint the
   nav collapses to a stacked list. A dropdown floating
   absolutely there would either overlay the sibling
   category buttons or run off-screen, so it's put back
   into normal flow instead: opening it pushes the rest
   of the list down, like a native accordion.
════════════════════════════════════════════ */
@media (max-width: 991.98px) {
    /* The header itself is .fixed-top (position: fixed, see
       header.html) so page scroll never reaches it - that's fine while
       it's short, but once a category's accordion opens, its total
       height (nav chrome + category buttons + the open list) can
       exceed the viewport. With no bound of its own, everything past
       the screen edge was simply unreachable: not visible, and not
       reachable by scrolling the page, since a fixed element doesn't
       move with it. Capping its own height and giving it its own
       scroll fixes that - this is a different, higher-up fix than
       .dropdown-menu.show's 70vh cap below, which only bounds one
       category's own list and doesn't help once the *header as a
       whole* is taller than the screen. */
    .fixed-top {
        max-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* The category bar's own markup hard-codes flex-row/flex-wrap/
       justify-content-center (see header.html) so it can sit as a single
       centered row on desktop. Below the breakpoint that made every
       button size to its own text and center on its own wrapped line -
       a different width per item instead of one consistent stacked list.
       #categoryNav's id beats those single-class Bootstrap utilities on
       specificity, no !important needed. */
    #categoryNav .navbar-nav {
        flex-direction: column;
        align-items: stretch;
    }
    #categoryNav .navbar-nav > li.nav-item {
        width: 100%;
    }
    #categoryNav .mymenu {
        width: 100%;
    }

    .dropdown-menu {
        position: static;
        width: 100%;
        max-width: 100%;
        margin-top: 6px;
        transform: none;
        transform-origin: top center;

        /* display:block+opacity/visibility alone would still take up
           layout space while "closed"; collapse it via max-height so
           the accordion actually pushes content instead of leaving a
           gap. */
        max-height: 0;
        overflow: hidden;
        padding: 0;
        border-width: 0;
        box-shadow: none;
        transition: max-height var(--transition-base), opacity var(--transition-base),
                    padding var(--transition-base), border-width var(--transition-base),
                    visibility 0s linear var(--transition-base);
    }
    .dropdown-menu.show {
        max-height: 70vh;
        overflow-y: auto;
        padding: 0;
        border-width: 1.5px;
        transition: max-height var(--transition-base), opacity var(--transition-base),
                    padding var(--transition-base), border-width var(--transition-base),
                    visibility 0s linear 0s;
    }

    .dropdown-submenu > .dropdown-menu {
        position: static;
        left: auto;
        right: auto;
        top: auto;
        margin: 2px 0 2px 14px;
        border-width: 0 0 0 2px;
        border-radius: 0;
        box-shadow: none;
        width: calc(100% - 14px);
        max-width: calc(100% - 14px);
    }

    .dropdown-submenu > a::after {
        margin-left: auto;
    }
}

/* Users who've asked their OS/browser to cut down on motion get an
   instant toggle instead of a skipped-but-still-timed transition. */
@media (prefers-reduced-motion: reduce) {
    .mymenu,
    .mymenu.dropdown-toggle::after,
    .dropdown-menu,
    .dropdown-item,
    .dropdown-submenu > a,
    .dropdown-submenu > a::after {
        transition: none !important;
    }
}
