/**
 * Mobile Navigation - Split Click Target Styles
 * 
 * Enables parent menu items to be clickable while providing
 * a separate toggle button to expand/collapse dropdown menus.
 *
 * @package TRDW
 * @since 1.0.2
 */

/* ============================================
   SPLIT CLICK TARGET - MOBILE ONLY
   ============================================ */

@media (max-width: 991.98px) {
    
    /* Container for the link + toggle button */
    .dropdown-link-wrapper {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }
    
    /* Parent link takes most of the space */
    .dropdown-parent-link {
        flex: 1;
        padding-right: 0.5rem !important;
    }
    
    /* Toggle button styling */
    .dropdown-toggle-split {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        padding: 0;
        margin: 0;
        border: none;
        background-color: transparent;
        cursor: pointer;
        border-left: 1px solid rgba(0, 0, 0, 0.1);
        transition: background-color 0.2s ease;
    }
    
    .dropdown-toggle-split:hover,
    .dropdown-toggle-split:focus {
        background-color: rgba(0, 61, 130, 0.1);
        outline: none;
    }
    
    .dropdown-toggle-split:focus-visible {
        outline: 2px solid var(--color-primary, #003d82);
        outline-offset: -2px;
    }
    
    /* Toggle icon (chevron) */
    .dropdown-toggle-icon {
        display: block;
        width: 10px;
        height: 10px;
        border-right: 2px solid var(--color-primary, #003d82);
        border-bottom: 2px solid var(--color-primary, #003d82);
        transform: rotate(45deg);
        transition: transform 0.25s ease;
    }
    
    /* Rotate chevron when dropdown is open */
    .nav-item.dropdown.show > .dropdown-link-wrapper .dropdown-toggle-icon,
    .dropdown.show > .dropdown-link-wrapper .dropdown-toggle-icon {
        transform: rotate(-135deg);
    }
    
    /* Nested dropdown toggles (third level) */
    .dropdown-menu .dropdown-toggle-split {
        width: 40px;
        min-width: 40px;
        height: 40px;
        min-height: 40px;
    }
    
    .dropdown-menu .dropdown-toggle-icon {
        width: 8px;
        height: 8px;
    }
    
    /* Ensure dropdown menus display correctly */
    .navbar-nav .dropdown-menu {
        position: static;
        float: none;
        width: 100%;
        margin-top: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        background-color: rgba(0, 0, 0, 0.02);
        display: none;
    }
    
    .navbar-nav .dropdown.show > .dropdown-menu {
        display: block;
    }
    
    /* Indent dropdown items */
    .navbar-nav .dropdown-menu .dropdown-item {
        padding-left: 1.5rem;
    }
    
    .navbar-nav .dropdown-menu .dropdown-link-wrapper {
        padding-left: 1rem;
    }
    
    /* Third level indentation */
    .navbar-nav .dropdown-menu .dropdown-menu .dropdown-item,
    .navbar-nav .dropdown-menu .dropdown-menu .dropdown-link-wrapper {
        padding-left: 2.5rem;
    }
    
    /* Visual separator between parent items with dropdowns */
    .nav-item.has-dropdown-toggle {
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    .nav-item.has-dropdown-toggle:last-child {
        border-bottom: none;
    }
    
}

/* ============================================
   DESKTOP - HIDE SPLIT TOGGLE
   ============================================ */

@media (min-width: 992px) {
    
    /* On desktop, show items inline without the wrapper affecting layout */
    .dropdown-link-wrapper {
        display: contents;
    }
    
    /* Hide the toggle button on desktop (dropdown shows on hover) */
    .dropdown-toggle-split {
        display: none;
    }
    
    /* Add dropdown arrow to parent links on desktop */
    .dropdown-parent-link::after {
        display: inline-block;
        margin-left: 0.5em;
        vertical-align: middle;
        content: "";
        border-top: 0.3em solid;
        border-right: 0.3em solid transparent;
        border-bottom: 0;
        border-left: 0.3em solid transparent;
    }
    
    /* Third level - arrow points right */
    .dropdown-menu .dropdown-parent-link::after {
        border-top: 0.3em solid transparent;
        border-right: 0;
        border-bottom: 0.3em solid transparent;
        border-left: 0.3em solid;
        float: right;
        margin-top: 0.4em;
        margin-left: auto;
    }
    
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Screen reader text for toggle buttons */
.dropdown-toggle-split .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles */
.dropdown-parent-link:focus {
    outline: 2px solid var(--color-primary, #003d82);
    outline-offset: -2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .dropdown-toggle-split {
        border-left: 2px solid currentColor;
    }
    
    .dropdown-toggle-icon {
        border-right-width: 3px;
        border-bottom-width: 3px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .dropdown-toggle-icon {
        transition: none;
    }
    
    .dropdown-toggle-split {
        transition: none;
    }
}