// Universal Chat Module Styles
// Clean sidebar design - reference main project style

:root {
    // 使用主项目开放平台的 Sidebar 颜色规范
    --chat-bg-primary: #ffffff;
    --chat-bg-secondary: #ffffff;  // 白色背景，与主项目一致
    --chat-text-primary: #131212;   // 深灰近黑
    --chat-text-secondary: #5E5E66; // 默认文字色（加深）
    --chat-text-muted: $text-hint;
    --chat-border-color: #F3F4F6;   // 浅边框
    --chat-hover-bg: #F3F4F6;       // 悬停背景 = 激活背景
    --chat-active-bg: #F3F4F6;      // 激活背景
    --chat-accent-color: #10b981;
    --chat-btn-bg: #F3F4F6;         // 按钮背景（浅灰，弱干扰）
    --chat-btn-text: #5E5E66;       // 按钮文字（灰色，不抢眼）
    --chat-sidebar-width: 280px;
    --chat-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

// Main container
.universal-chat-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--chat-bg-primary);
    overflow: hidden;
}

// Sidebar
.chat-sidebar {
    width: var(--chat-sidebar-width);
    background: var(--chat-bg-secondary);
    border-right: 1px solid var(--chat-border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    &.collapsed {
        width: 80px;
    }
}

.chat-sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-border-color);

    .logo {
        font-size: 20px;
        font-weight: 700;
        color: var(--chat-text-primary);
        display: flex;
        align-items: center;
        gap: 8px;
    }
}

.chat-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    &::-webkit-scrollbar {
        display: none;
    }
}

// New chat button - 弱干扰灰色系
.new-chat-btn {
    width: calc(100% - 24px);
    margin: 12px;
    padding: 10px 16px;
    background: var(--chat-btn-bg);
    border: none;
    border-radius: 8px;
    color: var(--chat-btn-text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--chat-transition);

    &:hover {
        background: var(--chat-hover-bg);
        color: var(--chat-text-primary);
    }

    .anticon {
        font-size: 16px;
    }
}

// Collapsible menu
.collapsible-menu {
    margin-bottom: 8px;

    .menu-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        cursor: pointer;
        border-radius: 8px;
        transition: var(--chat-transition);

        &:hover {
            background: var(--chat-hover-bg);
        }

        .menu-header-left {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .menu-icon {
            font-size: 18px;
            color: var(--chat-text-secondary);
        }

        .menu-title {
            font-size: 14px;
            font-weight: 500;
            color: var(--chat-text-secondary);
        }

        .menu-search-icon {
            font-size: 14px;
            color: var(--chat-text-muted);
            margin-left: 4px;
        }

        .menu-arrow {
            font-size: 12px;
            color: var(--chat-text-muted);
            transition: transform 0.2s ease;

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

    .menu-content {
        padding: 4px 0;
    }
}

// Simple app item
.simple-app-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px 36px;
    cursor: pointer;
    border-radius: 6px;
    transition: var(--chat-transition);

    &:hover {
        background: var(--chat-hover-bg);
    }

    .simple-app-icon {
        font-size: 18px;
    }

    .simple-app-name {
        font-size: 13px;
        color: var(--chat-text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
    }
}

// Empty item
.empty-item {
    padding: 12px 36px;
    font-size: 13px;
    color: var(--chat-text-muted);
    text-align: center;
}

// Recent chats section
.recent-chats-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--chat-border-color);

    .section-header {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        margin-bottom: 8px;
        font-size: 13px;
        font-weight: 500;
        color: var(--chat-text-secondary);
    }
}

