$system-note-icon-size: 32px;
$system-note-svg-size: 16px;
$note-form-margin-left: 72px;

@mixin vertical-line($left) {
  &::before {
    content: '';
    border-left: 2px solid $gray-100;
    position: absolute;
    top: 0;
    bottom: 0;
    left: $left;
  }
}

@mixin outline-comment() {
  margin: $gl-padding $gl-padding 0;
  border: 1px solid $border-color;
  border-radius: $border-radius-default;
}

.note-wrapper {
  padding: $gl-padding;

  &.outlined {
    @include outline-comment();
  }
}

.issuable-discussion {
  .main-notes-list {
    @include vertical-line(36px);
  }
}

.notes {
  display: block;
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;

  &.timeline > .timeline-entry {
    border: 1px solid $border-color;
    border-radius: $border-radius-default;
    margin: $gl-padding 0;

    &.system-note,
    &.note-form {
      border: 0;
    }

    &.note-form {
      margin-left: 0;

      @include notes-media('min', map-get($grid-breakpoints, md)) {
        margin-left: $note-form-margin-left;
      }

      .timeline-icon {
        @include notes-media('min', map-get($grid-breakpoints, sm)) {
          margin-left: -$note-icon-gutter-width;
        }
      }

      .timeline-content {
        margin-left: 0;
      }
    }

    .notes_content {
      border: 0;
      border-top: 1px solid $border-color;
    }
  }

  > .note-discussion {
    .card {
      border: 0;
    }
  }

  li.note {
    border-bottom: 1px solid $border-color;
  }

  .replies-toggle {
    background-color: $gray-light;
    padding: $gl-padding-8 $gl-padding;

    .collapse-replies-btn:hover {
      color: $blue-600;
    }

    &.expanded {
      border-bottom: 1px solid $border-color;

      span {
        cursor: pointer;
      }

      svg {
        position: relative;
        top: 3px;
      }
    }

    &.collapsed {
      color: $gl-text-color-secondary;

      svg {
        float: left;
        position: relative;
        top: $gl-padding-4;
        margin-right: $gl-padding-8;
        cursor: pointer;
      }

      img {
        margin: -2px 4px 0 0;
      }

      .author-link {
        color: $gl-text-color;
      }
    }

    .user-avatar-link {
      &:last-child img {
        margin-right: $gl-padding-8;
      }
    }

    .btn-link {
      border: 0;
      vertical-align: baseline;
    }
  }

  .note-created-ago,
  .note-updated-at {
    white-space: normal;
  }

  .discussion-body {
    .card {
      margin-bottom: 0;
    }
  }

  .discussion {
    display: block;
    position: relative;

    .timeline-discussion-body {
      margin-top: -$gl-padding-8;
      overflow-x: auto;
      overflow-y: hidden;

      .note-body {
        margin-top: $gl-padding-8;
      }
    }

    .diff-content {
      overflow: visible;
      padding: 0;
    }
  }

  > li {
    display: block;
    position: relative;
    border-bottom: 0;

    &.being-posted {
      pointer-events: none;
      opacity: 0.5;
      padding: $gl-padding;

      .dummy-avatar {
        background-color: $gl-gray-200;
        border: 1px solid darken($gl-gray-200, 25%);
      }

      .note-headline-light,
      .fa-spinner {
        margin-left: 3px;
      }
    }

    .editing-spinner {
      display: none;
    }

    &.is-requesting {
      .note-timestamp {
        display: none;
      }

      .editing-spinner {
        display: inline-block;
      }
    }

    &.is-editing {
      .note-header,
      .note-text,
      .edited-text {
        display: none;
      }

      .note-edit-form {
        display: block;

        &.current-note-edit-form + .note-awards {
          display: none;
        }
      }
    }

    .note-body {
      overflow-x: auto;
      overflow-y: hidden;

      .note-text {
        word-wrap: break-word;
      }
    }

    .note-awards {
      .js-awards-block {
        margin-top: 16px;
      }
    }

    .note-header {
      @include notes-media('max', map-get($grid-breakpoints, xs)) {
        .inline {
          display: block;
        }
      }
    }

    .note-emoji-button {
      position: relative;
      line-height: 1;

      .fa-spinner {
        display: none;
      }

      &.is-loading {
        .fa-smile-o {
          display: none;
        }

        .fa-spinner {
          display: inline-block;
        }
      }
    }
  }

  .system-note {
    padding: 6px 21px;
    margin: $gl-padding-24 0;
    background-color: transparent;

    .note-header-info {
      padding-bottom: 0;
    }

    &.timeline-entry::after {
      clear: none;
    }

    .system-note-message {
      &::first-letter {
        text-transform: lowercase;
      }

      a {
        color: $blue-600;
      }

      p {
        display: inline;
        margin: 0;

        &::first-letter {
          text-transform: lowercase;
        }
      }
    }

    .timeline-content {
      @include notes-media('min', map-get($grid-breakpoints, sm)) {
        margin-left: 30px;
      }
    }

    .note-header {
      padding-bottom: 0;
    }

    .note-body {
      overflow: hidden;

      .system-note-commit-list-toggler {
        color: $blue-600;
        padding: 10px 0 0;
        cursor: pointer;
        position: relative;
        z-index: 2;

        &:hover {
          color: $blue-600;
          text-decoration: underline;
        }
      }

      .note-text {
        p:first-child {
          display: none;
        }

        &.system-note-commit-list:not(.hide-shade) {
          max-height: 70px;
          overflow: hidden;
          display: block;

          ul {
            margin: 3px 0 3px 16px !important;
          }

          p:first-child {
            display: none;
          }

          &::after {
            content: '';
            height: 70px;
            position: absolute;
            left: $gl-padding-24;
            right: 0;
            bottom: 0;
            background: linear-gradient(rgba($white-light, 0.1) -100px, $white-light 100%);
          }
        }
      }
    }
  }

  .system-note,
  .discussion-filter-note {
    .timeline-icon {
      float: left;
      display: flex;
      align-items: center;
      background-color: $white-light;
      width: $system-note-icon-size;
      height: $system-note-icon-size;
      border: 1px solid $border-color;
      border-radius: $system-note-icon-size;
      margin: -6px $gl-padding 0 0;

      svg {
        width: $system-note-svg-size;
        height: $system-note-svg-size;
        fill: $gray-darkest;
        display: block;
        margin: 0 auto;
      }
    }
  }

  .discussion-filter-note {
    .timeline-icon {
      width: $system-note-icon-size + 6;
      height: $system-note-icon-size + 6;
      margin-top: -8px;
    }
  }
}

