// TODO: Make sure to move this out alongside the code when extracting a new repo

//--[ Theme ]-----------------------------------------------------------------------------------------------------------

@hr-color: #cdcdcd;
@grab-color: #949393;
@selection-color: #ddd;
@editor-background: #fff;
@brand-grey-lite: #949393;
@top-bg: #fff;
@brand-color: #4a90e2;
@action-button-color: rgba(53,64,82, 0.25);
@warning-color: #D24146;
@error-highlight: @warning-color;//#d82b3f;
@light-blue-bg: #edf4fc; //#f5f9fd;

@font-family-monospace:   "Source Code Pro", Menlo, Monaco, Consolas, "Courier New", monospace;
@font-family-header: "LatoLatinWebMedium", "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif;

@step-padding-tb: 11px;
@step-padding-lr: 16px;

// TODO: Make these ^^^ use the JDL variables

.pipeline-editor {
    display:flex;
    flex-direction: column;

    min-width: 640px; // avoid flow issues when resizing dialogs very small
    position: fixed;
    top: 120px;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: #fff;
    border-radius: 2px;
    z-index: 100;

    //--[ Common stuff ]----------------------------------------------------------------------------------------------------

    .editor-delete-btn {
        color: @warning-color;
        border-color: @warning-color;

        &:hover {
            color:@warning-color;
            border-color: @warning-color;
        }

        &[disabled], &[disabled]:hover {
            opacity:0.2;
        }
    }

    .editor-button-bar {
        padding: 4px 0;
        width: 100%;
        margin: 16px 0;
        > button {
            width: 100%;
        }
    }

    .editor-step .editor-button-bar {
        padding: 4px 2px 4px 28px;
        width: 100%;
        background: @hr-color;
        position: relative;

        &.arrow-up:before {
            content: '';
            display: inline-block;
            position: absolute;
            border: 8px solid #cdcdcd;
            border-left-color: transparent;
            width: 0;
            height: 0;
            border-right-color: transparent;
            border-top: 0;
            left: 8px;
            bottom: 0px;
        }

    }

    //--[ Outer Editor Component ]------------------------------------------------------------------------------------------

    .editor-main {
        display: flex;
        flex-wrap: nowrap;
        flex-direction:column;
        //align-items: stretch;
        width:100%;
        height:100%;
        flex-grow:1;
        position: relative;
        padding-right: 360px;
    }

    .editor-main-graph {
        display:flex;
        flex-grow: 10;
        flex-shrink: 0;
        flex-basis: 50%;
        background: @top-bg;
        border-bottom: solid 1px @hr-color;
        align-items: flex-start;
        overflow:auto;
        position: relative;

        .pipeline-validation-errors {
            width: 90%;
            padding: 0;
            margin: 0 5%;
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            align-items: center;
            justify-content: center;
            position: absolute;
            bottom: 0;
        }
    }

    .editor-main-selection-title {
        display:flex;
        flex-grow: 0;
        flex-shrink: 4;
        flex-basis: 8.5rem;
        align-items: center;

        h4 {
            margin: 0 2rem;
            font-size:20px;
            top:-3px;
            flex-grow:1;
        }

        .editor-button-bar {
            flex-grow: 0;
            width: auto;
            margin: 0 2rem;
            padding: 0;
        }
    }

    .editor-main-stage-details {
        display: flex;
        flex-grow: 10;
        flex-shrink: 4;
        flex-basis: 50%;
        overflow-x: auto;

        &.editor-details-placeholder {
            align-items: center;
            justify-content: center;
        }

        .empty-state-container {
            width: 70rem;
            text-align: center;

            p {
                font-size: 14pt;
            }

            .empty-state-content {
                max-width: none;
            }
        }
    }

    .editor-main-step-list {
        //min-height: 5em;
        width: 50%;
        border-right: solid 1px @hr-color;
        padding-left:2rem;
    }

    .editor-main-step-details {
        //min-height: 5em;
        width: 50%;
    }

    .editor-main-step-list p,
    .editor-main-step-details p {
        text-align: center;
    }

    //--[ "Dialog" page styles ]--------------------------------------------------------------------------------------------

    .editor-page-header-controls button + button {
        margin-left: 10px;
    }

    //--[ Pipeline Graph ]--------------------------------------------------------------------------------------------------

    .editor-graph-node {
        fill: @brand-grey-lite;
    }

    .editor-graph-node-inner {
        fill: #fff;
        transition: all 0.1s ease-in;
    }

    .editor-graph-nodegroup.selected {
        .editor-graph-node {
            fill: @brand-color;
        }
        .editor-graph-node-inner {
            fill: @brand-color;
            transform: scale(0);
        }
    }

    .editor-graph-nodegroup.errors text {
        font-size: 24px;
        font-weight: bold;
        font-family: monospace;
        fill: @error-highlight;
    }

    .editor-graph-nodegroup.errors .pipeline-selection-highlight {
        fill: @error-highlight;
        stroke: @error-highlight;
    }

    .pipeline-connector.placeholder {
        stroke: #eae9e9;
    }

    .pipeline-big-label {
        position: absolute;
        display: block;
        width: 120px;
        text-align: center;
        margin-left: -60px;
        margin-bottom: 21px;
        padding-bottom: 4px;
        text-overflow: ellipsis;
        max-width: 120px;
        white-space: nowrap;
        overflow: hidden;
        padding-top: 27px;
        cursor: pointer;

        &.top-level-parallel {
            svg {
                fill: #4a90e2 !important;
                position: absolute;
                top: 0;
                left: 50%;
                margin-left: -12px;

                + svg {
                    top: 6px;
                }
            }
            &:hover {
                color: #000;

                svg {
                    fill: darken(#4a90e2, 20%) !important;
                }
            }
            &.errors {
                .alerticon {
                    fill: @error-highlight !important;
                    position: absolute;
                    right: 0;
                    top: 9px;
                    left: 50%;
                    margin-left: 1px;
                }
            }
        }
    }

    .result-status-glyph polygon {
        fill: #cbcbcb;
    }

    .editor-add-node-placeholder {
        fill: #fff;
        stroke: #cbcbcb;
    }

    .start-node {
        fill: #cdcdcd;
    }

    //--[ Steps List ]------------------------------------------------------------------------------------------------------

    .editor-steps {
        display: flex;
        flex-direction: column;
        align-items: center;

        button.add svg {
            fill: #fff;
            vertical-align: middle;
            margin-right: 5px;
            margin-top: -2px;
        }
    }

    .editor-step {
        width: 100%;
        display: flex;
        background: @editor-background;
        position: relative;

        &.errors {
            > div > .editor-step-content:after {
                border: 1px solid @error-highlight;
                position: absolute;
                content: '';
                top: -1px; // cover the bottom border from above
                right: 0;
                bottom: 0;
                left: 0;
                cursor: pointer;
            }

            &:first-child .editor-step-content:after {
                top: 0;
            }
        }

        &.is-container {
            border-left: 1px solid @hr-color;
            border-bottom: 1px solid @hr-color;
            padding-bottom: @step-padding-tb;
        }
    }

    .editor-step + .editor-step .editor-step-content {
        border-top-width: 0;
    }

    .editor-step.is-container .editor-step:nth-child(2) .editor-step-content {
        border-top-width: 1px;
    }

    .editor-step-errors {
        color: @error-highlight;
    }

    .editor-step-main {
        width: 100%;
    }

    .editor-step-content {
        border: 1px solid @hr-color;
        border-right-width: 0;
    }

    .editor-step.is-container > .editor-step-main > .editor-step-content {
        border: 0;
    }

    .editor-step.selected > .editor-step-main {
        background: @selection-color;
    }

    .editor-step-content {
        padding: @step-padding-tb @step-padding-lr;
        cursor: pointer;
        position: relative;

        &:hover, &:active, &:focus {
            background: @light-blue-bg;
        }
    }

    .editor-steps > .editor-step {
        border-right: 1px solid @hr-color;
    }

    .editor-step .editor-step .editor-step-main { // nested steps
        border-right: 0;
        position: relative;
    }

    .editor-step.is-container .editor-step.nested {
        margin-left: @step-padding-lr;
        width: calc(~"100% - @{step-padding-lr}"); // prevent cards hanging over right edge
    }

    .editor-steps > .editor-step.missing .editor-step-content { // top-level 'no children' step
        cursor: default;
        &:hover, &:active, &:focus {
            background: #fff;
        }
    }

    .editor-step-detail section + section {
        margin-top: 16px;
    }

    .editor-step-label {
        display: block;
        font-weight: bold;
        font-size: 110%;
        padding-top: 0.3rem;
        padding-bottom: 0.3rem;
    }

    .editor-step-summary {
        display: block;
        color: @hr-color;
        font-size: 14px;
        max-height: 35px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: pre;
    }

    .editor-nested-steps {
        width: 100%;
    }

    // updated editor steps in the config panel
    .editor-steps > .editor-step:first-child > .editor-step-main {
        border-top: solid 1px @hr-color;
    }


    //--[ Step Details ]----------------------------------------------------------------------------------------------------

    .editor-step-detail {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        min-width: 296px;
    }

    textarea.editor-step-detail-script {
        min-width: 500px;
        min-height: 400px;
    }

    .editor-step-detail-script {
        margin-top:1em;
        flex-grow:1;
        border: solid 1px @brand-color;
        padding:0.5em;
        min-height: 4em;
        font-family: @font-family-monospace;
        white-space: nowrap;
    }

    .editor-step-detail-label {
        font-size:16px;
        font-family: @font-family-header;
    }

    // sheets
    .editor-config-panel {
        &.global, &.stage, &.step {
            width: 296px;
        }
    }

    .sheet-header {
        .more-menu {
            position: absolute;
            top: 8px;
            right: 0;
            cursor: pointer;

            svg {
                fill: @brand-color;
            }
        }

        .pipeline-validation-errors {
            margin: 20px 0 0 0;
        }
    }

    .editor-stage-settings {
        > div {
            margin-top: 20px;
        }
    }

    .editor-step-child-icon {
        position: absolute;
        left: -20px;
        top: 50%;
        margin-top: -7px;

        svg {
            fill: #fff;
        }
    }

    .editor-steps > .editor-step:first-child > .editor-step-main > div > .editor-step-child-icon {
        margin-top: -8px;
    }

    //--[ Step Drag and Drop ]----------------------------------------------------------------------------------------------------

    .editor-step-drag {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        cursor: -webkit-grab;

        display: flex;
        align-items: center;
        visibility: hidden;

        svg {
            fill: @grab-color;
            margin-right: 6px;
        }
    }

    .editor-step-content:hover .editor-step-drag {
        // show drag handle using visibility to avoid a horizontal layout jitter in Safari 11
        visibility: visible;
    }

    .editor-step-list-drop-zone {
        position: absolute;
        left: 0;
        width: 100%;
        height: 31px;

        &.before-item {
            top: 0;
        }

        &.after-item, &.first-child, &.last-child {
            bottom: 0;
        }

        &.last-child {
            height: @step-padding-tb;
        }
    }

    .editor-step.nested.is-container .editor-step-list-drop-zone.last-child {
        bottom: -@step-padding-tb;
    }

    .editor-step-list-drop-zone.is-drop-allowed {
        &.before-item {
            box-shadow: inset 0 3px 0 @brand-color;
        }

        &.after-item, &.first-child {
            box-shadow: inset 0 -3px 0 @brand-color;
        }
        &.last-child {
            background: @brand-color;
        }
    }

    // special handling for drag target at end of stage
    .editor-steps > .editor-step-list-drop-zone.last-child {
        position: static;
        border: 1px solid @hr-color;
        border-top-width: 0;
        background: #fff;
        display: none;
    }

    .is-performing-drag .editor-steps > .editor-step-list-drop-zone.last-child {
        display: block;

        &.is-drop-allowed {
            background: @brand-color;
        }
    }

    .editor-step-content.is-dragging {
        background-color: transparent;
        box-shadow: inset 0 0 5px @grab-color;

        // if container is being dragged, hide any of its nested steps / drop zones
        & ~ .editor-step.nested {
            display: none;
        }
        & ~ .editor-step-list-drop-zone {
            display:none;
        }
    }


    //--[ Step Select Dialog ]----------------------------------------------------------------------------------------------------

    .editor-step-selector {
        width: 296px;

        > div {
            border: 1px solid #cdcdcd;
            border-top: 0;
            background: #fff;
            padding: 10px 16px;
            font-size: 16px;
            cursor: pointer;

            &:first-child {
                border-top: 1px solid #cdcdcd;
            }

            &:hover, &:active, &:focus {
                background: @light-blue-bg;
            }
        }
    }

    .editor-step-search {
        position: relative;
        margin: -32px 0 4px 0;

        > svg {
            position: absolute;
            top: 50%;
            left: 3px;
            margin-top: -5px;
            fill: #dddddd;
        }
        > input {
            width: 100%;
            padding: 22px 13px 8px 31px;
            position: relative;
            display: block;
            background: transparent;
            border: 0;
            font-size: 1.2em;

            .placeholder({
                color: #888;
                font-style: italic;
            });
            &:focus {
                border-color: #4a90e2;
                border-radius: 0px;
                outline: none;
                margin: 0;
            }
        }
    }

    .placeholder(@rules) {
        &::-webkit-input-placeholder {
            @rules();
        }

        &:-moz-placeholder { /* Firefox 18- */
            @rules();
        }

        &::-moz-placeholder {  /* Firefox 19+ */
            @rules();
        }

        &:-ms-input-placeholder {
            @rules();
        }
    }

    .pipeline-editor-form {
        .form-item {
            .form-label {
                display: block;
                font-size: 1.1em;
                margin: 1em 0 .3em 0;
            }
            .form-input {
                display: block;
            }
        }
    }

    .editor-pipeline-dialog {
        width: 690px;
    }

    .load-save-usage-blurb {
        padding: 16px;
        margin: 0 0 30px 0;
        background: @light-blue-bg;

        > div {
            margin-top: 12px;
            text-align: right;
        }
    }

    .pipeline-editor-form > div {
        margin-top: .75em;
    }

    .split {
        display: table-row;
        .split-child {
            display: table-cell;
            width: 50%;
        }
    }

    .pipeline-validation-errors .error-list {
        display: block;
        margin: -1em 0 1.2em 0;
        color: @error-highlight;
        background: #fff4f4;
        padding: 16px;
        border-radius: 3px;
        border: 1px solid lighten(@error-highlight, 25%);
        margin-top: 10px;
        list-style: none;

        > li + li {
            margin-top: 4px;
        }
    }

    .editor-config-panel h5 {
        margin: .2em 0 .8em 0;
        border-bottom: 1px solid rgba(204, 215, 227, 0.5);
        padding: .3em 0;
    }

    .environment-entry {
        .split-child + .split-child {
            padding-left: 10px;
        }

        .FormElement {
            display: block;

            .FormElement-children {
                display: block;
            }
        }
    }

    .agent-parameters {
        margin: 0 -5px;

        .agent-param {
            padding: 0 5px;

            label > div:first-child {
                margin: 6px 0 0 1px;
            }

            .FormElement {
                margin-bottom: 0;
            }

            .TextInput {
                width: 100%;
            }

            .TextArea {
                min-height: 102px;
                height: auto;

                textarea {
                    min-height: 102px;
                    resize: none;
                    overflow-y:hidden;
                }
            }
        }
    }

    .environment-add-delete-icon {
        cursor: pointer;
        vertical-align: middle;
        background: transparent;
        display: inline-block;
        border: 0;
        padding: 0;
        margin: 0;

        &:hover, &:focus {
            background: transparent;
            border: 0;
            box-shadow: none;
        }

        &.add {
            circle {
                fill: #a5c8f1;
            }

            .result-status-glyph polygon {
                fill: #fff;
            }
        }

        &.delete circle {
            fill: #e8818d;
        }

        // FIXME hover/focus styles beyond just color
        &:hover, &:focus {
            &.add circle {
                fill: darken(#a5c8f1, 20%); //#4a90e2;
            }
            &.delete circle {
                fill: darken(#e8818d, 20%); //#d65766
            }
        }
    }

    .environment-entry {
        margin-top: 8px;
    }

    .FormElement.u-error-state > .FormElement-children > .TextInput {
        position: relative;
    }

    .FormElement.u-error-state > .FormElement-children > .TextInput:after,
    .FormElement.u-error-state > .FormElement-children > .PasswordInput:after {
        content: '!';
        position: absolute;
        right: 6px;
        top: 50%;
        margin-top: -9px;
        font-size: 16px;
        color: #fff;
        background: #d24146;
        border-radius: 100%;
        width: 18px;
        display: inline-block;
        height: 18px;
        text-align: center;
        vertical-align: middle;
        line-height: 17px;
        font-weight: bold;
    }

    .name-new-parallel.Dialog {
        .TextInput {
            display: block;
            width: 100%;
        }
    }

    // collapse-height-enter collapse-height-enter-active
    .collapse-height(@max-height: 300px) {
        overflow: hidden;
        &-enter {
            opacity: 0;
            max-height: 0;
            &-active {
                transition: all 250ms ease-in;
                opacity: 1;
                max-height: @max-height;
            }
        }
        &-leave {
            opacity: 1;
            max-height: @max-height;
            &-active {
                transition: all 400ms ease-in-out;
                opacity: 0;
                max-height: 0;
            }
        }
    }

    .collapse-height {
        .collapse-height() !important;
    }
}

.jenkins-blueocean-rundetails-top-widgets .pipeline-editor-link .svg-icon {
    fill: #fff;
}

.jenkins-pipeline-branches-list-action .pipeline-editor-link .svg-icon {
    fill: @action-button-color;

    &:hover {
        fill: @brand-color;
    }
}

.ResultPageHeader-run .pipeline-editor-link svg {
    fill: #ffffff;

    &:hover {
        fill: #ffffff;
    }
}

.pipeline-editor-link svg {
    fill: rgba(53, 64, 82, 0.25);

    &:hover {
        fill: #4a90e2;
    }
}

.pipeline-page {
    .editor-pipeline-dialog {
        min-width: 80%;
        max-width: 50em;
    }

    .editor-text-area {
        min-width: 20em;
        textarea {
            font: 13px monospace;
        }
    }
}

.dialog-token {
    width: 480px;

    .Dialog-content-margin {
        margin: 32px 40px;
    }

    .Dialog-button-bar {
        display: none;
    }

    &.loading {
        display: none;
    }

    .credentials-picker-github, .credentials-picker-github-enterprise {
        > .FormElement .FormElement-children {
            flex-direction: column;

            .button-connect {
                margin: 1em 0 0 0;
            }
        }
    }
}
