@blue: #005c97;
@grey: #3d5265;
@teal: #00b3ae;
@lightGrey: #f9f9f9;
@hoverGreyColor: #f1f1f1;
@citationCircleColor: #e6e7e8;
@citationCircleHoverColor: @grey;
@borderRadius: 0.4rem;
@marginBottom: 1.5em;
@sm: 500px;
@md: 800px;
@lg: 1200px;

.flex-center(@dir: row, @gap: 0) {
  display: flex;
  flex-direction: @dir;
  align-items: center;
  gap: @gap;
}

.line-clamp(@lines: 3) {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: @lines;
  line-clamp: @lines;
}

.text-ellipsis(@width: 100%) {
  overflow: hidden;
  width: @width;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.include-scrollbar {
  overflow: auto;
  scrollbar-width: thin;
}

mark {
  background-color: #ff0;
  color: #000;
}

.chat-window,
.claim-modal {
  h2,
  h3,
  h4,
  h5 {
    margin: calc(2rem - 0.1em) 0 1rem;
  }

  h2 {
    font-size: 2rem;
  }

  h3 {
    font-size: 1.625rem;
  }

  h4 {
    font-size: 1.25rem;
  }

  h5 {
    font-size: 1.125rem;
  }

  ol li,
  ul li,
  p {
    font-size: inherit;
  }
}

.chat-window {
  margin: 1.5em 0;

  .sources-sidebar {
    padding: 1em;
    background-color: #fff;
    box-shadow: -4px 0 4px rgba(0, 0, 0, 0.25) !important;

    .sources-sidebar-heading {
      justify-content: space-between;
      padding-bottom: 1em;
      border-bottom: 1px solid @grey;
      margin-bottom: 1em;
      .flex-center(row);

      .ui.button {
        margin: 0;

        &:hover,
        &:active,
        &:focus {
          border: none;
          box-shadow: none;
        }

        svg {
          height: auto;
        }
      }

      h4 {
        margin: 0;
      }
    }

    .source {
      &:not(:first-child) {
        padding-top: 0.8em !important;
        margin-top: 0.8em !important;
      }

      .source-header {
        .flex-center(row, 3px);

        .chat-citation {
          top: 0;
          margin-right: 0;
        }

        svg {
          top: -1px;
        }
      }

      .source-title {
        display: inline-block !important;
        margin: 0 3px !important;
        font-size: 15px;
        .text-ellipsis(250px);
      }

      .source-desc {
        font-size: 14px;
        .line-clamp(2);
      }
    }
  }

  .ui.button.clear-chat,
  .ui.button.claims-btn {
    .flex-center(row, 0.5em);

    svg {
      width: 18px;
      height: 18px;
    }
  }

  .messages ul {
    margin-bottom: 0;
  }

  .citation-text {
    overflow: auto;
    max-height: 350px;
  }

  .empty-state {
    margin-top: 2em;
  }

  .citations-header {
    margin-bottom: 0.5em;
    font-size: 15px;
    font-weight: bold;
  }

  .citation-buttons {
    padding: 0.5em 0.8em;
    border-radius: @borderRadius;
    margin-bottom: 1em;
    background-color: @lightGrey;

    .citation-buttons-container {
      .flex-center(row, 0.3em);
      flex-flow: wrap;

      .ui.button {
        padding: 0;
        background-color: transparent;
        color: #3b82f6;
        font-size: 14px;
        font-weight: normal;
        text-decoration-line: underline;
      }

      .ui.button.toggle-text {
        font-weight: bold;
        text-decoration: none;
      }
    }
  }

  .comment {
    display: flex;
    margin-bottom: @marginBottom;
    gap: 0.8em;

    i.inverted.circular.grey.icon {
      background-color: @grey !important;
    }

    i.icon,
    i.icons {
      font-size: 1em;
    }

    ul,
    ol {
      li {
        padding-bottom: 0.5em;
      }
    }

    .tool_info {
      padding-bottom: 0.2em;
      font-size: small;
    }
  }

  .chat-related-questions {
    margin-bottom: 2em;
  }

  .answer-tab {
    margin-top: 1.5em;

    .sources {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      margin-bottom: @marginBottom;
      gap: 0.8em;

      .source-link:hover {
        .source {
          background-color: @hoverGreyColor;
        }
      }

      .source {
        display: flex;
        width: 200px;
        flex-direction: column;
        padding: 0.6em 0.7em;
        border-radius: @borderRadius;
        background-color: @lightGrey;
        gap: 0.3em;

        &:hover {
          background-color: @hoverGreyColor;
        }

        @media screen and (max-width: @md) {
          width: calc(50% - 0.4em) !important;
        }

        @media screen and (max-width: @sm) {
          width: 100% !important;
        }
      }

      .source-header {
        @media screen and (max-width: @sm) {
          display: block !important;

          .source-title {
            display: inline;
          }

          svg.icon {
            position: relative;
            top: 2px;
            margin-left: 5px;
          }
        }
      }

      .source-header,
      .source-header a {
        width: 100%;
        color: @grey;

        .flex-center(row);
      }

      .source-title {
        padding-left: 0.2em;
        color: @grey;
        font-size: 13px;
        font-weight: bold;

        @media screen and (min-width: @sm) {
          .text-ellipsis(140px);
        }
      }

      .source-date {
        margin-top: auto;
      }
    }

    .source-desc {
      padding-top: 2px;
      color: @grey;
      font-size: 12px;
      text-align: left;

      .line-clamp(@lines: 2);
    }
  }

  .source-date {
    margin-top: 0.3em;
    line-height: 1;

    span {
      padding: 0.2em 0.4em;
      border-radius: 5px;
      background-color: #e5e7eb;
      color: @grey;
      font-size: 10px;
    }
  }

  .sources-listing {
    .source {
      &:not(:first-child) {
        display: inline-block;
        padding-top: 1em;
        border-top: 1px solid #eee;
        margin-top: 1em;
      }

      &:hover {
        .source-title {
          color: #008f8b;
        }

        svg {
          color: #008f8b;
        }
      }
    }

    .source-header {
      margin-bottom: 0.5em;
      color: @grey;
      font-size: 17px;
      font-weight: bold;

      .source-title {
        display: inline;
        margin: 0 5px;
      }

      .chat-citation {
        position: relative;
        top: -2px;

        &:hover {
          border: 1px solid #dbd9d9;
          background-color: #e6e7e8;
          color: #3d5265;
        }
      }

      svg {
        position: relative;
        top: 3px;
        margin-left: 1px;
      }
    }

    .source-desc {
      padding-top: 2px;
      color: @grey;
      font-size: 15px;
      text-align: left;
      .line-clamp(@lines: 3);
    }
  }

  .loader {
    position: relative;
    width: 10px;
    height: 10px;
    border-radius: 5px;
    margin-top: 1em;
    margin-left: 64px;
    animation: dot-flashing 1s infinite linear alternate;
    animation-delay: 0.5s;
    background-color: @grey;

    &:before,
    &:after {
      position: absolute;
      top: 0;
      display: inline-block;
      content: '';
    }

    &:before {
      left: -15px;
      width: 10px;
      height: 10px;
      border-radius: 5px;
      animation: dot-flashing 1s infinite alternate;
      animation-delay: 0s;
      background-color: @grey;
    }

    &:after {
      left: 15px;
      width: 10px;
      height: 10px;
      border-radius: 5px;
      animation: dot-flashing 1s infinite alternate;
      animation-delay: 1s;
      background-color: @grey;
    }
  }
}

.circle {
  width: 30px;
  height: 30px;
  flex: none;
  justify-content: center;
  border-radius: 50%;
  text-align: center;

  .flex-center(column);

  &.user {
    background-color: @teal;
  }

  &.assistant {
    background-color: @grey;
  }

  svg {
    margin: 0 auto;
  }
}

.quality-check-toggle {
  margin-top: 1em;

  .ui.toggle.checkbox {
    input:checked ~ label {
      color: @grey !important;
    }

    label {
      color: @grey;

      &:before {
        border: none !important;
      }
    }
  }
}

.quality-check-popup.ui.popup {
  padding: 0.6em 0.9em;
  font-size: 14px;
}

.ui.modal.claim-modal {
  .chat-window {
    margin-top: 1em;
    margin-bottom: 0;
  }

  .header {
    display: flex;
    padding-bottom: 0;
    border-bottom: none;
    gap: 0.5em;
  }

  .claim-text {
    margin-top: 0;
    color: @grey !important;
    font-style: italic;
    font-weight: bold;
  }

  .claim-rationale {
    font-size: 14px;
    line-height: 1.2;
  }

  .claim-source-link {
    color: inherit;

    .claim-source-title {
      &:hover {
        opacity: 0.8;
      }

      svg {
        position: relative;
        top: 2px;
        left: 5px;
      }
    }
  }

  .claim-source-title {
    margin-bottom: 1em;
  }

  .claim-source {
    padding: 0.5em 0.8em;
    border: 1px solid #e5e5e5;
    border-radius: @borderRadius;
    font-size: 16px;

    .claim-score {
      margin-bottom: 0.5em;
      font-size: 18px;
      font-weight: bold;
    }
  }

  .ui.secondary.pointing.menu {
    overflow: auto;
    padding-bottom: 0.125rem;
    border-width: 2px;

    &::-webkit-scrollbar {
      height: 4px;
    }

    .item {
      max-width: 200px;
      border-bottom-width: 2px;
      margin: 0em 0em -2px;
      color: #6c8295;

      &.active,
      &:hover {
        border-color: @grey !important;
        color: @grey !important;
        font-weight: bold;
      }

      span {
        font-size: 16px;
        font-weight: bold;
        text-align: left;
        .line-clamp(@lines: 2);
      }
    }
  }

  @media only screen and (min-width: @lg) {
    width: 1100px;
  }
}

.comment-tabs {
  margin-top: 0.5em;

  .ui.secondary.pointing.menu {
    border-width: 2px;
    margin-bottom: 1.5em;

    .item {
      border-bottom-width: 2px;
      margin-bottom: 0 !important;
      color: #6c8295;
      font-size: 16px;
      font-weight: bold;

      &.active,
      &:hover {
        border-color: @grey !important;
        border-bottom-width: 2px !important;
        margin-bottom: 0 !important;
        color: @grey !important;
        font-weight: bold;
      }
    }
  }

  .ui.segment {
    padding: 0;
  }
}

.ui.button.source.show-all-sources-btn {
  display: inline-block;
  margin: 0;
  box-shadow: none;
  text-align: left;

  &:hover,
  &:active {
    background-color: @hoverGreyColor;
  }

  .source-header {
    display: block;
  }

  .chat-citation {
    width: 1em;
    height: 1em;
  }

  .source-title {
    padding: 0;
    margin-top: 5px;

    @media screen and (max-width: @sm) {
      display: inline-block;
      margin-top: 10px;
    }
  }
}

.sources-count {
  font-family: monospace;
  font-size: 14px;
}

.verify-claims {
  display: flex;
  gap: 0.5em;
}

.related-questions-loader {
  .flex-center(row, 0.5em);
}

.starter-messages-container {
  display: grid;
  width: 100%;
  grid-gap: 0.7rem;
  grid-template-columns: repeat(2, 1fr);

  @media screen and (max-width: 580px) {
    grid-template-columns: 1fr;
  }
}

.relatedQuestionButton {
  margin-bottom: 0.3em;
  cursor: pointer;
  -webkit-user-select: none; /* Safari */
  -ms-user-select: none; /* IE 10 and IE 11 */
  user-select: none; /* Standard syntax */

  &:hover {
    color: rgba(61, 82, 101, 0.8);
  }
}

.feedback-modal {
  h3 {
    color: @grey;
  }

  .ui.form textarea {
    max-width: 100%;
  }

  .reason-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-bottom: @marginBottom;
    gap: 0.5em;
  }

  .ui.primary.button {
    background-color: @grey !important;

    &:hover {
      background-color: #334555 !important;
    }
  }

  .ui.inverted.primary.button {
    background-color: #fff !important;
    box-shadow: 0px 0px 0px 2px @grey inset !important;
    color: @grey;

    &:hover {
      background-color: @grey !important;
      box-shadow: 0px 0px 0px 2px @grey inset !important;
      color: #fff;
    }
  }
}

