@use 'sass:color';

$rp-type-blue: #6b7797;
$rp-highlight-blue: #8a96b5;
$rp-bg-blue: #dadfed;
$rp-yellow: #f3b111;
$rp-entry-arrow-width: 6px;

:root {
  --rp-base-font-size: var(--font-size-01);
  --rp-small-font-size: 0.625rem; // 10px
  --rp-icon-large-size: var(--font-size-04);
  --rp-bg-dim-blue: #fafafa;
  --rp-border-grey: #d9d9d9;
  --rp-green: #2c8e30;
  --rp-red: #c5060b;
  --rp-type-darkgrey: #3f3f3f;
  --rp-entry-ribbon-width: 4px;
  --rp-entry-arrow-width: 6px;
  --rp-semibold-weight: 600;
  --review-panel-width: 230px;
  --review-off-width: 22px;
  --rp-entry-animation-speed: 0.3s;
}

%rp-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: $rp-highlight-blue;
  color: var(--white);
  text-align: center;
  line-height: 1.3;
  user-select: none;
  border: 0;

  &:hover,
  &:focus {
    outline: 0;
    background-color: color.adjust($rp-highlight-blue, $lightness: -5%);
    text-decoration: none;
    color: var(--white);
  }

  &[disabled] {
    background-color: color.mix($rp-highlight-blue, $white, 50%);

    &:hover,
    &:focus {
      background-color: color.mix($rp-highlight-blue, $white, 50%);
    }
  }
}

.review-panel-toolbar {
  display: none;

  .rp-size-expanded & {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-03);
  }

  position: relative;
  border-bottom: 1px solid var(--rp-border-grey);
  background-color: var(--rp-bg-dim-blue);
  text-align: center;
  z-index: 3;
  flex-basis: 32px;
  flex-shrink: 0;
}

.review-panel-toolbar-label {
  cursor: pointer;
  text-align: right;
  flex-grow: 1;
}

.review-panel-toolbar-icon-on {
  margin-right: var(--spacing-03);
  color: var(--bg-accent-01);
}

.review-panel-toolbar-label-disabled {
  margin-right: var(--spacing-03);
  cursor: auto;
}

.rp-tc-state {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  overflow: hidden;
  list-style: none;
  padding: 0 var(--spacing-03);
  margin: 0;
  border-bottom: 1px solid var(--rp-border-grey);
  background-color: var(--rp-bg-dim-blue);
  text-align: left;
}

.rp-tc-state-collapse,
.rp-overview-file-header-collapse {
  display: inline-flex;
  transition: transform 0.15s ease;
  transform: rotateZ(0deg);

  &-on {
    transform: rotateZ(-90deg);
  }
}

.rp-tc-state-item {
  display: flex;
  align-items: center;
  padding: var(--spacing-02) 0;

  &:last-of-type {
    padding-bottom: var(--spacing-03);
  }
}

.rp-tc-state-separator {
  border-bottom: 1px solid var(--rp-border-grey);
}

.rp-tc-state-item-everyone {
  border-bottom: 1px solid var(--rp-border-grey);
}

.rp-tc-state-item-name {
  @extend .text-truncate;

  flex-grow: 1;
  font-weight: 600;
}

.rp-tc-state-item-name-disabled {
  opacity: 0.35;
}

.rp-entry-list {
  display: none;
  width: 100%;

  .rp-size-expanded &,
  .rp-size-mini & {
    display: block;
  }

  .rp-state-overview & {
    flex-grow: 2;
    overflow-y: auto;
  }
}

