.messageWrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  margin: 16px 0;
}

.messageContent {
  flex: 1;
  width: 100%; // Ensure container does not exceed parent width
  max-width: 100%; // Limit maximum width
  overflow-x: hidden; // Prevent content overflow
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.assistantTitle {
  font-weight: 500;
}

.response {
  font-family: "Alibaba PuHuiTi 2.0";
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0.2px;
  color: var(--text-primary);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  position: relative;
  width: 100%; // Ensure container does not exceed parent width
  max-width: 100%; // Limit maximum width
  overflow-x: hidden; // Prevent content overflow
}

.thought {
  font-size: 12px;
  line-height: 18px;
  color: #a6a6a6;
  padding-left: 12px;
  border-left: 1px solid #a6a6a6;
  margin: 4px 0 4px 4px;
  width: calc(100% - 16px);
}

// Add a container to wrap all sub_response
.subResponsesContainer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%; // Ensure container does not exceed parent width
  max-width: 100%; // Limit maximum width
  overflow-x: hidden; // Prevent content overflow
  color: var(--text-primary);
}

.subResponse {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  width: 100%;
  overflow: hidden;
  transition: background-color 0.2s ease;

  &:hover {
    background-color: rgba(0, 0, 0, 0.02); // Add hover effect
  }

  .icon {
    width: 24px;
    height: 24px;
    z-index: 1;
    position: relative;
    flex-shrink: 0;
  }

  .content {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }
}

.expandButton {
  width: 16px;
  height: 16px;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: auto;
  order: -1;

  img {
    width: 12px;
    height: 12px;
    transition: transform 0.2s ease;
    transform: rotate(0deg);
  }

  &.expanded img {
    transform: rotate(180deg);
  }
}

.subMessageItem {
  margin-left: 32px;

  &.hidden {
    display: none;
  }

  .thought {
    padding: 8px;
    background: var(--sidebar-conversation-bg);
    border-radius: 4px;
    border: none;
    margin: 0;
  }
}

.toolCallWrapper {
  // margin-left: 32px;
  margin-bottom: 8px;
}


.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}

.responseGroup {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subMessages {
  display: flex;
  flex-direction: column;
  position: relative;

  &::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: #e0e0e0;
  }
}

.subResponseContainer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;

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

