/**
 * Final comprehensive fix for dropdown alignment and width issues
 * This overrides all previous conflicting styles
 */

/* CRITICAL: Remove all previous positioning conflicts */
.sp-dropdown,
.sp-dropdown.sp-dropdown-main,
.sp-dropdown.sp-menu-right,
.sp-megamenu-wrapper .sp-dropdown {
    /* Reset everything */
    display: none !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    
    /* Width settings */
    width: auto !important;
    min-width: 220px !important;
    max-width: none !important;
    
    /* Styling */
    background: #ffffff !important;
    border: 1px solid #ddd !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    border-radius: 4px !important;
    overflow: visible !important;
    z-index: 99999 !important;
}

/* Parent menu items must be relative */
.sp-megamenu-parent > li {
    position: relative !important;
}

/* Show dropdowns on hover */
.sp-megamenu-parent > li:hover > .sp-dropdown,
.sp-megamenu-parent > li.active > .sp-dropdown {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Inner content styling */
.sp-dropdown .sp-dropdown-inner,
.sp-dropdown ul,
.sp-dropdown .sp-dropdown-items {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    list-style: none !important;
    background: transparent !important;
}

/* List items */
.sp-dropdown li {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
}

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

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

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

/* Width management - let content determine width */
.sp-dropdown {
    width: max-content !important;
    min-width: 220px !important;
    max-width: 400px !important;
}

/* Special handling for rightmost items only if needed */
@media (min-width: 992px) {
    /* Calculate if dropdown would overflow */
    .sp-megamenu-parent > li:last-child > .sp-dropdown,
    .sp-megamenu-parent > li:nth-last-child(2) > .sp-dropdown {
        /* Keep left alignment by default */
        left: 0 !important;
        right: auto !important;
    }
    
    /* Only if explicitly marked as right-aligned */
    .sp-dropdown.sp-menu-right {
        left: auto !important;
        right: 0 !important;
    }
}

/* Override any inline styles */
.sp-dropdown[style] {
    left: 0 !important;
    right: auto !important;
}

/* Specific menu fixes */
#sp-menu .sp-megamenu-parent > li > .sp-dropdown {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: auto !important;
}

/* Remove any conflicting display modes */
.sp-dropdown:not(:hover) {
    display: none !important;
}

/* Ensure proper width calculation */
.sp-dropdown * {
    box-sizing: border-box !important;
}

/* Force specific dropdown positions */
.item-437 > .sp-dropdown, /* Tools */
.item-123 > .sp-dropdown, /* H2i, LLC */
.item-101 > .sp-dropdown { /* Other menus */
    left: 0 !important;
    right: auto !important;
    position: absolute !important;
}

/* High specificity override */
#sp-header #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent > li > .sp-dropdown {
    position: absolute !important;
    left: 0 !important;
    right: auto !important;
    top: 100% !important;
}

/* Remove all transforms and weird positioning */
.sp-dropdown,
.sp-dropdown * {
    transform: none !important;
    float: none !important;
    clear: none !important;
}

/* Ensure dropdowns appear in correct position */
.sp-megamenu-parent > li {
    position: relative !important;
    display: inline-block !important;
}

/* Very specific override for stubborn dropdowns */
li.item-437.sp-menu-item.sp-has-child > .sp-dropdown {
    left: 0 !important;
    right: auto !important;
}

/* Debug positioning */
.sp-dropdown::before {
    content: '' !important;
    position: absolute !important;
    top: -5px !important;
    left: 20px !important;
    width: 10px !important;
    height: 10px !important;
    background: #fff !important;
    border-left: 1px solid #ddd !important;
    border-top: 1px solid #ddd !important;
    transform: rotate(45deg) !important;
    z-index: 1 !important;
}