/* LearnDash Course Category Navigation Styles */

.learndash-category-nav {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    margin: 20px 0;
}

/* Override any code tag styling that might be applied by themes or WordPress */
.learndash-category-nav code,
.learndash-category-nav .category-link code {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    font-family: inherit !important;
    font-size: inherit !important;
    color: inherit !important;
    border-radius: 0 !important;
    display: inline !important;
}

.learndash-category-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: block; /* Ensure proper block display for tree structure */
}

.learndash-category-nav .category-nav-level-0,
.learndash-category-nav .category-nav-level-1,
.learndash-category-nav .category-nav-level-2,
.learndash-category-nav .category-nav-level-3,
.learndash-category-nav .category-nav-level-4 {
    display: block; /* Override any grid/flex display */
    margin-left: 0;
    padding-left: 0;
}

.learndash-category-nav .category-item {
    position: relative;
    margin-bottom: 8px;
    overflow: visible; /* Ensure toggle button is not clipped */
}

/* Add tree connector lines */
.learndash-category-nav .category-item:not(:last-child)::after {
    content: '';
    position: absolute;
    left: -15px;
    top: 0;
    bottom: -8px;
    width: 1px;
    background: #e9ecef;
    z-index: 1;
}

.learndash-category-nav .category-item::before {
    content: '';
    position: absolute;
    left: -15px;
    top: 50%;
    width: 15px;
    height: 1px;
    background: #e9ecef;
    z-index: 1;
}

.learndash-category-nav .category-link {
    display: block;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    transition: all 0.3s ease;
    position: relative;
    padding-left: 16px; /* Reduced left padding for tree structure */
}

.learndash-category-nav .category-link:hover {
    background: #e9ecef;
    color: #007cba;
    text-decoration: none;
    border-color: #007cba;
}

.learndash-category-nav .category-item.has-children .category-link {
    padding-right: 50px;
    /* Ensure the category link provides proper positioning context */
    position: relative;
    z-index: 1;
}

.learndash-category-nav .toggle-children {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #007cba;
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
    /* Ensure the button stays within its parent container */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Prevent the button from being affected by content changes */
    flex-shrink: 0;
}

.learndash-category-nav .toggle-children:hover {
    background: #005a87;
}

/* Fix for toggle button positioning - ensure it stays in place */
.learndash-category-nav .category-item.has-children {
    position: relative;
    /* Ensure the toggle button container doesn't move */
    min-height: 48px; /* Minimum height to accommodate toggle button */
}

