/*
╔═══════════════════════════════════════════════════════════════════╗
║ IOTreeView - Generic hierarchical tree component                 ║
║ Theme-aware using CSS variables                                   ║
╚═══════════════════════════════════════════════════════════════════╝
*/

/* ====================================================================
   CONTAINER
   ==================================================================== */

.io-tree-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--io-surface-base);
    overflow: hidden;
    cursor: pointer;
}

/* ====================================================================
   HEADER
   ==================================================================== */

.io-tree-header {
    padding: var(--io-space-md);
    background: var(--io-surface-raised);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--io-space-sm);
    position: relative;
}

.io-tree-header::after {
     content: '';
    position: absolute;
    bottom: 0;
    left: 15%;  /* Start at 15% instead of 0 */
    width: 70%;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(var(--io-border-accent-fade-base), 0.3) 15%,
        rgba(var(--io-border-accent-fade-base), 1.0) 50%,
        rgba(var(--io-border-accent-fade-base), 0.3) 85%,
        transparent 100%
    );
    pointer-events: none;
}




/* ====================================================================
   SEARCH
   ==================================================================== */

.io-tree-search {
    display: flex;
    align-items: center;
    gap: var(--io-space-sm);
    padding: var(--io-space-sm) var(--io-space-md);
    background: var(--io-surface-sunken);
    border: 1px solid var(--io-border);
    border-radius: var(--io-radius-md);
    transition: all var(--io-transition-base);
}

.io-tree-search:focus-within {
    border-color: var(--io-accent);
    box-shadow: 0 0 0 3px var(--io-accent-subtle);
}

.io-tree-search i.fa-search {
    color: var(--io-text-tertiary);
    font-size: var(--io-text-sm);
}

.io-tree-search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--io-text-primary);
    font-size: var(--io-text-sm);
    font-family: var(--io-font-primary);
}

.io-tree-search-input::placeholder {
    color: var(--io-text-tertiary);
}

.io-tree-search-clear {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--io-radius-sm);
    color: var(--io-text-secondary);
    cursor: pointer;
    transition: all var(--io-transition-fast);
}

.io-tree-search-clear:hover {
    background: var(--io-surface-hover);
    color: var(--io-text-primary);
}

/* ====================================================================
   TOOLBAR
   ==================================================================== */

.io-tree-toolbar {
    display: flex;
    align-items: center;
    gap: var(--io-space-xs);
}

.io-tree-tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--io-surface-sunken);
    border: 1px solid var(--io-border);
    border-radius: var(--io-radius-sm);
    color: var(--io-text-secondary);
    cursor: pointer;
    transition: all var(--io-transition-fast);
    font-size: var(--io-text-sm);
}

.io-tree-tool-btn:hover {
    background: var(--io-surface-hover);
    color: var(--io-accent);
    border-color: var(--io-accent);
    box-shadow: var(--io-glow-sm);
}

.io-tree-tool-btn.active {
    background: var(--io-accent);
    color: var(--io-on-accent);
    border-color: var(--io-accent);
}

.io-tree-tool-btn:active {
    transform: scale(0.95);
}

.io-tree-divider {
    width: 1px;
    height: 24px;
    background: var(--io-border);
    margin: 0 var(--io-space-xs);
}

/* ====================================================================
   BODY (Scrollable)
   ==================================================================== */

.io-tree-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--io-space-md);
}

.io-tree-body::-webkit-scrollbar {
    width: 8px;
}

.io-tree-body::-webkit-scrollbar-track {
    background: transparent;
}

.io-tree-body::-webkit-scrollbar-thumb {
    background: var(--io-border);
    border-radius: var(--io-radius-full);
}

.io-tree-body::-webkit-scrollbar-thumb:hover {
    background: var(--io-accent);
}

/* ====================================================================
   TREE STRUCTURE
   ==================================================================== */

.io-tree {
    font-family: var(--io-font-primary);
    font-size: var(--io-text-sm);
    user-select: none;
}

/* ====================================================================
   TREE ITEM (Base Container)
   ==================================================================== */

.io-tree-item {
    position: relative;
}

/* Indentation based on depth */
.io-tree-item[data-depth="0"] {
    margin-left: 0;
}

.io-tree-item[data-depth="1"] {
    margin-left: var(--io-space-lg);
}

.io-tree-item[data-depth="2"] {
    margin-left: calc(var(--io-space-lg) * 2);
}

.io-tree-item[data-depth="3"] {
    margin-left: calc(var(--io-space-lg) * 3);
}

.io-tree-item[data-depth="4"] {
    margin-left: calc(var(--io-space-lg) * 4);
}

/* Tree connection lines */
.io-tree-item[data-depth]:not([data-depth="0"])::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 0;
    bottom: 50%;
    width: 1px;
    background: var(--io-border);
    opacity: 0.3;
}

.io-tree-item[data-depth]:not([data-depth="0"])::after {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    width: 12px;
    height: 1px;
    background: var(--io-border);
    opacity: 0.3;
}

/* ====================================================================
   NODE (Folder/File)
   ==================================================================== */

.io-tree-node {
    display: flex;
    align-items: center;
    padding: var(--io-space-sm) var(--io-space-md);
    border-radius: var(--io-radius-sm);
    cursor: pointer;
    transition: all var(--io-transition-base);
    gap: var(--io-space-sm);
    margin-bottom: 2px;
    cursor: pointer;
}

.io-tree-node:hover {
    background: var(--io-surface-hover);
    transform: translateX(2px);
}

.io-tree-node.active {
    background: var(--io-accent-subtle);
    border-left: 2px solid var(--io-accent);
}

/* ====================================================================
   CHEVRON (Expand/Collapse Indicator)
   ==================================================================== */

