/* =========================================================
   Tree menu
   Classic +/- tree version
   ========================================================= */

.menuBodyLocked {
  overflow: hidden;
}

.menuBackdrop {
  position: fixed;
  inset: 0;
  background: var(--colorMenuBackdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 9990;
}

.menuBackdrop--open {
  opacity: 1;
  pointer-events: auto;
}

.menu {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 280px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid var(--colorMenuBorder);
  background: linear-gradient(
    180deg,
    var(--colorMenuBgTop),
    var(--colorMenuBgBottom)
  );
  box-shadow:
    0 20px 60px var(--colorMenuShadow),
    0 0 0 1px var(--colorMenuShadowLine);
  transform: translateY(-8px) scale(0.985);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 9991;
  overflow: hidden;
}

.menu--open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.menuHeader {
  padding: 14px 16px;
  border-bottom: 1px solid var(--colorMenuHeaderBorder);
}

.menuTitle {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--colorMenuTitle);
}

.menuBody {
  overflow: auto;
  padding: 12px 12px 16px 12px;
}

.menu__panel {
  width: 100%;
  max-height: calc(100vh - 32px);
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.menu__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 12px 16px 12px;
}

.menu__footer {
  min-height: 36px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--colorMenuHeaderBorder);
  background: rgba(0, 0, 0, 0.16);
}

.menu__footerLabel {
  color: var(--colorMenuEmptyText);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.menu__themeToggle {
  position: relative;
  min-width: 112px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.menu__themeInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.menu__themeOptions {
  position: relative;
  width: 112px;
  height: 26px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 2px;
  border: 1px solid var(--colorMenuBorder);
  border-radius: 999px;
  background: var(--colorMenuToggleBg);
  overflow: hidden;
}

.menu__themeOptions::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(50% - 2px);
  height: calc(100% - 4px);
  border-radius: 999px;
  background: var(--colorBtnYellowBg);
  border: 1px solid var(--colorBtnYellowBorder);
  box-shadow: 0 0 10px rgba(234, 179, 8, 0.24);
  transition: transform 120ms ease;
}

.menu__themeInput:checked + .menu__themeOptions::before {
  transform: translateX(100%);
  background: var(--colorBtnBlueBg);
  border-color: var(--colorBtnBlueBorder);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.28);
}

.menu__themeOption {
  position: relative;
  z-index: 1;
  color: var(--colorMenuEmptyText);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  user-select: none;
}

.menu__themeInput:not(:checked) + .menu__themeOptions .menu__themeOption--light,
.menu__themeInput:checked + .menu__themeOptions .menu__themeOption--dark {
  color: var(--colorWhite);
}

.menu__themeText {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.menu__themeInput:not(:checked) ~ .menu__themeText::before {
  content: "Light";
}

.menu__themeInput:checked ~ .menu__themeText::before {
  content: "Dark";
}

.menu__themeInput:focus-visible + .menu__themeOptions {
  box-shadow: 0 0 0 1px var(--colorFieldFocusRing);
}

.menuList {
  min-height: 40px;
}

.menuEmpty {
  padding: 14px;
  color: var(--colorMenuEmptyText);
  font-size: 14px;
}

.menuTree,
.menuChildren {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menuTree {
  position: relative;
}

.menuItem {
  position: relative;
  margin: 0;
  padding: 0;
}

.menuChildren {
  position: relative;
  display: none;
}

.menuItem--open > .menuChildren {
  display: block;
}

.menuRow {
  position: relative;
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.menuRow:hover {
  background: var(--colorMenuRowHover);
}

.menuLeft {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
  gap: 6px;
}

.menuIndent {
  position: relative;
  width: calc(var(--tree-level) * 18px);
  min-width: calc(var(--tree-level) * 18px);
  height: 24px;
  flex: 0 0 auto;
}

.menuToggle {
  position: relative;
  transform: translateY(1.5px);
  width: 14px;
  height: 14px;
  min-width: 14px;
  border: 0;
  background: transparent;
  color: var(--colorMenuTreeLine);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  pointer-events: none;
}

.menuToggleBox {
  width: 14px;
  height: 14px;
  border: 1px solid var(--colorMenuTreeLine);
  background: var(--colorMenuToggleBg);
  color: var(--colorMenuTreeLine);
  font-size: 12px;
  line-height: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.menuToggleSpacer {
  width: 14px;
  height: 14px;
  display: inline-block;
}

.menuLabel {
  min-width: 0;
  color: var(--colorMenuLabel);
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menuItem--group > .menuRow .menuLabel {
  font-weight: 700;
  color: var(--colorMenuGroupLabel);
}

.menuItem--leaf > .menuRow .menuLabel {
  font-weight: 500;
  color: var(--colorMenuLeafLabel);
}

/* =========================================================
   Tree connector lines
   ========================================================= */

.menuChildren > .menuItem::before {
  content: "";
  position: absolute;
  left: 21px;
  top: -8px;
  bottom: -8px;
  width: 1px;
  background: var(--colorMenuTreeLine);
  opacity: 1;
}

.menuChildren > .menuItem::after {
  content: "";
  position: absolute;
  left: 21px;
  top: 18px;
  width: 21px;
  height: 1px;
  background: var(--colorMenuTreeLine);
  opacity: 1;
}

.menuChildren > .menuItem--last::before {
  bottom: calc(100% - 19px);
}

/* Make nested levels continue visually */
.menuChildren .menuChildren > .menuItem::before {
  left: 35px;
}

.menuChildren .menuChildren > .menuItem::after {
  left: 35px;
}

/* =========================================================
   Minor polish
   ========================================================= */

.menuRow--leaf .menuLabel {
  opacity: 0.96;
}

.menuRow--group .menuLabel {
  letter-spacing: 0.01em;
}

@media (max-width: 760px) {
  .menu {
    top: 10px;
    right: 10px;
    left: 10px;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 20px);
  }
}

/* =========================================================
   Leaf marker for menu points
   ========================================================= */

.menuItem--leaf > .menuRow .menuToggleSpacer {
  position: relative;
}

.menuItem--leaf > .menuRow .menuToggleSpacer::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--colorMenuTreeLine);
  display: block;
  margin: 4px auto 0;
}