.learndash-category-nav .category-link .toggle-children {
    /* Position relative to the category link */
    position: absolute !important;
    right: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    /* Prevent any layout shifts */
    will-change: transform;
    /* Ensure it doesn't overlap with other elements */
    z-index: 100 !important;
    /* Reset any inherited positioning */
    left: auto !important;
    bottom: auto !important;
    /* Ensure proper containment */
    margin: 0 !important;
    padding: 0 !important;
    /* Ensure the button is clickable and stops event propagation */
    pointer-events: auto;
    /* Make sure it's visually distinct */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.learndash-category-nav .toggle-children.expanded .toggle-icon {
    /* Don't rotate, we'll change the content instead */
    transform: none !important;
}

.learndash-category-nav .toggle-icon {
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
    /* Ensure smooth text change */
    display: inline-block;
    min-width: 12px;
    text-align: center;
    /* Force no rotation */
    transform: none !important;
}

/* Ensure no rotation on expanded state */
.learndash-category-nav .toggle-children.expanded .toggle-icon,
.learndash-category-nav .toggle-icon {
    transform: none !important;
}

.learndash-category-nav .children-container {
    margin-top: 8px;
    margin-left: 30px; /* Increased indentation for better tree structure */
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    border-left: 2px solid #e9ecef; /* Add visual tree connector */
    padding-left: 10px;
    /* Ensure children container doesn't affect parent positioning */
    position: relative;
    z-index: 0;
}

.learndash-category-nav .children-container.expanded {
    max-height: 2000px; /* Large enough to accommodate content */
}

.learndash-category-nav .course-count {
    color: #6c757d;
    font-size: 0.9em;
    font-weight: normal;
    margin-left: 8px;
}

/* Level-specific styling for better tree hierarchy */
.learndash-category-nav .category-nav-level-0 .category-link {
    background: #ffffff;
    border-left: 4px solid #007cba;
    font-weight: 600;
    font-size: 1.05em;
}

.learndash-category-nav .category-nav-level-1 .category-link {
    background: #f8f9fa;
    border-left: 4px solid #28a745;
    font-weight: 500;
    font-size: 1em;
}

.learndash-category-nav .category-nav-level-2 .category-link {
    background: #ffffff;
    border-left: 4px solid #ffc107;
    font-size: 0.95em;
    font-weight: 400;
}

.learndash-category-nav .category-nav-level-3 .category-link {
    background: #f8f9fa;
    border-left: 4px solid #dc3545;
    font-size: 0.9em;
    font-weight: 400;
}

.learndash-category-nav .category-nav-level-4 .category-link {
    background: #ffffff;
    border-left: 4px solid #6f42c1;
    font-size: 0.85em;
    font-weight: 400;
}

/* Flat navigation styles - separate from hierarchical */
.learndash-category-nav-flat {
    margin: 20px 0;
}

/* Ensure flat navigation doesn't inherit tree styles */
.learndash-category-nav-flat .category-nav-level-0,
.learndash-category-nav-flat .category-nav-level-1,
.learndash-category-nav-flat .category-nav-level-2,
.learndash-category-nav-flat .category-nav-level-3,
.learndash-category-nav-flat .category-nav-level-4 {
    display: block !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
    border-left: none !important;
}

.learndash-category-nav-flat .category-item::before,
.learndash-category-nav-flat .category-item::after {
    display: none !important;
}

/* Force flat navigation to be vertical list */
.learndash-category-nav-flat,
.learndash-category-nav-flat ul,
.learndash-category-nav-flat li {
    display: block !important;
    width: 100% !important;
    float: none !important;
    clear: both !important;
    grid-template-columns: none !important;
    grid-auto-flow: unset !important;
    flex-direction: unset !important;
    flex-wrap: unset !important;
}

.learndash-category-nav-flat .flat-category-list {
    display: block; /* Change from grid to block for vertical list */
    list-style: none;
    margin: 0;
    padding: 0;
}

.learndash-category-nav-flat .flat-category-item {
    margin: 0;
}

.learndash-category-nav-flat .flat-category-item a {
    display: block;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-align: left; /* Change from center to left alignment */
    margin-bottom: 8px; /* Add spacing between items */
}

.learndash-category-nav-flat .flat-category-item a:hover {
    background: #007cba;
    color: white;
    text-decoration: none;
    border-color: #007cba;
}

.learndash-category-nav-flat .course-count {
    color: #6c757d;
    font-size: 0.9em;
    margin-left: 8px;
}

.learndash-category-nav-flat .flat-category-item a:hover .course-count {
    color: rgba(255, 255, 255, 0.8);
}

/* Flat navigation indentation levels */
.learndash-category-nav-flat .flat-category-level-0 a {
    padding-left: 16px;
    font-weight: 600;
    background: #ffffff;
}

.learndash-category-nav-flat .flat-category-level-1 a {
    padding-left: 40px;
    font-weight: 500;
    background: #f8f9fa;
    font-size: 0.95em;
}

.learndash-category-nav-flat .flat-category-level-2 a {
    padding-left: 64px;
    font-weight: 400;
    background: #ffffff;
    font-size: 0.9em;
}

.learndash-category-nav-flat .flat-category-level-3 a {
    padding-left: 88px;
    font-weight: 400;
    background: #f8f9fa;
    font-size: 0.85em;
}

.learndash-category-nav-flat .flat-category-level-4 a {
    padding-left: 112px;
    font-weight: 400;
    background: #ffffff;
    font-size: 0.8em;
}

/* Add visual hierarchy indicators */
.learndash-category-nav-flat .flat-category-level-1 a::before {
    content: '├─ ';
    color: #6c757d;
    font-weight: normal;
    margin-right: 8px;
}

.learndash-category-nav-flat .flat-category-level-2 a::before {
    content: '├─ ';
    color: #6c757d;
    font-weight: normal;
    margin-right: 8px;
}

.learndash-category-nav-flat .flat-category-level-3 a::before {
    content: '├─ ';
    color: #6c757d;
    font-weight: normal;
    margin-right: 8px;
}

.learndash-category-nav-flat .flat-category-level-4 a::before {
    content: '├─ ';
    color: #6c757d;
    font-weight: normal;
    margin-right: 8px;
}

/* Responsive design */
@media (max-width: 768px) {
    .learndash-category-nav .category-link {
        padding: 10px 12px;
        padding-left: 12px;
        font-size: 0.9em;
    }
    
    .learndash-category-nav .category-item.has-children .category-link {
        padding-right: 45px;
    }
    
    .learndash-category-nav .toggle-children {
        right: 8px;
        width: 20px;
        height: 20px;
    }
    
    .learndash-category-nav .children-container {
        margin-left: 20px;
        padding-left: 8px;
    }
    
    /* Adjust tree connectors for mobile */
    .learndash-category-nav .category-item::before {
        width: 10px;
    }
    
    .learndash-category-nav .category-item:not(:last-child)::after {
        left: -10px;
    }
    
    /* Flat navigation indentation adjustments for mobile */
    .learndash-category-nav-flat .flat-category-level-1 a {
        padding-left: 30px;
    }
    
    .learndash-category-nav-flat .flat-category-level-2 a {
        padding-left: 45px;
    }
    
    .learndash-category-nav-flat .flat-category-level-3 a {
        padding-left: 60px;
    }
    
    .learndash-category-nav-flat .flat-category-level-4 a {
        padding-left: 75px;
    }
}

/* Accessibility improvements */
.learndash-category-nav .toggle-children:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.learndash-category-nav .category-link:focus {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

/* Animation for smooth expand/collapse */
.learndash-category-nav .children-container {
    transition: max-height 0.3s ease-out;
}

/* Loading state */
.learndash-category-nav.loading {
    opacity: 0.6;
    pointer-events: none;
}

.learndash-category-nav.loading::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #007cba;
    font-weight: bold;
}
