/**
 * 🌸 AI Smart Recommendation Widget
 * Floating chat assistant for product page
 * MengShen Created: 2026-02-23
 */

/* ═══════════════════════════════════════
   CSS 变量
   ═══════════════════════════════════════ */
:root {
    --ai-primary: #6366f1;
    --ai-primary-dark: #4f46e5;
    --ai-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
    --ai-gradient-soft: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
    --ai-panel-bg: rgba(255, 255, 255, 0.82);
    --ai-panel-border: rgba(255, 255, 255, 0.6);
    --ai-shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 40px rgba(99, 102, 241, 0.1);
    --ai-radius: 24px;
    --ai-panel-w: 400px;
    --ai-panel-h: 540px;
}

/* ═══════════════════════════════════════
   触发按钮 - 呼吸光晕
   ═══════════════════════════════════════ */
.ai-trigger-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ai-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    box-shadow:
        0 8px 32px rgba(99, 102, 241, 0.4),
        0 0 0 0 rgba(99, 102, 241, 0.3);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    animation: aiBreathe 3s ease-in-out infinite;
}

.ai-trigger-btn:hover {
    transform: scale(1.1);
    box-shadow:
        0 12px 40px rgba(99, 102, 241, 0.5),
        0 0 0 8px rgba(99, 102, 241, 0.08);
    animation: none;
}

.ai-trigger-btn:active {
    transform: scale(0.95);
}

.ai-trigger-btn .ai-icon-robot {
    transition: transform 0.3s ease, opacity 0.2s ease;
}

.ai-trigger-btn .ai-icon-close {
    position: absolute;
    transition: transform 0.3s ease, opacity 0.2s ease;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.ai-trigger-btn.is-open .ai-icon-robot {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.ai-trigger-btn.is-open .ai-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

@keyframes aiBreathe {

    0%,
    100% {
        box-shadow:
            0 8px 32px rgba(99, 102, 241, 0.4),
            0 0 0 0 rgba(99, 102, 241, 0.25);
    }

    50% {
        box-shadow:
            0 8px 32px rgba(99, 102, 241, 0.4),
            0 0 0 14px rgba(99, 102, 241, 0);
    }
}

/* ═══════════════════════════════════════
   对话面板
   ═══════════════════════════════════════ */
.ai-chat-panel {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: 9997;
    width: var(--ai-panel-w);
    height: var(--ai-panel-h);
    background: var(--ai-panel-bg);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid var(--ai-panel-border);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* 进出动画 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition:
        opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0s 0.35s;
}

.ai-chat-panel.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition:
        opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0s 0s;
}

/* ═══════════════════════════════════════
   面板头部
   ═══════════════════════════════════════ */
.ai-panel-header {
    background: var(--ai-gradient);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* 头部装饰 */
.ai-panel-header::before {
    content: '';
    position: absolute;
    right: -20px;
    top: -20px;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.ai-panel-header::after {
    content: '';
    position: absolute;
    right: 50px;
    bottom: -30px;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}

.ai-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.ai-header-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.3;
    letter-spacing: 0.3px;
}

.ai-header-subtitle {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ai-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
    animation: aiStatusPulse 2s ease-in-out infinite;
}

@keyframes aiStatusPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.ai-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.ai-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* ═══════════════════════════════════════
   消息区域
   ═══════════════════════════════════════ */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background: var(--ai-gradient-soft);
}

/* 自定义滚动条 */
.ai-messages::-webkit-scrollbar {
    width: 4px;
}

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

.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.15);
    border-radius: 4px;
}

.ai-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.3);
}

/* 消息行 */
.ai-msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    animation: aiMsgFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-msg-row.is-user {
    flex-direction: row-reverse;
}

@keyframes aiMsgFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 消息头像（仅AI侧） */
.ai-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--ai-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* 气泡 */
.ai-msg-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.65;
    letter-spacing: 0.1px;
    position: relative;
}

.ai-msg-row.is-ai .ai-msg-bubble {
    background: #fff;
    color: #334155;
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.ai-msg-row.is-user .ai-msg-bubble {
    background: var(--ai-gradient);
    color: #fff;
    border: none;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

/* 打字指示器 */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: aiTypingBounce 1.2s ease-in-out infinite;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiTypingBounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════
   快捷标签 (Quick Chips)
   ═══════════════════════════════════════ */
.ai-quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.ai-quick-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 20px;
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ai-quick-chip:hover {
    border-color: var(--ai-primary);
    color: var(--ai-primary);
    background: #eef2ff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.12);
}

.ai-quick-chip i {
    font-size: 11px;
    opacity: 0.7;
}

/* ═══════════════════════════════════════
   推荐产品卡片（嵌在AI消息中）
   ═══════════════════════════════════════ */
.ai-product-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.ai-product-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-decoration: none;
    display: block;
    position: relative;
    overflow: hidden;
}

.ai-product-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--ai-gradient);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ai-product-card:hover {
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.1);
    transform: translateY(-2px);
}

.ai-product-card:hover::before {
    opacity: 1;
}

.ai-product-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.ai-product-card-name {
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-product-card-name i {
    font-size: 11px;
    color: var(--ai-primary);
}

.ai-product-card-price {
    font-size: 15px;
    font-weight: 800;
    color: var(--ai-primary);
    letter-spacing: -0.5px;
}

.ai-product-card-price small {
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
    margin-left: 2px;
}

.ai-product-card-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-spec-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
    font-weight: 500;
}

.ai-spec-tag i {
    font-size: 9px;
    color: #94a3b8;
}

.ai-product-card-action {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 10px;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ai-primary);
    opacity: 0;
    transform: translateX(-4px);
    transition: all 0.2s ease;
}

.ai-product-card:hover .ai-product-card-action {
    opacity: 1;
    transform: translateX(0);
}

/* 推荐序号标记 */
.ai-rec-badge {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: var(--ai-gradient);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════
   输入区
   ═══════════════════════════════════════ */
.ai-input-area {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
}

.ai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 16px;
    padding: 4px 4px 4px 16px;
    transition: all 0.2s ease;
}

.ai-input-wrapper:focus-within {
    border-color: var(--ai-primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08);
}

.ai-input-field {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    color: #1e293b;
    padding: 8px 0;
    font-family: inherit;
    min-width: 0;
}

.ai-input-field::placeholder {
    color: #94a3b8;
    font-weight: 500;
}

.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--ai-gradient);
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.ai-send-btn:active {
    transform: scale(0.95);
}

.ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ═══════════════════════════════════════
   底部提示
   ═══════════════════════════════════════ */
.ai-powered-by {
    text-align: center;
    padding: 6px 16px 10px;
    font-size: 10px;
    color: #cbd5e1;
    font-weight: 500;
    letter-spacing: 0.5px;
    background: #fff;
}

/* ═══════════════════════════════════════
   移动端响应式
   ═══════════════════════════════════════ */
@media (max-width: 480px) {
    .ai-trigger-btn {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
        font-size: 20px;
    }

    .ai-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 85vh;
        border-radius: var(--ai-radius) var(--ai-radius) 0 0;
        transform: translateY(100%);
    }

    .ai-chat-panel.is-visible {
        transform: translateY(0);
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --ai-panel-w: 360px;
        --ai-panel-h: 500px;
    }
}