.message-actions {
  margin: 0.8em 0;

  .ui.basic.button {
    padding: 6px 8px;
    margin-right: 0.2em;

    &:active,
    &:focus {
      box-shadow: none;
      outline: none;
    }

    svg {
      width: 15px;
      height: 15px;
      margin: 0 !important;
      stroke: #0a0a0a;
    }

    &:hover {
      border-radius: 3px;
      background-color: @lightGrey !important;
      box-shadow: none;
    }
  }
}

.ui.button.starter-message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.7rem;
  border: 1px solid #e5e5e5;
  border-radius: @borderRadius;
  margin: 0;
  background-color: white;
  color: inherit;
  gap: 5px;
  line-height: normal;
  text-align: left;
  transition: background-color 0.3s ease;

  &:hover,
  &:active {
    background-color: #fbfbfb;
  }

  .starter-message-desc {
    color: #6b7280;
    font-size: 14px;
    font-weight: normal;
  }
}

.chat-citation {
  display: inline-block;
  width: 1.7em;
  height: 1.7em;
  border: 1px solid #dbd9d9;
  border-radius: 3em;
  margin-right: 3px;
  background-color: @citationCircleColor;
  color: @grey;
  cursor: pointer;
  font-size: 10px;
  font-weight: bold;
  line-height: 1.7em;
  text-align: center;

  &:hover {
    border: 1px solid @citationCircleHoverColor;
    background-color: @citationCircleHoverColor;
    color: #ffffff;
  }
}

