/**
 * AI Assistant Styles - 小元AI助手样式
 * 元思维交互式编程学习平台
 */

/* ===== AI 悬浮按钮 ===== */
.ai-float-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    /* v4: 小元本身已是品牌绿,按钮换成奶油白衬底,既显小元又托起整体 */
    background:
        radial-gradient(circle at 30% 28%, #ffffff 0%, #fef3c7 70%, #fde68a 100%);
    box-shadow:
        0 8px 24px -4px rgba(var(--primary-rgb), 0.4),
        0 0 0 4px rgba(255, 255, 255, 0.7) inset;
    cursor: pointer;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-bounce);
    border: 3px solid #ffffff;
    overflow: hidden;
}

.ai-float-btn:hover {
    transform: scale(1.08) rotate(-4deg);
    box-shadow:
        0 12px 28px -4px rgba(var(--primary-rgb), 0.55),
        0 0 0 4px rgba(255, 255, 255, 0.85) inset;
}

.ai-float-btn.chatting {
    animation: aiPulseGlow 2s infinite;
}

@keyframes aiPulseGlow {
    0%, 100% { box-shadow: 0 4px 20px rgba(var(--primary-rgb), 0.4); }
    50% { box-shadow: 0 4px 30px rgba(var(--primary-rgb), 0.8); }
}

/* 小元头像 */
.xiaoyuan-avatar {
    width: 55px;
    height: 55px;
    transition: transform 0.3s;
}

.ai-float-btn:hover .xiaoyuan-avatar {
    transform: scale(1.1);
}

/* ===== AI 聊天窗口 ===== */
.ai-chat-window {
    position: fixed;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-2xl);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    transform: scale(0.95);
    min-width: 320px;
    min-height: 400px;
    resize: both;
}

.ai-chat-window.open {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.ai-chat-window.minimized {
    height: 50px !important;
    min-height: 50px !important;
    resize: none;
}

.ai-chat-window.minimized .ai-chat-body,
.ai-chat-window.minimized .ai-chat-input-area {
    display: none;
}

/* ===== 聊天头部 ===== */
.ai-chat-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.ai-chat-header-avatar {
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ai-chat-header-info {
    flex: 1;
}

.ai-chat-header-info h3 {
    font-size: 15px;
    font-weight: 600;
    color: white;
}

.ai-chat-header-info p {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
}

.ai-chat-header-actions {
    display: flex;
    gap: 6px;
}

.header-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.header-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ===== 聊天主体 ===== */
.ai-chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 快捷问题 */
.quick-questions {
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.quick-question {
    padding: 5px 10px;
    border-radius: 15px;
    background: rgba(var(--primary-rgb), 0.08);
    border: 1px solid rgba(var(--primary-rgb), 0.15);
    color: #059669;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quick-question:hover {
    background: rgba(var(--primary-rgb), 0.2);
    border-color: rgba(var(--primary-rgb), 0.4);
    transform: translateY(-1px);
}

/* 消息区域 */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* ===== 消息气泡 ===== */
.ai-message {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.6;
    animation: messageSlide 0.3s ease;
    word-wrap: break-word;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message.assistant {
    align-self: flex-start;
    background: rgba(var(--primary-rgb), 0.08);
    border: 1px solid rgba(var(--primary-rgb), 0.15);
    color: #334155;
    border-bottom-left-radius: 4px;
}

.ai-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--accent) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message.system {
    align-self: center;
    background: rgba(100, 116, 139, 0.1);
    color: #64748b;
    font-size: 11px;
    padding: 6px 12px;
}

.ai-message.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* 打字指示器 */
.ai-message.typing {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 18px;
}

.typing-message {
    color: #64748b;
    font-size: 12px;
    margin-bottom: 4px;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* 流式消息（正在接收内容） */
.ai-message.streaming {
    border-color: rgba(var(--primary-rgb), 0.5);
    position: relative;
}

.ai-message.streaming::after {
    content: '▋';
    color: var(--primary);
    animation: cursorBlink 1s infinite;
    margin-left: 2px;
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ===== 输入区域 ===== */
.ai-chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: rgba(248, 250, 252, 0.8);
}

.ai-chat-input-area input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.9);
    color: #1e293b;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-chat-input-area input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
}

.ai-chat-input-area input::placeholder {
    color: rgba(100, 116, 139, 0.5);
}

.ai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.4);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== 代码块样式 ===== */
.ai-message .code-block {
    margin: 10px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: #f8fafc;
}

.ai-message .code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.04);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.ai-message .code-lang {
    font-size: 10px;
    color: var(--primary);
    font-weight: bold;
}

.ai-message .code-copy-btn {
    font-size: 10px;
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 4px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-message .code-copy-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1e293b;
}

.ai-message .code-copy-btn.copied {
    background: var(--primary);
    color: white;
}

.ai-message pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: #334155;
}

.ai-message pre code {
    background: none;
    padding: 0;
}

.ai-message .inline-code {
    font-family: var(--font-mono);
    background: rgba(var(--primary-rgb), 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: #059669;
}

/* 重试按钮 */
.retry-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 12px;
    background: rgba(var(--secondary-rgb), 0.1);
    border: 1px solid rgba(var(--secondary-rgb), 0.2);
    border-radius: 6px;
    color: #2563eb;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.retry-btn:hover {
    background: rgba(var(--secondary-rgb), 0.3);
    border-color: rgba(var(--secondary-rgb), 0.5);
}

/* 调整大小手柄 */
.resize-hint {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    cursor: se-resize;
    opacity: 0.3;
}