// Diff code in discussion view
.discussion-body .diff-file {
  .file-title {
    cursor: default;
    line-height: 42px;
    padding: 0 $gl-padding;
    border-top: 1px solid $border-color;
    border-radius: 0;

    @media (min-width: map-get($grid-breakpoints, md)) {
      top: 91px;

      .with-performance-bar & {
        top: 126px;
      }
    }

    &:hover {
      background-color: $gray-light;
    }

    .btn-clipboard {
      top: 10px;
    }
  }

  .line_content {
    white-space: pre-wrap;
  }
}

.tab-pane.notes {
  .diff-file .notes .system-note {
    margin: 0;
  }
}

.tab-pane.diffs {
  .system-note {
    padding: 0 $gl-padding;
    margin-left: 20px;
  }

  .notes > .note-discussion li.note.system-note {
    border-bottom: 0;
    padding: 0 $gl-padding;
  }
}

.diff-file {
  .is-over {
    .add-diff-note {
      display: inline-block;
    }
  }

  .discussion-notes {
    &:not(:last-child) {
      margin-bottom: 0;
    }

    .system-note {
      background-color: $white-light;
      padding: $gl-padding;
    }
  }

  // Merge request notes in diffs
  // Diff is inline
  .notes_content .note-header .note-headline-light {
    display: inline-block;
    position: relative;
  }

  .notes_holder {
    font-family: $regular-font;

    td {
      border: 1px solid $border-color;
      border-left: 0;

      &.notes_content {
        border-width: 1px 0;
        padding: 0;
        vertical-align: top;
        white-space: normal;

        &.parallel {
          border-width: 1px;

          &.new {
            border-right-width: 0;
          }
        }

        .notes {
          background-color: $white-light;
        }

        a code {
          top: 0;
          margin-right: 0;
        }
      }
    }
  }
}

