.folder-sidebar {
    position: fixed;
    top: 68px; /* Below header */
    left: 0px;
    width: 230px;
    height: calc(100vh - 88px);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-xs);
    overflow: hidden;
    flex-shrink: 0;
    z-index: var(--z-overlay);
    box-shadow: var(--shadow-header);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(8px);
    /* Default: hidden off-screen — prevents flash before JS runs */
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.folder-sidebar.visible {
    transform: translateX(0);
    opacity: 1;
    pointer-events: all;
}

.folder-sidebar.hidden-by-setting {
    display: none !important;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-color);
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.9em;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition-base);
    position: relative;
}

.sidebar-header:hover {
    background: var(--lora-surface);
}

.sidebar-header.root-selected {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
    color: var(--lora-accent);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    flex: 1;
    pointer-events: none;
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.6;
    transition: var(--transition-base);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-action-btn:hover {
    opacity: 1;
    background: var(--lora-surface);
    color: var(--text-color);
}

.sidebar-action-btn.active {
    opacity: 1;
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.15);
    color: var(--lora-accent);
}

.sidebar-action-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Remove old close button styles */
.sidebar-toggle-close {
    display: none;
}

/* ===== Sidebar Hidden Indicator (left edge) ===== */
.sidebar-hidden-indicator {
    position: fixed;
    left: 0;
    top: 68px; /* Align with sidebar header */
    z-index: var(--z-overlay);
    width: 14px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--border-color);
    opacity: 0.3;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.sidebar-hidden-indicator:hover {
    opacity: 0.7;
    background: var(--lora-accent);
}

.sidebar-hidden-indicator i {
    font-size: 11px;
    color: var(--text-muted);
    transition: color 0.15s ease;
}

.sidebar-hidden-indicator:hover i {
    color: white;
}

/* Subtle breathing animation for first-time discovery */
@keyframes sidebarBreathing {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 0.65; }
}

.sidebar-hidden-indicator.breathing {
    animation: sidebarBreathing 2.5s ease-in-out infinite;
    animation-delay: 0.5s;
}

.sidebar-hidden-indicator.breathing:hover {
    animation: none;
}

.sidebar-hidden-indicator-tooltip {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    padding: 4px 10px;
    background: var(--text-color);
    color: var(--bg-color);
    font-size: 0.8em;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.sidebar-hidden-indicator:hover .sidebar-hidden-indicator-tooltip {
    opacity: 1;
}

.sidebar-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* Sidebar Tree Node Styles */
.sidebar-tree-node {
    position: relative;
    user-select: none;
}

.sidebar-tree-node-content {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: var(--transition-base);
    font-size: 0.85em;
    border-left: 3px solid transparent;
    color: var(--text-color);
}

.sidebar-tree-node-content:hover {
    background: var(--lora-surface);
    color: var(--text-color);
}

.sidebar-tree-node-content.selected {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
    color: var(--lora-accent);
    border-left-color: var(--lora-accent);
    font-weight: 500;
}

.sidebar-tree-node-content.drop-target,
.sidebar-node-content.drop-target {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.15);
    color: var(--lora-accent);
    border-left-color: var(--lora-accent);
}

.sidebar-tree-node-content.drop-target .sidebar-tree-folder-icon,
.sidebar-node-content.drop-target .sidebar-folder-icon {
    color: var(--lora-accent);
    opacity: 1;
}

.sidebar-tree-expand-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

.sidebar-tree-expand-icon.expanded {
    transform: rotate(90deg);
}

.sidebar-tree-expand-icon i {
    font-size: 10px;
}

.sidebar-tree-folder-icon {
    margin-right: 8px;
    color: var(--text-muted);
    opacity: 0.7;
}

.sidebar-tree-node-content.selected .sidebar-tree-folder-icon {
    color: var(--lora-accent);
    opacity: 1;
}

.sidebar-tree-node-content:hover .sidebar-tree-folder-icon {
    color: var(--text-color);
    opacity: 0.9;
}

.sidebar-tree-folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-tree-children {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
}

.sidebar-tree-children.expanded {
    max-height: 50000px;
}

.sidebar-tree-children .sidebar-tree-node-content {
    padding-left: 32px;
}

.sidebar-tree-children .sidebar-tree-children .sidebar-tree-node-content {
    padding-left: 48px;
}

