.inboxPage {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.pageContent {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 32px 28px;
}

.summaryRow {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 18px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 13px;
}

.inboxTabs {
  :global(.ant-tabs-nav) {
    margin-bottom: 20px;
  }

  :global(.ant-tabs-tab) {
    padding: 12px 0;
    font-weight: 500;
  }
}

.tabLabel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.tabContent {
  padding-bottom: 8px;

  :global(.ant-empty) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 220px);
  }
}

.messagesToolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.messagesSelectionTools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.selectedCountText {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
}

.cardList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.paginationWrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.harvestGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 24px;
}

.messageDetail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.messageDetailMeta {
  :global(.ant-descriptions-item-label) {
    width: 140px;
  }
}

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

.messageDetailLabel {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
}

.messageDetailContent,
.messageDetailPayload {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fafafa;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.traceLoading,
.traceEmpty {
  padding: 12px;
  border-radius: 8px;
  border: 1px dashed rgba(0, 0, 0, 0.15);
  color: rgba(0, 0, 0, 0.55);
  margin: auto;
}

.traceTimeline {
  display: flex;
  flex-direction: column;
}

.traceContainer {
  max-height: 420px;
  overflow: auto;
}

.traceEntry {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0;
}

.traceCollapse {
  border: none;
  border-radius: 8px;
  background: transparent;
  transition: background 0.2s ease;

  &:hover {
    background: rgba(0, 0, 0, 0.02);
  }

  :global(.ant-collapse-item) {
    border: none !important;
    border-radius: 8px !important;
    overflow: hidden;
    background: transparent !important;
  }

  :global(.ant-collapse-header) {
    padding: 8px 10px 8px 6px !important;
    align-items: flex-start !important;
  }

  :global(.ant-collapse-content) {
    border-top: none !important;
    background: transparent !important;
  }

  :global(.ant-collapse-content-box) {
    padding: 0 10px 10px 6px !important;
  }
}

.traceCollapseActive {
  background: #f6f6f6;
}

.traceFoldHeader {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.traceFoldIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.5);
  font-size: 14px;
}

.traceFoldTitle {
  font-weight: 500;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.85);
}

.traceInlineChevron {
  display: inline-flex;
  align-items: center;
  color: rgba(0, 0, 0, 0.45);
  font-size: 12px;
  opacity: 0;
  transform: rotate(0deg);
  transition:
    opacity 0.15s ease,
    transform 0.2s ease;
}

.traceCollapse:hover .traceInlineChevron,
.traceCollapseActive .traceInlineChevron {
  opacity: 1;
}

.traceInlineChevronActive {
  transform: rotate(180deg);
}

.traceFoldTime {
  margin-left: auto;
  color: rgba(0, 0, 0, 0.42);
  font-size: 12px;
}

.traceAssistantMessage {
  font-size: 14px;
  line-height: 1.65;
  color: rgba(0, 0, 0, 0.88);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;

  :global(p),
  :global(ul),
  :global(ol),
  :global(blockquote),
  :global(pre) {
    margin: 0;
  }

  :global(p + p),
  :global(p + ul),
  :global(p + ol),
  :global(ul + p),
  :global(ol + p),
  :global(ul + ul),
  :global(ol + ol) {
    margin-top: 6px;
  }

  :global(ul),
  :global(ol) {
    padding-left: 22px;
  }

  :global(li) {
    margin: 0;
    line-height: 1.6;
  }

  :global(li + li) {
    margin-top: 4px;
  }
}

.traceUserRow {
  display: flex;
  justify-content: flex-end;
  padding-right: 10px;
}

.traceUserMessage {
  max-width: min(82%, 680px);
  background: var(--color-fill-tertiary, rgba(43, 18, 0, 0.06));
  color: var(--colorText, rgba(26, 23, 22, 0.88));
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.6;
  border: 1px solid var(--colorBorderSecondary, rgba(0, 0, 0, 0.06));
  white-space: pre-wrap;
  word-break: break-word;
}