// Date group
.date-group {
    margin-bottom: 16px;

    .date-label {
        padding: 6px 12px;
        font-size: 12px;
        color: var(--chat-text-muted);
        font-weight: 500;
    }

    .chat-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px 8px 24px;
        cursor: pointer;
        border-radius: 6px;
        transition: var(--chat-transition);

        &:hover {
            background: var(--chat-hover-bg);

            .chat-item-edit {
                opacity: 1;
            }
        }

        &.active {
            background: var(--chat-active-bg);

            .chat-item-title {
                color: var(--chat-text-primary);
                font-weight: 600;
            }
        }

        .chat-item-title {
            font-size: 13px;
            color: var(--chat-text-secondary);
            flex: 1;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .chat-item-edit {
            font-size: 14px;
            color: var(--chat-text-muted);
            opacity: 0;
            transition: opacity 0.2s ease;
            padding: 4px;
            cursor: pointer;

            &:hover {
                color: var(--chat-text-primary);
            }
        }
    }
}

// Empty chats
.empty-chats {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--chat-text-muted);

    p {
        margin-top: 16px;
        font-size: 13px;
    }
}

// Main chat area
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg-primary);
    overflow: hidden;
    position: relative;
}

// Chat messages
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;

    scrollbar-width: thin;
    &::-webkit-scrollbar {
        width: 6px;
    }
    &::-webkit-scrollbar-track {
        background: transparent;
    }
    &::-webkit-scrollbar-thumb {
        background: var(--chat-border-color);
        border-radius: 9999px;
    }
}

// Message bubble
.message-bubble {
    display: flex;
    gap: 16px;
    max-width: 80%;

    &.user {
        align-self: flex-end;
        flex-direction: row-reverse;

        .bubble-content {
            background: var(--chat-accent-color);
            color: white;
            border-radius: 20px 20px 4px 20px;
        }
    }

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

        .bubble-content {
            background: var(--chat-bg-secondary);
            color: var(--chat-text-primary);
            border-radius: 20px 20px 20px 4px;
        }
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        border-radius: 9999px;
        background: var(--chat-accent-color);
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 16px;
        flex-shrink: 0;
    }

    .bubble-content {
        padding: 16px 20px;
        font-size: 14px;
        line-height: 1.6;

        p { margin: 0; }

        :global {
            pre {
                background: var(--chat-bg-secondary);
                padding: 16px;
                border-radius: 8px;
                overflow-x: auto;
            }
            code {
                background: var(--chat-bg-secondary);
                padding: 2px 6px;
                border-radius: 4px;
                font-family: monospace;
            }
        }
    }
}