.sidebar-tree-children .sidebar-tree-children .sidebar-tree-children .sidebar-tree-node-content {
    padding-left: 64px;
}

/* Enhanced Sidebar Breadcrumb Styles */
.sidebar-breadcrumb-container {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    border-radius: var(--border-radius-xs);
    /* Sticky positioning to stick below header when scrolling
       top: 0 means stick at the top of the scroll container (page-content)
       which is at header height (48px) from the viewport */
    position: sticky;
    top: 0;
    z-index: calc(var(--z-header) - 1);
}

.sidebar-breadcrumb-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.85em;
}

.sidebar-breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--border-radius-xs);
    cursor: pointer;
    transition: var(--transition-base);
    color: var(--text-muted);
    position: relative;
}

.sidebar-breadcrumb-item:hover {
    background: var(--lora-surface);
    color: var(--text-color);
}

.sidebar-breadcrumb-item.active {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
    color: var(--lora-accent);
    font-weight: 500;
}

.sidebar-breadcrumb-separator {
    color: var(--text-muted);
    opacity: 0.6;
    margin: 0 2px;
}

/* New Breadcrumb Dropdown Styles */
.breadcrumb-dropdown {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.breadcrumb-dropdown-indicator {
    margin-left: 6px;
    color: inherit;
    opacity: 0.6;
    transition: var(--transition-base);
    pointer-events: none;
    font-size: 0.9em;
}

.sidebar-breadcrumb-item:hover .breadcrumb-dropdown-indicator {
    opacity: 0.9;
}

.sidebar-breadcrumb-item.placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.sidebar-breadcrumb-item.placeholder:hover {
    background: var(--lora-surface);
    color: var(--text-color);
}

.breadcrumb-dropdown.open .breadcrumb-dropdown-indicator {
    transform: rotate(180deg);
    opacity: 1;
}

.breadcrumb-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 160px;
    max-width: 240px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-xs);
    box-shadow: var(--shadow-lg);
    z-index: calc(var(--z-overlay) + 20);
    overflow-y: auto;
    max-height: 450px;
    display: none;
    margin-top: 4px;
}

.breadcrumb-dropdown.open .breadcrumb-dropdown-menu {
    display: block;
}

.breadcrumb-dropdown-item {
    padding: 6px 12px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: var(--transition-base);
}

.breadcrumb-dropdown-item:hover {
    background: var(--lora-surface);
}

.breadcrumb-dropdown-item.active {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
    color: var(--lora-accent);
    font-weight: 500;
}

/* Folder List Mode Styles */
.sidebar-folder-item {
    position: relative;
    user-select: none;
}

.sidebar-node-content {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: var(--transition-base);
    font-size: 0.85em;
    border-left: 3px solid transparent;
    color: var(--text-color);
}

.sidebar-node-content:hover {
    background: var(--lora-surface);
    color: var(--text-color);
}

.sidebar-folder-item.selected .sidebar-node-content {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
    color: var(--lora-accent);
    border-left-color: var(--lora-accent);
    font-weight: 500;
}

.sidebar-folder-icon {
    margin-right: 8px;
    color: var(--text-muted);
    opacity: 0.7;
    width: 16px;
    text-align: center;
}

.sidebar-folder-item.selected .sidebar-folder-icon {
    color: var(--lora-accent);
    opacity: 1;
}

.sidebar-node-content:hover .sidebar-folder-icon {
    color: var(--text-color);
    opacity: 0.9;
}

.sidebar-folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive Design */
@media (min-width: 2150px) {
    .folder-sidebar {
        width: 280px;
        left: 0px;
    }
}

@media (min-width: 3000px) {
    .folder-sidebar {
        width: 320px;
        left: 0px;
    }
}

@media (max-width: 1400px) {
    .folder-sidebar {
        width: 260px;
        left: 0px;
    }
}

/* Empty State */
.sidebar-tree-placeholder {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    opacity: 0.7;
}

.sidebar-tree-placeholder i {
    font-size: 2em;
    opacity: 0.5;
    margin-bottom: 8px;
    display: block;
}

/* Smooth transitions for tree nodes */
.sidebar-tree-node {
    overflow: hidden;
}

