/* ===========================
   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 — module selector pill ── */

.tree-dd-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    border: var(--lux-hairline, 1px) solid var(--lux-line, var(--border-color));
    border-radius: var(--lux-r-sm, 3px);
    background: var(--lux-bg-1, var(--bg-secondary));
    user-select: none;
    font-family: var(--font-mono, monospace);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--lux-ink, var(--text-color));
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}

/* Channel stripe on the left edge of the trigger */
.tree-dd-trigger::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 2px;
    background: var(--ch-signal, var(--primary-color));
    opacity: 0.4;
    transition: opacity 0.15s, box-shadow 0.15s;
}

.tree-dd-trigger:hover {
    border-color: var(--lux-line-bold, var(--border-color));
    background: var(--lux-bg-2, var(--bg-secondary));
}

.tree-dd-trigger:hover::before,
.tree-dd-trigger.open::before {
    opacity: 1;
    box-shadow: 0 0 8px color-mix(in srgb, var(--ch-signal, var(--primary-color)) 60%, transparent);
}

.tree-dd-trigger.open {
    border-color: color-mix(in srgb, var(--ch-signal, var(--primary-color)) 35%, var(--lux-line, var(--border-color)));
    background: var(--lux-bg-2, var(--bg-secondary));
}

.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;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    white-space: nowrap;
    color: var(--lux-ink, var(--text-color));
}

.tree-dd-trigger-count {
    background: var(--ch-signal, var(--primary-color));
    color: var(--lux-bg-0, var(--primary-contrast));
    font-family: var(--font-mono, monospace);
    font-size: 0.55rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 2px;
    min-width: 18px;
    text-align: center;
    letter-spacing: 0.04em;
    box-shadow: 0 0 6px color-mix(in srgb, var(--ch-signal, var(--primary-color)) 40%, transparent);
}

.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 — rack-selector popover ── */

.tree-dd-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 260px;
    max-width: 360px;
    max-height: 70vh;
    overflow-y: auto;
    background: linear-gradient(180deg,
        var(--lux-bg-1, var(--bg-color)) 0%,
        var(--lux-bg-2, var(--bg-color)) 100%);
    border: var(--lux-hairline, 1px) solid var(--lux-line-bold, var(--border-color));
    border-radius: var(--lux-r-md, 6px);
    box-shadow: var(--lux-shadow-rack, 0 8px 24px rgba(0, 0, 0, 0.25));
    z-index: 100;
    padding: 6px 0;
    margin-top: 6px;
    scrollbar-width: thin;
}

/* Channel accent rule at the top of the panel */
.tree-dd-panel::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--ch-signal, var(--primary-color)) 20%,
        var(--ch-cyan, var(--primary-color)) 50%,
        var(--ch-magenta, var(--primary-color)) 80%,
        transparent 100%);
    opacity: 0.5;
    pointer-events: none;
}

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

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

.tree-dd-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 4px;
    font-family: var(--font-mono, monospace);
    font-size: 0.56rem;
    font-weight: 600;
    color: var(--lux-ink-mute, var(--text-muted));
    text-transform: uppercase;
    letter-spacing: 0.22em;
    user-select: none;
    position: relative;
}

/* Small square dot prefix — reads like a silkscreened section marker. */
.tree-dd-group-header::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--lux-ink-faint, var(--text-muted));
    border-radius: 1px;
    flex-shrink: 0;
}

.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: 8px;
    padding: 7px 14px 7px 22px;
    cursor: pointer;
    font-family: var(--font-body, inherit);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--lux-ink-dim, var(--text-secondary));
    transition: color 0.1s, background 0.1s, box-shadow 0.1s;
    position: relative;
}

/* 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(--lux-ink, var(--text-color));
    background: var(--lux-bg-3, var(--bg-secondary));
}

/* Active leaf: LED pip on the left + channel glow + brighter text */
.tree-dd-leaf.active {
    color: var(--lux-ink, var(--text-color));
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--ch-signal, var(--primary-color)) 14%, transparent) 0%,
        transparent 80%);
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--ch-signal, var(--primary-color));
}

.tree-dd-leaf.active::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ch-signal, var(--primary-color));
    box-shadow: 0 0 6px var(--ch-signal, var(--primary-color));
    animation: pulse 2s ease-in-out infinite;
}

.tree-dd-leaf.active .tree-count {
    background: var(--ch-signal, var(--primary-color));
    color: var(--lux-bg-0, var(--primary-contrast));
    box-shadow: 0 0 6px color-mix(in srgb, var(--ch-signal, var(--primary-color)) 50%, transparent);
}

.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,
.tree-dd-group-count {
    background: var(--lux-bg-3, var(--border-color));
    color: var(--lux-ink-dim, var(--text-secondary));
    font-family: var(--font-mono, monospace);
    font-size: 0.56rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 2px;
    flex-shrink: 0;
    min-width: 18px;
    text-align: center;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

/* ── Group separator — hairline-dashed between top-level groups ── */

.tree-dd-group + .tree-dd-group {
    border-top: 1px dashed var(--lux-line, var(--border-color));
    margin-top: 4px;
    padding-top: 4px;
}
