.pipelines {
  .stage {
    max-width: 90px;
    width: 90px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-holder {
    width: 100%;

    @media (max-width: $screen-sm-max) {
      overflow: auto;
    }
  }

  .commit-title {
    margin: 0;
  }

  .table.ci-table {

    .label {
      margin-bottom: 3px;
    }

    .pipeline-id {
      color: $black;
    }

    .stage-cell {
      min-width: 130px; // Guarantees we show at least 4 stages in line
      width: 20%;
    }

    .pipelines-time-ago {
      text-align: right;
    }

    .pipeline-actions {
      padding-right: 0;
      min-width: 170px; //Guarantees buttons don't break in several lines.

      .btn-default {
        color: $gl-text-color-secondary;
      }

      .btn.btn-retry:hover,
      .btn.btn-retry:focus {
        border-color: $gray-darkest;
        background-color: $white-normal;
      }

      svg path {
        fill: $gl-text-color-secondary;
      }

      .dropdown-menu {
        max-height: 250px;
        overflow-y: auto;
      }

      .dropdown-toggle,
      .dropdown-menu {
        color: $gl-text-color-secondary;

        .fa {
          color: $gl-text-color-secondary;
          font-size: 14px;
        }
      }

      .btn-group {
        &.open {
          .btn-default {
            background-color: $white-normal;
            border-color: $border-white-normal;
          }
        }

        .btn {
          .icon-play {
            height: 13px;
            width: 12px;
          }
        }
      }

      .btn .text-center {
        display: inline;
      }

      .tooltip {
        white-space: nowrap;
      }
    }
  }
}

@media (max-width: $screen-md-max) {
  .content-list {
    &.builds-content-list {
      width: 100%;
      overflow: auto;
    }
  }
}

.table.ci-table {

  &.builds-page tbody tr {
    height: 71px;
  }

  tr {
    th {
      padding: 16px 8px;
      border: none;
    }

    td {
      padding: 10px 8px;
    }

    td.environments-actions {
      padding-right: 0;
    }

    td.stage-cell {
      padding: 10px 0;
    }

    .commit-link {
      padding: 9px 8px 10px 2px;
    }
  }

  tbody {
    border-top-width: 1px;
  }

  .build.retried {
    background-color: $gray-lightest;
  }

  .commit-link {
    a {
      &:focus {
        text-decoration: none;
      }
    }

    a:hover {
      text-decoration: none;
    }
  }

  .avatar {
    margin-left: 0;
    float: none;
  }

  .api {
    @extend .monospace;
  }

  .branch-commit {

    .ref-name {
      font-weight: bold;
      max-width: 120px;
      overflow: hidden;
      display: inline-block;
      white-space: nowrap;
      vertical-align: middle;
      text-overflow: ellipsis;
    }

    svg {
      height: 14px;
      width: 14px;
      vertical-align: middle;
      fill: $gl-text-color-secondary;
    }

    .fa {
      font-size: 12px;
      color: $gl-text-color;
    }

    .commit-sha {
      color: $gl-link-color;
    }

    .commit-title {
      max-width: 225px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .label {
      margin-right: 4px;
    }

    .label-container {
      font-size: 0;

      .label {
        margin-top: 5px;
      }
    }
  }

  .icon-container {
    display: inline-block;
    width: 10px;

    &.commit-icon {
      width: 15px;
      text-align: center;
    }
  }

  .duration,
  .finished-at {
    color: $gl-text-color-secondary;
    margin: 0;
    white-space: nowrap;

    .fa {
      font-size: 12px;
      margin-right: 4px;
    }

    svg {
      width: 12px;
      height: 12px;
      vertical-align: middle;
      margin-right: 4px;
    }
  }

  .build-link a {
    color: $gl-text-color;
  }

  .btn-group.open .dropdown-toggle {
    box-shadow: none;
  }
}

.stage-cell {
  font-size: 0;
  padding: 0 4px;

  > .stage-container > div > button > span > svg,
  > .stage-container > button > svg {
    height: 22px;
    width: 22px;
    position: absolute;
    top: -1px;
    left: -1px;
    z-index: 2;
    overflow: visible;
  }

  .stage-container {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    height: 22px;
    margin: 3px 6px 3px 0;

    // Hack to show a button tooltip inline
    button.has-tooltip + .tooltip {
      min-width: 105px;
    }

    // Bootstrap way of showing the content inline for anchors.
    a.has-tooltip {
      white-space: nowrap;
    }

    &:not(:last-child) {
      &::after {
        content: '';
        width: 7px;
        position: absolute;
        right: -7px;
        top: 10px;
        border-bottom: 2px solid $border-color;
      }
    }
  }
}

.admin-builds-table {
  .ci-table td:last-child {
    min-width: 120px;
  }
}

// Pipeline visualization
.pipeline-actions {
  border-bottom: none;
}

.tab-pane {
  &.builds .ci-table tr {
    height: 71px;
  }
}

.build-failures {
  .build-state {
    padding: 20px 2px;

    .build-name {
      float: right;
      font-weight: 500;
    }

    .ci-status-icon-failed svg {
      vertical-align: middle;
    }

    .stage {
      color: $gl-text-color-secondary;
      font-weight: 500;
      vertical-align: middle;
    }
  }

  .build-log {
    border: none;
    line-height: initial;
  }
}

// Pipeline graph
.pipeline-graph {
  width: 100%;
  background-color: $gray-light;
  padding: $gl-padding;
  white-space: nowrap;
  transition: max-height 0.3s, padding 0.3s;
  overflow: auto;

  .stage-column-list,
  .builds-container > ul {
    padding: 0;
  }

  a {
    text-decoration: none;
    color: $gl-text-color-secondary;
  }

  svg {
    vertical-align: middle;
    margin-right: 3px;
  }

  .stage-column {
    display: inline-block;
    vertical-align: top;

    &:not(:last-child) {
      margin-right: 44px;
    }

    &.left-margin {
      &:not(:first-child) {
        margin-left: 44px;

        .left-connector {
          &::before {
            content: '';
            position: absolute;
            top: 48%;
            left: -44px;
            border-top: 2px solid $border-color;
            width: 44px;
            height: 1px;
          }
        }
      }
    }

    &.no-margin {
      margin: 0;
    }

    li {
      list-style: none;
    }

    &:last-child {
      .build {
        // Remove right connecting horizontal line from first build in last stage
        &:first-child {
          &::after {
            border: none;
          }
        }
        // Remove right curved connectors from all builds in last stage
        &:not(:first-child) {
          &::after {
            border: none;
          }
        }
        // Remove opposite curve
        .curve {
          &::before {
            display: none;
          }
        }
      }
    }

    &:first-child {
      .build {
        // Remove left curved connectors from all builds in first stage
        &:not(:first-child) {
          &::before {
            border: none;
          }
        }
        // Remove opposite curve
        .curve {
          &::after {
            display: none;
          }
        }
      }
    }

    // Curve first child connecting lines in opposite direction
    .curve {
      display: none;

      &::before,
      &::after {
        content: '';
        width: 21px;
        height: 25px;
        position: absolute;
        top: -31px;
        border-top: 2px solid $border-color;
      }

      &::after {
        left: -44px;
        border-right: 2px solid $border-color;
        border-radius: 0 20px;
      }

      &::before {
        right: -44px;
        border-left: 2px solid $border-color;
        border-radius: 20px 0 0;
      }
    }
  }

  .stage-name {
    margin: 0 0 15px 10px;
    font-weight: bold;
    width: 176px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .build {
    position: relative;
    width: 186px;
    margin-bottom: 10px;
    white-space: normal;
    color: $gl-text-color-secondary;

    // Action Icons in big pipeline-graph nodes
    .ci-action-icon-container .ci-action-icon-wrapper {
      height: 30px;
      width: 30px;
      background: $white-light;
      border: 1px solid $border-color;
      border-radius: 100%;
      display: block;

      &:hover {
        background-color: $stage-hover-bg;
        border: 1px solid $stage-hover-bg;
      }

      svg {
        fill: $border-color;
        position: relative;
        left: -1px;
        top: -1px;
      }

      &:hover svg {
        fill: $gl-text-color;
      }
    }

    .ci-action-icon-container {
      position: absolute;
      right: 5px;
      top: 5px;
    }

    .ci-status-icon svg {
      height: 20px;
      width: 20px;
    }

    .dropdown-menu-toggle {
      background-color: transparent;
      border: none;
      padding: 0;
      color: $gl-text-color-secondary;

      &:focus {
        outline: none;
      }

      &:hover {
        color: $gl-text-color;

        .dropdown-counter-badge {
          color: $gl-text-color;
        }
      }
    }

    .build-content {
      display: inline-block;
      padding: 8px 10px 9px;
      width: 100%;
      border: 1px solid $border-color;
      border-radius: 30px;
      background-color: $white-light;

      &:hover {
        background-color: $stage-hover-bg;
        border: 1px solid $stage-hover-border;
        color: $gl-text-color;
      }
    }


    // Connect first build in each stage with right horizontal line
    &:first-child {
      &::after {
        content: '';
        position: absolute;
        top: 48%;
        right: -48px;
        border-top: 2px solid $border-color;
        width: 48px;
        height: 1px;
      }
    }

    // Connect each build (except for first) with curved lines
    &:not(:first-child) {
      &::after,
      &::before {
        content: '';
        top: -49px;
        position: absolute;
        border-bottom: 2px solid $border-color;
        width: 25px;
        height: 69px;
      }

      // Right connecting curves
      &::after {
        right: -25px;
        border-right: 2px solid $border-color;
        border-radius: 0 0 20px;
      }

      // Left connecting curves
      &::before {
        left: -25px;
        border-left: 2px solid $border-color;
        border-radius: 0 0 0 20px;
      }
    }

    // Connect second build to first build with smaller curved line
    &:nth-child(2) {
      &::after,
      &::before {
        height: 29px;
        top: -9px;
      }

      .curve {
        display: block;
      }
    }
  }
}

// Triggers the dropdown in the big pipeline graph
.dropdown-counter-badge {
  color: $border-color;
  font-weight: 100;
  font-size: 15px;
  position: absolute;
  right: 13px;
  top: 8px;
}

.ci-status-text {
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  display: inline-block;
  position: relative;
  font-weight: normal;
}

// Dropdown button in mini pipeline graph
.mini-pipeline-graph-dropdown-toggle {
  border-radius: 100px;
  background-color: $white-light;
  border-width: 1px;
  border-style: solid;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  transition: all 0.2s linear;
  position: relative;

  > .fa.fa-caret-down {
    position: absolute;
    left: 20px;
    top: 5px;
    display: inline-block;
    visibility: hidden;
    opacity: 0;
    color: inherit;
    font-size: 12px;
    transition: visibility 0.1s, opacity 0.1s linear;
  }

  &:active,
  &:focus,
  &:hover {
    outline: none;
    width: 35px;

    .fa.fa-caret-down {
      visibility: visible;
      opacity: 1;
    }
  }

  // Dropdown button animation in mini pipeline graph
  &.ci-status-icon-success {
    border-color: $green-500;
    color: $green-500;

    &:hover,
    &:focus,
    &:active {
      background-color: $green-50;
      border-color: $green-600;
      color: $green-600;

      svg {
        fill: $green-600;
      }
    }
  }

  &.ci-status-icon-failed {
    border-color: $red-500;
    color: $red-500;

    &:hover,
    &:focus,
    &:active {
      background-color: $red-50;
      border-color: $red-600;
      color: $red-600;

      svg {
        fill: $red-600;
      }
    }
  }

  &.ci-status-icon-pending,
  &.ci-status-icon-success_with_warnings {
    border-color: $orange-500;
    color: $orange-500;

    &:hover,
    &:focus,
    &:active {
      background-color: $orange-50;
      border-color: $orange-600;
      color: $orange-600;

      svg {
        fill: $orange-600;
      }
    }
  }

  &.ci-status-icon-running {
    border-color: $blue-400;
    color: $blue-400;

    &:hover,
    &:focus,
    &:active {
      background-color: $blue-50;
      border-color: $blue-600;
      color: $blue-600;

      svg {
        fill: $blue-600;
      }
    }
  }

  &.ci-status-icon-canceled,
  &.ci-status-icon-disabled,
  &.ci-status-icon-not-found,
  &.ci-status-icon-manual {
    border-color: $gl-text-color;
    color: $gl-text-color;

    &:hover,
    &:focus,
    &:active {
      background-color: rgba($gl-text-color, 0.1);
      border-color: $gl-text-color;
    }
  }

  &.ci-status-icon-created,
  &.ci-status-icon-skipped {
    border-color: $gray-darkest;
    color: $gray-darkest;

    &:hover,
    &:focus,
    &:active {
      background-color: rgba($gray-darkest, 0.1);
      border-color: $gray-darkest;
    }
  }
}

// dropdown content for big and mini pipeline
.big-pipeline-graph-dropdown-menu,
.mini-pipeline-graph-dropdown-menu {
  width: 195px;
  max-width: 195px;

  li {
    padding: 2px 3px;
  }

  .scrollable-menu {
    padding: 0;
    max-height: 245px;
    overflow: auto;
  }

  // Action icon on the right
  a.ci-action-icon-wrapper {
    color: $action-icon-color;
    border: 1px solid $action-icon-color;
    border-radius: 20px;
    width: 22px;
    height: 22px;
    padding: 2px 0 0 5px;
    cursor: pointer;
    float: right;
    margin: -26px 9px 0 0;
    font-size: 12px;
    background-color: $white-light;

    &:hover,
    &:focus {
      background-color: $stage-hover-bg;
      border: 1px solid transparent;
    }

    svg {
      width: 22px;
      height: 22px;
      left: -6px;
      position: relative;
      top: -3px;
      fill: $action-icon-color;
    }

    &:hover svg,
    &:focus svg {
      fill: $gl-text-color;
    }
  }

  // link to the build
  .mini-pipeline-graph-dropdown-item {
    padding: 3px 7px 4px;
    clear: both;
    font-weight: normal;
    line-height: 1.428571429;
    white-space: nowrap;
    margin: 0 5px;
    border-radius: 3px;

    // build name
    .ci-build-text,
    .ci-status-text {
      font-weight: 200;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      max-width: 70%;
      color: $gl-text-color-secondary;
      margin-left: 2px;
      display: inline-block;
      top: 1px;
      vertical-align: text-bottom;
      position: relative;
    }

    // status icon on the left
    .ci-status-icon {
      top: 3px;
      position: relative;

      > svg {
        overflow: visible;
        width: 18px;
        height: 18px;
      }
    }

    &:hover,
    &:focus {
      outline: none;
      text-decoration: none;
      color: $gl-text-color;
      background-color: $stage-hover-bg;
    }
  }
}

// Dropdown in the big pipeline graph
.big-pipeline-graph-dropdown-menu {
  width: 195px;
  min-width: 195px;
  left: auto;
  right: -195px;
  top: -4px;
  box-shadow: 0 1px 5px $black-transparent;

  .mini-pipeline-graph-dropdown-item {
    .ci-status-icon {
      top: -1px;
    }
  }
}

/**
 * Top arrow in the dropdown in the big pipeline graph
 */
.big-pipeline-graph-dropdown-menu {

  &::before,
  &::after {
    content: '';
    display: inline-block;
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    top: 18px;
  }

  &::before {
    left: -5px;
    margin-top: -6px;
    border-width: 7px 5px 7px 0;
    border-right-color: $border-color;
  }

  &::after {
    left: -4px;
    margin-top: -9px;
    border-width: 10px 7px 10px 0;
    border-right-color: $white-light;
  }
}

/**
 * Top arrow in the dropdown in the mini pipeline graph
 */
.mini-pipeline-graph-dropdown-menu {

  &::before,
  &::after {
    content: '';
    display: inline-block;
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    top: -6px;
    left: 2px;
    border-width: 0 5px 6px;
  }

  &::before {
    border-width: 0 5px 5px;
    border-bottom-color: $border-color;
  }

  &::after {
    margin-top: 1px;
    border-bottom-color: $white-light;
  }
}

/**
 * Terminal
 */
.terminal-icon {
  margin-left: 3px;
}

.terminal-container {
  .content-block {
    border-bottom: none;
  }

  #terminal {
    margin-top: 10px;
    min-height: 450px;
    box-sizing: border-box;

    > div {
      min-height: 450px;
    }
  }
}

/**
 * Play button with icon in dropdowns
 */
.ci-table .no-btn {
  border: none;
  background: none;
  outline: none;
  width: 100%;
  text-align: left;

  .icon-play {
    position: relative;
    top: 2px;
    margin-right: 5px;
    height: 13px;
    width: 12px;
  }
}

.pipeline-header-container {
  min-height: 55px;

  .text-center {
    padding-top: 12px;
  }

  .header-action-button .btn {
    margin-left: 5px;
  }
}