.rp-entry-indicator {
  display: none;
  z-index: 2; // above .review-panel-toggler

  .material-symbols {
    font-size: var(--font-size-02);
    vertical-align: sub;
  }

  .rp-size-mini & {
    display: block;
  }

  .rp-floating-entry & {
    display: block;
    position: static;
    width: calc(var(--review-off-width) - 4px);
  }

  .rp-size-mini &-add-comment {
    display: none;
  }

  position: absolute;
  left: 2px;
  right: 2px;
  text-align: center;
  background-color: $rp-highlight-blue;
  border-radius: var(--border-radius-base);
  color: var(--white);
  cursor: pointer;
  transition:
    top var(--rp-entry-animation-speed),
    left 0.1s,
    right 0.1s;

  .no-animate & {
    transition:
      left 0.1s,
      right 0.1s;
  }

  &-focused {
    left: 0;
    right: 4px;
    z-index: 1;
  }
}

.rp-entry-wrapper {
  &:hover .rp-entry-insert,
  &:hover .rp-entry-delete,
  &:hover .rp-entry-aggregate,
  &:hover .rp-entry-comment {
    display: block;
  }

  &.rp-entry-hidden {
    display: none;
  }
}

.rp-entry {
  .rp-state-current-file & {
    position: absolute;
    width: var(--review-panel-width);
  }

  .rp-state-current-file-mini &,
  .rp-floating-entry & {
    left: calc(var(--review-off-width) + var(--rp-entry-arrow-width));
    box-shadow: 0 0 10px 5px rgba(0 0 0 / 20%);
    z-index: 1;

    &::before {
      content: '';
      position: absolute;
      inset: calc((var(--review-off-width) + var(--rp-entry-arrow-width)) * -1)
        calc((var(--review-off-width) + var(--rp-entry-arrow-width)) * -1)
        calc((var(--review-off-width) + var(--rp-entry-arrow-width)) * -1)
        calc(-2 * var(--rp-entry-arrow-width) - 2px);
      z-index: -1;
    }

    &::after {
      @include triangle(
        left,
        $rp-entry-arrow-width,
        $rp-entry-arrow-width * 1.5,
        inherit
      );

      top: calc(var(--review-off-width) / 2 - var(--rp-entry-arrow-width));
      left: calc(
        (var(--rp-entry-ribbon-width) + var(--rp-entry-arrow-width)) * -1
      );
      content: '';
    }
  }

  .rp-state-current-file-mini & {
    display: none;
  }

  .rp-floating-entry & {
    position: absolute;
    width: var(--review-panel-width);
    left: calc(var(--review-off-width) + var(--rp-entry-arrow-width));
    top: 0;
  }

  .rp-state-current-file-mini.rp-layout-left &,
  .rp-floating-entry-layout-left & {
    border-left-width: 0;
    border-right-width: var(--rp-entry-ribbon-width);
    border-right-style: solid;

    &::before {
      left: calc((var(--review-off-width) + var(--rp-entry-arrow-width)) * -1);
    }

    &::after {
      @include triangle(
        right,
        $rp-entry-arrow-width,
        $rp-entry-arrow-width * 1.5,
        inherit
      );

      right: calc(
        (var(--rp-entry-ribbon-width) + var(--rp-entry-arrow-width)) * -1
      );
      left: auto;
    }
  }

  .rp-state-current-file-mini.rp-layout-left & {
    left: auto;
    right: calc(var(--review-off-width) + var(--rp-entry-arrow-width));

    &::before {
      right: calc(-2 * var(--rp-entry-arrow-width) - 2px);
    }
  }

  .rp-floating-entry-layout-left & {
    left: calc(
      (var(--review-panel-width) + var(--rp-entry-arrow-width) + 2px) * -1
    );

    &::before {
      right: calc(-2 * var(--rp-entry-arrow-width));
    }
  }

  .rp-state-current-file-expanded & {
    visibility: hidden;
    left: 5px;
    right: 5px;
    width: auto;

    &-focused {
      left: -2px;
      right: 12px;
      z-index: 1;
    }

    &-add-comment {
      right: auto;

      &.rp-entry-adding-comment {
        right: 5px;
      }
    }

    &-bulk-actions {
      right: auto;
    }
  }

  .rp-state-overview & {
    border-radius: 0;
    border-bottom: solid 1px var(--rp-border-grey);
    cursor: pointer;
  }

  .resolved-comments-dropdown & {
    position: static;
    margin-bottom: var(--spacing-03);
  }

  border-left: solid var(--rp-entry-ribbon-width) transparent;
  border-radius: var(--border-radius-base);
  background-color: var(--white);
  transition:
    top var(--rp-entry-animation-speed),
    left 0.1s,
    right 0.1s;

  .no-animate & {
    transition:
      left 0.1s,
      right 0.1s;
  }

  &-insert,
  &-aggregate {
    border-color: var(--rp-green);
  }

  &-delete {
    border-color: var(--rp-red);
  }

  &-comment {
    border-color: $rp-yellow;
  }

  &-comment-resolving {
    top: 4px;
    left: 6px;
    opacity: 0;
    z-index: 3;
    transform: scale(0.1);
    transform-origin: 0 0;
    transition:
      top 0.35s ease-out,
      left 0.35s ease-out,
      transform 0.35s ease-out,
      opacity 0.35s ease-out 0.2s;
  }

  &-comment-resolved {
    border-color: #aaa;
    background-color: #efefef;
  }

  &-add-comment {
    background-color: transparent;
    right: auto;
    border-left-width: 0;

    &.rp-entry-adding-comment {
      background-color: var(--white);
      right: 5px;
      border-left-width: 3px;
      border-left-color: $rp-yellow;
    }
  }

  &-bulk-actions {
    background-color: transparent;
    right: auto;
    border-left-width: 0;
  }
}

