/**
 * AI 聊天组件样式
 */

/* 浮动聊天按钮 */
.ai-chat-float-btn {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px hsl(var(--primary) / 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-float-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px hsl(var(--primary) / 0.6);
}

.ai-chat-float-btn svg {
    width: 28px;
    height: 28px;
    color: white;
}

.ai-chat-float-btn .notification-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid hsl(var(--background));
    display: none;
}

.ai-chat-float-btn.has-notification .notification-dot {
    display: block;
}

/* 聊天窗口 */
.ai-chat-window {
    position: fixed;
    bottom: 100px;
    left: 30px;
    width: 380px;
    height: 550px;
    background: hsl(var(--background-card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 1001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideIn 0.3s ease-out;
}

.ai-chat-window.open {
    display: flex;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 聊天头部 */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--gradient-primary);
    border-bottom: 1px solid hsl(var(--border));
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-avatar svg {
    width: 24px;
    height: 24px;
    color: white;
}

.ai-chat-header-text h4 {
    color: white;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.ai-chat-header-text span {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.ai-chat-close:hover {
    opacity: 1;
}

.ai-chat-close svg {
    width: 24px;
    height: 24px;
}

/* 聊天消息区域 */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 3px;
}

/* 消息气泡 */
.ai-chat-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-chat-message.ai {
    align-self: flex-start;
}

.ai-chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-message.user .ai-chat-message-avatar {
    background: hsl(var(--border));
}

.ai-chat-message.ai .ai-chat-message-avatar {
    background: var(--gradient-primary);
}

.ai-chat-message-avatar svg {
    width: 20px;
    height: 20px;
    color: white;
}

.ai-chat-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.ai-chat-message.user .ai-chat-message-content {
    background: var(--gradient-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-chat-message.ai .ai-chat-message-content {
    background: hsl(var(--background-soft));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text-primary));
    border-bottom-left-radius: 4px;
}

.ai-chat-message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

.ai-chat-message-content code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

.ai-chat-message-content p {
    margin: 0 0 8px 0;
}

.ai-chat-message-content p:last-child {
    margin-bottom: 0;
}

/* 加载动画 */
.ai-chat-message.loading .ai-chat-message-content {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px 20px;
}

.ai-chat-message.loading .dot {
    width: 8px;
    height: 8px;
    background: hsl(var(--text-muted));
    border-radius: 50%;
    animation: loadingDot 1.4s infinite ease-in-out both;
}

.ai-chat-message.loading .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-chat-message.loading .dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* 输入区域 */
.ai-chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid hsl(var(--border));
    background: hsl(var(--background-card));
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    background: hsl(var(--background-soft));
    border: 1px solid hsl(var(--border));
    border-radius: 24px;
    padding: 12px 18px;
    color: hsl(var(--text-primary));
    font-size: 16px; /* 移动端不小于 16px 防止缩放 */
    resize: none;
    outline: none;
    min-height: 48px;
    max-height: 120px;
    font-family: inherit;
    line-height: 1.5;
    -webkit-appearance: none; /* 移除 iOS 默认样式 */
    appearance: none;
}

.ai-chat-input:focus {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

.ai-chat-input::placeholder {
    color: hsl(var(--text-muted));
}

.ai-chat-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 15px hsl(var(--primary) / 0.4);
}

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-send svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* 新会话按钮 */
.ai-chat-new-session {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-chat-new-session:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* 欢迎消息 */
.ai-chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: hsl(var(--text-secondary));
}

.ai-chat-welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-welcome-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.ai-chat-welcome h3 {
    color: hsl(var(--text-primary));
    font-size: 18px;
    margin-bottom: 8px;
}

.ai-chat-welcome p {
    font-size: 14px;
    line-height: 1.6;
}

/* 移动端适配 */
@media (max-width: 480px) {
    .ai-chat-float-btn {
        bottom: 20px;
        left: 20px;
        width: 56px;
        height: 56px;
    }

    .ai-chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 80vh;
        max-height: -webkit-fill-available;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    .ai-chat-messages {
        -webkit-overflow-scrolling: touch;
    }

    .ai-chat-input {
        font-size: 16px;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    .ai-chat-input:focus {
        font-size: 16px;
    }
}

/* 错误提示 */
.ai-chat-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    margin: 0 20px 16px;
}