#chat-citation-popup {
  .ui.popup {
    padding: 0.8em;
    font-size: 13px;
  }

  .ui.popup > .header {
    font-size: 15px;
  }
}

.chat-form .ui.form {
  margin-top: 2em;

  .textarea-wrapper {
    width: 100%;
    justify-content: space-between;
    padding: 0.6em 0.8em;
    border: 1px solid #e5e5e5;
    border-radius: @borderRadius;
    background-color: #fbfbfb;
    .flex-center(row);

    textarea {
      max-width: none;
      min-height: auto !important;
      max-height: none !important;
      padding: 0;
      border: none !important;
      background: none !important;
      resize: none !important;
    }
  }

  .ui.button.submit-btn {
    padding: 0;
    margin: 0 0.5em 0 0.8em;
    background: none;

    &:hover {
      background: none;
    }

    svg {
      margin-top: 0.1em;
      color: @grey;
    }
  }
}

.tool_info.loading-text {
  animation: shimmer 2.5s linear infinite;
  background: linear-gradient(
    -90deg,
    #5c5c5c,
    #d5d5d5 20%,
    #5c5c5c 40%,
    #5c5c5c
  );
  -webkit-background-clip: text;
  background-clip: text;
  background-size: 200% 100%;
  font-size: 1rem;
  -webkit-text-fill-color: transparent;
}