.resize-hint::before,
.resize-hint::after {
    content: '';
    position: absolute;
    background: #64748b;
    border-radius: 1px;
}

.resize-hint::before {
    width: 8px;
    height: 2px;
    bottom: 2px;
    right: 2px;
    transform: rotate(-45deg);
}

.resize-hint::after {
    width: 2px;
    height: 8px;
    bottom: 2px;
    right: 2px;
    transform: rotate(-45deg);
}

/* 表情动画 */
.emoji-float {
    position: absolute;
    font-size: 20px;
    animation: floatUp 2s ease-out forwards;
    pointer-events: none;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.5); }
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
    .ai-float-btn.chatting,
    .ai-message,
    .typing-dot,
    .emoji-float {
        animation: none;
    }
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    /* 悬浮按钮 - 移动端稍小 */
    .ai-float-btn {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }

    .xiaoyuan-avatar {
        width: 46px;
        height: 46px;
    }

    /* 聊天窗口 - 移动端全屏 */
    .ai-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        min-width: 0 !important;
        min-height: 0 !important;
        border-radius: 0;
        resize: none;
    }

    .ai-chat-window.open {
        animation: mobileSlideIn 0.3s ease;
    }

    @keyframes mobileSlideIn {
        from { opacity: 0; transform: translateY(100%); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* 隐藏调整大小手柄 */
    .resize-hint {
        display: none;
    }

    /* 头部 - 移动端调整 */
    .ai-chat-header {
        padding: 14px 16px;
        cursor: default;
    }

    .ai-chat-header-avatar {
        width: 40px;
        height: 40px;
    }

    .ai-chat-header-info h3 {
        font-size: 16px;
    }

    .ai-chat-header-info p {
        font-size: 12px;
    }

    .header-action-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    /* 快捷问题 - 移动端可滚动 */
    .quick-questions {
        padding: 12px 16px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .quick-questions::-webkit-scrollbar {
        display: none;
    }

    .quick-question {
        padding: 8px 14px;
        font-size: 13px;
        flex-shrink: 0;
    }

    /* 消息区域 */
    .ai-chat-messages {
        padding: 16px;
        gap: 12px;
    }

    /* 消息气泡 */
    .ai-message {
        max-width: 85%;
        padding: 12px 16px;
        font-size: 14px;
        line-height: 1.7;
    }

    .ai-message.typing {
        padding: 16px 20px;
    }

    /* 代码块 */
    .ai-message .code-block {
        margin: 12px -8px;
        border-radius: 8px;
    }

    .ai-message pre {
        padding: 14px;
        font-size: 13px;
    }

    /* 输入区域 */
    .ai-chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        gap: 10px;
    }

    .ai-chat-input-area input {
        padding: 12px 16px;
        font-size: 16px; /* 防止iOS缩放 */
        border-radius: 12px;
    }

    .ai-send-btn {
        width: 48px;
        height: 48px;
        border-radius: 12px;
    }

    /* 重试按钮 */
    .retry-btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}

/* 平板适配 */
@media (min-width: 769px) and (max-width: 1024px) {
    .ai-float-btn {
        width: 60px;
        height: 60px;
        bottom: 20px;
        right: 20px;
    }

    .xiaoyuan-avatar {
        width: 50px;
        height: 50px;
    }

    .ai-chat-window {
        min-width: 360px;
        min-height: 450px;
    }

    .ai-message {
        max-width: 82%;
        font-size: 14px;
    }

    .ai-chat-header-info h3 {
        font-size: 15px;
    }

    .header-action-btn {
        width: 32px;
        height: 32px;
    }

    .quick-question {
        padding: 6px 12px;
        font-size: 12px;
    }

    .ai-chat-input-area input {
        font-size: 15px;
        padding: 11px 14px;
    }

    .ai-send-btn {
        width: 44px;
        height: 44px;
    }
}

/* 小屏手机适配 (≤375px) */
@media (max-width: 375px) {
    .ai-message {
        max-width: 90%;
        font-size: 13px;
        padding: 10px 12px;
    }

    .quick-question {
        padding: 6px 10px;
        font-size: 11px;
    }

    .ai-chat-header {
        padding: 10px 12px;
        gap: 8px;
    }

    .ai-chat-header-info h3 {
        font-size: 14px;
    }

    .ai-chat-input-area {
        padding: 10px 12px;
        gap: 8px;
    }

    .ai-chat-input-area input {
        padding: 10px 12px;
        font-size: 16px;
    }

    .ai-send-btn {
        width: 42px;
        height: 42px;
    }
}

/* iPhone安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .ai-chat-input-area {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }

        .ai-float-btn {
            bottom: calc(16px + env(safe-area-inset-bottom));
        }
    }
}

/* 横屏手机适配 */
@media (max-width: 768px) and (max-height: 500px) and (orientation: landscape) {
    .ai-chat-header {
        padding: 8px 12px;
    }

    .ai-chat-header-avatar {
        width: 30px;
        height: 30px;
    }

    .quick-questions {
        padding: 6px 12px;
    }

    .quick-question {
        padding: 4px 8px;
        font-size: 11px;
    }

    .ai-chat-messages {
        padding: 8px 12px;
        gap: 8px;
    }

    .ai-message {
        padding: 8px 12px;
        font-size: 13px;
        line-height: 1.5;
    }

    .ai-chat-input-area {
        padding: 8px 12px;
    }

    .ai-chat-input-area input {
        padding: 8px 12px;
    }

    .ai-send-btn {
        width: 38px;
        height: 38px;
    }
}