.rp-entry-body {
  display: flex;
  align-items: center;
  padding: var(--spacing-02) var(--spacing-03);
}

.rp-entry-action-icon {
  font-size: var(--rp-icon-large-size);
  padding: 0 var(--spacing-02);
  line-height: 0;

  .rp-state-overview & {
    display: none;
  }
}

.rp-entry-details {
  line-height: 1.4;
  margin-left: var(--spacing-03);

  // We need to set any low-enough flex base size (0px), making it growable (1) and non-shrinkable (0).
  // This is needed to ensure that IE makes the element fill the available space.
  flex: 1 0 1px;
  overflow-x: auto;

  .rp-state-overview & {
    margin-left: 0;
  }
}

.rp-entry-metadata {
  font-size: var(--rp-small-font-size);
}

.rp-entry-metadata-element {
  display: inline-block;
}

.rp-entry-user {
  font-weight: var(--rp-semibold-weight);
  font-style: normal;
}

.rp-comment-actions {
  a {
    color: $rp-type-blue;
  }
}

.rp-content-highlight {
  color: var(--rp-type-darkgrey);
  font-weight: var(--rp-semibold-weight);
  text-decoration: none;
}

del.rp-content-highlight {
  text-decoration: line-through;
}

.rp-entry-actions {
  display: flex;

  .rp-state-overview .rp-entry-list & {
    display: none;
  }
}

