.sp-bps-ai-chat {
    position: relative;
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 229, 255, 0.12);
    border-radius: 20px;
    background: rgba(12, 14, 22, 0.65);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35), 0 0 60px rgba(0, 229, 255, 0.04);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.sp-bps-ai-chat__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1.2rem;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.08) 0%, rgba(124, 58, 237, 0.08) 100%);
    border-bottom: 1px solid rgba(0, 229, 255, 0.1);
}

.sp-bps-ai-chat__avatar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.2) 0%, rgba(124, 58, 237, 0.2) 100%);
    border: 1px solid rgba(0, 229, 255, 0.25);
    color: #00e5ff;
    animation: sp-pulse-glow 3s ease-in-out infinite;
}

@keyframes sp-pulse-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(0, 229, 255, 0.15); }
    50%      { box-shadow: 0 0 18px rgba(0, 229, 255, 0.3); }
}

.sp-bps-ai-chat__header-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sp-bps-ai-chat__header-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.01em;
}

.sp-bps-ai-chat__header-status {
    font-size: 0.78rem;
    color: #8ff8cd;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sp-bps-ai-chat__header-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8ff8cd;
    box-shadow: 0 0 6px rgba(143, 248, 205, 0.5);
    animation: sp-status-blink 2.5s ease-in-out infinite;
}

@keyframes sp-status-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

.sp-bps-ai-chat__messages {
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 1rem 1.2rem;
}

.sp-bps-ai-chat__messages:empty {
    display: none;
}

.sp-bps-ai-chat__bubble {
    max-width: 85%;
    padding: 0.7rem 1rem;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.7;
    white-space: pre-wrap;
    animation: sp-bubble-in 0.25s ease-out;
}

@keyframes sp-bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sp-bps-ai-chat__bubble--assistant {
    align-self: flex-end;
    border: 1px solid rgba(0, 229, 255, 0.14);
    background: rgba(0, 229, 255, 0.06);
    color: #e4fbff;
    border-end-end-radius: 4px;
}

.sp-bps-ai-chat__bubble--user {
    align-self: flex-start;
    border: 1px solid rgba(124, 58, 237, 0.18);
    background: rgba(124, 58, 237, 0.1);
    color: #ffffff;
    border-end-start-radius: 4px;
}

.sp-bps-ai-chat__message-form {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    padding: 0.8rem 1.2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(7, 10, 16, 0.4);
}

.sp-bps-ai-chat__message-form textarea {
    flex: 1;
    padding: 0.65rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: rgba(18, 18, 26, 0.8);
    color: #ffffff;
    font: inherit;
    font-size: 0.92rem;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.sp-bps-ai-chat__message-form textarea:focus {
    outline: none;
    border-color: rgba(0, 229, 255, 0.4);
    box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.08);
}

.sp-bps-ai-chat__message-form textarea:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.sp-bps-ai-chat__composer-actions {
    display: flex;
    flex-shrink: 0;
}

.sp-bps-ai-chat__button {
    min-width: auto;
    padding: 0.55rem 1.3rem;
    font-size: 0.88rem;
    border-radius: 12px;
}

.sp-bps-ai-chat__status {
    position: absolute;
    bottom: 0.45rem;
    right: 1.2rem;
    min-height: 1.2em;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.78rem;
    pointer-events: none;
}

.sp-bps-ai-chat__notice {
    padding: 0.5rem 1.2rem;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.5);
}

.sp-bps-ai-chat__status.is-error,
.sp-bps-ai-chat__notice {
    color: #ffb4c1;
}

.sp-bps-ai-chat__status.is-success {
    color: #8ff8cd;
}

.sp-bps-ai-chat__dock {
    position: fixed !important;
    top: auto !important;
    right: 20px !important;
    bottom: 20px !important;
    left: auto !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.2) 0%, rgba(124, 58, 237, 0.2) 100%) !important;
    border: 1px solid rgba(0, 229, 255, 0.25) !important;
    color: #00e5ff !important;
    cursor: pointer !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 10001 !important;
    will-change: transform, opacity;
    animation: sp-pulse-glow 3s ease-in-out infinite;
}

.sp-bps-ai-chat__dock-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #00e5ff;
}

.sp-bps-ai-chat__dock-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.8;
}

