/* 小影子 AI客服 - 喜庆米黄红版（微信浏览器优化） */

/* ========== 基础容器 ========== */
.ai-customer-wrapper {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== 悬浮入口图标 ========== */
.ai-customer-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #c0392b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    position: relative;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.ai-customer-icon:active {
    opacity: 0.8;
}

.ai-customer-icon svg {
    width: 30px;
    height: 30px;
    fill: #fff;
}

.ai-customer-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #e74c3c;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #fff;
    font-weight: bold;
}

.ai-customer-badge.show {
    display: flex;
}

/* ========== 聊天窗口（桌面端） ========== */
.ai-customer-chat {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 320px;
    height: 440px;
    background: #fdf5e6;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 2px solid #c0392b;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.ai-customer-chat.active {
    display: flex;
}

/* ========== 全屏模式（桌面端手动全屏） ========== */
.ai-customer-chat.fullscreen {
    width: 100vw;
    height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    border: none;
}

/* ========== 聊天头部 ========== */
.ai-chat-header {
    background: #c0392b;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 48px;
}

.ai-chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.ai-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-avatar-right {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.ai-chat-avatar-right svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

.ai-chat-header-actions {
    display: flex;
    gap: 6px;
}

.ai-chat-action-btn {
    width: 48px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    -webkit-tap-highlight-color: transparent;
}

.ai-chat-action-btn:active {
    background: rgba(255, 255, 255, 0.4);
}

.ai-chat-action-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.ai-btn-label {
    font-size: 10px;
    color: #fff;
    line-height: 1;
    font-weight: 500;
}

/* ========== 文章上下文指示器 ========== */
.ai-article-context-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fdf5e6;
    border-top: 1px solid #e8c9a0;
    font-size: 12px;
    color: #8b4513;
    flex-shrink: 0;
}

.ai-article-context-indicator.show {
    display: flex;
}

.ai-article-context-indicator svg {
    width: 14px;
    height: 14px;
    fill: #c0392b;
    flex-shrink: 0;
}

.ai-article-context-indicator .ai-article-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-article-context-indicator .ai-article-close-btn {
    width: 22px;
    height: 22px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8b4513;
    padding: 0;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ai-article-context-indicator .ai-article-close-btn:active {
    color: #c0392b;
}

.ai-article-context-indicator .ai-article-close-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ========== 消息区域 ========== */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fdf5e6;
    -webkit-overflow-scrolling: touch;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(192, 57, 43, 0.2);
    border-radius: 2px;
}

/* ========== 消息气泡 ========== */
.ai-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
}

.ai-message.bot {
    align-self: flex-start;
}

.ai-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ai-message.bot .ai-message-avatar {
    background: #c0392b;
}

.ai-message.bot .ai-message-avatar svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.ai-message.user .ai-message-avatar {
    background: #d4a574;
}

.ai-message.user .ai-message-avatar svg {
    width: 14px;
    height: 14px;
    fill: #fff;
}

.ai-message-content {
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-message.bot .ai-message-content {
    background: #f5e6d3;
    color: #3a2a1a;
    border-bottom-left-radius: 3px;
    border: 1px solid #e8c9a0;
}

.ai-message.user .ai-message-content {
    background: #c0392b;
    color: #fff;
    border-bottom-right-radius: 3px;
}

/* ========== 打字指示器 ========== */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 9px 12px;
    background: #f5e6d3;
    border-radius: 10px;
    border-bottom-left-radius: 3px;
    width: fit-content;
    border: 1px solid #e8c9a0;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    background: #c0392b;
    border-radius: 50%;
    animation: typing 1.2s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* ========== 输入区域 ========== */
.ai-chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #e8c9a0;
    background: #fdf5e6;
    flex-shrink: 0;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    padding: 9px 14px;
    border: 1px solid #d4a574;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    background: #fff;
    color: #3a2a1a;
    min-width: 0;
    -webkit-appearance: none;
}

.ai-chat-input:focus {
    border-color: #c0392b;
}

