* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'AlibabaPuHuiTi';
    src: url('../fonts/alibaba-puhuiti-regular.woff2') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

body {
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f5f5;
    height: 100vh;
    margin: 0;
    padding: 20px;
}

.as-chat-container {
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    height: 100vh;
    flex: 1;
    /* 充满父容器的剩余空间 */
    max-width: 1200px;
    margin: auto;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.as-chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
}

.as-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.as-avatar {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.as-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
}

.tag {
    font-size: 12px;
    color: #666;
    background-color: #f5f5f5;
    padding: 2px 8px;
    border-radius: 4px;
}

.as-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    width: 100%;
    padding-top: 40px;
}

.message {
    position: relative;
    display: flex;
    margin-bottom: 24px;
    gap: 16px;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-content {
    position: relative;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    display: flex;
    flex-direction: column;
}

.user .message-content {
    background-color: white;
    color: #333;
    border: 1px solid #e5e5e5;
}

.ai .message-content {
    background-color: #f5f5f5;
    color: #1a1a1a;
}

.as-chat-input-container {
    padding: 16px 24px;
    border-top: 1px solid #e5e5e5;
}

.as-input-wrapper {
    position: relative;
    margin-bottom: 8px;
}

.as-bottom-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.as-left-tools {
    display: flex;
    gap: 8px;
}

.as-right-tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.action-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: #666;
    transition: all 0.3s;
}

.action-button:hover {
    background-color: #f5f5f5;
    color: #2b7fff;
}

.as-primary-button {
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    min-width: 64px;
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    border: none;
}

.as-primary-button:hover {
    background-color: #1a6cd6;
}

#as-user-input {
    width: 100%;
    padding: 12px;
    padding-right: 0;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    resize: none;
    outline: none;
    transition: border-color 0.3s;
    min-height: 44px;
    max-height: 200px;
    overflow-y: hidden;
}

#as-user-input:focus {
    border-color: #2b7fff;
    overflow-y: auto;
}

.button-container {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 8px;
}

#as-send-button {
    background-color: #333;
    color: white;
}

#as-send-button:hover {
    background-color: #1a1a1a;
}

#as-stop-button {
    background-color: #ff4d4f;
    color: white;
}

#as-stop-button:hover {
    background-color: #ff7875;
}

.hidden {
    display: none !important;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
}

.tool-button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.7;
    transition: opacity 0.3s;
    padding: 4px;
}

.tool-button:hover {
    opacity: 1;
    background-color: #f5f5f5;
    border-radius: 4px;
}

.emoji-picker {
    position: relative;
}

.emoji-button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .as-container {
        height: 100vh;
        border-radius: 0;
    }

    .message-content {
        max-width: 90%;
    }
}

.as-right-tools button {
    margin: 0;
}

#as-clear-chat,
#as-clear-input {
    background-color: transparent;
    color: #333;
    border: 1px solid #e5e5e5;
}

#as-clear-chat:hover,
#as-clear-input:hover {
    background-color: #f5f5f5;
}

.as-right-tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.expanded {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1000;
    background: white;
    transform: none;
    padding: 20px;
    border-radius: 0;
}

.expanded #as-user-input {
    height: calc(100% - 40px) !important;
    max-height: none !important;
    resize: none;
}

.expanded .top-actions {
    position: fixed;
    top: 20px;
    right: 20px;
}

.expanded::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: -1;
}

/* 消息时间样式 */
.message-time {
    position: absolute;
    top: -20px;
    font-size: 12px;
    color: #999;
    line-height: 1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

/* AI消息时间靠左 */
.ai .message-time {
    left: 40px;
}

/* 用户消息时间靠右 */
.user .message-time {
    right: 40px;
}

/* 鼠标悬停时显示时间 */
.message:hover .message-time {
    opacity: 1;
    visibility: visible;
}

/* 删除之前的所有箭头相关样式 */
.time-tooltip,
.time-tooltip::after,
.message-time::after {
    display: none;
}

/* 添加小三角 */
.message-time::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px 4px 0 4px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.75) transparent transparent transparent;
}

/* 悬浮时显示时间 */
.message:hover .message-time {
    opacity: 1;
    visibility: visible;
}

/* 消息操作按钮容器 - 修改位置到消息框外部 */
.message-actions {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.2s;
}

/* AI消息的复制按钮位置（右侧） */
.ai .message-actions {
    left: calc(100% + 8px);
}

/* 用户消息的复制按钮位置（左侧） */
.user .message-actions {
    right: calc(100% + 8px);
}

/* 复制按钮样式 */
.copy-button {
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    padding: 0;
}

.copy-button:hover {
    color: #2b7fff;
}

/* 显示复制按钮 */
.message:hover .message-actions {
    opacity: 1;
}

