/**
 * Tree View Component
 * Hierarchical tree structure with TOC-style sharp edges and ">" toggles
 */

.tree-view {
    width: 100%;
    font-size: 0.875rem;
    color: var(--theme-text-primary);
}

/* Tree List */
.tree-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-children {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-left: 1.25rem;
    border-left: 1px solid var(--theme-border);
    margin-left: 0.5rem;
}

/* Tree Item */
.tree-item {
    position: relative;
    margin: 0;
}

.tree-item-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    border-radius: 0;
    user-select: none;
}

.tree-item-content:hover {
    background-color: rgba(0, 0, 0, var(--alpha-hover));
}

.tree-item-content:active {
    background-color: rgba(0, 0, 0, 0.08);
}

/* Toggle Button - Angle style like TOC */
.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 0.75rem;
    height: 0.75rem;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--theme-text-secondary);
    transition:
        transform var(--transition-speed),
        color var(--transition-speed);
    flex-shrink: 0;
    position: relative;
}

.tree-toggle:hover {
    color: var(--theme-text-primary);
}

/* SVG angle icon */
.tree-toggle::before {
    content: "";
    display: block;
    width: 0.375rem;
    height: 0.375rem;
    border-right: 1px solid currentColor;
    border-bottom: 1px solid currentColor;
    transform: rotate(-45deg);
}

.tree-toggle.is-expanded::before {
    transform: rotate(45deg);
}

/* Spacer for alignment when no toggle */
.tree-spacer {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

/* Icon */
.tree-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    font-size: 1rem;
    color: var(--theme-text-secondary);
    flex-shrink: 0;
}

/* Label */
.tree-label {
    flex: 1;
    font-weight: 500;
    color: var(--theme-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Active/Selected State */
.tree-item.is-active > .tree-item-content {
    background-color: rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

.tree-item.is-active > .tree-item-content .tree-label {
    color: var(--theme-accent);
}

/* Disabled State */
.tree-item.is-disabled > .tree-item-content {
    opacity: var(--alpha-disabled);
    cursor: not-allowed;
    pointer-events: none;
}

/* Sharp Edges - No border radius (TOC style) */
.tree-view,
.tree-item-content {
    border-radius: 0;
}

/* Compact Variant */
.tree-view-compact .tree-item-content {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}

.tree-view-compact .tree-children {
    padding-left: 1rem;
}

/* Bordered Variant */
.tree-view-bordered {
    border: 1px solid var(--theme-border);
    padding: 0.5rem;
}

/* Card Variant */
.tree-view-card {
    background-color: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* With Connecting Lines (Enhanced Visual) */
.tree-view-lines .tree-item::before {
    content: "";
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 50%;
    width: 1px;
    background-color: var(--theme-border);
}

.tree-view-lines .tree-item::after {
    content: "";
    position: absolute;
    left: 0.5rem;
    top: 50%;
    width: 0.5rem;
    height: 1px;
    background-color: var(--theme-border);
}

.tree-view-lines .tree-item:last-child::before {
    bottom: 50%;
}

/* Animations */
@keyframes tree-slide-down {
    from {
        opacity: 0;
        max-height: 0;
        overflow: hidden;
    }
    to {
        opacity: 1;
        max-height: 1000px;
    }
}

.tree-children {
    animation: tree-slide-down 0.2s ease-out;
}

/* Focus Styles */
.tree-toggle:focus,
.tree-item-content:focus {
    outline: 2px solid var(--theme-accent);
    outline-offset: 2px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .tree-view {
        font-size: 0.8125rem;
    }

    .tree-item-content {
        padding: 0.5rem 0.375rem;
    }

    .tree-children {
        padding-left: 1rem;
    }
}