#fact-check-toggle[disabled] ~ label {
  opacity: 1;
}

.halloumi-feedback-button {
  margin-top: 1.5em;
  font-size: 15px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 6px solid @teal;
  border-radius: 50%;
  border-top: 6px solid @blue;
  animation: spin-rotate 1s infinite linear; // spin 2s linear infinite;
  animation-delay: 0.5s;
}

.feedback-toast {
  position: fixed;
  z-index: 9999;
  bottom: -100px;
  left: 50%;
  display: flex;
  align-items: center;
  padding: 15px 25px;
  border-radius: 3px;
  font-size: 18px;
  opacity: 0;
  transform: translateX(-50%);
  transition:
    bottom 0.35s ease-in-out,
    opacity 0.35s ease-in-out;

  &.active {
    bottom: 20px;
    opacity: 1;
  }

  &.success {
    border: 1px solid #2c662d;
    background-color: #fcfff5;
    color: #2c662d;
  }

  &.error {
    border: 1px solid #db2828;
    background-color: #ffe8e6;
    color: #db2828;
  }
}

@keyframes dot-flashing {
  0% {
    background-color: @grey;
  }

  50%,
  100% {
    background-color: rgba(61, 82, 101, 0.2);
  }
}

@keyframes spin-rotate {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(180deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}
