/* Document Query - Tree view, filters, and document management */

/* View Toggle */
.view-toggle {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-2) var(--space-3);
    background-color: var(--gray-100);
    border-radius: var(--radius);
}

.view-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--font-size-base);
}

.view-toggle-btn:hover {
    color: var(--text-secondary);
}

.view-toggle-btn.active {
    background-color: var(--white);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Filter Panel */
.filter-panel {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    border: 1px solid var(--border);
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 500;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.filter-group .form-input,
.filter-group .form-select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--white);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.filter-group .form-input:focus,
.filter-group .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.1);
}

.filter-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.filter-actions .btn {
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
}

/* Tree View Container */
.tree-view {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.tree-view-content {
    padding: var(--space-4);
    max-height: 600px;
    overflow-y: auto;
}

/* Tree Node */
.tree-node {
    margin: 0;
    list-style: none;
}

.tree-node-item {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    user-select: none;
    position: relative;
    margin-bottom: var(--space-1);
}

.tree-node-item:hover {
    background-color: var(--gray-50);
}

.tree-node-item.selected {
    background-color: rgba(0, 112, 243, 0.05);
    border-left: 3px solid var(--primary);
    padding-left: calc(var(--space-4) - 3px);
}

.tree-node-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

.tree-node-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    margin-right: var(--space-2);
    border: none;
    background-color: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    font-size: var(--font-size-lg);
}

.tree-node-toggle:hover {
    color: var(--text-primary);
    background-color: var(--gray-100);
    border-radius: var(--radius-sm);
}

.tree-node-toggle.expanded {
    transform: rotate(90deg);
}

.tree-node-toggle.collapsed {
    transform: rotate(0deg);
}

.tree-node-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Tree Node Children Container */
.tree-node-children {
    list-style: none;
    margin: 0;
    padding: 0;
    padding-left: var(--space-6);
    border-left: 1px solid var(--border);
    margin-left: var(--space-3);
}

.tree-node-children.hidden {
    display: none;
}

.tree-node-children.collapsed {
    display: none;
}

/* Tree Node Icons and Content */
.tree-node-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-right: var(--space-2);
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: var(--font-size-base);
}

.tree-document-icon {
    color: var(--info);
}

.tree-folder-icon {
    color: var(--warning);
}

.tree-node-label {
    flex: 1;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-node-item.selected .tree-node-label {
    color: var(--primary);
    font-weight: 600;
}

.tree-node-meta {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
    padding-left: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.tree-node-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    background-color: var(--gray-100);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-secondary);
}

/* Loading States */
.tree-node-loading {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.tree-node-loading .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
    margin: 0;
}

.tree-loading-skeleton {
    height: 40px;
    background: linear-gradient(
        90deg,
        var(--gray-100) 0%,
        var(--gray-200) 50%,
        var(--gray-100) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-3);
}

/* Empty State */
.tree-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12);
    text-align: center;
    color: var(--text-muted);
    min-height: 200px;
}

.tree-empty-icon {
    font-size: 2.5rem;
    color: var(--gray-400);
    margin-bottom: var(--space-4);
}

.tree-empty-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.tree-empty-description {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    max-width: 300px;
}

/* Tree Breadcrumb */
.tree-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background-color: var(--gray-50);
    border-bottom: 1px solid var(--border);
    font-size: var(--font-size-sm);
    overflow-x: auto;
}

.tree-breadcrumb-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-primary);
    white-space: nowrap;
}

.tree-breadcrumb-separator {
    color: var(--text-muted);
}

.tree-breadcrumb-item a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.tree-breadcrumb-item a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* Tree Search */
.tree-search-box {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.tree-search-box .form-input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Context Menu */
.tree-context-menu {
    position: fixed;
    background-color: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    min-width: 200px;
    z-index: var(--z-dropdown);
    animation: slideDown var(--transition-base);
}

.tree-context-item {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-4);
    text-align: left;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: all var(--transition-fast);
}

.tree-context-item:hover {
    background-color: var(--gray-50);
    color: var(--primary);
}

.tree-context-item:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tree-context-item:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.tree-context-item.danger {
    color: var(--danger);
}

.tree-context-item.danger:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

/* Responsive */
@media (max-width: 768px) {
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        flex-direction: column;
    }

    .filter-actions .btn {
        width: 100%;
    }

    .tree-view-content {
        max-height: 400px;
    }

    .tree-node-children {
        padding-left: var(--space-4);
    }

    .tree-breadcrumb {
        font-size: var(--font-size-xs);
    }

    .tree-node-meta {
        display: none;
    }

    .view-toggle {
        width: 100%;
        justify-content: space-around;
    }

    .view-toggle-btn {
        flex: 1;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .filter-panel {
        padding: var(--space-4);
    }

    .tree-view-content {
        max-height: 300px;
        padding: var(--space-2);
    }

    .tree-node-item {
        padding: var(--space-2) var(--space-3);
    }

    .tree-node-toggle {
        width: 20px;
        height: 20px;
    }

    .tree-node-children {
        padding-left: var(--space-2);
        margin-left: var(--space-1);
    }

    .tree-context-menu {
        min-width: 150px;
    }

    .tree-node-label {
        font-size: var(--font-size-xs);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .tree-node-item,
    .tree-node-toggle,
    .tree-context-item,
    .view-toggle-btn {
        transition: none;
    }
}

/* New Tree Structure Styles */
.tree-container {
    padding: var(--space-4);
}

.tree-node {
    margin-bottom: var(--space-1);
}

.tree-node-header {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    background-color: transparent;
    border: 1px solid transparent;
}

.tree-node-header:hover {
    background-color: var(--gray-50);
    border-color: var(--border);
}

.tree-toggle {
    margin-right: var(--space-2);
    color: var(--text-muted);
    font-size: 0.875rem;
    display: inline-block;
    transition: transform var(--transition-fast);
    width: 16px;
    text-align: center;
}

.tree-toggle-empty {
    opacity: 0;
}

.tree-node.collapsed .tree-toggle {
    transform: rotate(-90deg);
}

.tree-node.collapsed .tree-node-content {
    display: none;
}

.tree-node-content {
    padding-left: var(--space-8);
    margin-top: var(--space-2);
    border-left: 2px solid var(--gray-200);
    margin-left: var(--space-3);
}

.tree-documents {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tree-document {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background-color: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.tree-document:hover {
    background-color: var(--gray-50);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.tree-doc-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
}

.tree-doc-info svg {
    color: var(--info);
    flex-shrink: 0;
}

.tree-doc-info > div {
    flex: 1;
    min-width: 0;
}

.tree-doc-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: var(--font-size-base);
    margin-bottom: var(--space-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-doc-meta {
    display: flex;
    gap: var(--space-4);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.tree-doc-meta span {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.tree-doc-meta span::before {
    content: "•";
    margin-right: var(--space-1);
}

.tree-doc-meta span:first-child::before {
    content: "";
    margin-right: 0;
}

.tree-doc-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

.tree-doc-actions .btn {
    padding: var(--space-2);
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tree-doc-actions .btn:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.tree-doc-actions .btn svg {
    color: currentColor;
}

/* Print styles */
@media print {
    .view-toggle,
    .filter-panel,
    .tree-search-box,
    .tree-context-menu {
        display: none !important;
    }

    .tree-view {
        box-shadow: none;
        border: 1px solid var(--border);
    }

    .tree-node-children {
        padding-left: var(--space-4);
    }

    .tree-doc-actions {
        display: none !important;
    }
}
