.menu-button {
  background-color: transparent;
  border: none;
  outline: none;
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 6px;
  cursor: pointer;
  position: relative;

  .line {
    display: block;
    background-color: var(--black-color);
    width: 24px;
    height: 4px;
    border-radius: 2px;
    transition: all 0.3s ease-in-out;
    transform-origin: center;

    &:nth-of-type(2) {
      width: 32px;
    }
  }
}

.menu-button.active {
  .line {
    /* Primeira linha - rotaciona 45° e move para o centro */
    &:nth-of-type(1) {
      transform: translateY(10px) rotate(45deg);
      width: 32px;
    }

    /* Segunda linha - desaparece */
    &:nth-of-type(2) {
      opacity: 0;
      transform: scaleX(0);
    }

    /* Terceira linha - rotaciona -45° e move para o centro */
    &:nth-of-type(3) {
      transform: translateY(-10px) rotate(-45deg);
      width: 32px;
    }
  }
}

.menu-container {
  position: absolute;
  top: 100%;
  left: 0;
  width: 90%;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem;
  background-color: var(--white-color);
  z-index: 100;
  transform: translateX(-100%);
  opacity: 0;
  transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;

  /* Menu principal (nível 1) */
  .menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  /* Item de menu nível 1 */
  .menu-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;

    > a {
      flex: 1;
      font: 600 2rem/1.2 var(--primary-font);
      color: var(--secondary-color);
      padding: 1rem 0;
      text-decoration: none;
      position: relative;
      min-width: 0; /* Permite que o texto quebre se necessário */
    }

    /* Indicador de página atual - barra lateral (sem mudar cor do texto) */
    &.current-menu-item > a::before,
    &.current_page_item > a::before {
      content: "";
      position: absolute;
      left: -1.5rem;
      top: 50%;
      transform: translateY(-50%);
      width: 4px;
      height: 70%;
      background-color: var(--primary-color);
      border-radius: 2px;
    }
  }

  /* Botão toggle para submenu - alinhado à direita */
  .submenu-toggle {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-left: 1rem; /* Garante espaço entre o texto e a seta */

    svg {
      width: 24px;
      height: 24px;
      stroke: var(--secondary-color);
      transition: transform 0.3s ease;
    }

    &.active svg {
      transform: rotate(180deg);
    }
  }

  /* Submenu (nível 2) - sempre em nova linha */
  .sub-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    background-color: rgba(0, 0, 0, 0.02);
    width: 100%; /* Força o submenu a ocupar 100% da largura */
    order: 999; /* Garante que o submenu apareça sempre por último */

    &.active {
      max-height: 1000px;
    }

    > .menu-item {
      border-bottom: 1px solid rgba(0, 0, 0, 0.05);
      padding-left: 1.5rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      width: 100%;

      > a {
        flex: 1;
        font: 600 1.5rem/1.2 var(--primary-font);
        padding: 0.75rem 0;
        min-width: 0;
      }

      /* Indicador de página atual - nível 2 (sem mudar cor) */
      &.current-menu-item > a::before,
      &.current_page_item > a::before {
        left: -1.5rem;
        width: 3px;
        height: 60%;
      }
    }

    /* Submenu nível 3 */
    .sub-menu {
      background-color: rgba(0, 0, 0, 0.04);
      width: 100%;
      order: 999;

      > .menu-item {
        padding-left: 2rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        width: 100%;

        > a {
          flex: 1;
          font: 500 1rem/1.2 var(--secondary-font);
          padding: 0.5rem 0;
          min-width: 0;
        }

        /* Indicador de página atual - nível 3 (sem mudar cor) */
        &.current-menu-item > a::before,
        &.current_page_item > a::before {
          left: -2.5rem;
          width: 2px;
          height: 50%;
        }
      }
    }
  }
}

.menu-container.active {
  transform: translateX(0);
  opacity: 1;
}

.menu-container + .menu-overlay {
  display: none;
}