.diffs {
  .discussion-notes {
    margin-left: 0;
    border-left: 0;
  }

  .note-wrapper {
    &.system-note {
      border: 0;
      margin-left: 20px;
    }
  }

  .discussion-reply-holder {
    border-radius: 0 0 $border-radius-default $border-radius-default;
    position: relative;
  }
}

.commit-diff {
  .notes_content {
    background-color: $white-light;
  }
}

.discussion-header,
.note-header-info {
  a {
    color: inherit;

    &:hover {
      color: $blue-600;
    }

    &:focus,
    &:hover {
      text-decoration: none;

      .note-header-author-name {
        text-decoration: underline;
      }
    }
  }

  .author-link {
    color: $gl-text-color;
  }
}

.discussion-header {
  min-height: 72px;

  .note-header-info {
    padding-bottom: 0;
  }

  .timeline-content {
    overflow-x: auto;
    overflow-y: hidden;
  }
}

.unresolved {
  .note-header-info {
    margin-top: $gl-padding-8;
  }
}

.note-header {
  display: flex;
  justify-content: space-between;
}

.note-header-info {
  min-width: 0;
  padding-bottom: $gl-padding-8;

  &.discussion {
    padding-bottom: 0;
  }
}

.system-note .note-header-info {
  padding-bottom: 0;
}

.note-headline-light {
  display: inline;

  @include notes-media('max', map-get($grid-breakpoints, xs)) {
    display: block;
  }
}

.note-headline-light,
.discussion-headline-light {
  color: $gl-text-color-secondary;
}

.discussion-headline-light {
  a {
    color: $blue-600;
  }
}