/* 加载动画 */
@keyframes loading {
    0% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.7;
    }

    100% {
        opacity: 0.3;
    }
}

.message-content.loading {
    position: relative;
    min-width: 60px;
    min-height: 24px;
}

.message-content.loading::after {
    content: '...';
    position: absolute;
    left: 16px;
    top: 12px;
    animation: loading 1.5s infinite;
    font-size: 14px;
    letter-spacing: 2px;
}

/* 确保加载状态下的文本不会显示 */
.message-content.loading:empty {
    background-color: #f5f5f5;
}

/* 加载指示器样式 */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #f5f5f5;
    border-radius: 8px;
    margin-bottom: 8px;
}

.typing-indicator span {
    width: 4px;
    height: 4px;
    background: #666;
    border-radius: 50%;
    animation: typing 1.4s infinite;
    opacity: 0.3;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }
}

/* 模式切换按钮样式 */
.mode-toggle-button {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 100px;
    padding: 6px 12px;
    transition: all 0.3s ease;
}

.mode-icon {
    font-size: 16px;
}

.mode-text {
    font-size: 14px;
}

/* 流式模式样式 */
.mode-toggle-button.streaming-mode {
    background-color: #2b7fff;
}

.mode-toggle-button.streaming-mode:hover {
    background-color: #1a6cd6;
}

/* 块式模式样式 */
.mode-toggle-button.blocking-mode {
    background-color: #666;
}

.mode-toggle-button.blocking-mode:hover {
    background-color: #555;
}

/* 添加动画效果 */
.mode-toggle-button .mode-icon {
    transition: transform 0.3s ease;
}

.mode-toggle-button:hover .mode-icon {
    transform: scale(1.2);
}

/* 附加内容样式 */
.append-contents {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* 图片样式 */
.append-image {
    margin: 5px 0;
    max-width: 100%;
    border-radius: 8px;
    cursor: zoom-in;
    transition: transform 0.3s ease;
}

.append-image:hover {
    transform: scale(1.02);
}

/* PDF 容器样式 */
.pdf-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 5px 0;
    padding: 12px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    width: 350px;
    max-width: 100%;
}

.pdf-icon {
    width: 24px;
    height: 24px;
}

.pdf-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pdf-name {
    font-size: 14px;
    color: #1a1a1a;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.pdf-size {
    font-size: 12px;
    color: #666;
}

.preview-button {
    padding: 6px 16px;
    background: #2b7fff;
    color: white;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.3s;
}

.preview-button:hover {
    background: #1a6cd6;
}

/* 图片预览相关样式 */
.image-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-preview-overlay.active {
    opacity: 1;
}

.image-preview-overlay img {
    max-width: 90%;
    max-height: 90vh;
    object-fit: contain;
}

.as-menu-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.as-toggle-questions {
    background-color: #a6a6a6;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    min-width: 64px;
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    width: 100%;
    display: none;
}

.as-question-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.as-menu-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 calc(20% - 8px);
    /* 每个 .as-menu-bar 占据 20% 的宽度，并减去间隙 */
}

.as-question-button {
    background-color: #a6a6a6;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    min-width: 64px;
    font-family: 'AlibabaPuHuiTi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    width: 100%;
    /* 让按钮充满 .as-menu-bar */
}

.as-question-button:hover {
    background-color: #1a6cd6;
}

.menu-bar {
    position: relative;
}

.menu-content {
    position: absolute;
    bottom: 100%;
    /* 显示在按钮上方 */
    left: 0;
    background-color: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    white-space: nowrap;
    /* 防止文本换行 */
    min-width: 200px;
    /* 设置最小宽度 */
    padding: 8px;
    transform: translateY(-8px);
}

.menu-content.hidden {
    display: none;
    /* 确保 hidden 类也是隐藏的 */
}

.menu-content:not(.hidden) {
    display: block;
    /* 显示菜单内容 */
}

.menu-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    color: #1a1a1a;
    transition: background-color 0.3s;
    display: block;
    /* 使每个项目占据一整行 */
    width: 100%;
    /* 宽度占满容器 */
    text-align: left;
    /* 文本左对齐 */
    border-radius: 4px;
    /* 添加圆角 */
}

.menu-item:not(:last-child) {
    margin-bottom: 4px;
    /* 项目之间添加间距 */
}

.menu-item:hover {
    background-color: #f5f5f5;
}

/* 确保菜单不会超出屏幕 */
@media (max-width: 768px) {
    .menu-content {
        min-width: 150px;
        /* 移动端稍微减小最小宽度 */
        max-width: calc(100vw - 32px);
        /* 防止超出屏幕 */
    }
}

