/* ========================================
   AI 小猴子助手样式
   意式奢华设计语言
   ======================================== */

/* --- 悬浮猴子按钮 --- */
.ai-monkey-container {
    position: fixed;
    right: 20px;
    bottom: 140px; /* 在 mobile-fab 上方 */
    z-index: 97;
}

.ai-monkey-avatar {
    width: 60px;
    height: 70px;
    border-radius: 0;
    border: none;
    background: none;
    cursor: grab;
    box-shadow: none;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    -webkit-tap-highlight-color: transparent;
    /* 呼吸动画 */
    animation: ai-breathe 3s ease-in-out infinite;
}

.ai-monkey-avatar:active {
    cursor: grabbing;
}

/* 呼吸动画 */
@keyframes ai-breathe {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* 拖拽状态 */
.ai-monkey-container.dragging .ai-monkey-avatar {
    animation: none;
    transform: scale(1.1);
    transition: transform 0.15s;
}

.ai-monkey-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(46, 110, 143, 0.35);
}

.ai-monkey-avatar img {
    width: 60px;
    height: 70px;
    border-radius: 0;
    pointer-events: none;
}

.ai-monkey-avatar:hover {
    transform: scale(1.05);
}

/* 未读气泡 */
.ai-monkey-bubble {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: #4A8DB7;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none; /* 默认隐藏 */
}

.ai-monkey-bubble.show {
    display: block;
    animation: bubblePulse 2s ease-in-out infinite;
}