.messageItem {
  border: 2px solid transparent;
  border-radius: 8px;
  transition: all 0.2s ease;
  margin: 4px 0;

  &.selectedMessage {
    background-color: var(--message-selected-bg, rgba(37, 99, 235, 0.05));
    border-color: var(--message-selected-border, #2563eb);
  }

  // Can add mouse hover effect
  &:hover {
    background-color: var(--message-hover-bg, rgba(37, 99, 235, 0.02));
  }
}

.messageContainer {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.agentContentWrapper {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mainResponse {
  color: var(--text-primary);
  white-space: pre-wrap;
  line-height: 1.6;
}

.toolCall {
  margin-left: 24px;
  background-color: rgba(0, 0, 0, 0.02);
  border-radius: 4px;
  padding: 8px;
}

.expandableContent {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  opacity: 0;

  &.expanded {
    max-height: 1000px;
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
  }
}

.toolSection,
.fileSection,
.thoughtSection,
.clarificationSection {
  margin-top: 12px;
  padding: 12px;
  background-color: rgba(0, 0, 0, 0.02);
  border-radius: 6px;
}

.thoughtSection {
  color: #666;
  font-style: italic;
}

.fileSection {
  .fileItem {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background-color: rgba(0, 0, 0, 0.02);
    border-radius: 6px;
    margin-bottom: 8px;

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

.clarificationSection {
  .optionsContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .optionButton {
    padding: 6px 12px;
    border-radius: 6px;
    background-color: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;

    &:hover:not(:disabled) {
      background-color: rgba(0, 0, 0, 0.05);
    }

    &:disabled {
      cursor: not-allowed;
      opacity: 0.5;
    }

    &.selected {
      background-color: rgba(0, 0, 0, 0.1);
      border-color: rgba(0, 0, 0, 0.2);
      color: rgba(0, 0, 0, 0.8);
      font-weight: 500;

      &:disabled {
        opacity: 1; // Selected button remains fully opaque
      }
    }

    transform: rotate(180deg);
  }
}

.messageFooter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-left: 16px;
  font-size: 12px;
}

.timestamp {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 4px;
}

.status {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;

  &.running {
    background: #e6f4ff;
    color: #1677ff;
  }

  &.error {
    background: #fff2f0;
    color: #ff4d4f;
  }

  &.waiting {
    background: #f5f5f5;
    color: #666;
  }
}

.feedback {
  display: flex;
  flex-direction: row; // Changed to left to right
  justify-content: flex-start; // Ensure left alignment
  margin: 0 12px;
}

.textContent {
  line-height: 1.5;
}

.files {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filesMessage {
  padding: 16px 0;
  background: none;
}

.filesList {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.fileItem {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--message-fileItem-bg);
  border-radius: 12px;
  box-shadow: 0 1px 6px 0 rgba(99, 102, 241, 0.06);
  padding: 10px 18px;
  min-width: 200px;
  max-width: 260px;
  margin-bottom: 0;
  transition: box-shadow 0.2s, border 0.2s, background 0.2s;
  border: 1px solid var(--sps-color-border-secondary);

  &:hover,
  &.selected {
    background: var(--message-content);
    box-shadow: 0 2px 12px 0 rgba(99, 102, 241, 0.12);
  }
}

.fileLeft {
  display: flex;
  align-items: center;
  margin-right: 5px;
}

.fileIcon {
  width: 28px;
  height: 28px;
  margin-right: 3px;
}

.fileInfoBlock {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.fileName {
  font-weight: 600;
  color: var(--message-fileItem-text);
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fileSize {
  color: #60a5fa;
  font-size: 13px;
  font-weight: 400;
}

.downloadBtn {
  position: absolute;
  right: 12px;
  bottom: 10px;
  text-decoration: none;
  font-weight: 600;
  color: #6366f1;
  font-size: 13px;
  margin-top: auto;
  transition: color 0.2s;
  &:hover {
    color: #4338ca;
    text-decoration: none;
  }
}

@keyframes blink {

  0%,
  100% {
    opacity: 0;
  }

  50% {
    opacity: 1;
  }
}

.markdown {
  // Basic text styles
  font-size: 14px;
  line-height: 1.4;
  // Ensure container does not exceed parent width
  width: 100%;
  // Limit maximum width
  max-width: 100%;

  // Heading styles
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 0.3em 0 0.1em;
    font-weight: 600;
    line-height: 1.2;
  }

  h1 {
    font-size: 1.4em;
  }

  h2 {
    font-size: 1.2em;
  }

  h3 {
    font-size: 1.1em;
  }

  h4 {
    font-size: 1em;
  }

  h5 {
    font-size: 0.9em;
  }

  h6 {
    font-size: 0.8em;
  }

  // Paragraph styles
  p {
    margin: 0;
    line-height: 1.4;

    &+p {
      margin-top: 0.2em;
    }
  }

  // List styles
  ul,
  ol {
    margin: 0.1em 0;
    padding-left: 1.2em;
  }

  li {
    // display: flex;
    // flex-direction: column;
    margin: 0;
    padding: 0;
    line-height: 1.4;

    p {
      margin: 0;
      display: inline-block;
    }

    &+li {
      margin-top: 0.1em;
    }
  }

  // Code styles
  code {
    padding: 0.1em 0.2em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(175, 184, 193, 0.2);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas,
      Liberation Mono, monospace;
  }

  pre {
    padding: 8px;
    margin: 0.2em 0;
    font-size: 85%;
    line-height: 1.4;
    background-color: rgba(175, 184, 193, 0.2);
    border-radius: 4px;

    code {
      padding: 0;
      margin: 0;
      background-color: transparent;
      border: 0;
      // display: block; // Make code block occupy a single line
      width: 100%;
      // Allow code to wrap
      white-space: pre-wrap;
      // Ensure long words can wrap
      word-wrap: break-word;
    }
  }

  // Quote styles
  blockquote {
    margin: 0.2em 0;
    padding: 0 0.5em;
    color: #656d76;
    border-left: 0.2em solid #d0d7de;
  }

  // Table styles
  table {
    margin: 0.2em 0;
    border-spacing: 0;
    border-collapse: collapse;
    width: 100%;

    th,
    td {
      padding: 4px 8px;
      border: 1px solid #d0d7de;
    }

    tr {
      background-color: #ffffff;
      border-top: 1px solid #d0d7de;

      &:nth-child(2n) {
        background-color: #f6f8fa;
      }
    }
  }

  // Image styles
  img {
    max-width: 100%;
    height: auto;
    margin: 0.2em 0;
  }

  // Divider styles
  hr {
    height: 1px;
    margin: 0.2em 0;
    background-color: #d0d7de;
    border: 0;
  }

  // Link styles
  a {
    color: #0969da;
    text-decoration: none;

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

  // Specifically handle spaces created by line breaks
  br {
    // Changed to inline display
    display: inline;
    // Preserve line break effect
    white-space: pre;
    margin: 0;
    padding: 0;
    height: 0.3em;
    visibility: visible;
  }

  // Handle consecutive line breaks
  br+br {
    display: none;
  }

  // Handle line breaks in paragraphs
  p {
    br {
      display: inline;
      white-space: pre;
      height: 0.3em;
    }
  }

  // Handle line breaks in list items
  li {
    br {
      display: inline;
      white-space: pre;
      height: 0.3em;
    }
  }

  // Task list styles
  input[type="checkbox"] {
    margin: 0 0.3em 0 0;
    vertical-align: middle;
  }

  // Task list item styles
  li:has(input[type="checkbox"]) {
    list-style: none;
    margin-left: -1.2em;
    padding-left: 1.2em;
    display: flex;
    align-items: flex-start;
    gap: 0.2em;

    p {
      margin: 0;
      flex: 1;
    }
  }

  // Remove extra spacing from first and last elements
  *:first-child {
    margin-top: 0;
  }

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

.thinkingContent {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
}

.thinkingDots {
  display: flex;
  gap: 4px;
  margin-left: 4px;

  span {
    width: 6px;
    height: 6px;
    background-color: #666;
    border-radius: 50%;
    animation: thinking 1.4s infinite ease-in-out;

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

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

    &:nth-child(3) {
      animation-delay: 0.4s;
    }
  }
}

.thinkingText {
  font-size: 14px;
}

@keyframes thinking {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.6;
  }

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

.responseGroup {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.response {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.subMessages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clarificationMessage {
  border-radius: 20px;
  opacity: 1;
  background: var(--message-clarification-bg);
  padding: 11px 12px;
  margin-bottom: 12px;

  .question {
    font-family: PingFang SC;
    font-size: 14px;
    font-weight: normal;
    line-height: 20px;
    letter-spacing: 0px;
    font-variation-settings: "opsz" auto;
    color: var(--text-secondary);
    margin-bottom: 12px;
  }

  .options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;

    .option {
      width: 100%;
      border-radius: 12px;
      opacity: 1;
      background: var(--message-option-bg);
      box-sizing: border-box;
      border: 1px solid var(--message-option-border);
      padding: 10px 30px;
      text-align: left;
      cursor: pointer;
      transition: all 0.2s ease;
      color: var(--text-primary);

      &:hover {
        background: var(--message-option-bg-hover);
        border-color: #2563eb;
      }

      &.selected {
        background: var(--message-option-bg-hover);
        border-color: #2563eb;
        color: #2563eb;
      }

      &:disabled {
        cursor: not-allowed;
        opacity: 0.5;
      }
    }
  }

  .confirmButton {
    margin-top: 12px;
    padding: 8px 16px;
    border-radius: 8px;
    background: #2563eb;
    color: var(--text-primary);
    border: none;
    cursor: pointer;
    float: right;

    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    &:hover:not(:disabled) {
      background: #1d4ed8;
    }
  }
}

.collapsibleContent {
  position: relative;
}

.gradientWrapper {
  position: relative;
  height: 30px;
  background: linear-gradient(to bottom,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.1) 50%,
      rgba(255, 255, 255, 0.3) 100%);
}

.collapseButton {
  width: 100%;
  height: 30px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow {
  color: #666;
  font-size: 12px;
  transition: transform 0.2s ease;
}

.arrow.up {
  transform: rotate(-90deg);
}

.arrow.down {
  transform: rotate(90deg);
}

/* Mouse hover effect */
.collapseButton:hover .arrow {
  color: #333;
}

