/* ==========================================================================
 * AI 客服悬浮窗样式 ai-chat.css
 * 由 ai-chat.js 自动注入（官网/商城全站复用）；外壳 .ai-chat-fab/.ai-chat-panel
 * 的基础样式在 site.css，本文件补充内部结构样式。
 * ========================================================================== */

#ai-chat-root { position: relative; z-index: 430; }
.ai-chat-fab { cursor: pointer; }
.ai-chat-fab .ai-chat-fab-label {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: var(--r-pill);
    background: rgba(7, 11, 20, .88);
    border: 1px solid var(--glass-border-strong);
    backdrop-filter: blur(12px);
    font-size: var(--fs-xs);
    color: var(--text-2);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base), transform var(--t-base);
}
.ai-chat-fab:hover .ai-chat-fab-label { opacity: 1; transform: translateY(-50%) translateX(-2px); }
.ai-chat-panel { pointer-events: auto; }

.ai-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(140deg, rgba(34, 211, 238, .12), rgba(139, 92, 246, .1));
    flex: none;
}
.ai-chat-brand {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: var(--grad-brand);
    color: #fff;
    flex: none;
}
.ai-chat-brand svg { width: 19px; height: 19px; }
.ai-chat-heading { flex: 1; min-width: 0; }
.ai-chat-title { font-size: var(--fs-sm); font-weight: 650; color: var(--text); }
.ai-chat-status { display: flex; align-items: center; gap: 5px; margin-top: 2px; font-size: 11px; color: var(--text-3); }
.ai-chat-status .ai-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--emerald); box-shadow: 0 0 8px rgba(52, 211, 153, .8); }
.ai-chat-close { color: var(--text-3); }
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0;
}
.ai-chat-body::-webkit-scrollbar { width: 4px; }
.ai-chat-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .14); border-radius: 4px; }

.ai-msg { display: flex; gap: 8px; max-width: 88%; }
.ai-msg.is-user { align-self: flex-end; flex-direction: row-reverse; }
.ai-msg + .ai-msg { margin-top: 2px; }
.ai-avatar {
    width: 26px;
    height: 26px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    flex: none;
    background: rgba(34, 211, 238, .14);
    border: 1px solid rgba(34, 211, 238, .28);
    color: var(--cyan-bright);
    font-size: 11px;
}
.ai-avatar svg { width: 14px; height: 14px; }
.ai-msg.is-user .ai-avatar { background: var(--grad-cta); border-color: transparent; color: var(--text-inverse); }
.ai-bubble {
    padding: 10px 14px;
    border-radius: 14px 14px 14px 4px;
    background: rgba(255, 255, 255, .055);
    border: 1px solid var(--line);
    font-size: var(--fs-sm);
    color: var(--text-2);
    line-height: 1.7;
    word-break: break-word;
    white-space: pre-wrap;
}
.ai-msg.is-user .ai-bubble {
    border-radius: 14px 14px 4px 14px;
    background: var(--grad-cta);
    border-color: transparent;
    color: var(--text-inverse);
}
.ai-msg.is-error .ai-bubble { border-color: rgba(251, 113, 133, .35); color: var(--rose); background: rgba(251, 113, 133, .08); }
.ai-msg.is-typing .ai-bubble { display: inline-flex; align-items: center; gap: 4px; padding: 14px 16px; }
.ai-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    animation: ai-typing 1.2s infinite ease-in-out;
}
.ai-typing-dot:nth-child(2) { animation-delay: .16s; }
.ai-typing-dot:nth-child(3) { animation-delay: .32s; }
@keyframes ai-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.ai-quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; flex: none; }
.ai-quick-btn {
    padding: 6px 12px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line-2);
    background: rgba(255, 255, 255, .03);
    font-size: var(--fs-xs);
    color: var(--text-2);
    transition: all var(--t-fast);
}
.ai-quick-btn:hover { color: var(--cyan-bright); border-color: var(--accent-line); background: var(--accent-soft); }

.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: rgba(7, 11, 20, .6);
    flex: none;
}
.ai-chat-input {
    flex: 1;
    min-width: 0;
    max-height: 96px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--line-2);
    background: rgba(255, 255, 255, .04);
    color: var(--text);
    font-size: var(--fs-sm);
    line-height: 1.55;
    resize: none;
    font-family: inherit;
}
.ai-chat-input:focus { border-color: var(--cyan); box-shadow: var(--ring); outline: none; }
.ai-chat-input::placeholder { color: var(--text-4); }
.ai-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--grad-cta);
    color: var(--text-inverse);
    flex: none;
    transition: filter var(--t-fast), opacity var(--t-fast);
}
.ai-send svg { width: 18px; height: 18px; }
.ai-send:hover { filter: brightness(1.08); }
.ai-send:disabled { opacity: .45; cursor: not-allowed; }
.ai-disclaimer { padding: 0 12px 10px; font-size: 10px; color: var(--text-4); text-align: center; flex: none; }

/* 转人工卡片 */
.ai-transfer-card {
    margin-top: 6px;
    padding: 12px;
    border-radius: var(--r-md);
    border: 1px solid rgba(34, 211, 238, .3);
    background: rgba(34, 211, 238, .06);
    display: grid;
    gap: 10px;
    justify-items: center;
}
.ai-transfer-qr {
    width: 132px;
    height: 132px;
    padding: 8px;
    border-radius: var(--r-sm);
    background: #fff;
    display: grid;
    place-items: center;
}
.ai-transfer-qr img, .ai-transfer-qr svg { width: 100%; height: 100%; display: block; }
.ai-transfer-title { font-size: var(--fs-sm); font-weight: 650; color: var(--text); text-align: center; }
.ai-transfer-tip { font-size: var(--fs-xs); color: var(--text-3); text-align: center; line-height: 1.6; }
.ai-transfer-card .btn { width: 100%; }

/* 移动端面板位置（与 site.css 壳配合） */
@media (max-width: 768px) {
    .ai-chat-panel {
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: calc(100vw - 16px) !important;
        height: min(70dvh, 520px);
        max-height: calc(100dvh - 130px);
        bottom: calc(76px + env(safe-area-inset-bottom));
        box-sizing: border-box;
        overflow: hidden;
    }
    .ai-chat-fab { right: 14px; bottom: calc(70px + env(safe-area-inset-bottom)); width: 48px; height: 48px; }
    .mall-body .ai-chat-fab { bottom: calc(76px + env(safe-area-inset-bottom)); }
    .ai-chat-fab .ai-chat-fab-label { display: none; }
    .ai-chat-input { font-size: 16px !important; line-height: 1.4; }
    .ai-chat-header { padding: 12px 14px; }
    .ai-chat-input-area { padding: 10px; }
    .ai-chat-body { padding: 14px 12px; }
    .ai-chat-quick { padding: 0 12px 8px; gap: 6px; }
    .ai-quick-btn { font-size: 12px; padding: 6px 10px; }
}


/* mobile: customer-service panel is a full-screen sheet */
@media (max-width: 768px) {
    .ai-chat-panel {
        position: fixed !important;
        inset: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: none !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border: 0 !important;
        z-index: 520 !important;
    }
    .ai-chat-panel .ai-chat-header {
        padding-top: max(14px, env(safe-area-inset-top)) !important;
    }
    .ai-chat-panel .ai-chat-body { flex: 1 1 0 !important; }
    .ai-chat-panel .ai-chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    }
    #ai-chat-root:has(.ai-chat-panel.is-open) .ai-chat-fab { display: none !important; }
}
