/**
 * HyCOforce AI Bot - 小力机器人样式
 * 所有class已添加 aibot- 前缀，避免与宿主页面冲突
 */

/* ========== 浮动按钮（可拖动） ========== */
.aibot-fab {
    position: fixed;
    top: 50%;
    right: 24px;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    z-index: 9999;
    transition: box-shadow 0.3s;
    user-select: none;
    -webkit-user-select: none;
}

.aibot-fab:active {
    cursor: grabbing;
}

.aibot-fab img {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    pointer-events: none;
    background: #fff;
    box-shadow: 0 0 15px rgba(26, 117, 166, 0.5);
    animation: aibot-avatarGlow 3s ease-in-out infinite;
}

@keyframes aibot-avatarGlow {
    0%, 100% { box-shadow: 0 0 15px rgba(26, 117, 166, 0.4); }
    50% { box-shadow: 0 0 30px rgba(26, 117, 166, 0.7), 0 0 50px rgba(26, 117, 166, 0.3); }
}

.aibot-fab.active {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* ========== 气泡提示 ========== */
.aibot-bubble-tip {
    position: fixed;
    z-index: 9998;
    background: #fff;
    border-radius: 16px;
    padding: 12px 18px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.aibot-bubble-tip.show {
    opacity: 1;
    transform: translateY(-50%) scale(1);
    pointer-events: auto;
    cursor: pointer;
}

.aibot-bubble-tip::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 8px solid transparent;
}

.aibot-bubble-tip.arrow-right::after {
    right: -16px;
    top: 50%;
    transform: translateY(-50%);
    border-left-color: #fff;
}

.aibot-bubble-tip.arrow-down::after {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-color: #fff;
}

/* ========== 聊天窗口 ========== */
.aibot-window {
    position: fixed;
    width: 380px;
    height: 560px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    transform: scale(0);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.aibot-window.open {
    transform: scale(1);
    opacity: 1;
    pointer-events: all;
}

/* ========== 聊天头部 ========== */
.aibot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #fff;
    color: #333;
    flex-shrink: 0;
    border-bottom: 1px solid #eee;
}

.aibot-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aibot-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: transparent;
}

.aibot-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    box-shadow: 0 0 0 2px rgba(26, 117, 166, 0.5);
    animation: aibot-avatarGlow 3s ease-in-out infinite;
}

.aibot-header-info h3 {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.aibot-header-info p {
    font-size: 11px;
    color: #999;
    margin: 0;
}

.aibot-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.aibot-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.aibot-close svg {
    width: 18px;
    height: 18px;
    fill: #999;
}

/* ========== 消息区域 ========== */
.aibot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fb;
}

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

.aibot-messages::-webkit-scrollbar-thumb {
    background: rgba(26, 117, 166, 0.2);
    border-radius: 2px;
}

.aibot-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
}

.aibot-msg.bot {
    align-self: flex-start;
}

.aibot-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.aibot-msg-avatar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.aibot-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.aibot-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.aibot-msg.bot .aibot-msg-avatar img {
    box-shadow: 0 0 0 2px rgba(26, 117, 166, 0.5);
    animation: aibot-avatarGlow 3s ease-in-out infinite;
}

.aibot-msg-name {
    font-size: 10px;
    color: #999;
    text-align: center;
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aibot-msg-content-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aibot-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}

.aibot-msg.bot .aibot-msg-bubble {
    background: #fff;
    color: #333;
    border: 1px solid rgba(26, 117, 166, 0.1);
    border-top-left-radius: 4px;
}

.aibot-msg.user .aibot-msg-bubble {
    background: #1A75A6;
    color: #fff;
    border-top-right-radius: 4px;
}

/* 正在输入动画 */
.aibot-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

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

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

@keyframes aibot-typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ========== 快捷问题 ========== */
.aibot-quick-questions {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid rgba(26, 117, 166, 0.08);
    background: #fff;
}

.aibot-quick-btn {
    padding: 4px 12px;
    border: 1px solid rgba(26, 117, 166, 0.2);
    border-radius: 14px;
    background: rgba(26, 117, 166, 0.04);
    color: #1A75A6;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.aibot-quick-btn:hover {
    background: rgba(26, 117, 166, 0.1);
    border-color: rgba(26, 117, 166, 0.3);
}

/* ========== 输入区域 ========== */
.aibot-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid rgba(26, 117, 166, 0.1);
    flex-shrink: 0;
}

.aibot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid rgba(26, 117, 166, 0.15);
    border-radius: 22px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: #f8f9fb;
}

.aibot-input:focus {
    border-color: #1A75A6;
    background: #fff;
}

.aibot-input::placeholder {
    color: #bbb;
}

.aibot-send {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #1A75A6 0%, #1565c0 100%);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.aibot-send:hover {
    transform: scale(1.05);
}

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

.aibot-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ========== 手机端 ========== */
@media (max-width: 768px) {
    /* 手机端显示机器人，调整位置避免与其他元素重合 */
    .aibot-fab {
        top: auto;
        bottom: 120px;
        left: auto;
        right: 16px;
        transform: none;
        width: 50px;
        height: 50px;
        /* 允许任意方向移动 */
        position: fixed;
        touch-action: none;
    }

    .aibot-fab img {
        width: 50px;
        height: 50px;
    }

    /* 手机端聊天窗口 - 底部弹出抽屉式，不占满全屏 */
    .aibot-window {
        width: 100% !important;
        height: 55vh !important;
        max-height: 420px !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        transform-origin: bottom center;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .aibot-window.open {
        transform: scale(1) !important;
        transform: translateY(0) !important;
    }

    /* 关闭按钮更明显 */
    .aibot-close {
        width: 32px;
        height: 32px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 50%;
    }

    .aibot-close svg {
        width: 20px;
        height: 20px;
    }

    /* 手机端消息区域调整 */
    .aibot-messages {
        padding: 12px;
    }

    /* 手机端输入区域调整 - 不自动聚焦 */
    .aibot-input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
    }

    .aibot-input {
        font-size: 16px; /* 防止 iOS 自动缩放 */
    }

    /* 手机端快捷问题调整 */
    .aibot-quick-questions {
        padding: 8px 12px;
    }

    /* 手机端气泡提示位置调整 */
    .aibot-bubble-tip {
        bottom: 180px !important;
        top: auto !important;
        right: 70px !important;
        left: auto !important;
        transform: none !important;
    }

    .aibot-bubble-tip.show {
        transform: scale(1) !important;
    }

    .aibot-bubble-tip::after {
        display: none;
    }
}