.sp-bps-ai-chat__dock.is-docked {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sp-bps-ai-chat__dock.is-bouncing {
    animation: sp-bps-ai-chat-dock-bounce-in 0.8s cubic-bezier(0.18, 0.89, 0.25, 1.18) both;
}

@keyframes sp-bps-ai-chat-dock-shimmer {
    0%, 100% {
        box-shadow: 0 14px 36px rgba(0, 0, 0, 0.26), 0 0 20px rgba(0, 229, 255, 0.15), 0 0 40px rgba(0, 229, 255, 0.1);
    }
    50% {
        box-shadow: 0 14px 36px rgba(0, 0, 0, 0.26), 0 0 30px rgba(0, 229, 255, 0.35), 0 0 60px rgba(124, 58, 237, 0.25);
    }
}

@keyframes sp-bps-ai-chat-dock-bounce-in {
    0% {
        opacity: 0;
        transform: translate(-42vw, -38vh) scale(0.2) rotate(-18deg);
    }
    55% {
        opacity: 1;
        transform: translate(10px, 10px) scale(1.1) rotate(4deg);
    }
    75% {
        transform: translate(-4px, -4px) scale(0.96) rotate(0deg);
    }
    100% {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
}

.sp-bps-ai-chat.is-docked {
    opacity: 0;
    transform: translate(42vw, 38vh) scale(0.15);
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.18, 0.89, 0.25, 1.18);
    z-index: 10000 !important;
}

.sp-bps-ai-chat.is-docked > *:not(.sp-bps-ai-chat__dock) {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sp-bps-ai-chat.is-restoring {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.18, 0.89, 0.25, 1.18);
}

.sp-bps-ai-chat.is-restoring > *:not(.sp-bps-ai-chat__dock) {
    opacity: 1;
    transition: opacity 0.3s ease 0.1s;
}

.sp-bps-ai-chat:not(.is-docked) {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

@media (max-width: 767px) {
    .sp-bps-ai-chat {
        margin-top: 1.5rem;
        margin-inline: 0;
        border-radius: 16px;
        width: 100%;
        max-width: 100%;
    }

    .sp-bps-ai-chat__header {
        padding: 0.85rem 1rem;
    }

    .sp-bps-ai-chat__avatar {
        width: 40px;
        height: 40px;
    }

    .sp-bps-ai-chat__header-title {
        font-size: 0.95rem;
    }

    .sp-bps-ai-chat__header-status {
        font-size: 0.75rem;
    }

    .sp-bps-ai-chat__messages {
        max-height: 280px;
        padding: 0.9rem 1rem;
        gap: 0.6rem;
        -webkit-overflow-scrolling: touch;
    }

    .sp-bps-ai-chat__bubble {
        max-width: 88%;
        padding: 0.7rem 0.9rem;
        font-size: 0.9rem;
        line-height: 1.5;
        border-radius: 14px;
    }

    .sp-bps-ai-chat__bubble--user {
        border-radius: 14px 14px 4px 14px;
    }

    .sp-bps-ai-chat__bubble--bot {
        border-radius: 14px 14px 14px 4px;
    }

    .sp-bps-ai-chat__message-form {
        padding: 0.85rem 1rem;
        gap: 0.6rem;
        flex-wrap: wrap;
    }

    .sp-bps-ai-chat__message-form textarea {
        flex: 1 1 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        min-height: 44px;
        border-radius: 12px;
        -webkit-appearance: none;
        appearance: none;
    }

    .sp-bps-ai-chat__button {
        flex: 0 0 auto;
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
        min-height: 44px;
        border-radius: 12px;
    }

    .sp-bps-ai-chat__dock {
        right: 12px;
        bottom: 12px;
        top: auto;
        transform: translate(0, 0) scale(0.85);
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: linear-gradient(135deg, rgba(0, 229, 255, 0.2) 0%, rgba(124, 58, 237, 0.2) 100%);
        border: 1px solid rgba(0, 229, 255, 0.25);
        color: #00e5ff;
        animation: sp-pulse-glow 3s ease-in-out infinite;
    }

    .sp-bps-ai-chat__dock.is-docked {
        transform: translate(0, 0) scale(1);
    }

    @keyframes sp-bps-ai-chat-dock-bounce-in {
        0% {
            opacity: 0;
            transform: translate(-22vw, -28vh) scale(0.2) rotate(-18deg);
        }
        55% {
            opacity: 1;
            transform: translate(8px, 8px) scale(1.08) rotate(4deg);
        }
        75% {
            transform: translate(-3px, -3px) scale(0.97) rotate(0deg);
        }
        100% {
            opacity: 1;
            transform: translate(0, 0) scale(1) rotate(0deg);
        }
    }

    /* Lead capture form mobile */
    .sp-bps-ai-chat__lead-form {
        padding: 1rem;
    }

    .sp-bps-ai-chat__lead-field {
        margin-block-end: 0.75rem;
    }

    .sp-bps-ai-chat__lead-field input {
        padding: 0.85rem 1rem;
        font-size: 1rem;
        min-height: 48px;
    }
}

/* Touch optimizations for chat */
@media (hover: none) and (pointer: coarse) {
    .sp-bps-ai-chat__button,
    .sp-bps-ai-chat__dock {
        min-height: 48px;
        min-width: 48px;
    }

    .sp-bps-ai-chat__message-form textarea {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .sp-bps-ai-chat__lead-field input {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .sp-bps-ai-chat__bubble {
        -webkit-tap-highlight-color: transparent;
    }
}
