/* ========================================================================
   FlashVPN 官网 - 客服聊天 (悬浮按钮 + 面板) 样式
   ======================================================================== */

.chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: #fff;
    border: 0;
    cursor: pointer;
    box-shadow: 0 12px 30px -8px rgba(37, 99, 235, 0.55), 0 4px 12px -2px rgba(0, 0, 0, 0.18);
    z-index: 1500;
    font-size: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-fab:hover {
    transform: scale(1.08) rotate(-4deg);
    box-shadow: 0 18px 40px -10px rgba(37, 99, 235, 0.65);
}

.chat-fab:active {
    transform: scale(0.95);
}

.chat-fab.is-open {
    background: var(--text-primary);
    transform: rotate(90deg);
}

.chat-fab.is-open:hover {
    transform: rotate(90deg) scale(1.05);
}

.chat-fab-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    opacity: 0.7;
    animation: chatFabPulse 2.4s ease-out infinite;
    pointer-events: none;
}

@keyframes chatFabPulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    70%  { transform: scale(1.3); opacity: 0;   }
    100% { transform: scale(1.3); opacity: 0;   }
}

.chat-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: var(--shadow-sm);
    animation: chatFabBadgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chatFabBadgePop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

.chat-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 130px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 0 24px 50px -12px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatPanelIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

.chat-panel.hidden {
    display: none;
}

@keyframes chatPanelIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.chat-panel.is-minimized {
    height: auto;
}

.chat-panel.is-minimized .chat-body {
    display: none;
}

.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: #fff;
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.chat-title {
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.2;
}

.chat-status {
    font-size: 0.75rem;
    opacity: 0.85;
    line-height: 1.2;
    margin-top: 2px;
}

.chat-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 5px;
    vertical-align: middle;
}

.chat-status.is-offline::before {
    background: #f87171;
}

.chat-header-actions {
    display: flex;
    gap: 0.2rem;
}

.chat-icon-btn {
    width: 30px;
    height: 30px;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: background 0.2s ease;
}

.chat-icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-light);
}

.chat-guest {
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    text-align: center;
    gap: 0.7rem;
}

.chat-guest-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 0.3rem;
}

.chat-guest h4 {
    font-size: 1.15rem;
    color: var(--text-primary);
    margin: 0;
}

.chat-guest p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 0.6rem;
    line-height: 1.6;
}

.chat-guest .auth-submit {
    margin-top: 0.3rem;
}

.chat-conversation {
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.18);
    border-radius: 3px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.chat-empty i {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

/* 入场动画仅对新增消息触发 (避免轮询时整列表闪烁) */
.chat-msg.chat-msg-new {
    animation: chatMsgIn 0.25s ease;
}

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.is-user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg.is-agent {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-msg.is-system {
    align-self: center;
    align-items: center;
    max-width: 90%;
}

.chat-bubble {
    padding: 0.55rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chat-msg.is-user .chat-bubble {
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.is-agent .chat-bubble {
    background: #fff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.chat-msg.is-system .chat-bubble {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 0.25rem 0.6rem;
    border: 1px dashed var(--border-color);
}

.chat-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding: 0 0.2rem;
}

.chat-msg.is-user .chat-meta {
    color: rgba(15, 23, 42, 0.45);
}

.chat-msg.pending .chat-bubble {
    opacity: 0.65;
}

.chat-msg.failed .chat-bubble {
    border: 1px dashed #ef4444;
    color: #b91c1c;
}

.chat-msg-failed-tip {
    font-size: 0.72rem;
    color: #b91c1c;
    margin-top: 0.25rem;
    cursor: pointer;
}

.chat-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 0.55rem 0.85rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chatTypingDot 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-4px); opacity: 1; }
}

.chat-input {
    border-top: 1px solid var(--border-color);
    background: #fff;
    padding: 0.55rem;
    display: flex;
    gap: 0.4rem;
    align-items: flex-end;
}

.chat-input textarea {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    resize: none;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-light);
    transition: border-color 0.2s ease;
    min-height: 38px;
    max-height: 130px;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.chat-send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn.sending i {
    animation: chatSending 1s linear infinite;
}

@keyframes chatSending {
    to { transform: rotate(360deg); }
}

.chat-closed-banner {
    background: #fef3c7;
    color: #92400e;
    text-align: center;
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
    border-top: 1px solid #fde68a;
}

.chat-closed-banner button {
    background: transparent;
    border: 0;
    color: #92400e;
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
    padding: 0;
}

/* ---- 响应式 ---- */
@media (max-width: 480px) {
    .chat-fab {
        right: 16px;
        bottom: 16px;
        width: 54px;
        height: 54px;
    }

    .chat-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: none;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}
