html, body, main, .page, .sidebar {
    height: 100%;
}

main, .page {
    overflow-y: auto;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.page {
    width: 100%;
    display: flex;
}

    .page .container-fluid {
        flex: 1;
        min-width: 0;
        background: linear-gradient(180deg, #fff, #f6faf7);
    }

.sidebar {
    overflow-y: auto;
    width: 20%;
    max-width: 1000px;
    flex: 0 0 auto;
    position: relative;
    background: #faf9f7;
    transition: margin-left 0.3s ease, opacity 0.3s ease;
}

.sidebar.collapsed {
    display: none;
}

@media (max-width: 992px) {
    .sidebar {
        width: 33.33333333%;
    }
}

.tree {
    position: relative;
    font-size: 0.875rem;
}

.tree ul {
    list-style-type: none;
    padding-left: 1.25rem;
    margin: 0;
    border-left: 1px solid #e2ddd8;
}

.tree > ul {
    padding-left: 0;
    border-left: none;
}

.tree-list {
    list-style-type: none;
    display: inherit;
}

    .tree-list a:hover {
        color: inherit;
    }

    .tree-list:first-child {
        padding-left: 0;
    }

.tree-node {
    overflow: hidden;
}

.tree-node.active > .tree-inner .tree-label {
    background: #e8f0fe;
    border-radius: 0.375rem;
}

.tree-node.active > .tree-inner .tree-label .tree-link {
    color: #0d6efd;
}

.tree-expander-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    width: 22px;
    height: 22px;
    text-align: center;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: background 0.15s;
    color: #6c757d;
    font-size: 0.75rem;
}

.tree-expander-container:hover {
    background: #e9ecef;
    color: #212529;
}

.tree-inner {
    display: flex;
    align-items: center;
    margin-bottom: 1px;
}

.tree-label {
    width: 100%;
    border-radius: 0.375rem;
    transition: background 0.15s;
}

.tree-node-content {
    padding: 0.375rem 0.5rem;
    display: flex;
    align-items: center;
}

.tree-text {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.tree-noleaf-text {
    font-weight: 600;
}

.tree-link {
    text-decoration: none !important;
    color: #212529;
}

.tree-icon {
    display: inline;
    margin-right: 6px;
}

.tree-num {
    display: inline-flex;
    margin-left: 0.25rem;
    font-weight: normal;
    color: #6c757d;
    font-size: 0.8125rem;
}

.tree-highlight .tree-node-content:not(.tree-selected,.tree-disabled):hover {
    background-color: #f0ece8;
    border-radius: 0.375rem;
}

 /* Drag and drop indicators */
 /* ----------------------------------------- */
.tree-line-indicator,
.tree-over-indicator {
    position: absolute;
    top: -100px;
    z-index: 9999;
    pointer-events: none;
}

/* Line indicator for moving before or after a node */
.tree-line-indicator {
    height: 1px;
    background: green;
}

    /* Arrow left */
    .tree-line-indicator::before {
        position: absolute;
        display: block;
        content: '';
        top: -4px;
        left: -8px;
        width: 0;
        height: 0;
        border-left: 5px solid green;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
    }

/* "Over" indicator for moving into a node */
.tree-over-indicator {
    content: '';
    border: 1px solid green;
    border-radius: 0.25rem;
}

#resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -2px;
    width: 4px;
    height: 100%;
    cursor: ew-resize;
    z-index: 10;
}

#resizer::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 1px;
    width: 2px;
    background: transparent;
    transition: background 0.2s;
}

#resizer:hover::before,
#resizer.active::before {
    background: #0d6efd;
}

#resizer span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 32px;
    border-radius: 3px;
    background: #c8cdd3;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, height 0.2s;
}

#resizer span svg {
    display: none;
}

#resizer:hover span,
#resizer.active span {
    background: #0d6efd;
    height: 48px;
}

.noselect {
    user-select: none;
}

/* --- Sidebar expand button (visible when collapsed) --- */
#sidebar-expand {
    flex: 0 0 auto;
    width: 28px;
    border: none;
    border-right: 1px solid #e2ddd8;
    background: #faf9f7;
    color: #6c757d;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

#sidebar-expand:hover {
    background: #f0ece8;
    color: #212529;
}

/* Show expand button only when sidebar is collapsed */
.sidebar.collapsed ~ #sidebar-expand {
    display: flex;
}

/* Hide gutter when sidebar is collapsed */
.sidebar.collapsed ~ #sidebar-gutter {
    display: none;
}

/* --- Mobile: sidebar as off-canvas overlay --- */
@media (max-width: 767.98px) {
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85% !important;
        max-width: 320px;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .sidebar.collapsed {
        display: block !important;
        transform: translateX(-100%);
    }

    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 1049;
    }

    .sidebar-backdrop.show {
        display: block;
    }

    #sidebar-gutter,
    #sidebar-expand {
        display: none !important;
    }
}
