/**
 * list-view.css — the LIST's styles, and nothing else (goes with list-view.js).
 *
 * Marius: *"The list should be its own thing."* A host that mounts the list alone loads THIS file
 * alone.
 * ⛔ So nothing here may style anything but the list — a global `.btn` rule would repaint every
 * button on a host that has its own. The page's button rules live in item-page.css.
 */

:root {
    --sidebar-width: 280px;
    --sidebar-min-width: 180px;
    --sidebar-max-width: 500px;
}

/* ===== Left Sidebar Panel ===== */
.sidebar-panel {
    width: var(--sidebar-width);
    min-width: var(--sidebar-min-width);
    max-width: var(--sidebar-max-width);
    background: var(--bg-medium);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Search Box */
.sidebar-search {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-default);
    background: var(--bg-dark);
}

.search-wrapper {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    position: relative;
}

.search-input {
    flex: 1;
    min-width: 0;
    padding: var(--space-sm) var(--space-md);
    padding-right: 32px;
    background: var(--bg-darkest);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-md);
    transition: border-color var(--transition-base);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.clear-search-btn {
    position: absolute;
    right: 42px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: none;
}

.clear-search-btn.visible {
    display: block;
}

.clear-search-btn:hover {
    color: var(--text-primary);
}

.add-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-light);
    color: var(--color-success);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-base);
}

.add-btn:hover {
    background: var(--bg-hover);
    border-color: var(--color-success);
}

.add-btn.visible {
    display: flex;
}

/* Sidebar List Container */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.sidebar-list::-webkit-scrollbar {
    width: 6px;
}

.sidebar-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

/* ===== Tree Renderer Styles ===== */
.tree-root {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-children {
    list-style: none;
    margin: 0;
    margin-left: 14px;
    padding-left: 4px;
}

.tree-node {
    position: relative;
    margin: 0;
}

.tree-node-content {
    position: relative;
    display: flex;
    align-items: center;
    padding: 4px 8px 4px 11px;
    margin: 1px 0;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
    min-height: 20px;
    transition: background-color var(--transition-base);
}

.tree-node-content:hover,
.tree-node-content.hovered {
    background: rgba(196, 125, 49, 0.15);
}

.tree-node-content.selected {
    background: rgba(196, 125, 49, 0.2) !important;
    border-left: 2px solid #c47d31;
    padding-left: 9px;
}

/* Colored bar for parents (thick, rounded) */
.tree-node-content::before {
    content: '';
    position: absolute;
    left: 0;
    top: 3px;
    bottom: 3px;
    width: 4px;
    background: transparent;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    z-index: 2;
    transition: width 0.15s ease;
}

/* Thin line for all items */
.tree-node-content::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 3px;
    bottom: 3px;
    width: 1px;
    background: transparent;
    z-index: 1;
}

/* Level 0, 3, 6... - Green */
.tree-node[data-level-color="0"] > .tree-node-content::after {
    background: #3ab03a;
}
.tree-node[data-level-color="0"] > .tree-node-content.has-children::before {
    background: #3ab03a;
}

/* Level 1, 4, 7... - Orange */
.tree-node[data-level-color="1"] > .tree-node-content::after {
    background: #c47d31;
}
.tree-node[data-level-color="1"] > .tree-node-content.has-children::before {
    background: #c47d31;
}

/* Level 2, 5, 8... - Purple */
.tree-node[data-level-color="2"] > .tree-node-content::after {
    background: #803ea5;
}
.tree-node[data-level-color="2"] > .tree-node-content.has-children::before {
    background: #803ea5;
}

/* Hide thin line for parent items (they have the thick bar) */
.tree-node[data-level-color="0"] > .tree-node-content.has-children::after,
.tree-node[data-level-color="1"] > .tree-node-content.has-children::after,
.tree-node[data-level-color="2"] > .tree-node-content.has-children::after {
    display: none;
}

.tree-node-content.has-children {
    font-weight: 500;
}

/* Hover effect: grow the thick bar slightly */
.tree-node-content.has-children:hover::before {
    width: 5px;
}

.tree-node-line {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 16px;
}

/* Hide expand indicator (we use colored bars instead) */
.tree-expand-indicator {
    display: none;
}

.tree-node-main {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: var(--space-xs);
}

.tree-node-title {
    color: var(--text-primary);
    font-size: var(--font-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-node-ref {
    color: var(--accent-primary-text);
    font-size: var(--font-sm);
    opacity: 0.8;
    cursor: pointer;
    flex-shrink: 0;
}

.tree-node-ref:hover {
    opacity: 1;
    text-decoration: underline;
}

.tree-highlight {
    background: rgba(255, 200, 50, 0.3);
    border-radius: 2px;
    padding: 0 2px;
}

/* A short marker the mount asks for on a row (`badge`). A mount that asks for none gets none. */
.tree-node-badge {
    color: var(--text-secondary);
    font-size: var(--font-sm);
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 0.85;
}

/* Edit Controls */
.tree-edit-controls {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-base);
    flex-shrink: 0;
}

.tree-node-content:hover .tree-edit-controls,
.tree-node-content.selected .tree-edit-controls {
    opacity: 1;
}

.tree-edit-btn {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: 3px;
    background: var(--bg-light);
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.tree-add-btn {
    color: var(--color-success);
}

.tree-add-btn:hover {
    border-color: var(--color-success);
    background: var(--bg-hover);
}

.tree-delete-btn {
    color: var(--color-error);
}

.tree-delete-btn:hover {
    border-color: var(--color-error);
    background: var(--bg-hover);
}

/* Drag and Drop */
.tree-node-content.dragging {
    opacity: 0.5;
}

.tree-node-content.drag-over-top {
    border-top: 2px solid #3b82f6;
}

.tree-node-content.drag-over-bottom::after {
    content: '';
    position: absolute;
    left: 20px;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--color-success);
}

.drag-indicator {
    position: absolute;
    left: 20px;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--color-success);
    pointer-events: none;
}

/* Empty state */
.tree-empty {
    text-align: center;
    padding: var(--space-3xl);
    color: var(--text-muted);
}

.tree-empty-icon {
    font-size: 48px;
    margin-bottom: var(--space-lg);
    opacity: 0.5;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar-panel {
        width: 100%;
        max-width: none;
        height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-default);
    }
}
