/* =====================================================
   AI 悬浮球 + 聊天面板
   Apple 风格：毛玻璃、弹性弹出、悬停微动
   ===================================================== */

/* ---- 悬浮球 ---- */
.chat-orb {
    position: fixed;
    right: 28px;
    bottom: 28px;
    width: 64px;
    height: 64px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    cursor: pointer;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--transition-pro);
}

.chat-orb:hover {
    transform: translateY(-3px);
}

.chat-orb-halo {
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.45) 0%, rgba(240, 147, 251, 0.18) 45%, transparent 72%);
    filter: blur(10px);
    opacity: 0.85;
    animation: orb-breathe 4.5s ease-in-out infinite;
    transition: opacity var(--transition-smooth), transform var(--transition-pro);
    pointer-events: none;
}

.chat-orb:hover .chat-orb-halo {
    opacity: 1;
    transform: scale(1.18);
}

.chat-orb-core {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 45%, #4facfe 100%);
    background-size: 200% 200%;
    animation: gradient-shift 6s ease infinite;
    color: #ffffff;
    box-shadow: 0 10px 30px rgba(82, 92, 190, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform var(--transition-pro), box-shadow var(--transition-smooth);
}

.chat-orb:hover .chat-orb-core {
    transform: scale(1.06);
    box-shadow: 0 16px 42px rgba(82, 92, 190, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.chat-orb-initial {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: opacity var(--transition-fast), transform var(--transition-smooth);
}

.chat-orb-close {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
    transition: opacity var(--transition-fast), transform var(--transition-smooth);
}

.chat-orb.is-open .chat-orb-initial {
    opacity: 0;
    transform: scale(0.5);
}

.chat-orb.is-open .chat-orb-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chat-orb.is-open {
    transform: none;
}

/* 悬停标签 */
.chat-orb-label {
    position: absolute;
    right: calc(100% + 14px);
    top: 50%;
    transform: translate(10px, -50%) scale(0.96);
    padding: 9px 15px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    color: var(--color-text);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth), transform var(--transition-pro);
}

.chat-orb:hover .chat-orb-label,
.chat-orb:focus-visible .chat-orb-label {
    opacity: 1;
    transform: translate(0, -50%) scale(1);
}

.chat-orb.is-open .chat-orb-label {
    opacity: 0;
}

/* ---- 聊天面板 ---- */
.chat-panel {
    position: fixed;
    left: 28px;
    bottom: 28px;
    width: min(380px, calc(100vw - 56px));
    height: min(560px, calc(100dvh - 120px));
    z-index: 1290;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.18),
        0 0 0 1px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    opacity: 0;
    transform: translateY(28px) scale(0.94);
    transform-origin: 18% 100%;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-panel-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 18px;
    gap: 8px;
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.chat-panel-identity {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-panel-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 45%, #4facfe 100%);
    background-size: 200% 200%;
    animation: gradient-shift 6s ease infinite;
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-panel-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.chat-panel-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34c759;
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
}

.chat-panel-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.chat-panel .chat-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    color: var(--color-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.chat-panel .chat-action-btn:hover {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

/* 面板内消息区高度自适应 */
.chat-panel .chat-messages {
    flex: 1;
    max-height: none;
    min-height: 0;
    padding: 6px 2px;
}

.chat-panel .chat-message {
    max-width: 86%;
}

.chat-panel .chat-bubble {
    font-size: 14px;
    padding: 11px 14px;
}

.chat-panel .chat-form {
    margin-top: 4px;
    padding-top: 10px;
}

.chat-panel .chat-input-wrap {
    padding: 5px 5px 5px 6px;
}

.chat-panel .chat-voice,
.chat-panel .chat-send {
    width: 36px;
    height: 36px;
}

.chat-panel .chat-error {
    order: 2;
}

/* 面板内滚动条 */
.chat-panel .chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-panel .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}

/* ---- 动画 ---- */
@keyframes orb-breathe {
    0%, 100% { opacity: 0.75; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.08); }
}

/* ---- 响应式 ---- */
@media (max-width: 768px) {
    .chat-orb {
        right: 18px;
        bottom: 18px;
        width: 56px;
        height: 56px;
    }

    .chat-orb-label {
        display: none;
    }

    .chat-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: min(82dvh, 640px);
        border-radius: 24px 24px 0 0;
        transform: translateY(40px) scale(0.98);
    }

    .chat-panel.open {
        transform: translateY(0) scale(1);
    }

    .chat-panel-inner {
        padding: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-orb,
    .chat-orb-core,
    .chat-orb-halo,
    .chat-orb-label,
    .chat-panel {
        transition: none;
        animation: none;
    }
}
