ul.sequence {
    @include clearfix;
    position: relative;
}

li.sequence-member {
    @include clearfix;
    position: relative;
    border: 1px solid transparent;
    border-width: 1px 0;

    &:hover {
        background-color: $color-input-focus;
        border-color: darken($color-input-focus, 10%);

        .sequence-member-inner {
            > .struct-block > label,
            > .char_field > label,
            .sequence > label {
                opacity: 1;
            }
        }
    }

    &:hover .object-help {
        opacity: 1;
    }

    .struct-block .fields {
        @include column(10);
        padding-left: 0;
        padding-right: 0;
    }

    .struct-block .sequence-container {
        @include column(9);
        padding-left: 0;
        padding-right: 0;

        .sequence-member-inner {
            padding: 1.5em 0;
        }
    }

    // The top level sequence doesn't have a sequnce-member-inner. This block is basically for things that should only affect inner blocks
    .sequence-member-inner {
        @include clearfix;
        position: relative;
        padding: 1.5em 50px;

        .sequence-member {
            border: 0;
        }

        // sequences within sequences, such as a ListBlock within StructBlock
        > .sequence .sequence-inner {
            @include column(10);
            padding-left: 0;
            padding-right: 0;
        }

        .sequence-type-list .sequence-container-inner {
            @include column(10);
            padding-left: 0;
            padding-right: 0;
        }

        .sequence-type-list .sequence-member-inner {
            padding: 0;
            padding-top: 0.5em;
            padding-bottom: 1.2em;
        }
    }

    .fields > li {
        position: relative;
    }
}

// Image chooser as direct descendant of top-level streamfield has special display
.sequence-member-inner > .widget-admin_image_chooser {
    label {
        display: none;
    }

    .field-content {
        display: block;
        float: none;
        width: 100%;
        text-align: center;
        max-width: 500px;
        margin: auto;
        border: 1px solid $color-grey-4;
        padding: 1em;
    }

    .chooser {
        .chosen {
            padding: 0;
        }

        .unchosen {
            &:before {
                float: none;
                font-size: 4em;
                margin: 0;
            }
        }

        .preview-image {
            float: none;
            margin: 0;
        }
    }

    .actions li {
        display: inline-block;
        float: none;
    }
}


// This horridly specific selector ensures text inputs, rich text fields and textareas 
// that are direct children of highest level sequence should be borderless and full-width
.block_field > .field-content > .input > .sequence-container > .sequence-container-inner > .sequence > .sequence-member > .sequence-member-inner {
    > .widget-text_input input,
    > .widget-rich_text_area .richtext,
    > .widget-textarea textarea { 
        border: 0;
        padding: 0;
        background-color: transparent;
        max-width: 1024px;
    }
}

// Controls for ordering and deletion of items in a sequence
.sequence-controls {
    @include transition(opacity 0.2s ease);
    border-radius: 2px 0 0;
    border: 1px solid darken($color-input-focus, 10%);
    border-width: 1px 1px 0;
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: -30px; 
    right: 0;
    z-index: 1;
    overflow: visible;
    background-color: $color-input-focus;
    padding: 0 0 0 1em;
    height: 30px;

    h3 {
        margin: 0;
        font-size: 0.7rem;
        display: inline-block;
        margin-right: 1em;
        line-height: 1.8rem;

        label {
            color: $color-teal;
            font-weight: normal;
            text-transform: uppercase;
            float: none;
            width: auto;
            padding: 0;
            margin: 0;
        }
    }

    button.icon.text-replace {
        width: 1.8rem;
        height: 1.8rem;

        &:before {
            line-height: 1.3em;
            font-size: 0.9rem;
        }
    }

    // .buttons only exists for menus in stream_member.html
    .button-group {
        float: right;
    }

    &:hover .buttons,
    &:hover label {
        opacity: 1;
    }

    .disabled {
        display: none;
    }       
}

// list controls are slightly different as they require closer proximity to their associated fields
.list-controls {
    border-radius: 0;
    background: transparent;
    top: 1.5em;
    border: 0;
    padding: 0;
    overflow: hidden;
    height: auto;
}

.sequence-type-list .object-help {
    margin-top: 1.5em;
}

// Menu of other blocks to be added at each position 
.stream-menu {
    @include transition(all 0.2s ease);
    box-shadow: inset 0 0 45px rgba(0, 0, 0, 0.3);
    position: relative;
    background-color: $color-grey-1;
    opacity: 1;
    z-index: 5;

    .toggle {
        @include transition(color 0.2s ease);
        border-radius: 50px;
        position: absolute;
        top: -0.5em;
        left: 0;
        right: 0;
        margin: 0 auto;
        cursor: pointer;
        font-size: 1.7em;
        width: 1em;
        height: 1em;
        display: block;
        z-index: 5;
        color: $color-grey-1;
        background-color: $color-white;
        outline: none;

        span {
            @include visuallyhidden();
        }

        &:before {
            transform: rotate(-45deg);
            position: absolute;
            font-family: wagtail;
            content: 'B';
            line-height: 1em;
            text-align: center;
        }
    }

    .stream-menu-inner {
        transform: translate3d(0, 0, 0);
        max-width: 50em;
        margin: auto;
        overflow: hidden;
    }

    ul {
        @include transition(all 0.2s ease);
        @include clearfix;
        transform: translate3d(0, 0, 0) scale(1);
        visibility: visible;
        opacity: 1;
        padding: 1em 1em 0;
        overflow: hidden;
    }

    li {
        @include column(3);
        padding-bottom: $grid-gutter-width;
        padding-left: 0;
        padding-right: 0;

        &:nth-child(4n+1) {
            clear: left;
        }
    }

    button {
        @include transition(all 0.2s ease);
        background-color: transparent;
        border: 0;
        color: darken($color-grey-3, 5%);
        height: auto;
        display: block;
        width: 100%;
        padding: 0 0 0.5em;
        outline: $color-teal;
        overflow: visible;

        span {
            text-transform: none;
            white-space: pre-wrap;
            width: 100%;
            display: block;
            overflow: hidden;
            padding: 0 1em;
            box-sizing: border-box;
        }

        &:before {
            display: block;
            font-family: wagtail;
            font-size: 2em;
            width: 100%;
            height: 2em;
            line-height: 2em;
            text-align: center;
        }

        &:hover,
        &:focus {
            background-color: $color-teal;
            color: $color-white;
        }
    }

    &.stream-menu-closed {
        box-shadow: none;

        .stream-menu-inner ul {
            transform: scale(0.9);
            opacity: 0;
        }

        .toggle {
            color: $color-grey-3;
            background-color: $color-white;

            &:before {
                transform: rotate(0deg);
            }

            &:focus {
                color: $color-teal;
            }
        }

        &:hover {
            border-top-color: $color-teal;

            .toggle {
                color: $color-teal;
            }
        }
    }

    @media screen and (min-width: $breakpoint-mobile) {
        li {
            @include column(2);

            &:nth-child(4n+1) {
                clear: none;
            }

            &:nth-child(6n+1) {
                clear: left;
            }
        }
    }
}

.sequence-member .stream-menu {
    margin: auto auto 0;
}

.sequence-member .stream-menu-closed {
    opacity: 0;
    visibility: hidden;
}

.sequence-member:hover {
    .sequence-controls {
        visibility: visible;
        opacity: 1;
    }

    .stream-menu {
        visibility: visible;
        opacity: 1;
    }
}

@media screen and (min-width: $breakpoint-mobile) {
    .object li.sequence-member:hover .object-help {
        opacity: 1;
    }
}
