/**
 * AI聊天模块样式
 * 支持PC端和移动端自适应
 * 作者：海耀星软件科技
 */

/* ==================== 主容器 ==================== */
#ai-chat-widget {
    position: fixed;
    bottom: 5.8vw;
    right: 2.7vw;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif;
    pointer-events: none; /* 默认不拦截点击事件 */
}

/* 容器内的元素可以点击 */
#ai-chat-widget * {
    pointer-events: auto;
}

/* ==================== 悬浮触发按钮 ==================== */
#ai-chat-trigger {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: pulse 2s infinite;
}

#ai-chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

#ai-chat-trigger:active {
    transform: scale(0.95);
}

/* 脉冲动画 */
@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.6);
    }
}

/* 未读消息徽章 */
#ai-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid white;
    animation: bounce 0.5s ease;
}

#ai-chat-badge.show {
    display: flex;
}

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

/* ==================== 聊天窗口 ==================== */
#ai-chat-window {
    display: none;
    position: fixed;
    bottom: 20px;
    right: calc(2.7vw + 48px + 15px); /* 触发按钮宽度 + 间距，向左展开 */
    width: 380px;
    height: 600px;
    max-width: calc(100vw - 2.7vw - 48px - 35px);
    max-height: calc(100vh - 40px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
}

#ai-chat-window.show {
    display: flex;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ==================== 聊天窗口头部 ==================== */
#ai-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

#ai-chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 16px;
}

#ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    padding: 2px;
    object-fit: cover;
}

#ai-chat-status {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#ai-chat-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    margin-right: 6px;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#ai-chat-status-text {
    font-size: 12px;
    opacity: 0.9;
}

#ai-chat-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

#ai-chat-minimize,
#ai-chat-close {
    cursor: pointer;
    font-size: 22px;
    opacity: 0.9;
    transition: all 0.2s;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

#ai-chat-minimize:hover,
#ai-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* ==================== 消息列表区域 ==================== */
#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9fafb;
    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: #d1d5db;
    border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ==================== 消息项 ==================== */
.ai-message-item {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

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

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

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    border: 2px solid #e5e7eb;
}

.ai-message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 14px;
    white-space: pre-wrap;
}

.ai-message-item.ai .ai-message-bubble {
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-radius: 12px 12px 12px 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ai-message-item.user .ai-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 4px 12px;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.ai-message-time {
    font-size: 11px;
    color: #9ca3af;
    padding: 0 4px;
}

.ai-message-item.user .ai-message-time {
    text-align: right;
}

/* ==================== 打字指示器 ==================== */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ai-typing-text {
    font-size: 14px;
    color: #6b7280;
    font-weight: 400;
}

.ai-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ==================== 快捷问题 ==================== */
.ai-quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.ai-quick-question-btn {
    padding: 8px 14px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    font-size: 13px;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.ai-quick-question-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* ==================== 输入区域 ==================== */
#ai-chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: white;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: flex-end;
}

#ai-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    outline: none;
    font-size: 14px;
    resize: none;
    font-family: inherit;
    transition: all 0.2s;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.5;
}

#ai-chat-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#ai-chat-input::placeholder {
    color: #9ca3af;
}

#ai-chat-send {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    height: 40px;
}

#ai-chat-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#ai-chat-send:active {
    transform: translateY(0);
}

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

/* ==================== 移动端适配 ==================== */
@media (max-width: 768px) {
    /* 移动端容器不占据全屏，只在需要时显示 */
    #ai-chat-widget {
        bottom: auto;
        right: auto;
        left: auto;
        top: auto;
        width: auto;
        height: auto;
    }

    /* 悬浮按钮 */
    #ai-chat-trigger {
        position: fixed;
        bottom: 138px; /* 返回顶部 bottom:45px + 高30px + 动画扩展空间 */
        right: 2.7vw;
        width: 30px;
        height: 30px;
        border-radius: 8px;
        z-index: 10000;
    }

    /* 聊天窗口全屏显示 */
    #ai-chat-window {
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    #ai-chat-window.show {
        animation: slideUpMobile 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    /* 头部 */
    #ai-chat-header {
        padding: 12px 16px;
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    /* 消息列表 */
    #ai-chat-messages {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    /* 快捷问题 */
    .ai-quick-questions {
        padding: 10px 16px;
    }

    .ai-quick-question-btn {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* 输入区域 */
    #ai-chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    #ai-chat-input {
        font-size: 16px; /* 防止iOS自动缩放 */
    }

    #ai-chat-send {
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* 平板及小屏PC适配 */
@media (min-width: 769px) and (max-width: 1200px) {
    #ai-chat-window {
        width: min(380px, calc(100vw - 2.7vw - 48px - 35px));
        height: min(600px, calc(100vh - 40px));
        right: calc(2.7vw + 48px + 15px);
    }
}

/* 小屏手机适配 */
@media (max-width: 375px) {
    #ai-chat-trigger {
        width: 30px;
        height: 30px;
        bottom: 100px;
        right: 2.7vw;
    }

    .ai-message-content {
        max-width: 75%;
    }

    .ai-message-bubble {
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* ==================== 暗黑模式支持（可选） ==================== */
@media (prefers-color-scheme: dark) {
    #ai-chat-window {
        background: #1f2937;
    }

    #ai-chat-messages {
        background: #111827;
    }

    .ai-message-item.ai .ai-message-bubble {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }

    #ai-chat-input-area {
        background: #1f2937;
        border-top-color: #374151;
    }

    #ai-chat-input {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }

    #ai-chat-input::placeholder {
        color: #6b7280;
    }

    .ai-quick-questions {
        background: #111827;
        border-top-color: #374151;
    }

    .ai-quick-question-btn {
        background: #374151;
        color: #667eea;
        border-color: #4b5563;
    }
}

/* ==================== 打印时隐藏 ==================== */
@media print {
    #ai-chat-widget {
        display: none !important;
    }
}

