/* menu.css v4.1 | bun/public/css/menu.css */

:root {
  --menu-w: 90px;
  --item-h: 100px;
  --mob-h: 50px;
  --submenu-bottom: calc(
    max(16px, env(safe-area-inset-bottom)) + var(--mob-h) + 2px
  );
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- LAYOUT --- */
.app-layout-container {
  position: relative !important;
  overflow-x: hidden !important;
  display: flex !important;
  flex-direction: row;
  width: 100%;

  @media (max-width: 768px) {
    display: block !important;
    overflow-x: visible !important;
  }
}

.page-content-shifter {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* menu.js sets --menu-items on the element holding the drawer */
.has-vertical-menu {
  @media (min-width: 769px) {
    min-height: calc(var(--item-h) * var(--menu-items, 0));
  }
}

body {
  @media (max-width: 768px) {
    padding-bottom: env(safe-area-inset-bottom) !important;
  }
}

/* --- HAMBURGER BUTTON --- */
.hamburger-menu {
  position: relative;
  z-index: 101;
  right: 12px;

  @media (max-width: 768px) {
    display: none;
  }
}

.menu__btn {
  width: 35px;
  height: 50px;
  cursor: pointer;
  position: relative;
  z-index: 1;

  & span,
  & span::before,
  & span::after {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    border-radius: 3px;
    background: var(--theme-on-accent);
    transition:
      transform 0.3s var(--ease),
      top 0.3s var(--ease);
  }

  & span {
    margin-top: -2px;

    &::before {
      content: "";
      top: -10px;
    }

    &::after {
      content: "";
      top: 10px;
    }
  }

  &.open span {
    background: transparent;

    &::before {
      top: 0;
      transform: rotate(45deg);
    }

    &::after {
      top: 0;
      transform: rotate(-45deg);
    }
  }
}

/* --- ITEMS (shared by the bar and the submenu) --- */
:is(.vertical-menu, .submenu) {
  &,
  & * {
    box-sizing: border-box;
  }

  & :is(a, button) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 5px;
    border: 0;
    background: none;
    font: inherit;
    color: var(--theme-nav-text);
    text-decoration: none;
    cursor: pointer;
    transition:
      background-color 0.2s,
      color 0.3s;

    @media (hover: hover) {
      &:hover:not(.active, .parent-active) {
        background: var(--theme-nav-hover);
      }
    }

    &:focus-visible {
      outline: 2px solid var(--theme-nav-active-text);
      outline-offset: -3px;
    }
  }

  & .mi {
    flex: none;
    width: 1.5rem;
    height: 1.5rem;
    margin-bottom: 8px;
    fill: currentColor;

    @media (max-width: 768px) {
      width: 1.1rem;
      height: 1.1rem;
      margin: 0;
    }
  }

  & span {
    font-size: 0.8rem;
    text-align: center;
    line-height: 1.1;

    @media (max-width: 768px) {
      max-width: 100%;
      padding: 0 1px;
      font-size: 10px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

/* --- MENU: drawer on desktop, bottom bar on mobile --- */
.vertical-menu {
  position: absolute;
  top: 0;
  right: calc(var(--menu-w) * -1);
  z-index: 100;
  display: flex;
  flex-direction: column;
  width: var(--menu-w);
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: var(--theme-nav-bg);
  box-shadow: -2px 0 5px rgba(var(--theme-shadow-rgb), 0.1);
  scrollbar-width: thin;
  scrollbar-color: var(--theme-nav-scrollbar) transparent;
  opacity: 0;
  visibility: hidden;
  transition:
    right 0.3s var(--ease),
    opacity 0.3s,
    visibility 0.3s;

  &.open {
    right: 0;
    opacity: 1;
    visibility: visible;
  }

  @media (max-width: 768px) {
    position: fixed;
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    z-index: 141;
    flex-direction: row;
    width: auto;
    height: var(--mob-h);
    overflow: hidden;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(var(--theme-shadow-rgb), 0.15);
    scrollbar-width: none;
    opacity: 1;
    visibility: visible;
    transition: translate 0.3s var(--ease);

    &.menu-hidden {
      translate: 0 calc(100% + max(60px, env(safe-area-inset-bottom) + 20px));
    }

    &.open {
      right: 8px;
    }
  }

  & > ul {
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;

    @media (max-width: 768px) {
      display: flex;
      justify-content: space-between;
      height: 100%;
    }

    & > li {
      height: var(--item-h);
      border-bottom: 1px solid var(--theme-nav-line);

      @media (max-width: 768px) {
        position: relative;
        display: flex;
        flex: 1;
        min-width: 0;
        height: 100%;
        border-bottom: none;

        &::after {
          content: "";
          position: absolute;
          top: 10%;
          right: 0;
          width: 1px;
          height: 80%;
          background: var(--theme-nav-divider);
        }

        &:last-child::after {
          display: none;
        }

        & > :is(a, button) {
          gap: 2px;
          padding: 2px 0;
        }

        &:first-child > :is(a, button) {
          padding-left: 10px;
        }

        &:last-child > :is(a, button) {
          padding-right: 10px;
        }
      }

      & > a {
        &.active {
          background: var(--theme-nav-active-bg);
          color: var(--theme-nav-active-text);
        }

        &.parent-active {
          background: linear-gradient(
            90deg,
            var(--theme-nav-active-bg) 0%,
            var(--theme-nav-active-fade) 100%
          );
          color: var(--theme-nav-active-text);
        }

        @media (max-width: 768px) {
          &.active {
            background: var(--theme-nav-active-mobile-bg);
          }
        }
      }
    }
  }

  & .parent-arrow {
    position: absolute;
    left: 8px;
    top: 12px;
    width: 1.2rem;
    height: 1.2rem;
    margin: 0;
    color: var(--theme-nav-active-text);
    pointer-events: none;

    @media (max-width: 768px) {
      left: 20%;
      top: 0;
      width: 1rem;
      height: 1rem;
      transform: translateX(-50%) rotate(90deg);
    }
  }

  /* While the highlight slides, the old item drops its own background */
  &.is-sliding > ul > li > a:is(.active, .parent-active) {
    background: transparent;
  }

  /* Visibility by role */
  &:not(.is-staff) .staff-only,
  &.is-guest .hide-for-guest,
  & > ul > li.is-hidden {
    display: none;
  }

  body.tg-miniapp & > ul > li:has(> a[href="/"], > #logoutBtn) {
    display: none;
  }
}

#menuStart {
  position: relative;
  -webkit-touch-callout: none;
  user-select: none;

  &:not([href]) {
    cursor: default;
  }
}

/* Highlight that slides to the clicked item while the next page loads */
.menu-slide {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  background: var(--theme-nav-active-bg);
  pointer-events: none;
  transition:
    translate 0.3s var(--ease),
    width 0.3s var(--ease),
    height 0.3s var(--ease);

  @media (max-width: 768px) {
    background: var(--theme-nav-active-mobile-bg);
  }
}

/* --- SUBMENU: flyout on desktop, sheet above the bar on mobile --- */
.has-submenu {
  position: relative;
}

.submenu {
  position: fixed;
  z-index: 150;
  width: var(--menu-w);
  max-height: 500px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  background: var(--theme-nav-bg);
  border-right: 1px solid var(--theme-nav-line);
  box-shadow: -2px 0 5px rgba(var(--theme-shadow-rgb), 0.15);
  scrollbar-width: thin;
  scrollbar-color: var(--theme-nav-scrollbar) transparent;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  translate: -15px 0;
  transition:
    opacity 0.2s,
    translate 0.3s var(--ease),
    visibility 0.2s;

  &.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    translate: 0 0;
  }

  & li {
    height: var(--item-h);
    border-bottom: 1px solid var(--theme-nav-line);
    opacity: 0;
    translate: -10px 0;
    transition:
      opacity 0.3s,
      translate 0.3s;
  }

  /* menu.js sets --i (item index) for the staggered entrance */
  &.show li {
    opacity: 1;
    translate: 0 0;
    transition-delay: calc(min(var(--i, 0), 8) * 50ms + 50ms);
  }

  & a {
    &.active {
      background: var(--theme-nav-active-bg);
      color: var(--theme-nav-active-text);
    }

    & span {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3;
      overflow: hidden;
      word-break: break-word;
    }

    & .mi {
      scale: 0.8;
      transition: scale 0.4s var(--ease);
    }
  }

  &.show a .mi {
    scale: 1;
  }

  @media (max-width: 768px) {
    display: flex;
    flex-direction: column;
    max-height: 60vh;
    overflow: hidden;
    border: 1px solid var(--theme-nav-line);
    border-bottom: none;
    box-shadow: 0 -4px 10px rgba(var(--theme-shadow-rgb), 0.1);
    scrollbar-width: none;
    translate: 0 calc(100% + 20px);

    &.show {
      translate: 0 0;
    }

    & li {
      display: flex;
      flex-shrink: 0;
      width: 100%;
      height: var(--mob-h);
      translate: 0 10px;

      &:last-child {
        border-bottom: none;
      }
    }

    &.show li {
      translate: 0 0;
    }

    & a {
      gap: 2px;
      padding: 2px 0;

      & .mi {
        scale: 1;
      }

      & span {
        display: block;
        -webkit-line-clamp: unset;
        width: 100%;
        padding: 0 2px;
      }

      &.active {
        background: var(--theme-nav-active-mobile-bg);
      }
    }
  }
}

.menu-backdrop {
  @media (max-width: 768px) {
    position: fixed;
    inset: 0;
    z-index: 140;
    background-color: rgba(var(--theme-shadow-rgb), 0.5);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      opacity 0.3s ease,
      visibility 0.3s;

    &.show {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  :is(.vertical-menu, .submenu, .menu-backdrop, .menu__btn span),
  :is(.vertical-menu, .submenu) *,
  .menu__btn span::before,
  .menu__btn span::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
