@use "sass:math";

$size: 5px;

.llm {

  &__form,
  .form {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
  }

  &__container {
    padding-top: 1.9230769231rem;
    padding-bottom: 1.9230769231rem;
    // background: #404040;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: calc(100% - 120px);

    .form {
      flex-grow: 1;
      display: flex;
      flex-direction: column;
    }
  }

  &__app {
    flex: 0 0 100px;
    display: flex;
    align-items: center;
    gap: 3em;
  }

  &__row {
    padding: 10px 0;

    h4,
    p {
      margin: 0;
    }

    pre {
      padding: 5px 10px;
      max-height: 150px;
      overflow-x: hidden;
      overflow-y: auto;
      white-space: pre-line;
      border: 1px solid var(--theme-elevation-150);
      background: var(--theme-input-bg);
    }

    .btn {
      margin: 0;
    }
  }

  &__row+.llm__row {
    border-top: 1px solid var(--theme-elevation-150);
  }

  &__flex {
    display: flex;
    column-gap: 5px;
  }

  &__main {
    flex-grow: 1;
    position: relative;
    max-height: calc(100vh - 375px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  &__thread {
    display: flex;
    margin-bottom: 1em;

    &.user {
      justify-content: flex-end;
    }

    &.assistant {
      justify-content: flex-start;
    }
  }

  &__message {
    width: calc(100% - 80px);
    max-width: 600px;
    padding: 1em;
    border: 1px solid var(--theme-elevation-150);
    background: var(--theme-input-bg);
    color: var(--theme-elevation-800);
    border-radius: 0;

    code {
      display: block;
      word-break: break-all;
      padding: 5px 10px;
      margin-bottom: 8px;
      border-radius: 3px;
      background: rgba(0, 0, 0, 0.5);
    }
  }

  &__text {
    margin: 0 0 0.5em 0;

    &:last-child {
      margin: 0;
    }

    p {
      margin: 0;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      margin: 0.5em 0;
    }

    img {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 230px;
      margin: 8px 0;
      padding: 6px;
      border: 2px solid rgba(255, 255, 255, 0.15);
      border-radius: 3px;
      aspect-ratio: 4/3;
      object-fit: cover;
    }
  }

  &__card {
    display: block;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.5);

    &-title {
      margin: 0.2em 0 0.4em 0;
      font-size: 1.5em;
      line-height: 1.25;
    }

    &-abstract,
    &-description {
      line-height: 1.45;
      margin-bottom: 10px;
    }

    &-title,
    &-abstract,
    &-description {
      p {
        margin: 0;
      }

      em {
        font-style: normal;
      }
    }

    &-image {
      img {
        display: flex;
        justify-content: center;
        align-items: center;
        max-width: 230px;
        margin: 8px 0;
        padding: 6px;
        border: 2px solid rgba(255, 255, 255, 0.15);
        border-radius: 3px;
        aspect-ratio: 4/3;
        object-fit: cover;
      }
    }
  }

  &__pill {
    padding: 2px 4px;
    line-height: 1.25;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
  }

  &__pill+.llm__pill {
    margin-left: 4px;
  }

  &__foot {
    position: relative;
    flex: 0 0 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1em;
  }

  &__upload {
    position: relative;

    &-cta {
      pointer-events: none;
    }

    &-input {
      position: absolute;
      inset: 0;
      opacity: 0;
      cursor: pointer;
    }

    &-file {
      position: absolute;
      right: 0;
      bottom: 100%;
      margin: 0;
      padding: 0.2em 1em;
      border-radius: 8px;

      .btn__label {
        display: flex;
        align-items: center;
        column-gap: 0.35em;
      }

      .llm__upload-filename {
        display: block;
        max-width: 100px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        font-family: var(--llm-pill-font-family);
        font-weight: 700;
      }

      &:hover {
        .llm__upload-image {
          display: block;
        }
      }
    }

    &-image {
      display: none;
      position: absolute;
      max-width: 96px;
      max-height: 96px;
      bottom: 100%;
      right: 0;
      border-radius: 8px;
      margin-bottom: 0.3rem;
      box-shadow: shadow(xs);
      pointer-events: none;
    }
  }

  .field-type.textarea {
    flex-grow: 1;
    margin: 0;

    .textarea-outer {
      height: 80px;
      max-height: 80px;
      min-height: 80px;
      line-height: 1.25;
    }
  }

  &__chatCompletion {
    position: relative;
  }

  &__busyIndicator {
    position: absolute;
    display: block;
    width: 40px;
    height: 30px;
    left: 10px;
    bottom: 0;
    // outline: 1px solid white;
    user-select: none;
    pointer-events: none;
    transition: none;

    &::before {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      display: block;
      border-radius: 50%;
      background: rgba(255, 255, 255, 1.0);
      // background: rgba(255, 255, 255, 0.6);
      transform: translate(-50%, -50%);
      z-index: 2;
      width: $size;
      height: $size;
      margin-top: $size;
      margin-left: $size * -0.5;
      animation: llmBouncing .45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
      animation-delay: .20s;
    }

    &>span {

      &::before,
      &::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        display: block;
        border-radius: 50%;
        background: rgba(255, 255, 255, 1.0);
        // background: rgba(255, 255, 255, 0.6);
        transform: translate(-50%, -50%);
        z-index: 2;
        width: $size;
        height: $size;
        margin-top: $size;
        margin-left: $size * -0.5;
        animation: llmBouncing .45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
      }

      &::before {
        margin-left: $size * -2.8;
      }

      &::after {
        margin-left: $size * 1.8;
        animation-delay: .40s;
      }
    }
  }
}

@keyframes llmBouncing {
  from {
    transform: translateY(0) scaleY(.8);
  }

  to {
    transform: translateY($size * -2);
  }
}

.preview-btn {

  &,
  &:hover {
    background: #11d951;
    border-color: green;
    box-shadow: none;
    color: black;
    font-weight: 500;
    outline: 2px solid #05aec0;
    outline-offset: 2px;
  }

  &:hover {
    background: #0ecd4a;
  }
}
