:host {
    display: block;
    min-width: 0;
}

.workspace-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 24px;
    border-bottom: 1px solid var(--mat-sys-outline-variant);
    background: var(--app-header-bg, var(--mat-sys-surface-container-low));
    app-region: drag;
}

.playlist-switcher {
    width: min(260px, 32vw);
    flex-shrink: 0;
    app-region: no-drag;
}

.search-field {
    flex: 1;
    min-width: 160px;
    max-width: 560px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--app-search-border, var(--mat-sys-outline-variant));
    background: var(--app-search-bg, var(--mat-sys-surface-container));
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    transition:
        border-color 0.15s ease,
        background-color 0.15s ease,
        box-shadow 0.15s ease;
    app-region: no-drag;

    &:focus-within {
        border-color: var(--mat-sys-primary);
        box-shadow: 0 0 0 3px
            color-mix(in srgb, var(--mat-sys-primary) 12%, transparent);
    }

    mat-icon {
        font-size: 18px;
        width: 18px;
        height: 18px;
        color: var(--mat-sys-on-surface-variant);
        flex-shrink: 0;
    }

    .search-chip {
        max-width: 200px;
        padding: 0 10px;
        height: 24px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: var(--mat-sys-on-surface-variant);
        background: color-mix(
            in srgb,
            var(--mat-sys-surface-container-high) 76%,
            transparent
        );
        border: 1px solid
            color-mix(in srgb, var(--mat-sys-outline-variant) 82%, transparent);
        font-size: 0.75rem;
        font-weight: 600;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 1;
        min-width: 48px;
    }

    .search-chip--scope {
        color: var(--mat-sys-on-surface);
    }

    .search-chip--status {
        color: var(--app-selection-color, var(--mat-sys-primary));
        background: color-mix(
            in srgb,
            var(--app-selection-surface, var(--mat-sys-primary-container)) 70%,
            transparent
        );
        border-color: color-mix(
            in srgb,
            var(--app-selection-border, var(--mat-sys-primary)) 52%,
            transparent
        );
    }

    input {
        flex: 1;
        border: none;
        outline: none;
        background: transparent;
        color: var(--mat-sys-on-surface);
        font: inherit;
        font-size: 0.875rem;

        &:disabled {
            cursor: not-allowed;
            opacity: 0.5;
        }

        &::placeholder {
            color: var(--mat-sys-on-surface-variant);
            opacity: 0.7;
        }
    }

    .command-trigger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: 22px;
        min-width: 36px;
        padding: 0 6px;
        margin-right: -2px;
        color: var(--mat-sys-on-surface-variant);
        background: color-mix(
            in srgb,
            var(--mat-sys-surface-container-high) 76%,
            transparent
        );
        border: 1px solid
            color-mix(in srgb, var(--mat-sys-outline-variant) 70%, transparent);
        border-radius: 5px;
        font-family: inherit;
        font-size: 0.7rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        line-height: 1;
        cursor: pointer;
        flex-shrink: 0;
        transition:
            color 0.15s ease,
            background 0.15s ease,
            border-color 0.15s ease;

        &:hover {
            background: var(--mat-sys-surface-container-highest);
            color: var(--mat-sys-on-surface);
            border-color: color-mix(
                in srgb,
                var(--mat-sys-outline-variant) 100%,
                transparent
            );
        }

        &:focus-visible {
            outline: 2px solid var(--mat-sys-primary);
            outline-offset: 1px;
        }
    }
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    app-region: no-drag;

    button,
    a {
        color: var(--mat-sys-on-surface-variant);
        border-radius: 8px;
        transition:
            color 0.15s ease,
            background 0.15s ease;

        &:hover {
            color: var(--mat-sys-on-surface);
            background: var(--mat-sys-surface-container);
        }

        &.is-active {
            color: var(--app-selection-color);
            background: linear-gradient(
                145deg,
                var(--app-selection-surface-strong),
                var(--app-selection-surface)
            );
            box-shadow:
                inset 0 0 0 1px var(--app-selection-border),
                0 10px 20px -16px var(--app-selection-glow);
        }
    }
}

.header-actions--leading {
    margin-left: -4px;
}

.header-actions--trailing {
    margin-left: auto;
    padding-left: 8px;
    border-left: 1px solid var(--mat-sys-outline-variant);
    app-region: no-drag;
}

// ─── Download Activity Indicator ─────────────────────────────────────────────
.download-btn-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.download-activity-bar {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    pointer-events: none;
    z-index: 10;
}

.download-activity-bar__fill {
    display: block;
    position: absolute;
    top: 0;
    left: -50%;
    width: 50%;
    height: 100%;
    border-radius: inherit;
    background: var(--app-selection-color, #78adff);
    animation: download-bar-slide 1.4s ease-in-out infinite;
}

@keyframes download-bar-slide {
    0% {
        left: -50%;
    }

    50% {
        left: 100%;
    }

    100% {
        left: -50%;
    }
}

@media (max-width: 960px) {
    .search-field {
        min-width: 120px;
        flex: 1 1 150px;

        .search-chip {
            max-width: 150px;
        }
    }
}

@media (max-width: 780px) {
    .workspace-header {
        padding-inline: 10px;
        gap: 10px;
    }

    .playlist-switcher {
        width: 190px;
    }

    .header-actions {
        gap: 0;
    }

    .search-field {
        gap: 6px;
        padding-inline: 10px;

        .search-chip {
            max-width: 116px;
            padding-inline: 8px;
        }
    }
}

@media (max-width: 640px) {
    .playlist-switcher {
        width: auto;
        min-width: 140px;
        flex: 1;
    }

    .search-field {
        .search-chip--status {
            display: none;
        }
    }
}
