// 品牌色
$brand-color: #0055AA;
$brand-color-light: #EBF5FF;
$brand-color-hover: #004488;

.ai-chat-container {
    display: flex;
    height: 100%;
    background: #f8fafc;
    position: relative;
    overflow: hidden;
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
}

// ==================== 折叠状态的历史栏 ====================
.history-collapsed {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 48px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    z-index: 10;

    .history-toggle-btn {
        padding: 8px;
        color: #64748b;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
        margin-bottom: 8px;

        &:hover {
            color: $brand-color;
            background: $brand-color-light;
        }
    }

    .history-icons {
        flex: 1;
        overflow-y: auto;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 8px 0;
    }

    .history-icon-btn {
        padding: 8px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
            color: #64748b;
            background: #f1f5f9;
        }

        &.active {
            color: $brand-color;
            background: $brand-color-light;
        }
    }

    .expand-btn {
        padding: 8px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
            color: #64748b;
            background: #f1f5f9;
        }
    }
}

// ==================== 展开时的关闭按钮 ====================
.history-close-btn {
    position: absolute;
    left: 256px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: none;
    border-radius: 0 8px 8px 0;
    padding: 8px;
    cursor: pointer;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    color: #64748b;

    &:hover {
        background: #f8fafc;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
    }
}

// ==================== 历史对话侧边栏 ====================
.history-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    z-index: 10;
    transition: all 0.3s ease;
    overflow: hidden;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);

    &.open {
        width: 256px;
    }

    .sidebar-inner {
        width: 256px;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .sidebar-header {
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        border-bottom: 1px solid #f1f5f9;

        .title {
            font-weight: 500;
            color: #1e293b;
        }

        .new-chat-btn {
            padding: 6px;
            color: #64748b;
            background: transparent;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;

            &:hover {
                color: $brand-color;
                background: $brand-color-light;
            }
        }
    }

    .conversation-list {
        flex: 1;
        overflow-y: auto;
        padding: 8px;

        .empty-tip {
            padding: 16px;
            text-align: center;
            color: #94a3b8;
            font-size: 14px;
        }
    }

    .conversation-item {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        padding: 10px 12px;
        margin-bottom: 4px;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
            background: #f8fafc;

            .delete-btn {
                opacity: 1;
            }
        }

        &.active {
            background: $brand-color-light;
            color: $brand-color;
        }

        .conv-icon {
            flex-shrink: 0;
            margin-top: 2px;
        }

        .conv-info {
            flex: 1;
            min-width: 0;
        }

        .conv-title {
            font-size: 14px;
            font-weight: 500;
            color: #374151;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .conv-time {
            font-size: 12px;
            color: #94a3b8;
            margin-top: 2px;
        }

        .delete-btn {
            padding: 4px;
            color: #94a3b8;
            background: transparent;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            opacity: 0;
            transition: all 0.2s;

            &:hover {
                color: #ef4444;
            }
        }
    }
}

// ==================== 主聊天区域 ====================
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: all 0.3s ease;
    margin-left: 48px;

    &.sidebar-open {
        margin-left: 256px;
    }
}

// ==================== 消息容器 ====================
.messages-container {
    flex: 1;
    overflow-y: auto;
}

// ==================== 空状态 ====================
.empty-state {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;

    .empty-content {
        text-align: center;
        max-width: 600px;
    }

    .logo-wrapper {
        width: 80px;
        height: 80px;
        background: linear-gradient(135deg, $brand-color 0%, $brand-color-hover 100%);
        border-radius: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 24px;
        box-shadow: 0 8px 24px rgba($brand-color, 0.3);

        .logo-icon {
            font-size: 40px;
            color: #fff;
        }
    }

    .title {
        font-size: 24px;
        font-weight: 700;
        color: #1e293b;
        margin: 0 0 8px;
    }

    .desc {
        font-size: 14px;
        color: #64748b;
        margin: 0 0 32px;
        line-height: 1.6;
    }

    .quick-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        max-width: 480px;
        margin: 0 auto;
    }

    .quick-card {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 16px;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.2s;
        text-align: left;

        &:hover {
            border-color: $brand-color;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }

        .quick-icon {
            width: 36px;
            height: 36px;
            background: $brand-color-light;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: $brand-color;
            transition: all 0.2s;
        }

        &:hover .quick-icon {
            background: $brand-color;
            color: #fff;
        }

        .quick-label {
            font-size: 14px;
            font-weight: 500;
            color: #374151;
        }
    }
}

