.assistant {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: $white;
  overflow: hidden;
  border-left: 1px solid $palette-neutral-400;
}

.assistant__header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid $palette-neutral-200;
  flex-shrink: 0;
  height: 51px;
  gap: 12px;
}

%scrollbar-thin {
  scrollbar-gutter: stable;

  // Make scrollbar thin
  scrollbar-width: thin; // Firefox

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
  }
}

.assistant__content {
  @extend %scrollbar-thin;

  flex: 1;
  padding: 20px 11px 0 20px;
  overflow-y: auto;
  display: flex;
  scrollbar-gutter: stable;
}

.assistant__header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.assistant__header-separator {
  width: 1px;
  height: 16px;
  background-color: $palette-neutral-200;
}

.assistant__header-icon {
  font-size: 16px;
  color: $palette-neutral-700;

  &:hover {
    color: $palette-neutral-1200;
  }
}

.assistant__title {
  @extend %ellipsis;

  font-size: 13px;
  font-weight: ⁨;
  line-height: 20px;
  flex: 1;

  i {
    margin-right: 10px;
    color: $palette-blue-500;
  }
}

.assistant__welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.assistant__welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, $palette-blue-500 0%, lighten($palette-blue-500, 10%) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba($palette-blue-500, 0.2);

  i {
    font-size: 36px;
    color: $white;
  }
}

.assistant__welcome-title {
  font-size: 20px;
  font-weight: 600;
  color: $palette-neutral-1300;
  margin: 0 0 12px;
}

.assistant__welcome-subtitle {
  font-size: 13px;
  color: $palette-neutral-1200;
  line-height: 1.5;
  margin: 0 0 32px;
}

.assistant__welcome-title-greeting {
  color: $palette-neutral-700;
}

.assistant__input {
  padding: 20px;
  padding-top: 8px;
  flex-shrink: 0;
}

.assistant__input-status-icon {
  color: $palette-blue-500;
  font-size: 14px;
}

.assistant__input-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 400;
  line-height: 20px;
  border-radius: 12px 12px 0 0;
  background: $palette-neutral-25;
  color: $palette-neutral-900;

  &.is-running {
    color: #16829c;
    background-color: $palette-cyan-50;
  }
}

.assistant__input-section {
  background: $palette-neutral-25;

  &.is-running {
    background-color: $palette-cyan-50;
  }
}

.assistant__input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: $white;
  border: 1px solid $palette-neutral-500;
  transition: all 0.2s;
  padding-bottom: 12px;

  @include rounded($rounded-md);
  @include elevation($elevation-low);

  &.has-context {
    padding-top: 36px;
  }
}

.assistant__input-textarea {
  @extend %scrollbar-thin;

  flex: 1;
  border: none;
  resize: none;
  background: transparent;
  font-size: 13px;
  line-height: 20px;
  max-height: 120px;
  outline: none;
  box-shadow: none;
  padding: 8px 50px 0 16px;

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

  &::placeholder {
    color: $palette-neutral-600;
  }
}

.assistant__context-badge {
  @extend %ellipsis;

  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 8px;
  background: $palette-neutral-100;
  border-radius: 16px;
  font-size: 10px;
  color: $palette-neutral-900;
  max-width: calc(100% - 16px);
}

.assistant__context-text {
  font-weight: 500;
  letter-spacing: 0.2px;
}

.assistant__send-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: $palette-neutral-1200;
  color: $white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;

  i {
    font-size: 14px;
  }

  &--is-running i {
    animation: spin 2.5s linear infinite;
  }

  &:hover:not(.assistant__send-button--disabled) {
    background: $palette-neutral-1200;
    transform: scale(1.05);
  }

  &:active:not(.assistant__send-button--disabled) {
    transform: scale(0.95);
  }

  &--disabled {
    background: $palette-neutral-600;
    cursor: not-allowed;

    i {
      color: white;
    }
  }
}

// Message list

.assistant__messages-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.assistant__typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;

  span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: $palette-neutral-800;
    animation: typing-bounce 1.4s infinite ease-in-out;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }
  }
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.assistant__message {
  display: flex;

  &--human {
    justify-content: flex-end;
  }

  &--ai {
    justify-content: flex-start;
  }
}

.assistant__message-content {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;

  .assistant__message--human & {
    align-items: flex-end;
  }

  .assistant__message--ai & {
    align-items: flex-start;
  }
}

.assistant__message-bubble {
  background-color: $white;
  border: 1px solid $palette-neutral-200;
  border-radius: 12px;
  padding: 12px 16px;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  min-width: 0;
  display: block;

  .assistant__message--human & {
    background-color: $palette-neutral-100;
    border-color: $palette-neutral-100;
  }
}

.assistant__message-text {
  font-size: 13px;
  line-height: 20px;
  margin: 0;
  padding: 0;
  width: 100%;
  text-align: left;
  display: block;
  text-indent: 0;
  border: 0;
  outline: 0;

  // Markdown styles
  p {
    margin: 0 0 8px;
    color: $palette-neutral-1200;

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

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 12px 0 8px;
    font-weight: 600;
    line-height: 1.3;
    color: $palette-neutral-1200;
  }

  h1 {
    font-size: 1.5em;
  }

  h2 {
    font-size: 1.3em;
  }

  h3 {
    font-size: 1.15em;
  }

  h4 {
    font-size: 1em;
  }

  h5 {
    font-size: 0.95em;
  }

  h6 {
    font-size: 0.9em;
  }

  h1:first-child,
  h2:first-child,
  h3:first-child,
  h4:first-child,
  h5:first-child,
  h6:first-child {
    margin-top: 0;
  }

  ul,
  ol {
    margin: 8px 0;
    padding-left: 20px;
    color: $palette-neutral-1200;
  }

  li {
    margin: 4px 0;
    line-height: 1.5;
    color: $palette-neutral-1200;
  }

  code {
    background-color: $palette-neutral-100;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: Monaco, 'Courier New', monospace;
    font-size: 0.9em;
  }

  pre {
    background-color: $palette-neutral-100;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;

    code {
      background-color: transparent;
      padding: 0;
      font-size: 0.85em;
    }
  }

  blockquote {
    border-left: 3px solid $palette-blue-200;
    padding-left: 12px;
    margin: 8px 0;
    color: $palette-neutral-800;
  }

  a {
    color: $palette-blue-500;
    text-decoration: none;

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

  strong {
    font-weight: 600;
  }

  em {
    font-style: italic;
  }

  hr {
    border: none;
    border-top: 1px solid $palette-neutral-400;
    margin: 12px 0;
  }

  table {
    @extend %scrollbar-thin;

    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    overflow-x: auto;
    display: block;

    th,
    td {
      border: 1px solid $palette-neutral-400;
      padding: 8px;
      text-align: left;
      min-width: 80px;
      white-space: nowrap;
    }

    th {
      background-color: $palette-neutral-100;
      font-weight: 600;
    }
  }

  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: wrap;

  // Remove any inherited spacing
  &::before,
  &::after {
    content: none;
  }

  .assistant__message--human & code {
    background-color: rgba(255, 255, 255, 0.2);
  }
}

.assistant__chat-history-spacer {
  width: 300px;
}
