/**
 * Fix dropdown alignment with parent menu items
 * Ensures dropdowns appear directly below their triggers
 */

/* Reset positioning for proper alignment */
.sp-megamenu-parent > li {
    position: relative !important;
}

/* Standard left-aligned dropdowns */
.sp-megamenu-parent > li > .sp-dropdown {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: auto !important;
    margin: 0 !important;
    transform: none !important;
}

/* Only right-align the last dropdown if it would go off screen */
.sp-megamenu-parent > li:last-child > .sp-dropdown {
    left: auto !important;
    right: 0 !important;
}

/* Fix dropdown width while maintaining alignment */
.sp-dropdown {
    width: auto !important;
    min-width: 200px !important;
    max-width: 400px !important;
    white-space: nowrap !important;
}

/* Ensure dropdown doesn't inherit unwanted positioning */
.sp-dropdown.sp-dropdown-main {
    position: absolute !important;
    display: none;
}

/* Show on hover */
.sp-megamenu-parent > li:hover > .sp-dropdown {
    display: block !important;
}

/* Remove any display table/flex that might affect positioning */
.sp-dropdown {
    display: block !important;
}

.sp-dropdown .sp-dropdown-inner {
    display: block !important;
}

/* Ensure menu items expand naturally */
.sp-dropdown ul,
.sp-dropdown .sp-dropdown-items {
    display: block !important;
    width: 100% !important;
}

/* Let content determine width but maintain block layout */
.sp-dropdown {
    width: max-content !important;
    min-width: fit-content !important;
    max-width: 400px !important;
}

/* Fix specific menu alignments */
.sp-megamenu-parent > li.item-437 > .sp-dropdown { /* Tools */
    left: 0 !important;
    right: auto !important;
}

.sp-megamenu-parent > li.item-123 > .sp-dropdown { /* H2i, LLC */
    left: 0 !important;
    right: auto !important;
}

/* Ensure consistent dropdown behavior */
.sp-dropdown {
    background: #ffffff !important;
    border: 1px solid #ddd !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    border-radius: 4px !important;
    padding: 0 !important;
    overflow: hidden !important;
    z-index: 99999 !important;
}

/* Links styling */
.sp-dropdown a {
    display: block !important;
    padding: 12px 20px !important;
    color: #333 !important;
    background: #fff !important;
    text-decoration: none !important;
    border-bottom: 1px solid #eee !important;
    white-space: nowrap !important;
}

.sp-dropdown li:last-child a {
    border-bottom: none !important;
}

.sp-dropdown a:hover {
    background: #f5f5f5 !important;
}

/* Only apply special positioning to dropdowns that need it */
@media (min-width: 992px) {
    /* Check if dropdown would overflow viewport */
    .sp-megamenu-parent > li:nth-last-child(2) > .sp-dropdown {
        left: 0 !important; /* Keep default alignment */
    }
    
    /* Only the very last item gets right alignment */
    .sp-megamenu-parent > li:last-child > .sp-dropdown {
        left: auto !important;
        right: 0 !important;
    }
}

/* Remove any transforms or transitions that might affect position */
.sp-dropdown {
    transform: none !important;
    transition: opacity 0.2s ease, visibility 0.2s ease !important;
}

/* Ensure dropdowns stay within their parent's bounds */
.sp-megamenu-wrapper {
    position: relative !important;
}

/* Debug - ensure proper positioning */
.sp-megamenu-parent > li > .sp-dropdown {
    margin-top: 0 !important;
    margin-left: 0 !important;
}