.note-headline-meta {
  .system-note-separator {
    color: $gl-text-color-disabled;
  }

  .note-timestamp {
    white-space: nowrap;
  }

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

/**
 * Actions for Discussions/Notes
 */

.discussion-actions {
  float: right;
  color: $gray-darkest;

  @include media-breakpoint-down(xs) {
    width: 100%;
    margin: $gl-padding-8 0;
  }

  .btn-group > .discussion-next-btn {
    margin-left: -1px;
  }

  svg {
    height: 15px;
  }
}

.note-actions {
  align-self: flex-start;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
  color: $gray-darkest;

  @include notes-media('max', map-get($grid-breakpoints, sm) - 1) {
    float: none;
    margin-left: 0;
  }
}

.more-actions {
  display: flex;
  align-items: flex-end;

  .tooltip {
    white-space: nowrap;
  }
}

.more-actions-toggle {
  &:hover .icon,
  &:focus .icon {
    color: $blue-600;
  }
}

.more-actions-dropdown {
  width: 180px;
  min-width: 180px;
}

.note-actions-item {
  margin-left: 12px;
  display: flex;
  align-items: center;

  &.more-actions {
    // compensate for narrow icon
    margin-left: 10px;
  }
}

.note-action-button {
  @include emoji-menu-toggle-button;
}

.discussion-toggle-button {
  padding: 0;
  background-color: transparent;
  border: 0;
  line-height: 20px;
  font-size: 13px;
  transition: color 0.1s linear;

  &:hover {
    color: $blue-600;
  }

  &:focus {
    text-decoration: underline;
    outline: none;
    color: $blue-600;
  }

  .fa {
    margin-right: 3px;
    font-size: 10px;
    line-height: 18px;
    vertical-align: top;
  }
}

.note-role {
  margin: 0 3px;
}

.note-role-special {
  position: relative;
  display: inline-block;
  color: $gl-text-color-secondary;
  font-size: 12px;
  text-shadow: 0 0 15px $gl-text-color-inverted;
}

/**
 * Line note button on the side of diffs
 */

.line_holder .is-over:not(.no-comment-btn) {
  .add-diff-note {
    opacity: 1;
    z-index: 101;
  }
}

.add-diff-note {
  @include btn-comment-icon;
  opacity: 0;
  margin-left: -50px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
}

.disabled-comment {
  background-color: $gray-light;
  border-radius: $border-radius-base;
  border: 1px solid $border-gray-normal;
  color: $note-disabled-comment-color;
  padding: 90px 0;

  &.discussion-locked {
    border: 0;
    background-color: $white-light;
  }

  a {
    color: $blue-600;
  }
}

.line-resolve-all-container {
  @include notes-media('min', map-get($grid-breakpoints, sm)) {
    margin-right: 0;
  }

  > div {
    white-space: nowrap;
  }

  .btn-group {
    margin-left: -4px;
  }

  .discussion-next-btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  .btn {
    svg {
      fill: $gray-darkest;
    }

    &.discussion-create-issue-btn {
      margin-left: -4px;
      border-radius: 0;
      border-right: 0;

      a {
        padding: 0;
        line-height: 0;

        &:hover {
          text-decoration: none;
          border: 0;
        }
      }
    }
  }
}

.line-resolve-all {
  vertical-align: middle;
  display: inline-block;
  padding: 6px 10px;
  background-color: $gray-light;
  border: 1px solid $border-color;
  border-radius: $border-radius-default;

  &.has-next-btn {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
  }

  .line-resolve-btn {
    margin-right: 5px;

    svg {
      vertical-align: middle;
    }
  }
}

.line-resolve-btn {
  position: relative;
  top: 0;
  padding: 0;
  background-color: transparent;
  border: 0;
  outline: 0;
  color: $gray-darkest;
  transition: color $general-hover-transition-duration $general-hover-transition-curve;

  &.is-disabled {
    cursor: default;
  }

  &:not(.is-disabled) {
    &:hover,
    &:focus {
      color: $green-600;
    }
  }

  &.is-active {
    color: $green-600;

    &:hover,
    &:focus {
      color: $green-700;
    }
  }

  .loading {
    margin: 0;
    height: auto;
  }
}

// Vue refactored diff discussion adjustments
.files {
  .diff-discussions {
    .note-discussion.timeline-entry {
      padding-left: 0;

      &:last-child {
        border-bottom: 0;
      }

      > .timeline-entry-inner {
        padding: 0;

        > .timeline-content {
          margin-left: 0;
        }

        > .timeline-icon {
          display: none;
        }
      }

      .discussion-body {
        padding-top: 0;

        .discussion-wrapper {
          border: 0;
        }
      }
    }
  }

  .diff-comment-form {
    display: block;
  }

  .add-diff-note svg {
    margin-top: 4px;
  }
}

.discussion-filter-container {
  .btn > svg {
    width: $gl-col-padding;
    height: $gl-col-padding;
  }

  .dropdown-menu {
    margin-bottom: $gl-padding-4;

    @include media-breakpoint-down(md) {
      margin-left: $btn-side-margin + $contextual-sidebar-collapsed-width;
    }

    @include media-breakpoint-down(xs) {
      margin-left: $btn-side-margin;
    }
  }
}

//This needs to be deleted when Snippet/Commit comments are convered to Vue
// See https://gitlab.com/gitlab-org/gitlab-ce/issues/53918#note_117038785
.unstyled-comments {
  .discussion-header {
    padding: $gl-padding;
    border-bottom: 1px solid $border-color;
  }

  .discussion-form-container {
    padding: $gl-padding;
  }
}