@keyframes bubblePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* --- 对话面板 --- */
.ai-chat-panel {
    position: fixed;
    right: 20px;
    bottom: 210px; /* 在猴子按钮上方 */
    width: 340px;
    height: 460px;
    background: var(--color-card, #FFFFFF);
    border-radius: var(--radius, 16px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 997;
    /* 默认隐藏 */
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-chat-panel.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* 标题栏 - 毛玻璃金色渐变 */
.ai-chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #4A8DB7, #2E6E8F);
    color: #fff;
    flex-shrink: 0;
}

.ai-chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 10px;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.ai-chat-header-name {
    flex: 1;
    font-family: 'Playfair Display', 'Noto Serif SC', Georgia, serif;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.ai-chat-header-status {
    font-size: 11px;
    opacity: 0.8;
    font-weight: 400;
    display: block;
    font-family: 'Inter', -apple-system, sans-serif;
    letter-spacing: 0;
}

.ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

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

/* 消息区域 */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--color-bg, #F6F9FC);
    -webkit-overflow-scrolling: touch;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(74, 141, 183, 0.3);
    border-radius: 3px;
}

/* 消息气泡 */
.ai-msg {
    display: flex;
    margin-bottom: 14px;
    align-items: flex-start;
}

.ai-msg-monkey {
    flex-direction: row;
}

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

.ai-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ai-msg-monkey .ai-msg-avatar {
    margin-right: 8px;
}

.ai-msg-user .ai-msg-avatar {
    margin-left: 8px;
    /* 用户头像用纯色圆 */
    background: linear-gradient(135deg, #4A8DB7, #6BAED6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-msg-content {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-msg-monkey .ai-msg-content {
    background: var(--color-bg-warm, #F0F5FA);
    color: var(--color-text, #2C2C2C);
    border-bottom-left-radius: 4px;
}

.ai-msg-user .ai-msg-content {
    background: rgba(74, 141, 183, 0.12);
    color: var(--color-text, #2C2C2C);
    border-bottom-right-radius: 4px;
}

/* 打字指示器 */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: var(--color-bg-warm, #F0F5FA);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4A8DB7;
    margin: 0 2px;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* 输入区域 */
.ai-chat-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--color-card, #FFFFFF);
    border-top: 1px solid var(--color-border, #DCE5EE);
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid var(--color-border, #DCE5EE);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    background: var(--color-bg, #F6F9FC);
    color: var(--color-text, #2C2C2C);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.ai-chat-input:focus {
    border-color: #4A8DB7;
    box-shadow: 0 0 0 3px rgba(74, 141, 183, 0.15);
}

.ai-chat-input::placeholder {
    color: var(--color-text-light, #6B7D8E);
    font-style: italic;
}

.ai-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #4A8DB7, #5A9BC7);
    color: #fff;
    margin-left: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ai-chat-send:hover {
    background: linear-gradient(135deg, #5A9BC7, #4A8AAD);
    transform: scale(1.05);
}

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

.ai-chat-send svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* --- 移动端适配 --- */
@media screen and (max-width: 768px) {
    .ai-monkey-container {
        right: 16px;
        bottom: 80px; /* Tab Bar上方 */
    }
    
    .ai-monkey-avatar {
        width: 52px;
        height: 52px;
    }
    
    .ai-monkey-avatar img {
        width: 40px;
        height: 40px;
    }
    
    .ai-chat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        transform-origin: bottom center;
    }
    
    .ai-chat-panel.open {
        transform: translateY(0);
    }
}

/* 小屏手机 */
@media screen and (max-width: 380px) {
    .ai-chat-panel {
        height: 75vh;
    }
    
    .ai-chat-header {
        padding: 10px 14px;
    }
    
    .ai-msg-content {
        max-width: 82%;
        font-size: 13px;
    }
}

/* ============ 对话框内媒体播放器 ============ */
.ai-chat-media-result {
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(246, 249, 252, 0.5);
}

.ai-chat-music-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(74, 141, 183, 0.15);
    transition: background 0.2s;
}

.ai-chat-music-item:last-child {
    border-bottom: none;
}

.ai-chat-music-item:hover {
    background: rgba(74, 141, 183, 0.1);
}

.ai-chat-music-item.playing {
    background: rgba(74, 141, 183, 0.15);
}

.ai-chat-music-item .music-play-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4A8DB7, #2E6E8F);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    flex-shrink: 0;
}

.ai-chat-music-item .music-info {
    flex: 1;
    min-width: 0;
}

.ai-chat-music-item .music-title {
    font-size: 13px;
    color: #2E3A4A;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-music-item .music-artist {
    font-size: 11px;
    color: #2E6E8F;
}

.ai-chat-video-embed {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.ai-chat-video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.ai-loading {
    color: #2E6E8F;
    font-size: 13px;
    padding: 8px 0;
}

/* ============ AI 迷你播放条 ============ */
.ai-music-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: linear-gradient(135deg, rgba(74,141,183,0.08) 0%, rgba(74,141,183,0.15) 100%);
    border-top: 1px solid rgba(74,141,183,0.15);
    flex-shrink: 0;
}

.ai-music-cover {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--color-bg, #F6F9FC);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gold, #4A8DB7);
    font-size: 13px;
    border: 1.5px solid rgba(74,141,183,0.3);
}

.ai-music-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-music-cover.is-playing {
    animation: coverSpin 8s linear infinite;
}

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

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

.ai-music-title {
    font-size: 12px;
    color: var(--color-text, #2C2C2C);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.ai-music-progress {
    height: 2px;
    background: rgba(74,141,183,0.2);
    border-radius: 1px;
}

.ai-music-progress-fill {
    height: 100%;
    background: var(--color-gold, #4A8DB7);
    border-radius: 1px;
    width: 0%;
    transition: width 0.3s linear;
}

.ai-music-play,
.ai-music-next {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--color-gold, #4A8DB7);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.ai-music-play:active,
.ai-music-next:active {
    background: rgba(74,141,183,0.15);
}

/* 无障碍：减少动画 */
@media (prefers-reduced-motion: reduce) {
    .ai-monkey-avatar {
        animation: none;
    }
    
    .ai-typing-dot {
        animation: none;
        opacity: 0.6;
    }
    
    .ai-chat-panel {
        transition: opacity 0.15s ease;
    }
}

/* ============ IP形象多状态动画 ============ */

/* 待机呼吸 */
.ai-monkey-avatar img,
.ai-monkey-avatar svg {
    transition: transform 0.3s ease;
}

/* 思考状态 */
.ai-monkey-container.thinking .ai-monkey-avatar img {
    animation: monkeyThink 1.5s ease-in-out infinite;
}

@keyframes monkeyThink {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

/* 开心状态 */
.ai-monkey-container.happy .ai-monkey-avatar img {
    animation: monkeyHappy 0.5s ease;
}

@keyframes monkeyHappy {
    0% { transform: scale(1); }
    30% { transform: scale(1.15) translateY(-4px); }
    60% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* 说话状态 */
.ai-monkey-container.talking .ai-monkey-avatar img {
    animation: monkeyTalk 0.4s ease-in-out infinite;
}

@keyframes monkeyTalk {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* ============ 麦克风按钮 ============ */
.ai-mic-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--color-text-light, #6B7D8E);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.ai-mic-btn:hover {
    color: var(--color-gold, #4A8DB7);
}

/* 录音中 */
.ai-mic-btn.recording {
    color: #E74C3C;
    animation: micPulse 1s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { background: rgba(231, 76, 60, 0.08); }
    50% { background: rgba(231, 76, 60, 0.2); }
}

/* 语音不可用时隐藏 */
.ai-mic-btn.hidden {
    display: none;
}

/* 无障碍：减少动画 - 音乐播放 */
@media (prefers-reduced-motion: reduce) {
    .ai-music-cover.is-playing {
        animation: none;
    }
}