.rp-entry-button {
  @extend %rp-button;

  flex: 1 1 50%;
  border-right: solid 1px var(--white);
  padding: var(--spacing-01) 0;

  &:last-child {
    border-bottom-right-radius: var(--border-radius-base);
    border-right-width: 0;
  }

  .rp-state-current-file-mini.rp-layout-left &,
  .rp-floating-entry-layout-left & {
    &:first-child {
      border-bottom-left-radius: var(--border-radius-base);
    }

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

  .material-symbols {
    font-size: inherit;
    font-weight: bold;
  }
}

.rp-comment {
  margin: var(--spacing-01) var(--spacing-03);
  padding-bottom: var(--spacing-02);
  line-height: 1.4;
  border-bottom: solid 1px var(--rp-border-grey);

  &:last-child {
    margin-bottom: var(--spacing-01);
    border-bottom-width: 0;
  }

  .rp-state-overview .rp-entry-list & {
    margin: var(--spacing-02) var(--spacing-03);

    &:first-child {
      margin-top: 0;
      padding-top: var(--spacing-02);
    }
  }
}

.rp-comment-content {
  margin: 0;
  color: var(--rp-type-darkgrey);
  overflow-x: auto; // Long words, like links can overflow without this.
  white-space: pre-wrap;
}

.rp-comment-resolver {
  color: $rp-type-blue;
}

.rp-comment-resolver-content {
  font-style: italic;
  margin: 0;
}

.rp-comment-reply {
  padding: 0 var(--spacing-03);
}

.rp-add-comment-btn,
.rp-bulk-actions-btn {
  @extend %rp-button;

  padding: 5px 10px;
  border-radius: var(--border-radius-base);

  .material-symbols {
    font-size: inherit;
    vertical-align: middle;
    font-weight: bold;
  }
}

.rp-bulk-actions-btn {
  border-radius: 0;

  &:first-child {
    border-top-left-radius: var(--border-radius-base);
    border-bottom-left-radius: var(--border-radius-base);
  }

  &:last-child {
    border-top-right-radius: var(--border-radius-base);
    border-bottom-right-radius: var(--border-radius-base);
    margin-left: 1px;
  }
}

.rp-new-comment {
  padding: var(--spacing-03);
}

.rp-comment-input {
  display: block;
  width: 100%;
  font-size: var(--rp-base-font-size);
  padding: var(--spacing-01) var(--spacing-03);
  border-radius: 3px;
  border: solid 1px var(--rp-border-grey);
  resize: vertical;
  color: var(--rp-type-darkgrey);
  background-color: var(--white);
  margin: var(--spacing-02) 0;
  overflow-x: hidden;
  min-height: 3em;
  max-height: 400px;
}

.rp-icon-delete {
  display: inline-block;
  line-height: 1;
  font-style: normal;
  font-size: 0.8em;
  text-decoration: line-through;
  font-weight: var(--rp-semibold-weight);

  &::before {
    content: 'Ab';
  }
}

.rp-resolved-comment {
  border-left: solid var(--rp-entry-ribbon-width) $rp-yellow;
  border-radius: var(--border-radius-base);
  background-color: var(--white);
  margin-bottom: var(--spacing-03);
}

.rp-resolved-comment-context {
  background-color: color.adjust($rp-yellow, $lightness: 35%);
  padding: var(--spacing-02) var(--spacing-03);
}

.rp-resolved-comment-context-file {
  font-weight: var(--rp-semibold-weight);
}

.rp-resolved-comment-context-quote {
  color: #000;
  font-family: $font-family-monospace;
  margin: 0;
}

.rp-entry-callout {
  transition:
    top var(--rp-entry-animation-speed),
    height var(--rp-entry-animation-speed);

  .rp-state-current-file & {
    position: absolute;
    border-top: 1px solid grey;
    border-right: 1px dashed grey;

    &::after {
      content: '';
      position: absolute;
      top: -1px;
      left: 3px;
      bottom: 0;
      border-bottom: 1px solid grey;
    }
  }

  .rp-state-current-file-expanded & {
    width: 3px;

    &::after {
      width: 3px;
    }
  }

  .rp-state-current-file-mini & {
    width: 1px;

    &::after {
      width: 1px;
    }
  }

  .rp-state-overview & {
    display: none;
  }

  .rp-state-current-file &-inverted {
    border-top: none;
    border-bottom: 1px solid grey;

    &::after {
      top: 0;
      bottom: -1px;
      border-top: 1px solid grey;
      border-bottom: none;
    }
  }

  .rp-state-current-file &-insert {
    border-color: var(--rp-green);

    &::after {
      border-color: var(--rp-green);
    }
  }

  .rp-state-current-file &-delete {
    border-color: var(--rp-red);

    &::after {
      border-color: var(--rp-red);
    }
  }

  .rp-state-current-file &-comment {
    border-color: $rp-yellow;

    &::after {
      border-color: $rp-yellow;
    }
  }

  .rp-size-mini &-add-comment {
    display: none;
  }
}

.rp-overview-file-header {
  padding: var(--spacing-01) var(--spacing-03);
  border-top: solid 1px var(--rp-border-grey);
  border-bottom: solid 1px var(--rp-border-grey);
  background-color: var(--rp-bg-dim-blue);
  margin-top: var(--spacing-05);
  font-weight: var(--rp-semibold-weight);
  text-align: center;
  cursor: pointer;
}

.rp-overview-file-num-entries {
  font-weight: normal;
  font-size: 0.9em;
}

.rp-overview-file-header-collapse {
  float: left;

  .material-symbols {
    font-size: var(--font-size-02);
  }
}

.rp-overview-file-entries {
  overflow: hidden;
}

.rp-comment-wrapper {
  transition: 0.35s opacity ease-out 0.2s;

  &-resolving {
    opacity: 0;
  }
}

.rp-nav {
  display: none;
  flex-shrink: 0;

  .rp-size-expanded & {
    display: flex;
  }

  .rp-state-current-file & {
    position: absolute;
    bottom: 0;
  }

  width: 100%;
  font-size: var(--rp-icon-large-size);
  text-align: center;
  background-color: var(--rp-bg-dim-blue);
  border-top: solid 1px var(--rp-border-grey);
  z-index: 2;
}

.rp-nav-item {
  display: block;
  color: color.adjust($rp-type-blue, $lightness: 25%);
  flex: 0 0 50%;
  border-top: solid 3px transparent;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  background: none;
  padding-bottom: var(--spacing-01);

  &:hover,
  &:focus {
    text-decoration: none;
    color: $rp-type-blue;
  }

  &-active {
    color: $rp-type-blue;
    border-top: solid 3px $rp-highlight-blue;
  }
}

.rp-nav-label {
  display: block;
  font-size: var(--rp-base-font-size);
}

.resolved-comments-toggle {
  background-color: var(--bg-light-secondary);
  font-size: var(--font-size-02);
  color: color.adjust($rp-type-blue, $lightness: 25%);
  border: solid 1px var(--rp-border-grey);
  border-radius: var(--border-radius-base);
  display: block;
  padding: 0;
  height: 22px;
  width: 22px;
  line-height: 1.4;

  &:hover,
  &:focus {
    text-decoration: none;
    color: $rp-type-blue;
  }
}

.resolved-comments-backdrop {
  display: none;
  position: fixed;
  inset: 0;

  &-visible {
    display: block;
  }
}

.resolved-comments-dropdown {
  display: none;
  position: absolute;
  width: 300px;
  left: -150px;
  max-height: calc(100vh - 100px);
  margin-top: calc(var(--rp-entry-arrow-width) * 1.5);
  margin-left: 1em;
  background-color: $rp-bg-blue;
  text-align: left;
  align-items: stretch;
  justify-content: center;
  border-radius: var(--border-radius-base);
  box-shadow: 0 0 20px 10px rgba(0 0 0 / 30%);
  z-index: 1;

  &::before {
    content: '';

    @include triangle(
      top,
      $rp-entry-arrow-width * 3,
      $rp-entry-arrow-width * 1.5,
      $rp-bg-blue
    );

    top: calc(var(--rp-entry-ribbon-width) * -2);
    left: 50%;
    margin-left: calc(var(--rp-entry-arrow-width) * -0.75);
  }

  &-open {
    display: flex;
  }
}

.resolved-comments-scroller {
  flex: 0 0 auto; // Can't use 100% in the flex-basis key here, IE won't account for padding.
  width: 100%; // We need to set the width explicitly, as flex-basis won't work.
  padding: var(--spacing-03);
  overflow-y: auto;
  max-height: calc(
    100vh - 100px
  ); // We also need to explicitly set the max-height, IE won't compute the flex-determined height.
}

.rp-collapse-toggle {
  padding: var(--spacing-01) 0;
  color: $rp-type-blue;
  font-weight: var(--rp-semibold-weight);
  border: 0;
  background-color: transparent;

  &:hover,
  &:focus {
    color: color.adjust($rp-type-blue, $lightness: -5%);
    text-decoration: none;
  }
}

.rp-track-changes-indicator {
  display: block;
  padding: 5px 10px;
  background-color: rgba(240 240 240 / 90%);
  color: $rp-type-blue;
  text-align: center;
  border-bottom-left-radius: var(--border-radius-base);
  white-space: nowrap;

  &.rp-track-changes-indicator-on-dark {
    background-color: rgba(88 88 88 / 80%);
    color: var(--white);

    &:hover,
    &:focus {
      background-color: rgba(88 88 88 / 100%);
      color: var(--white);
    }
  }

  &:hover,
  &:focus {
    outline: 0;
    text-decoration: none;
    background-color: rgba(240 240 240 / 100%);
    color: $rp-type-blue;
  }
}

.review-panel-toggler {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  opacity: 0.5;
  color: $rp-highlight-blue;
  z-index: 1;
  background-color: transparent;
  transition: background 0.1s;
  flex-direction: column;
  padding: 0;
  border: 0;

  .rp-size-mini &,
  .rp-size-expanded & {
    display: flex;
  }

  .rp-size-expanded & {
    .review-panel-toggler-icon .material-symbols {
      transform: translateX(-50%) rotate(180deg);
    }
  }

  &:hover,
  &:focus {
    color: $rp-highlight-blue;
    background-color: var(--white);
  }

  .review-panel-toggler-icon {
    position: sticky;
    top: 50%;
    bottom: 50%;
    width: 100%;
    overflow: hidden;

    .material-symbols {
      transform: translateX(-50%);
      margin-left: 50%;
    }
  }
}

.review-panel {
  position: relative;
  z-index: 6;
  flex-shrink: 0;
  background-color: $rp-bg-blue;
  border-left: solid 0 var(--rp-border-grey);
  font-family: $font-family-base;
  line-height: $line-height-base;
  font-size: var(--rp-base-font-size);
  color: $rp-type-blue;
  box-sizing: content-box;

  .rp-size-expanded & {
    display: flex;
    flex-direction: column;
    width: var(--review-panel-width);
    overflow: visible;
    border-left-width: 1px;
  }

  .rp-size-mini & {
    width: var(--review-off-width);
    z-index: 6;
    border-left-width: 1px;
  }

  .review-panel-toolbar-collapse-button {
    display: inline-flex;
    align-items: center;
    border: none;
    background: none;
    padding: 0;
    color: $rp-type-blue;
  }

  &.rp-current-file-container {
    display: none;

    .rp-size-mini &,
    .rp-size-expanded & {
      display: block;
    }

    .review-panel-toolbar {
      position: sticky;
      top: 0;
    }

    .rp-nav {
      position: sticky;
      bottom: 0;
    }
  }

  .rp-entry-list-react {
    position: relative;
    overflow: hidden;

    .rp-size-mini & {
      overflow: visible;
    }
  }

  .rp-state-current-file & {
    .review-panel-tools {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      position: absolute;
      inset: 0;
    }
  }

  .rp-state-overview & {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
  }
}

.rp-floating-entry {
  position: absolute;
  font-size: var(--rp-base-font-size);
  color: $rp-type-blue;
}

.rp-floating-entry,
.review-panel {
  .rp-entry-metadata {
    button {
      padding: 0;
      border: 0;
      background-color: transparent;
      color: var(--bg-info-01);

      &:hover,
      &:focus {
        text-decoration: underline;
      }
    }
  }
}

.rp-in-editor-widgets {
  position: sticky;
  top: 0;
  right: 0;
  font-size: 0.6875rem; // 11px
  z-index: 2;
  font-family: $font-family-sans-serif;

  .rp-in-editor-widgets-inner {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
  }

  .rp-track-changes-indicator {
    border: 0;
  }

  .rp-add-comment-btn,
  .rp-bulk-actions-btn {
    white-space: nowrap;
    border-radius: 0;

    &:last-child {
      border-bottom-left-radius: var(--border-radius-base);
    }
  }
}

.track-changes-indicator-circle {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 100%;
  background-color: var(--bg-accent-01);
}