.sidebar-tree-children {
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-tree-expand-icon {
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Visual separator for nested levels */
.sidebar-tree-children .sidebar-tree-node-content {
    position: relative;
}

.sidebar-tree-children .sidebar-tree-node-content::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border-color);
    opacity: 0.3;
}

/* Responsive Design — Mobile: overlay when shown */
@media (max-width: 1024px) {
    .folder-sidebar {
        top: 68px;
        left: 0px;
        width: calc(100vw - 32px);
        max-width: 320px;
        height: calc(100vh - 88px);
        z-index: calc(var(--z-overlay) + 10);
    }

    /* Mobile overlay when sidebar is shown */
    .folder-sidebar.visible::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: -1;
        backdrop-filter: blur(2px);
    }
}

@media (max-width: 768px) {
    .folder-sidebar {
        width: calc(100vw - 32px);
        max-width: 280px;
        left: 0px;
    }

    .sidebar-breadcrumb-nav {
        font-size: 0.8em;
    }

    .sidebar-breadcrumb-item {
        padding: 3px 6px;
    }
}

/* Hide scrollbar but keep functionality */
.sidebar-tree-container::-webkit-scrollbar {
    width: 6px;
}

.sidebar-tree-container::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-tree-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar-tree-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Drag and Drop - Create Folder Zone ===== */

/* Empty state drag hint */
.sidebar-empty-hint {
    margin-top: 12px;
    font-size: 0.8em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-radius: var(--border-radius-xs);
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.05);
    border: 1px dashed oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.2);
}

.sidebar-empty-hint i {
    font-size: 0.9em;
    opacity: 0.8;
    margin: 0;
    display: inline;
}

/* Create folder drop zone */
.sidebar-create-folder-zone {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    padding: 16px;
    border: 2px dashed oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.4);
    border-radius: var(--border-radius-xs);
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.08);
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition-base);
    pointer-events: none;
    z-index: 10;
}

.sidebar-create-folder-zone.active {
    opacity: 1;
    transform: translateY(0);
}

.sidebar-create-folder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--lora-accent);
    font-size: 0.85em;
    text-align: center;
}

.sidebar-create-folder-content i {
    font-size: 1.5em;
    opacity: 0.8;
}

/* Create folder input container */
.sidebar-create-folder-input-container {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    padding: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-xs);
    box-shadow: var(--shadow-lg);
    z-index: 20;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sidebar-create-folder-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-create-folder-input-wrapper > i {
    color: var(--lora-accent);
    font-size: 1em;
}

.sidebar-create-folder-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-xs);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.85em;
    outline: none;
    transition: var(--transition-base);
}

.sidebar-create-folder-input:focus {
    border-color: var(--lora-accent);
    box-shadow: 0 0 0 2px oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.15);
}

.sidebar-create-folder-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--border-radius-xs);
    cursor: pointer;
    transition: var(--transition-base);
    background: transparent;
    color: var(--text-muted);
}

.sidebar-create-folder-btn:hover,
.sidebar-create-folder-btn:focus-visible {
    background: var(--lora-surface);
    color: var(--text-color);
    outline: none;
}

.sidebar-create-folder-confirm:hover,
.sidebar-create-folder-confirm:focus-visible {
    background: oklch(from var(--success-color) l c h / 0.15);
    color: var(--success-color);
    outline: none;
}

.sidebar-create-folder-cancel:hover,
.sidebar-create-folder-cancel:focus-visible {
    background: oklch(from var(--error-color) l c h / 0.15);
    color: var(--error-color);
    outline: none;
}

.sidebar-create-folder-hint {
    margin-top: 6px;
    font-size: 0.75em;
    color: var(--text-muted);
    text-align: center;
    opacity: 0.8;
}

/* Dragging state for sidebar */
.folder-sidebar.dragging-active {
    border-color: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.5);
    box-shadow: 0 0 0 3px oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1),
                0 2px 8px rgba(0, 0, 0, 0.08);
}

.folder-sidebar.dragging-active .sidebar-tree-container {
    background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.02);
}

/* Tree container positioning for create folder elements */
.sidebar-tree-container {
    position: relative;
}

/* Folder context menu - positioned relative to sidebar */
#sidebarFolderContextMenu {
    z-index: var(--z-modal, 1002);
}
