$preview-reduction: 70px;

.neo-input {

    &.is-static {

        .ni_block .block-checkbox,
        .ni_block .block-settings,
        .ni_block .block-reorder,
        .ni_buttons {
            display: none;
        }

        .ni_block:last-child {
            margin-bottom: 0;
        }
    }

    &.is-translatable {

        .field > .heading .locale {
            display: none;
        }
    }
}

.ni {

    &_buttons {
        position: relative;
        height: 30px;

        > .btngroup,
        > .menubtn {
            position: absolute;
            top: 0;

            body.ltr & { left:  0; }
            body.rtl & { right: 0; }
        }
    }

    &_blocks {

        > .ni_buttons {
            margin-bottom: 10px;
        }
    }

    &_spinner {
        margin-bottom: 10px;
        text-align: center;
    }

    &_block {
        box-sizing: border-box;
        width: 100%;
        overflow: hidden;
        margin-bottom: 10px;
        border-radius: 4px;
        border: 1px solid #e3e5e8;
        background-color: #f3f7fc;
        padding: 0;

        &:focus {
            outline: 0;
        }

        &_topbar {
            position: relative;
            height: 30px;
            line-height: 30px;
            color: #8f98a3;
            transition: background-color 0.5s;
            padding: 0 14px;

            &_left,
            &_right {
                display: flex;
                position: absolute;
                top: 0; bottom: 0;
            }

            &_left {

                body.ltr & {
                    left:  14px;
                }

                body.rtl & {
                    right: 14px;
                }
            }

            &_right {
                z-index: 1;
                min-width: 100px;

                body.ltr & {
                    right: 14px;
                }

                body.rtl & {
                    left:  14px;
                }
            }

            &_item {
                cursor: default;
                padding: 0 8px;
                -webkit-user-select: none;
                -moz-user-select: none;
                user-select: none;
                white-space: nowrap;

                body.ltr &:not(:first-child),
                body.rtl &:not(:last-child) {
                    padding-left: 0;
                }
                
                &:first-child {
                    padding-left: 0;
                }
                
                &:last-child {
                    padding-right: 0;
                }

                &.size-full {
                    flex-grow: 1;
                }

                &.clip-text {
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                &.title {

                    .blocktype {
                        // Add vertical padding so there's more hit area for the checkbox
                        padding: 8px 0;
                        
                        &.has-errors {
                            color: #da5a47;
                        }
                    }

                    .preview {
                        pointer-events: none; // Allow the double-click expand/collapse work it's magic
                        position: absolute;
                        width: calc(100% - #{$preview-reduction});
                        height: 30px;
                        overflow: hidden;
                        color: #b9bfc6;
                        transition: opacity 0.2s;

                        body.ltr & { margin-left:  8px; }
                        body.rtl & { margin-right: 8px; }

                        &:empty {
                            // Fixes bug where the blocktype can get clipped prematurely
                            display: none;
                        }

                        &_section {
                            display: inline-block;
                            padding: 0 8px;
                            height: 30px;
                            line-height: 30px;

                            body.ltr & { border-left:  1px solid #e3e5e8; }
                            body.rtl & { border-right: 1px solid #e3e5e8; }
                        }

                        img,
                        &_color {
                            vertical-align: top;
                            margin-top: 15px;
                            transform: translateY(-50%);
                        }

                        img {
                            max-width: 30px;
                            max-height: 30px;
                        }

                        &_color {
                            display: inline-block;
                            width: 16px;
                            height: 16px;
                            border-radius: 50%;
                        }

                        .status {

                            body.ltr & { margin-right: 6px; }
                            body.rtl & { margin-left:  6px; }
                        }
                    }
                }

                &.tabs {
                    position: relative;
                    transition: opacity 0.2s;

                    .tabs_inner {
                        white-space: nowrap;

                        body.ltr & { right: 0; direction: ltr; }
                        body.rtl & { left:  0; direction: rtl; }
                    }

                    .tabs_btn {
                        position: absolute;
                        top: 0;
                        display: inline-flex;
                        cursor: pointer;
                        height: 30px;
                        padding: 0 9px;
                        border: 1px solid #e3e5e8;
                        border-top: 0;
                        border-bottom-color: #fbfcfd;
                        margin-bottom: -1px;
                        background-color: #fbfcfd;
                        color: #576575;

                        body.ltr & { right: 8px; }
                        body.rtl & { left:  8px;  }

                        &.has-errors {
                            color: #da5a47;
                        }
                    }

                    .tab {
                        display: inline-block;
                        height: 30px;
                        padding: 0 10px;
                        border-bottom-color: #fafafa;
                        color: rgba(#29323d, 0.5);

                        &:hover {
                            color: #0d78f2;
                        }

                        &.is-selected {
                            cursor: default;
                            padding: 0 9px;
                            border-left: 1px solid #e3e5e8;
                            border-right: 1px solid #e3e5e8;
                            border-bottom-width: 1px;
                            border-bottom-style: solid;
                            margin-bottom: -1px;
                            background-color: #fbfcfd;
                            color: #576575;

                            &.is-blank {
                                border-bottom-color: #f1f5f8;
                                background-color: transparent;
                                transition: border-bottom-color 0.5s;
                            }
                        }

                        &.has-errors {
                            color: #da5a47;
                        }
                    }
                }

                .invisible {
                    visibility: hidden;
                    pointer-events: none;
                }

                > .checkbox {
                    position: relative;
                    display: block;
                    height: 100%;
                    color: #29323d;

                    &::before {
                        position: absolute;
                        top: 50%;
                        margin-top: -8px;
                    }

                    &::after {
                        display: none;
                    }
                }

                > .status {
                    margin: 10px 5px 0 0;
                }

                > a {
                    color: rgba(#29323d, 0.25);

                    &:hover {
                        color: #0d78f2;
                    }
                }
            }
        }

        &_body {
            overflow: hidden;
            padding: 0 14px 14px;
        }

        &_content {
            border-top: 1px solid #e3e5e8;

            &:empty {
                display: none;
            }

            &_tab {
                padding: 14px 0 0;

                &.is-blank {
                    padding: 0;
                    border-top: 0;
                }

                #content &,
                .lp-editor & {

                    &:not(.is-selected) {
                        display: none;
                    }
                }

                > .field {
                    margin: 15px 0 0 0;
                }
            }
        }

        &_children {
            padding: 14px 0 7px;
            border-top: 1px solid #e3e5e8;
            transition: background-color 0.5s;

            .ni_block_body > &:not(:first-child) {
                margin-top: 14px;
            }
        }

        &_collapsed-children {
            overflow: hidden;

            &_child {
                height: 2px;
                border-top: 1px solid #e3e5e8;
                background-color: #fbfcfd;
                margin-top: -3px;
                transition: margin-top 0.2s; // 200ms to match jQuery transition duration
            }
        }

        &.is-level-odd {
            background-color: #fbfcfd;

            > .ni_block_topbar > .ni_block_topbar_right {

                > .ni_block_topbar_item.tabs .tab.is-blank {
                    border-bottom-color: white;
                }
            }
        }

        &.is-expanded {

            > .ni_block_topbar {

                .title > .preview {
                    opacity: 0;
                }
            }
        }

        &.is-collapsed {
            padding-bottom: 0;

            > .ni_block_topbar {

                .ni_block_topbar_left {

                    overflow: hidden;

                    &::before {
                        content: '';
                        pointer-events: none;
                        position: absolute;
                        top: 0;
                        bottom: 0;
                        left: 0;
                        right: 0;
                        z-index: 1;

                        body.ltr & {
                            background-image: linear-gradient(-90deg, #f3f7fc 0, rgba(243, 247, 252, 0) 40px, rgba(243, 247, 252, 0) 100%);
                        }

                        body.rtl & {
                            background-image: linear-gradient(90deg, #f3f7fc 0, rgba(243, 247, 252, 0) 40px, rgba(243, 247, 252, 0) 100%);
                        }
                    }

                    body.ltr & {
                        right: $preview-reduction;
                    }
    
                    body.rtl & {
                        left: $preview-reduction;
                    }
                }

                .ni_block_topbar_right {
                    pointer-events: none;

                    > .tabs {
                        opacity: 0;
                    }

                    > :not(.tabs) {
                        pointer-events: auto;
                    }
                }
            }

            > .ni_block_collapsed-children {

                .ni_block_collapsed-children_child {
                    margin-top: 0;
                }
            }
        }

        &.is-disabled {

            .ni_block_topbar_item {

                &.title .preview {
                    opacity: 0;
                }
            }

            .ni_block_content_tab {

                .field {
                    pointer-events: none;
                    opacity: 0.5;
                    -webkit-user-select: none;
                    -moz-user-select: none;
                    user-select: none;
                }
            }
        }

        &.is-empty {
            padding: 6px 0; // Add some vertical size to blocks without fields or children so they stand out more

            &.is-level-odd {
                background-color: white;
            }
        }
    }
}

.neo_block_tabs-menu {

    a.is-selected {
        cursor: default;
        pointer-events: none;
        opacity: 0.25;
    }

    a.has-errors {
        color: #da5a47;
    }
}

// Tweak the styles of nested Matrix fields so it doesn't look so confusing
.ni_block .matrixblock,
.neo-matrixblock {
    border-color: #ccc;
    background-color: white;
    box-shadow: 0 1px 5px -1px rgba(black, 0.1);

    > .titlebar {
        border-bottom-color: #eee;
        background-color: #fbfcfd;
    }
}
