/**
 * css 书写规范
 * https://alidocs.dingtalk.com/i/nodes/Mk5evdR04jBV523gq4AgJQL3x2OlParn
 */
@import '~@cainiaofe/cn-ui-theme-light/token.scss';
@import '../../styles/markdown.scss';

.cn-ai-chat-shell {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;

  // -------------------------------------------------------------------------
  // Header slot
  // -------------------------------------------------------------------------
  &__header {
    flex-shrink: 0;
  }

  // -------------------------------------------------------------------------
  // Message area (scrollable)
  // -------------------------------------------------------------------------
  &__messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 12px 24px;

    // 隐藏滚动条
    scrollbar-width: none;
    -ms-overflow-style: none;

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

    // 顶部和底部内容渐隐遮罩
    -webkit-mask-image: linear-gradient(
      to bottom,
      transparent 0,
      black 20px,
      black calc(100% - 20px),
      transparent 100%
    );
    mask-image: linear-gradient(
      to bottom,
      transparent 0,
      black 20px,
      black calc(100% - 20px),
      transparent 100%
    );
  }

  // -------------------------------------------------------------------------
  // History loading indicator
  // -------------------------------------------------------------------------
  &__history-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    color: #999;
    font-size: 12px;
    flex-shrink: 0;

    &::before {
      content: '';
      display: inline-block;
      width: 14px;
      height: 14px;
      margin-right: 6px;
      border: 2px solid #e0e0e0;
      border-top-color: #999;
      border-radius: 50%;
      animation: cn-ai-chat-shell-spin 0.6s linear infinite;
    }
  }

  &__history-no-more {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 0;
    color: #c0c0c0;
    font-size: 12px;
    flex-shrink: 0;
  }

  // -------------------------------------------------------------------------
  // 历史消息与当前会话分割线（加载历史后出现）
  // -------------------------------------------------------------------------
  &__session-divider {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 0 4px;
    margin: 0;
  }

  &__session-divider-line {
    flex: 1 1 auto;
    height: 1px;
    background: #e7e8ed;
    min-width: 8px;
  }

  &__session-divider-text {
    flex-shrink: 0;
    font-size: 12px;
    line-height: 1.4;
    color: #999;
    font-weight: 500;
    letter-spacing: 0.02em;
  }

  @keyframes cn-ai-chat-shell-spin {
    to {
      transform: rotate(360deg);
    }
  }

  // -------------------------------------------------------------------------
  // Empty state
  // -------------------------------------------------------------------------
  &__empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #999;
    font-size: 14px;
  }

  // -------------------------------------------------------------------------
  // Message item
  // -------------------------------------------------------------------------
  &__message {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    min-width: 0;
    word-wrap: break-word;
    word-break: break-word;

    &--user {
      align-self: flex-end;
      align-items: flex-end;

      .cn-ai-chat-shell__message-text {
        background: #e5e8ff;
        color: #333;
        border-radius: 12px 0 12px 12px;
      }
    }

    &--assistant {
      align-self: flex-start;
      align-items: flex-start;

      .cn-ai-chat-shell__message-text {
        background: #f5f5f5;
        color: #333;
        border-radius: 12px 12px 12px 4px;
      }
    }
  }

  &__message-content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 8px 80px 20px 12px;

    @include markdown-content-styles-agent;

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;

      code {
        -webkit-text-fill-color: currentColor;
        color: #374151;
        background-clip: border-box;
      }
    }

    strong {
      background: linear-gradient(
        120deg,
        rgba(102, 126, 234, 0.1) 0%,
        rgba(118, 75, 162, 0.1) 100%
      );
      padding: 1px 4px;
      border-radius: 4px;
    }

    ul li::before {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }

    a {
      color: #667eea;
      border-bottom-color: rgba(102, 126, 234, 0.4);

      &:hover {
        color: #764ba2;
      }
    }

    code:not([class*='language-']) {
      background: #f6f8fa;
      padding: 0.2em 0.4em;
      border-radius: 6px;
      font-family:
        ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
      font-size: 85%;
      color: inherit;
    }
  }

  &__message-text {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.6;
  }

  // -------------------------------------------------------------------------
  // Quick Replies
  // -------------------------------------------------------------------------
  &__quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 80px 0 12px;
    align-self: flex-start;
  }

  &__quick-reply-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    font-size: 13px;
    line-height: 1.4;
    color: #333;
    background: #fff;
    border: 1px solid #e7e8ed;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;

    &:hover:not(:disabled) {
      color: #667eea;
      border-color: #667eea;
      background: rgba(102, 126, 234, 0.06);
    }

    &:active:not(:disabled) {
      transform: scale(0.97);
    }

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

  // -------------------------------------------------------------------------
  // Input area
  // -------------------------------------------------------------------------
  &__input-area {
    flex-shrink: 0;
    border-radius: 16px;
    padding: 12px;
    backdrop-filter: blur(25px);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #fff 60%);

    &-content {
      padding: 8px;
      border-radius: 16px;
      background: rgba(241, 241, 241, 0.8);
      backdrop-filter: blur(25px);
    }
  }

  &__sender.cn-sender-main {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e7e8ed;
    padding: 8px;
    box-sizing: border-box;
    transition: border-color 0.2s ease;

    &:focus-within {
      border-color: #8f6cff;
    }

    .cn-sender-content {
      margin: 0;
      padding: 0;
      min-height: 74px;
      align-items: flex-start;
    }

    .cn-sender-input-slot {
      font-size: 14px;
      padding: 4px 8px;
      line-height: 22px;

      &:empty::before {
        color: rgba(0, 0, 0, 0.25);
        line-height: 22px;
      }
    }

    .cn-sender-footer {
      margin: 0;
      padding: 0;
    }

    .cn-sender-header {
      margin: 0;
      padding: 0;
    }

    .cn-sender-actions-btn-record-icon svg {
      fill: #000000ec;
    }
  }

  &__sender-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }

  // -------------------------------------------------------------------------
  // Footer extra slot
  // -------------------------------------------------------------------------
  &__footer-extra {
    flex-shrink: 0;
  }
}
