/* ========== 聊天浮窗按钮 ========== */
.chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3);
    transition: all 0.3s ease;
    animation: fabPulse 3s ease-in-out infinite;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 32px var(--accent-glow);
}

.chat-fab-icon {
    font-size: 26px;
    line-height: 1;
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ff4757;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

@keyframes fabPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3); }
    50% { box-shadow: 0 4px 36px rgba(37, 99, 235, 0.45); }
}

/* ========== 聊天窗口 ========== */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 380px;
    height: 520px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: none;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    animation: chatSlideIn 0.3s ease;
}

.chat-widget.open {
    display: flex;
}

@keyframes chatSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========== 聊天头部 ========== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--gradient);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

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

.chat-status {
    font-size: 12px;
    color: #a7f3d0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a7f3d0;
    display: inline-block;
    animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

/* ========== 消息区域 ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* 欢迎 */
.chat-welcome {
    text-align: center;
    padding: 20px 10px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.chat-welcome-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

/* 消息气泡 */
.msg {
    max-width: 80%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    animation: msgIn 0.25s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-admin {
    align-self: flex-start;
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.msg-admin .msg-time {
    text-align: left;
}

/* ========== 联系信息表单 ========== */
.chat-form {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f9fafb;
    overflow-y: auto;
}

.chat-form-inner {
    text-align: center;
    width: 100%;
}

.chat-form-icon {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background: rgba(37, 99, 235, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.chat-form-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.chat-form-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.chat-form-fields {
    text-align: left;
}

.chat-field {
    margin-bottom: 16px;
}

.chat-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.chat-field input,
.chat-field select {
    width: 100%;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.chat-field input:focus,
.chat-field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.chat-field input::placeholder {
    color: var(--text-muted);
}

.chat-contact-row {
    display: flex;
    gap: 8px;
}

.chat-contact-row select {
    width: 120px;
    flex-shrink: 0;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.chat-contact-row input {
    flex: 1;
    min-width: 0;
}

.chat-form-btn {
    width: 100%;
    padding: 13px 20px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2), 0 0 0 1px rgba(255,255,255,0.1) inset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 4px;
}

.chat-form-btn:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3), 0 0 0 1px rgba(255,255,255,0.15) inset;
}

.chat-form-btn:active {
    filter: brightness(0.95);
}

/* ========== 输入区域 ========== */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #ffffff;
    flex-shrink: 0;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
}

.chat-input-bar input {
    flex: 1;
    padding: 12px 16px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: #f9fafb;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.chat-input-bar input:focus {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input-bar input::placeholder {
    color: var(--text-muted);
}

.chat-input-bar button {
    padding: 12px 20px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2), 0 0 0 1px rgba(255,255,255,0.1) inset;
}

.chat-input-bar button:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3), 0 0 0 1px rgba(255,255,255,0.15) inset;
}

.chat-input-bar button:active {
    filter: brightness(0.95);
}

/* ========== 响应式 — 手机 ========== */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        padding: 14px 16px;
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    .chat-form {
        padding: 20px 16px;
    }

    .chat-form-title {
        font-size: 20px;
    }

    .chat-form-btn {
        padding: 15px 20px;
        font-size: 16px;
        border-radius: 14px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .chat-input-bar input {
        padding: 14px 16px;
        font-size: 16px;
    }

    .chat-input-bar button {
        padding: 14px 20px;
        font-size: 15px;
    }

    .chat-fab {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }

    .chat-close {
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}