// Welcome screen
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;

    .welcome-logo {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 40px;

        .logo-icon {
            width: 40px;
            height: 40px;
            object-fit: contain;
        }

        .logo-text {
            font-size: 28px;
            font-weight: 700;
            color: var(--chat-text-primary);
        }

        .logo-slogan {
            font-size: 20px;
            color: var(--chat-text-secondary);
            font-weight: 400;
        }
    }

    .welcome-input-container {
        width: 100%;
        max-width: 800px;
        margin: 0 auto 24px;

        .chat-input-wrapper {
            background: white;
            border: 1px solid var(--chat-border-color);
            border-radius: 16px;
            padding: 16px 24px;
            transition: var(--chat-transition);

            &:focus-within {
                border-color: var(--chat-accent-color);
                box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
            }

            .input-placeholder {
                font-size: 15px;
                color: var(--chat-text-muted);
                min-height: 28px;
                margin-bottom: 16px;
                line-height: 1.6;

                &:empty::before {
                    content: attr(data-placeholder);
                    color: var(--chat-text-muted);
                }
            }

            .input-actions {
                display: flex;
                align-items: center;
                justify-content: space-between;
                gap: 12px;
                padding-top: 8px;

                .left-actions {
                    display: flex;
                    align-items: center;
                    gap: 8px;
                    flex-wrap: wrap;
                    flex: 1;

                    .action-btn {
                        width: 36px;
                        height: 36px;
                        border-radius: 50%;
                        background: transparent;
                        border: none;
                        cursor: pointer;
                        color: var(--chat-text-secondary);
                        transition: var(--chat-transition);
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        &:hover {
                            background: var(--chat-hover-bg);
                        }
                    }

                    .feature-btn {
                        display: flex;
                        align-items: center;
                        gap: 6px;
                        padding: 8px 14px;
                        background: var(--chat-bg-secondary);
                        border: 1px solid var(--chat-border-color);
                        border-radius: 20px;
                        font-size: 13px;
                        color: var(--chat-text-secondary);
                        cursor: pointer;
                        transition: var(--chat-transition);
                        position: relative;
                        white-space: nowrap;

                        &:hover {
                            background: var(--chat-hover-bg);
                        }

                        &.active {
                            background: rgba(16, 185, 129, 0.1);
                            border-color: var(--chat-accent-color);
                            color: var(--chat-accent-color);

                            .feature-icon {
                                color: var(--chat-accent-color);
                            }
                        }

                        .feature-icon {
                            font-size: 15px;
                        }

                        .feature-label {
                            font-size: 13px;
                        }

                        .new-tag {
                            position: absolute;
                            top: -6px;
                            right: -6px;
                            background: var(--chat-accent-color);
                            color: white;
                            font-size: 9px;
                            padding: 1px 5px;
                            border-radius: 4px;
                        }
                    }
                }

                .right-actions {
                    display: flex;
                    align-items: center;
                    gap: 8px;
                    flex-shrink: 0;

                    .voice-btn {
                        width: 36px;
                        height: 36px;
                        border-radius: 50%;
                        background: transparent;
                        border: none;
                        cursor: pointer;
                        color: var(--chat-text-secondary);
                        transition: var(--chat-transition);
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        &:hover {
                            background: var(--chat-hover-bg);
                        }
                    }

                    .send-btn {
                        width: 36px;
                        height: 36px;
                        border-radius: 50%;
                        background: var(--chat-bg-secondary);
                        border: none;
                        cursor: pointer;
                        color: var(--chat-text-muted);
                        transition: var(--chat-transition);
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        &:not(:disabled) {
                            background: var(--chat-accent-color);
                            color: white;
                        }

                        &:hover:not(:disabled) {
                            opacity: 0.9;
                        }

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

    .suggestion-container {
        text-align: center;

        .suggestion-title {
            font-size: 13px;
            color: var(--chat-text-muted);
            margin-bottom: 16px;
        }

        .suggestion-list {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 8px;

            .suggestion-item {
                padding: 8px 16px;
                background: var(--chat-bg-secondary);
                border-radius: 20px;
                font-size: 13px;
                color: var(--chat-text-secondary);
                cursor: pointer;
                transition: var(--chat-transition);

                &:hover {
                    background: #f3f4f6;
                }
            }
        }
    }
}

// Footer
.chat-footer {
    padding: 16px;
    text-align: center;

    .footer-content {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        font-size: 12px;
        color: var(--chat-text-muted);

        .footer-divider {
            color: var(--chat-border-color);
        }

        .footer-link {
            color: var(--chat-text-muted);
            text-decoration: none;

            &:hover {
                color: var(--chat-text-secondary);
            }
        }
    }
}

// Loading indicator
.loading-indicator {
    display: flex;
    gap: 4px;
    padding: 12px;

    .loading-dot {
        width: 8px;
        height: 8px;
        border-radius: 9999px;
        background: var(--chat-text-muted);
        animation: loadingBounce 1.4s ease-in-out infinite both;

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

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

// Back button
.back-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--chat-border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--chat-text-secondary);
    transition: var(--chat-transition);

    &:hover {
        background: var(--chat-bg-secondary);
    }
}

// Responsive
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);

        &.open {
            transform: translateX(0);
        }
    }

    .message-bubble {
        max-width: 90%;
    }

    .welcome-screen {
        padding: 24px 16px;

        .welcome-logo {
            flex-direction: column;
            gap: 8px;
        }
    }
}