// ==================== 消息列表 ====================
.messages-list {
    margin: 0 auto;
    padding: 24px 16px;

    .chat-header {
        text-align: center;
        padding: 16px 0 24px;
        border-bottom: 1px solid #f1f5f9;
        margin-bottom: 24px;

        .chat-title {
            font-size: 18px;
            font-weight: 600;
            color: #1e293b;
            margin: 0;
        }
    }

    .message-row {
        display: flex;
        gap: 12px;
        margin-bottom: 24px;

        &.user {
            flex-direction: row-reverse;

            .message-content {
                align-items: flex-end;
            }

            .message-bubble {
                background: $brand-color;
                color: #fff;
                border-radius: 16px 16px 4px 16px;
            }

            .message-time {
                text-align: right;
            }
        }
    }

    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;

        &.user {
            background: $brand-color;
            color: #fff;
        }

        &.assistant {
            background: linear-gradient(135deg, $brand-color 0%, $brand-color-hover 100%);
            color: #fff;
        }
    }

    .message-content {
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-width: 80%;

        &.user {
            align-items: flex-end;
        }
    }

    .message-bubble {
        padding: 12px 16px;
        border-radius: 16px 16px 16px 4px;
        background: #fff;
        border: 1px solid #f1f5f9;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

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

        .typing-cursor {
            display: inline-block;
            animation: blink 0.8s infinite;
            color: $brand-color;
            font-weight: bold;
        }

        .loading-dots {
            display: flex;
            gap: 4px;
            padding: 4px 0;

            span {
                width: 6px;
                height: 6px;
                background: #94a3b8;
                border-radius: 50%;
                animation: bounce 1.4s infinite ease-in-out both;

                &:nth-child(1) { animation-delay: -0.32s; }
                &:nth-child(2) { animation-delay: -0.16s; }
                &:nth-child(3) { animation-delay: 0s; }
            }
        }
    }

    .message-time {
        font-size: 12px;
        color: #94a3b8;
    }

    // 用户消息气泡中的样式
    .message-row.user .message-bubble {
        .message-time {
            color: rgba(255, 255, 255, 0.7);
        }
    }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