.ai-chat-input::placeholder {
    color: #b89a7a;
}

.ai-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #c0392b;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ai-chat-send-btn:active {
    background: #a93226;
    opacity: 0.85;
}

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

.ai-chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

/* ========== 底部导航 ========== */
.ai-chat-bottom-bar {
    display: flex;
    justify-content: space-around;
    padding: 6px 8px;
    border-top: 1px solid #e8c9a0;
    background: #fdf5e6;
    flex-shrink: 0;
}

.ai-bottom-btn,
.ai-article-read-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 10px;
    border: none;
    background: none;
    cursor: pointer;
    color: #8b4513;
    font-size: 11px;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}

.ai-bottom-btn:active,
.ai-article-read-btn:active {
    background: rgba(192, 57, 43, 0.1);
}

.ai-article-read-btn {
    color: #c0392b;
}

.ai-article-read-btn.reading {
    color: #e74c3c;
    opacity: 0.7;
}

.ai-article-read-btn.loaded {
    color: #27ae60;
}

.ai-bottom-btn svg,
.ai-article-read-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ========== 移动端适配（≤768px 全屏显示） ========== */
@media (max-width: 768px) {
    .ai-customer-wrapper {
        bottom: 12px;
        right: 12px;
    }

    .ai-customer-icon {
        width: 48px;
        height: 48px;
    }

    .ai-customer-icon svg {
        width: 26px;
        height: 26px;
    }

    /* 手机端默认全屏显示 */
    .ai-customer-chat {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        border: none;
    }

    .ai-chat-header {
        padding: 10px 14px;
        min-height: 44px;
    }

    .ai-chat-title {
        font-size: 15px;
    }

    .ai-chat-avatar-right {
        width: 28px;
        height: 28px;
    }

    .ai-chat-avatar-right svg {
        width: 18px;
        height: 18px;
    }

    .ai-chat-action-btn {
        width: 44px;
        height: 38px;
    }

    .ai-chat-action-btn svg {
        width: 15px;
        height: 15px;
    }

    .ai-btn-label {
        font-size: 9px;
    }

    .ai-chat-messages {
        padding: 10px;
        gap: 8px;
    }

    .ai-message {
        max-width: 90%;
    }

    .ai-message-content {
        padding: 8px 10px;
        font-size: 14px;
    }

    .ai-chat-input-area {
        padding: 8px 10px;
        /* 兼容 iOS 底部安全区域 */
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .ai-chat-input {
        padding: 8px 12px;
        font-size: 16px; /* 防止 iOS 自动放大 */
    }

    .ai-chat-send-btn {
        width: 36px;
        height: 36px;
    }

    .ai-chat-bottom-bar {
        padding: 4px 6px;
        padding-bottom: calc(4px + env(safe-area-inset-bottom));
    }

    .ai-bottom-btn,
    .ai-article-read-btn {
        padding: 6px 8px;
        min-width: 44px;
        min-height: 44px;
    }

    .ai-bottom-btn svg,
    .ai-article-read-btn svg {
        width: 18px;
        height: 18px;
    }

    .ai-bottom-btn span,
    .ai-article-read-btn span {
        font-size: 10px;
    }

    .ai-article-context-indicator {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* ========== 小屏手机适配（≤375px） ========== */
@media (max-width: 375px) {
    .ai-chat-header {
        padding: 8px 12px;
    }

    .ai-chat-title {
        font-size: 14px;
    }

    .ai-chat-header-right {
        gap: 6px;
    }

    .ai-chat-avatar-right {
        display: none; /* 超小屏隐藏头像节省空间 */
    }

    .ai-chat-action-btn {
        width: 40px;
        height: 36px;
    }

    .ai-chat-action-btn svg {
        width: 14px;
        height: 14px;
    }

    .ai-btn-label {
        font-size: 8px;
    }

    .ai-chat-input {
        font-size: 16px;
        padding: 8px 10px;
    }

    .ai-chat-messages {
        padding: 8px;
    }

    .ai-message-content {
        font-size: 14px;
        padding: 8px 10px;
    }
}
