@import '../../scss/mixin';

.prompt {
  width: 100%;
}

.form {
  gap: size(1);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
}

.control {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 64px;
  box-shadow: shadow(xs);
  border-radius: 0;
  background: var(--llm-input-background);
  overflow: visible;
  gap: 4px;
  margin: 0;

  @include bp(md) {
    gap: 8px;
  }

  :global(.llm__busyIndicator) {
    display: none;
    position: absolute;
    left: 4px;
    top: 50%;
    margin: -16px 0 0 0;
    pointer-events: none;

    &::before {
      background: var(--llm-input-accent);
      opacity: 0.4;
    }

    &>span {

      &::before,
      &::after {
        background: var(--llm-input-accent);
        opacity: 0.4;
      }
    }
  }
}

.isStreaming {
  :global(.llm__busyIndicator) {
    display: block;
  }
}

.label {
  @include srOnly();
}

.textareaGroup {
  position: relative;
  width: 100%;
}

.textarea {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 0;
  border: none;
  resize: none;
  font-family: var(--llm-input-font-family);
  font-size: rem(1);
  line-height: 1.3;
  border-radius: 0;
  background: transparent;
  color: var(--llm-input-foreground);
  pointer-events: auto;
  overflow: clip;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
  padding: 0 12px;

  &:focus {
    outline-color: currentColor;
  }

  &::placeholder {
    font-family: var(--llm-input-font-family);
    font-size: inherit;
    // font-size: 16px;
    // line-height: 1.3;
    color: var(--llm-color-neutral-300);
  }

  &[aria-disabled="true"] {
    pointer-events: none;
    color: transparent;
    user-select: none;

    &::placeholder {
      color: transparent;
    }
  }

  field-sizing: content;
}

:global(.llm__reset) {
  .textarea {
    padding: 0 12px;
  }
}

.hasSpeechRecognition {
  .textarea {
    padding-left: 0;
  }
}

.microphone,
.speak {
  @include button();
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  font-size: 16px;
  color: var(--llm-input-accent);
  outline: 2px solid transparent;
  outline-offset: 2px;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;

  @include bp(md) {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  svg {
    width: 18px;
    height: 18px;
  }
}

.uploadGroup {
  position: relative;
  border-radius: 0;
  outline: 2px solid transparent;
  outline-offset: 2px;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;

  @include bp(md) {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  &:has(.uploadInput:focus),
  &:has(.uploadInput:focus-visible) {
    outline-color: var(--llm-color-outline);
  }

  &:has(.uploadInput:hover) {
    outline-color: color-mix(in srgb, var(--llm-color-outline) 10%, transparent 90%);
  }

  &:has(.uploadInput:active) {
    outline-color: var(--llm-color-accent-foreground);
  }
}

.uploadInput {
  appearance: none;
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: none;
  border: none;
  color: transparent;
  outline: none;
  font-size: 0;
  opacity: 0;
  cursor: pointer;
}

.upload {
  @include button();
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 16px;
  color: var(--llm-input-accent);
  outline: none;
  pointer-events: none;

  svg {
    width: 18px;
    height: 18px;
  }
}

.uploadFile {
  @include button();
  position: absolute;
  right: 0;
  bottom: 100%;
  display: flex;
  align-items: center;
  column-gap: 0.35em;
  padding: 0.2em 1em;
  margin-bottom: 0.3rem;
  font-size: 12px;
  border-radius: 0;
  backdrop-filter: blur(20px);
  background: transparent;
  color: var(--neutral-700);

  span {
    max-width: 100px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    font-family: var(--llm-pill-font-family);
    font-weight: 700;
  }

  svg {
    flex-shrink: 0;
    width: 1em;
    height: 1em;
    fill: currentColor;
  }

  img {
    display: none;
    position: absolute;
    max-width: 96px;
    max-height: 96px;
    bottom: 100%;
    right: 0;
    border-radius: 0;
    margin-bottom: 0.3rem;
    box-shadow: shadow(xs);
    pointer-events: none;
    object-fit: contain;
  }

  &:hover {
    img {
      display: block;
    }
  }
}

:global(.llm__reset) {
  .uploadFile {
    background: transparent;
    color: var(--neutral-700);
  }
}

.submit,
.stop {
  @include button();
  flex-shrink: 0;
  width: 36px;
  height: 45px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--llm-input-background);
  color: var(--llm-input-accent);
  border-radius: 0;

  @include bp(md) {
    width: 48px;
    height: 60px;
  }

  >i {
    position: relative;
    z-index: 2;
    width: 18px;
    height: 18px;

    @include bp(md) {
      width: 24px;
      height: 24px;
    }

    svg {
      display: block;
      width: 100%;
      height: 100%;
    }
  }

  &:disabled,
  &[aria-disabled="true"] {
    pointer-events: none;

    i {
      opacity: 0.4;
    }
  }
}