.io-tree-chevron {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--io-text-tertiary);
    transition: transform var(--io-transition-base);
    flex-shrink: 0;
    font-size: 12px;
}

.io-tree-chevron.expanded {
    transform: rotate(90deg);
}

.io-tree-chevron-placeholder {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ====================================================================
   ICON
   ==================================================================== */

.io-tree-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: color var(--io-transition-base);
}

.io-tree-node.folder .io-tree-icon {
    color: var(--io-accent);
}

.io-tree-node.file .io-tree-icon {
    color: var(--io-text-secondary);
}

.io-tree-node:hover .io-tree-icon {
    filter: drop-shadow(0 0 4px var(--io-accent-glow));
}

/* ====================================================================
   LABEL
   ==================================================================== */

.io-tree-label {
    flex: 1;
    color: var(--io-text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.io-tree-node.folder .io-tree-label {
    font-weight: 600;
}

/* ====================================================================
   COUNT BADGE
   ==================================================================== */

.io-tree-count {
    font-size: var(--io-text-xs);
    font-weight: 700;
    color: var(--io-text-tertiary);
    background: var(--io-surface-sunken);
    padding: 2px 6px;
    border-radius: var(--io-radius-sm);
    flex-shrink: 0;
}

.io-tree-node:hover .io-tree-count {
    background: var(--io-surface-raised);
    color: var(--io-text-secondary);
}

/* ====================================================================
   CHILDREN CONTAINER (Collapsible)
   ==================================================================== */

.io-tree-children {
    overflow: hidden;
    transition: max-height var(--io-transition-slow) ease-out,
                opacity var(--io-transition-slow) ease-out;
}

.io-tree-children.collapsed {
    max-height: 0 !important;
    opacity: 0;
}

.io-tree-children.expanded {
    max-height: 10000px !important;  /* ← ADD THIS */
    opacity: 1;
}
/* ====================================================================
   CONTEXT MENU
   ==================================================================== */

.io-tree-context-menu {
    background: var(--io-surface-raised);
    border: 1px solid var(--io-border);
    border-radius: var(--io-radius-sm);
    box-shadow: var(--io-shadow-lg);
    padding: var(--io-space-xs);
    min-width: 180px;
    font-family: var(--io-font-primary);
    font-size: var(--io-text-sm);
}

.io-tree-context-item {
    display: flex;
    align-items: center;
    gap: var(--io-space-sm);
    padding: var(--io-space-sm) var(--io-space-md);
    border-radius: var(--io-radius-sm);
    cursor: pointer;
    transition: all var(--io-transition-fast);
    color: var(--io-text-primary);
}

.io-tree-context-item:hover {
    background: var(--io-surface-hover);
    color: var(--io-accent);
}

.io-tree-context-item.danger {
    color: var(--io-error);
}

.io-tree-context-item.danger:hover {
    background: var(--io-error-subtle);
    color: var(--io-error);
}

.io-tree-context-item i {
    width: 16px;
    text-align: center;
    color: var(--io-text-secondary);
}

.io-tree-context-item:hover i {
    color: inherit;
}

/* ====================================================================
   EMPTY STATE
   ==================================================================== */

.io-tree-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--io-space-2xl);
    color: var(--io-text-tertiary);
    text-align: center;
}

.io-tree-empty i {
    font-size: 64px;
    margin-bottom: var(--io-space-lg);
    opacity: 0.3;
}

.io-tree-empty p {
    margin: 0;
    font-size: var(--io-text-base);
}

/* ====================================================================
   RESPONSIVE
   ==================================================================== */

@media (max-width: 768px) {
    .io-tree-header {
        padding: var(--io-space-sm);
    }
    
    .io-tree-body {
        padding: var(--io-space-sm);
    }
    
    .io-tree-node {
        padding: var(--io-space-xs) var(--io-space-sm);
    }
    
    .io-tree-toolbar {
        overflow-x: auto;
    }
}

/* ====================================================================
   ACCESSIBILITY
   ==================================================================== */

.io-tree-node:focus-visible {
    outline: 2px solid var(--io-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .io-tree-node,
    .io-tree-chevron,
    .io-tree-children,
    .io-tree-tool-btn {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .io-tree-node.active {
        border-left-width: 3px;
    }
}

/* ====================================================================
   NODE (Folder/File)
   ==================================================================== */

.io-tree-node {
    display: flex;
    align-items: center;
    padding: var(--io-space-sm) var(--io-space-md);
    border-radius: var(--io-radius-sm);
    cursor: pointer;
    transition: all var(--io-transition-base);
    gap: var(--io-space-sm);
    margin-bottom: 2px;
}

.io-tree-node.file {
}

.io-tree-node.folder {
    cursor: pointer;
}

.io-tree-node:hover {
    background: var(--io-surface-hover);
}

.io-tree-node.folder:hover {
    transform: translateX(2px);
}

.io-tree-node.active {
    background: var(--io-accent-subtle);
    border-left: 2px solid var(--io-accent);
}

/* ====================================================================
   CHEVRON (Expand/Collapse Indicator)
   ==================================================================== */

.io-tree-chevron {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--io-text-tertiary);
    transition: transform var(--io-transition-base);
    flex-shrink: 0;
    font-size: 12px;
}

.io-tree-chevron.rotated {
    transform: rotate(90deg);
}

.io-tree-chevron-placeholder {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    display: inline-block;
}

/* ====================================================================
   CHILDREN CONTAINER (Collapsible)
   ==================================================================== */

.io-tree-children {
    overflow: visible; /* Changed from hidden */
    margin-left: var(--io-tree-indent, 24px);
}

.io-tree-children.collapsed {
    display: none;
}

.io-tree-children.expanded {
    display: block;
}