.traceStandaloneAligned {
  margin-left: 6px;
  margin-right: 10px;
}

.toolDetailWrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolSection {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.traceCodeHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: #f5f5f5;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.traceCodeTitle {
  font-size: 12px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.65);
}

.traceCodeCopyBtn {
  border: none;
  background: transparent;
  color: rgba(0, 0, 0, 0.5);
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
  padding: 2px;

  &:hover {
    color: rgba(0, 0, 0, 0.8);
  }
}

.traceJsonBlock {
  margin: 0;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.traceJsonBlock {
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
}

.toolCodeBlock {
  margin: 0;
  border-radius: 0;
  border: none;
  background: #fff;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

.traceMarkdownBlock {
  font-size: 13px;
  line-height: 1.75;

  :global(.markdown > p),
  > :global(p) {
    margin: 0 0 8px;
  }

  :global(p:last-child) {
    margin-bottom: 0;
  }

  :global(pre) {
    margin: 8px 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    overflow-x: auto;
  }

  :global(code) {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
      "Liberation Mono", "Courier New", monospace;
  }
}

@media (max-width: 960px) {
  .pageContent {
    padding: 14px;
  }

  .inboxTabs {
    padding: 0;
  }

  .harvestGrid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .tabContent {
    min-height: 280px;
  }
}

/* ─── Dark mode ─────────────────────────────────────────────────────────────── */
:global(.dark-mode) {
  .inboxPage {
    background: #141414;
  }

  .inboxTabs {
    background: transparent;
  }

  .selectedCountText,
  .messageDetailLabel,
  .traceLoading,
  .traceEmpty,
  .summaryRow {
    color: rgba(255, 255, 255, 0.55);
  }

  .messageDetailContent,
  .messageDetailPayload {
    background: #1f1f1f;
    border-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.82);
  }

  .traceLoading,
  .traceEmpty {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.02);
  }

  .traceCollapse:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .traceCollapseActive {
    background: rgba(255, 255, 255, 0.06);
  }

  .traceFoldIcon {
    color: rgba(255, 255, 255, 0.55);
  }

  .traceFoldTitle,
  .traceAssistantMessage {
    color: rgba(255, 255, 255, 0.85);
  }

  .traceInlineChevron,
  .traceFoldTime {
    color: rgba(255, 255, 255, 0.5);
  }

  .toolSection,
  .traceJsonBlock,
  .traceMarkdownBlock :global(pre) {
    border-color: #3a3a3a;
    background: #1a1a1a;
  }

  .traceCodeHeader {
    background: #242424;
    border-bottom-color: #3a3a3a;
  }

  .traceCodeTitle {
    color: rgba(255, 255, 255, 0.7);
  }

  .traceCodeCopyBtn {
    color: rgba(255, 255, 255, 0.55);

    &:hover {
      color: rgba(255, 255, 255, 0.85);
    }
  }

  .traceJsonBlock,
  .toolCodeBlock,
  .traceMarkdownBlock {
    color: rgba(255, 255, 255, 0.82);
  }

  .toolCodeBlock {
    background: #1a1a1a;
  }

  .traceUserMessage {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.15);
  }
}

@media (max-width: 768px) {
  .pageContent {
    padding: 0 16px 20px;
  }

  .inboxTabs {
    :global(.ant-tabs-nav) {
      overflow-x: auto;
      white-space: nowrap;

      &::-webkit-scrollbar {
        display: none;
      }
    }

    :global(.ant-tabs-tab) {
      flex-shrink: 0;
    }
  }

  .messagesToolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .messagesSelectionTools {
    flex-wrap: wrap;
    width: 100%;

    :global(.ant-select) {
      width: 100% !important;
    }

    :global(.ant-btn) {
      flex-shrink: 0;
    }
  }

  .harvestGrid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .paginationWrap {
    justify-content: center;
  }
}
