/* ===========================
   Tree Dropdown Navigation
   =========================== */

.tree-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.tree-sidebar {
    position: sticky;
    top: var(--sticky-top, 90px);
    z-index: 20;
    padding: 8px 0 4px;
    /* dropdown panel positions against this */
    /* sticky already establishes containing block, but be explicit */
}

.tree-content {
    flex: 1;
    min-width: 0;
}

/* ── Trigger bar ── */

.tree-dd-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    user-select: none;
    font-size: 0.82rem;
    color: var(--text-color);
    transition: border-color 0.15s, background 0.15s;
}

.tree-dd-trigger:hover {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 6%, var(--bg-secondary));
}

.tree-dd-trigger.open {
    border-color: var(--primary-color);
}

.tree-dd-trigger-icon {
    flex-shrink: 0;
    line-height: 1;
}

.tree-dd-trigger-icon .icon {
    width: 14px;
    height: 14px;
}

.tree-dd-trigger-title {
    font-weight: 600;
    white-space: nowrap;
}

.tree-dd-trigger-count {
    background: var(--primary-color);
    color: var(--primary-contrast);
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
}

.tree-dd-chevron {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    margin-left: 2px;
}

.tree-dd-trigger.open .tree-dd-chevron {
    transform: rotate(180deg);
}

.tree-dd-extra {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    border-left: 1px solid var(--border-color);
    padding-left: 8px;
}

/* ── Dropdown panel ── */

.tree-dd-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    max-width: 340px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 100;
    padding: 4px 0;
    margin-top: 4px;
}

.tree-dd-panel.open {
    display: block;
}

/* ── Group header (non-clickable category label) ── */

.tree-dd-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px 3px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    user-select: none;
}

.tree-dd-group-header.tree-dd-depth-1 {
    padding-left: 24px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
}

.tree-dd-group-header.tree-dd-depth-2 {
    padding-left: 36px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
}

.tree-dd-group-header .tree-node-icon {
    flex-shrink: 0;
    line-height: 1;
}

.tree-dd-group-header .tree-node-icon .icon {
    width: 13px;
    height: 13px;
}

.tree-dd-group-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-dd-group-count {
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.58rem;
    font-weight: 600;
    padding: 0 4px;
    border-radius: 8px;
    min-width: 14px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Leaf (clickable item) ── */

.tree-dd-leaf {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 20px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color 0.1s, background 0.1s;
}

/* Indent leaves inside nested groups */
.tree-dd-group-header.tree-dd-depth-1 ~ .tree-dd-children > .tree-dd-leaf,
.tree-dd-group .tree-dd-group .tree-dd-leaf {
    padding-left: 32px;
}

.tree-dd-group .tree-dd-group .tree-dd-group .tree-dd-leaf {
    padding-left: 44px;
}

.tree-dd-leaf:hover {
    color: var(--text-color);
    background: var(--bg-secondary);
}

.tree-dd-leaf.active {
    color: var(--primary-text-color);
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    font-weight: 600;
}

.tree-dd-leaf.active .tree-count {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

.tree-dd-leaf .tree-node-icon {
    flex-shrink: 0;
    line-height: 1;
}

.tree-dd-leaf .tree-node-icon .icon {
    width: 14px;
    height: 14px;
}

.tree-dd-leaf .tree-node-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Count badge (shared) ── */

.tree-count {
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0 5px;
    border-radius: 8px;
    flex-shrink: 0;
    min-width: 16px;
    text-align: center;
}

/* ── Group separator ── */

.tree-dd-group + .tree-dd-group {
    border-top: 1px solid var(--border-color);
    margin-top: 2px;
    padding-top: 2px;
}