.menu-container.active + .menu-overlay {
  display: block;
  position: fixed;
  top: 100%;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.menu-open {
  overflow: hidden;
}
.search-button {
  cursor: pointer;
  background-color: transparent;
  outline: none;
  border: none;

  display: inline-flex;
  vertical-align: middle;
  height: 110px;
  margin-top: 40px;
  width: 45%;
}
.header__link-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* ========================================
   DESKTOP - 1024px+
   ======================================== */
@media (min-width: 1024px) {
  .search-button {
    cursor: pointer;
    display: block;
    height: auto;
    margin-top: 0;
    width: auto;
  }
  .menu-button {
    display: none;
  }
  .menu-container {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 0;
    background-color: transparent;
    transform: translateX(0);
    opacity: 1;
    display: flex;
    align-items: center;
    gap: 1.5rem;

    .menu-item {
      border-bottom: none;
      display: block; /* ✅ Reseta o flex do mobile */
      position: relative;
      width: auto; /* ✅ Reseta o width: 100% do mobile */
      justify-content: initial; /* ✅ Reseta o space-between */

      > a {
        font: 400 2rem/1 var(--primary-font);
        padding: 0.5rem 0;
        white-space: nowrap;
        transition: color 0.3s ease;
        min-width: initial; /* ✅ Reseta o min-width do mobile */

        &:hover {
          color: var(--primary-color);
        }
      }

      .submenu-toggle {
        width: 20px;
        height: 20px;
        margin-left: 0.25rem;
        display: inline-flex;
        vertical-align: middle;

        svg {
          width: 16px;
          height: 16px;
        }
      }

      &.current-menu-item > a::before,
      &.current_page_item > a::before {
        display: none;
      }
    }
    .header__link-wrapper {
      margin-top: 0;
    }
    .sub-menu {
      position: absolute;
      top: 100%;
      left: 0;
      max-width: 280px;
      max-height: none;
      background-color: #fff;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
      border-radius: 4px;
      padding: 0.5rem 0;
      margin-top: 0.5rem;
      opacity: 0;
      visibility: hidden;
      transform: translateY(-10px);
      transition: all 0.3s ease;
      z-index: 1000;
      width: auto; /* ✅ Reseta o width: 100% do mobile */
      order: initial; /* ✅ Reseta o order: 999 do mobile */

      &.active {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        max-height: none;
      }

      > .menu-item {
        padding-left: 0;
        display: block; /* ✅ Reseta o flex do mobile */
        border-bottom: none;
        width: auto; /* ✅ Reseta o width: 100% do mobile */
        justify-content: initial; /* ✅ Reseta o space-between */

        > a {
          font: 600 1.25rem/1.4 var(--primary-font);
          padding: 0.75rem 1.5rem;
          display: block;
          min-width: initial; /* ✅ Reseta o min-width do mobile */

          &:hover {
            background-color: rgba(180, 201, 65, 0.1);
          }
        }

        /* Indicador nível 2 - barra lateral */
        &.current-menu-item > a::before,
        &.current_page_item > a::before {
          left: 0;
          width: 3px;
          height: 100%;
          top: 0;
          transform: none;
        }
      }

      /* Submenu nível 3 - dropdown lateral */
      .sub-menu {
        position: absolute;
        top: 0;
        left: 100%;
        margin-top: 0;
        margin-left: 0.5rem;
        width: auto; /* ✅ Reseta o width: 100% do mobile */
        order: initial; /* ✅ Reseta o order: 999 do mobile */

        > .menu-item {
          padding-left: 0;
          display: block; /* ✅ Reseta o flex do mobile */
          width: auto; /* ✅ Reseta o width: 100% do mobile */
          justify-content: initial; /* ✅ Reseta o space-between */

          > a {
            font: 500 1.25rem/1.4 var(--secondary-font);
            padding: 0.5rem 1.5rem;
            min-width: initial; /* ✅ Reseta o min-width do mobile */
          }

          &.current-menu-item > a::before,
          &.current_page_item > a::before {
            left: 0;
            width: 2px;
            height: 100%;
          }
        }
      }
    }
  }

  .menu {
    flex-direction: row !important;
    gap: 2rem !important;
    align-items: center;
  }

  .menu-item:hover > .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .menu-overlay {
    display: none !important;
  }

  .menu-open {
    overflow: auto;
  }
}