// ==================== 快捷命令栏 ====================
.quick-bar {
    padding: 8px 16px;
    border-top: 1px solid #f1f5f9;
    background: #fff;

    .quick-bar-inner {
        margin: 0 auto;
        display: flex;
        gap: 8px;
        overflow-x: auto;

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

    .quick-pill {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 20px;
        font-size: 12px;
        color: #64748b;
        cursor: pointer;
        white-space: nowrap;
        transition: all 0.2s;

        &:hover {
            border-color: $brand-color;
            background: $brand-color-light;
            color: $brand-color;
        }

        .el-icon {
            color: $brand-color;
        }
    }
}

// ==================== 输入区域 ====================
.input-area {
    padding: 24px;
    background: #f8fafc;

    .input-wrapper {
        margin: 0 auto;
    }

    .input-card {
        background: #fff;
        border-radius: 16px;
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
        border: 1px solid #e2e8f0;
        overflow: hidden;
    }

    .input-row {
        display: flex;
        align-items: flex-end;
        gap: 8px;
        padding: 12px 16px;
    }

    .chat-textarea {
        flex: 1;
        border: none;
        outline: none;
        resize: none;
        font-size: 14px;
        color: #374151;
        background: transparent;
        line-height: 1.5;
        max-height: 120px;
        min-height: 24px;

        &::placeholder {
            color: #94a3b8;
        }
    }

    .tool-btn {
        padding: 8px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
        flex-shrink: 0;

        &:hover {
            color: #64748b;
            background: #f1f5f9;
        }

        &.uploading {
            cursor: not-allowed;
            opacity: 0.6;
        }

        .spin {
            animation: spin 1s linear infinite;
        }
    }

    .send-btn {
        padding: 10px;
        background: #e2e8f0;
        color: #94a3b8;
        border: none;
        border-radius: 12px;
        cursor: not-allowed;
        transition: all 0.2s;
        flex-shrink: 0;

        &.active {
            background: $brand-color;
            color: #fff;
            cursor: pointer;
            box-shadow: 0 2px 8px rgba($brand-color, 0.3);

            &:hover {
                background: $brand-color-hover;
            }
        }
    }

    .disclaimer {
        text-align: center;
        font-size: 12px;
        color: #94a3b8;
        margin: 12px 0 0;
    }
}

// ==================== Markdown样式 ====================
.message-bubble {
    // 粗体
    strong {
        font-weight: 600;
        color: inherit;
    }

    // 斜体
    em {
        font-style: italic;
    }

    // 行内代码
    .inline-code {
        background: rgba(0, 0, 0, 0.05);
        padding: 2px 6px;
        border-radius: 4px;
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        font-size: 13px;
        color: #e53e3e;
    }

    // 代码块
    .code-block {
        background: rgba(0, 0, 0, 0.05);
        padding: 12px;
        border-radius: 8px;
        overflow-x: auto;
        margin: 8px 0;

        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 13px;
            line-height: 1.5;
            color: #334155;
        }
    }

    // 链接
    .md-link {
        color: $brand-color;
        text-decoration: underline;

        &:hover {
            color: $brand-color-hover;
        }
    }

    // 标题
    .md-h1 {
        font-size: 20px;
        font-weight: 700;
        margin: 12px 0 8px;
        color: inherit;
    }

    .md-h2 {
        font-size: 18px;
        font-weight: 600;
        margin: 10px 0 6px;
        color: inherit;
    }

    .md-h3 {
        font-size: 16px;
        font-weight: 600;
        margin: 8px 0 4px;
        color: inherit;
    }

    // 列表
    .md-ul, .md-ol {
        margin: 8px 0;
        padding-left: 20px;
    }

    .md-li {
        margin: 4px 0;
        line-height: 1.6;
    }
}

// 用户消息中的markdown样式（白色背景）
.message-bubble.user {
    .inline-code {
        background: rgba(255, 255, 255, 0.2);
        color: #fff;
    }

    .code-block {
        background: rgba(255, 255, 255, 0.15);

        code {
            color: #fff;
        }
    }

    .md-link {
        color: #fff;
        text-decoration: underline;
    }
}

// ==================== 文件上传相关样式 ====================
.uploaded-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
}

.uploaded-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    max-width: 200px;

    .file-preview {
        width: 32px;
        height: 32px;
        border-radius: 4px;
        overflow: hidden;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;

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

        &.document {
            background: $brand-color-light;
            color: $brand-color;
        }
    }

    .file-name {
        flex: 1;
        font-size: 12px;
        color: #374151;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .remove-file-btn {
        padding: 4px;
        color: #94a3b8;
        background: transparent;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.2s;
        flex-shrink: 0;

        &:hover {
            color: #ef4444;
            background: #fef2f2;
        }
    }
}

// 消息气泡外的文件样式
.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.message-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    max-width: 220px;
    text-decoration: none;
    color: #374151;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);

    &:hover {
        border-color: $brand-color;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .file-preview {
        width: 36px;
        height: 36px;
        border-radius: 6px;
        overflow: hidden;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;

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

        &.document {
            background: $brand-color-light;
            color: $brand-color;
        }
    }

    .file-name {
        flex: 1;
        font-size: 13px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