@media (max-width: 768px) {
    .pdf-container {
        width: 100%;
        padding: 8px;
    }

    .pdf-icon {
        width: 20px;
        height: 20px;
    }

    .preview-button {
        padding: 4px 12px;
        font-size: 12px;
    }
}

/* 添加禁用状态的样式 */
.as-primary-button:disabled {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
    opacity: 0.7;
    border: 1px solid #e5e5e5;
}

/* 添加过渡效果 */
.as-primary-button {
    transition: all 0.3s ease;
}

/* 清空会话按钮禁用状态 */
#as-clear-chat:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

/* 确认对话框样式 */
.confirm-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.confirm-dialog-overlay.active {
    opacity: 1;
}

.confirm-dialog {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.confirm-dialog.active {
    transform: translateY(0);
}

.confirm-dialog-content {
    margin-bottom: 20px;
    font-size: 16px;
    color: #333;
    text-align: center;
}

.confirm-dialog-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.confirm-dialog-button {
    padding: 8px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.confirm-button {
    background-color: #ff4d4f;
    color: white;
}

.confirm-button:hover {
    background-color: #ff7875;
}

.cancel-button {
    background-color: #f0f0f0;
    color: #666;
}

.cancel-button:hover {
    background-color: #d9d9d9;
}

/* 移动端适配样式 */


@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .as-chat-container {
        height: 100vh;
        border-radius: 0;
    }

    /* 优化菜单容器布局 */
    .as-menu-container {
        flex-wrap: wrap;
        /* 允许菜单按钮换行 */
        gap: 6px;
        /* 减小间距 */
        padding: 8px;
    }

    .menu-bar {
        flex: 1 1 auto;
        /* 允许菜单按钮伸缩 */
        min-width: calc(50% - 6px);
        /* 确保每行最多两个按钮 */
    }

    .as-question-button {
        width: 100%;
        /* 按钮占满容器宽度 */
        padding: 8px 12px;
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 优化菜单内容显示 */
    .menu-content {
        min-width: 200px;
        max-width: calc(100vw - 32px);
        bottom: calc(100% + 4px);
        left: 50%;
        transform: translateX(-50%) translateY(-4px);
    }

    /* 优化输入区域 */
    .as-chat-input-container {
        padding: 8px;
    }

    .as-input-wrapper {
        margin-bottom: 6px;
    }

    #as-user-input {
        padding: 10px;
        font-size: 14px;
        max-height: 120px;
        /* 限制移动端输入框最大高度 */
    }

    /* 优化底部按钮布局 */
    .as-bottom-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .as-right-tools {
        width: 100%;
        justify-content: flex-end;
        gap: 6px;
    }

    .as-primary-button {
        padding: 6px 12px;
        font-size: 13px;
        min-width: auto;
        /* 移除最小宽度限制 */
    }

    /* 优化消息显示 */
    .message {
        margin-bottom: 16px;
        gap: 8px;
    }

    .message-content {
        max-width: calc(100% - 40px);
        /* 考虑头像和间距 */
        padding: 10px 12px;
        font-size: 14px;
    }

    .as-avatar {
        width: 28px;
        height: 28px;
    }

    /* 优化 PDF 容器显示 */
    .pdf-container {
        width: 100%;
        padding: 8px;
    }

    .pdf-icon {
        width: 20px;
        height: 20px;
    }

    .pdf-info {
        font-size: 12px;
    }

    .preview-button {
        padding: 4px 12px;
        font-size: 12px;
    }

    /* 优化确认对话框 */
    .confirm-dialog {
        width: calc(100% - 32px);
        max-width: none;
        margin: 0 16px;
        padding: 16px;
    }

    .confirm-dialog-content {
        font-size: 14px;
    }

    .confirm-dialog-button {
        padding: 6px 16px;
        font-size: 13px;
    }

    /* 优化复制按钮位置 */
    .message-actions {
        opacity: 1;
        /* 在移动端始终显示复制按钮 */
    }

    .copy-button {
        width: 24px;
        height: 24px;
    }
}

/* 针对超小屏幕的优化 */
@media (max-width: 360px) {
    .menu-bar {
        min-width: 100%;
        /* 在超小屏幕上每个按钮占据整行 */
    }

    .as-right-tools {
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .as-right-tools button {
        flex: 1 1 auto;
        min-width: calc(50% - 4px);
        /* 确保按钮合理分布 */
    }
}

/* 针对横屏模式的优化 */
@media (max-height: 500px) and (orientation: landscape) {
    .as-chat-container {
        height: 100vh;
    }

    .as-chat-messages {
        height: calc(100vh - 180px);
    }

    #as-user-input {
        max-height: 80px;
    }

    .as-menu-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px;
        -webkit-overflow-scrolling: touch;
    }

    .menu-bar {
        flex: 0 0 auto;
    }
}