/**
 * AI 助手样式
 * 完美适配 PC 和移动端
 */

/* 基础容器 */
.ai-assistant {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', Roboto, sans-serif;
}

/* ========== 移动端图标 ========== */
.ai-assistant-icon {
    position: fixed;
    bottom: 20px;
    left: 20px; /* 改为左侧 */
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10000;
    animation: pulse 2s ease-in-out infinite;
}

.ai-assistant-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.5);
}

.ai-assistant-icon:active {
    transform: scale(0.95);
}

.ai-assistant-icon svg {
    width: 32px;
    height: 32px;
    fill: white;
}

/* AI 文字样式 */
.ai-assistant-icon::before {
    content: 'AI';
    font-size: 24px;
    font-weight: 800;
    color: white;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ai-assistant-icon svg {
    display: none; /* 隐藏 SVG，显示文字 */
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

/* ========== 聊天窗口基础 ========== */
.ai-chat-window {
    position: fixed;
    bottom: 90px;
    left: 20px; /* 改为左侧 */
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
}

.ai-chat-window.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========== 聊天头部 ========== */
.ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.ai-chat-controls {
    display: flex;
    gap: 8px;
}

.ai-chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-chat-btn:active {
    transform: scale(0.95);
}

/* ========== 消息区域 ========== */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #e2e8f0;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ========== 消息样式 ========== */
.ai-message {
    display: flex;
    gap: 12px;
    animation: messageSlide 0.3s ease-out;
    align-items: flex-start;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.ai-message-avatar.user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-message-avatar.assistant {
    background: #f7fafc;
    color: #667eea;
    border: 2px solid #e2e8f0;
}

.ai-message-content {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
    max-width: calc(100% - 48px);
}

.ai-message.user {
    flex-direction: row-reverse;
}

.ai-message.user .ai-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message.assistant .ai-message-content {
    background: white;
    color: #2d3748;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* ========== 加载动画 ========== */
.ai-loading {
    display: flex;
    gap: 6px;
    padding: 8px 0;
}

.ai-loading-dot {
    width: 8px;
    height: 8px;
    background: #cbd5e0;
    border-radius: 50%;
    animation: loadingBounce 1.4s ease-in-out infinite;
}

.ai-loading-dot:nth-child(1) {
    animation-delay: 0s;
}

.ai-loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes loadingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ========== 输入区域 ========== */
.ai-chat-input {
    display: flex;
    padding: 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    gap: 10px;
}

.ai-chat-input input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.ai-chat-input input:focus {
    border-color: #667eea;
}

.ai-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 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.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.ai-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== PC端最小化状态 ========== */
.ai-chat-window.minimized {
    height: 60px;
    overflow: hidden;
}

.ai-chat-window.minimized .ai-chat-messages,
.ai-chat-window.minimized .ai-chat-input {
    display: none;
}

/* ========== 移动端适配 ========== */
@media (max-width: 768px) {
    /* 移动端图标 */
    .ai-assistant-icon {
        bottom: 15px;
        left: 15px; /* 改为左侧 */
        width: 56px;
        height: 56px;
        z-index: 10001; /* 确保图标在最上层 */
    }

    .ai-assistant-icon svg {
        width: 28px;
        height: 28px;
    }

    /* 移动端聊天窗口全屏显示 */
    .ai-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        transform: translateY(100%);
        z-index: 10000;
        max-width: none;
        max-height: none;
    }

    .ai-chat-window.show {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    /* 移动端头部 */
    .ai-chat-header {
        padding: 16px;
    }

    .ai-chat-header h3 {
        font-size: 16px;
    }

    /* 移动端消息区域 */
    .ai-chat-messages {
        padding: 15px;
        gap: 12px;
    }

    .ai-message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .ai-message-content {
        font-size: 14px;
        padding: 10px 14px;
        max-width: calc(100% - 44px);
    }

    /* 移动端输入 */
    .ai-chat-input {
        padding: 12px 15px;
    }

    .ai-chat-input input {
        font-size: 16px; /* 防止 iOS 自动缩放 */
        padding: 10px 16px;
    }

    .ai-send-btn {
        width: 40px;
        height: 40px;
    }

    /* 禁用最小化功能 */
    .ai-chat-window.minimized {
        height: 100vh;
        transform: translateY(0);
    }

    .ai-chat-window.minimized .ai-chat-messages,
    .ai-chat-window.minimized .ai-chat-input {
        display: flex;
    }

    .ai-chat-header {
        cursor: default;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* 防止移动端滚动穿透 */
    .ai-chat-window.show {
        position: fixed;
        overflow: hidden;
    }
    
    body.ai-chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* ========== 小屏手机优化 ========== */
@media (max-width: 480px) {
    .ai-assistant-icon {
        width: 52px;
        height: 52px;
        bottom: 12px;
        left: 12px; /* 改为左侧 */
    }

    .ai-assistant-icon svg {
        width: 26px;
        height: 26px;
    }

    .ai-chat-header {
        padding: 14px;
    }

    .ai-chat-messages {
        padding: 12px;
        gap: 10px;
    }

    .ai-message-content {
        font-size: 13px;
        padding: 9px 12px;
    }
}

/* ========== 横屏手机适配 ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .ai-chat-window {
        height: 100vh;
    }

    .ai-chat-messages {
        padding: 10px 15px;
    }

    .ai-chat-input {
        padding: 10px 15px;
    }
}

/* ========== 高分辨率优化 ========== */
@media (min-width: 1440px) {
    .ai-chat-window {
        width: 420px;
        height: 650px;
    }

    .ai-chat-header h3 {
        font-size: 19px;
    }

    .ai-message-content {
        font-size: 15px;
    }
}

/* ========== 深色模式支持（可选） ========== */
@media (prefers-color-scheme: dark) {
    .ai-chat-window {
        background: #1a202c;
    }

    .ai-chat-messages {
        background: #2d3748;
    }

    .ai-message.assistant .ai-message-content {
        background: #4a5568;
        color: #e2e8f0;
    }

    .ai-message-avatar.assistant {
        background: #2d3748;
        color: #a0aec0;
        border-color: #4a5568;
    }

    .ai-chat-input {
        background: #1a202c;
        border-top-color: #4a5568;
    }

    .ai-chat-input input {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .ai-chat-input input:focus {
        border-color: #667eea;
    }

    .ai-chat-messages::-webkit-scrollbar-track {
        background: #2d3748;
    }

    .ai-chat-messages::-webkit-scrollbar-thumb {
        background: #4a5568;
    }
}

/* ========== 无障碍优化 ========== */
@media (prefers-reduced-motion: reduce) {
    .ai-assistant-icon,
    .ai-chat-window,
    .ai-message,
    .ai-send-btn,
    .ai-chat-btn {
        animation: none !important;
        transition: none !important;
    }
}

/* ========== 打印样式 ========== */
@media print {
    .ai-assistant {
        display: none !important;
    }
}
