.module-list-container {
    display: flex;
}

/* hide the janky initial layout */
@keyframes P-module-list-fade-in {
    0% {
        opacity: 0;
    }
}

.module-list {
    flex: 1;
    position: relative;
    animation: P-module-list-fade-in 0.5s 0.3s backwards;

    .add-module {
        padding: 0.75em;
        display: flex;
        justify-content: center;
        align-items: center;

        & > button {
            margin: 0;
            padding: 0;
            border: none;
            background: var(--P-separator);
            width: 3em;
            height: 3em;
            border-radius: 50%;
            position: relative;
            color: inherit;

            &::before,
            &::after {
                content: '';
                position: absolute;
                width: 1.5em;
                height: 2px;
                background: currentColor;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
            &::after {
                transform: translate(-50%, -50%) rotate(90deg);
            }

            &:active {
                opacity: 0.5;
            }
        }
    }

    .module-item {
        background: var(--P-item-bg);
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        border-bottom: 1px solid rgba(0, 0, 0, 0.3);
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;

        &.is-selected {
            background: var(--P-item-selected-bg);
        }

        &.is-being-dragged {
            z-index: 1;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        }

        & > .i-header {
            padding: 0.3em 0.5em;
            display: flex;

            & > .i-title {
                display: flex;
                align-items: center;
                flex: 1;
                font-size: 1.1em;

                & > .i-remove {
                    font: inherit;
                    margin: 0;
                    padding: 0;
                    background: none;
                    width: 1.5em;
                    height: 1.5em;
                    border-radius: 0.5em;
                    color: inherit;
                    border: 1px solid rgb(var(--P-color-accent));
                    position: relative;
                    vertical-align: 0.3em;

                    &:active {
                        background: rgb(var(--P-color-accent));
                        color: rgb(var(--P-color-accent-fg));
                    }

                    &::before {
                        content: '';
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        width: 0.8em;
                        height: 1.5px;
                        transform: translate(-50%, -50%);
                        background: currentColor;
                    }
                }

                & > .i-label {
                    display: contents;

                    & > .i-index {
                        display: inline-block;
                        font-weight: bold;
                        min-width: 2em;
                        text-align: right;
                        font-feature-settings: 'tnum' 1;
                    }
                    & > .i-title {
                        flex: 1;
                        margin: 0 0.5em;

                        .i-display-title {
                            display: inline-block;
                            text-align: inherit;
                            border: 1px solid transparent;
                            border-radius: 0.4em;
                            padding: 0.2em;
                            margin: calc(-0.2em - 1px);
                            background: none;
                            color: inherit;
                            font: inherit;
                            cursor: text;
                            transition: border-color 0.2s;

                            &:hover {
                                border-color: var(--P-separator);
                            }

                            .i-edit-icon {
                                display: inline-flex;
                                position: relative;
                                width: 1em;
                                height: 1em;
                                background: none;
                                border: none;
                                font: inherit;
                                color: inherit;
                                vertical-align: -0.15em;
                                margin-left: 0.4em;
                                transition: opacity 0.2s;

                                svg {
                                    position: absolute;
                                    top: 50%;
                                    left: 50%;
                                    transform: translate(-50%, -50%);
                                }
                            }

                            @media (hover: hover) {
                                .i-edit-icon {
                                    opacity: 0;
                                }
                                &:hover .i-edit-icon,
                                &:focus-within .i-edit-icon,
                                .i-edit-icon:focus {
                                    opacity: 1;
                                }
                            }
                        }

                        .i-description {
                            font-size: smaller;
                            opacity: 0.5;
                        }
                    }
                }
            }

            & > .i-header-controls {
                display: flex;
                align-items: center;

                button {
                    font: inherit;
                    background: none;
                    border: 1px solid var(--P-separator);
                    color: rgb(var(--P-color-fg));
                    min-width: 2em;
                    min-height: 2em;
                    transition: opacity 0.3s;

                    &:not(:first-child) {
                        border-left: none;
                    }
                    &:first-child {
                        border-top-left-radius: 0.5em;
                        border-bottom-left-radius: 0.5em;
                    }
                    &:last-child {
                        border-top-right-radius: 0.5em;
                        border-bottom-right-radius: 0.5em;
                    }

                    &:active {
                        color: rgb(var(--P-color-fg) / 0.5);
                        transition: opacity 0.05s;
                    }
                }

                .i-drag-button {
                    position: relative;
                    line-height: 0;

                    .i-drag-icon {
                        display: inline-block;
                        position: relative;
                        width: 1em;
                        height: 1em;
                        vertical-align: middle;

                        & > .i-line {
                            position: absolute;
                            left: 0;
                            right: 0;
                            top: 50%;
                            height: 2px;
                            border-radius: 1px;
                            background: currentColor;

                            &:nth-child(1) {
                                transform: translateY(-250%);
                            }
                            &:nth-child(2) {
                                transform: translateY(-50%);
                            }
                            &:nth-child(3) {
                                transform: translateY(150%);
                            }
                        }
                    }

                    &::before,
                    &::after {
                        content: '';
                        position: absolute;
                        pointer-events: none;
                        border: 0.7em solid transparent;
                        transition: transform 0.3s var(--P-ease-default), opacity 0.3s ease-out;
                        opacity: 0;
                        left: 50%;
                    }
                    &::before {
                        border-bottom-color: rgb(var(--P-color-fg));
                        bottom: calc(100% + 0.5em);
                        transform: translate(-50%, 0.5em);
                    }
                    &::after {
                        border-top-color: rgb(var(--P-color-fg));
                        top: calc(100% + 0.5em);
                        transform: translate(-50%, -0.5em);
                    }

                    &:active {
                        &::before,
                        &::after {
                            opacity: 0.5;
                        }
                    }
                    &:focus {
                        &::before,
                        &::after {
                            opacity: 1;
                            transform: translateX(-50%);
                        }
                    }
                }
            }

            @media (hover: hover) {
                &:hover > .i-title > .i-label > .i-title .i-edit-icon {
                    opacity: 0.3;
                }
            }
        }

        & > .i-editor {
            position: relative;
            padding: 0.3em 0.5em;
            padding-left: 2.3em;

            &:empty {
                display: none;
            }
        }

        & > .i-footer {
            position: relative;
            margin-top: 0.5em;
            padding-top: 0.5em;

            &::before {
                content: '';
                position: absolute;
                left: 0.5em;
                right: 0.5em;
                top: 0;
                border-top: 1px solid var(--P-separator);
            }

            & > .i-sends {
                padding: 0.5em;
                display: flex;
                gap: 0.5em;

                & > .i-label {
                    min-width: 5em;
                    padding-top: 0.1em;
                }

                & > .i-list {
                    margin: 0;
                    padding: 0;
                    list-style: none;
                    line-height: 1.5;

                    & > .i-send-target {
                        display: inline-block;

                        select {
                            width: 8em;
                        }
                    }
                }

                &.is-named-sends {
                    & > .i-label {
                        padding-top: 0;
                    }
                    &.has-sends > .i-label {
                        padding-top: 0.25em;
                    }
                }

                &.is-named-sends > .i-list {
                    flex: 1;

                    & > .i-send-target {
                        display: flex;
                        justify-content: stretch;
                        align-items: center;
                        gap: 0.5em;

                        select {
                            flex: 1;
                        }
                        .uikit-text-field,
                        .text-field-placeholder {
                            flex: 2;
                        }

                        & + .i-send-target {
                            margin-top: 0.5em;
                        }
                    }
                }
            }
        }

        &.is-collapsed {
            & > .i-editor,
            & > .i-footer {
                display: none;
            }
        }
    }
}
