/* ── Chat Widget ── */
.chat-toggle {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #6c63ff;
    border: none;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(108, 99, 255, .4);
    transition: transform .2s, box-shadow .2s;
    animation: chatPulse 2.5s infinite;
}
.chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(108, 99, 255, .55);
    animation: none;
}
.chat-toggle.open { animation: none; }
@keyframes chatPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(108, 99, 255, .4); }
    50% { box-shadow: 0 4px 30px rgba(108, 99, 255, .7), 0 0 60px rgba(108, 99, 255, .15); }
}
.chat-toggle svg {
    width: 26px;
    height: 26px;
    fill: #fff;
    transition: opacity .2s, transform .3s;
}
.chat-toggle .chat-icon-close { display: none; }
.chat-toggle.open .chat-icon-open { display: none; }
.chat-toggle.open .chat-icon-close { display: block; }

/* ── Panel ── */
.chat-panel {
    position: fixed;
    bottom: 170px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: #111;
    border: 1px solid rgba(108, 99, 255, .25);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,.5), 0 0 80px rgba(108, 99, 255, .08);
    opacity: 0;
    transform: translateY(20px) scale(.95);
    pointer-events: none;
    transition: opacity .3s cubic-bezier(.4,0,.2,1), transform .3s cubic-bezier(.4,0,.2,1);
}
.chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header — animated gradient */
.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #161616 0%, #1a1535 50%, #161616 100%);
    background-size: 200% 200%;
    animation: headerShimmer 6s ease infinite;
    border-bottom: 1px solid rgba(108, 99, 255, .15);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}
@keyframes headerShimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(108, 99, 255, .4), transparent);
}
.chat-header-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    flex-shrink: 0;
    animation: dotPulse 2s infinite;
}
@keyframes dotPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, .4); }
    50% { box-shadow: 0 0 0 5px rgba(76, 175, 80, 0); }
}
.chat-header-text h4 {
    margin: 0;
    font-size: 14px;
    color: #fff;
    font-weight: 600;
}
.chat-header-text p {
    margin: 2px 0 0;
    font-size: 11px;
    color: rgba(255,255,255,.45);
}
.chat-header-badge {
    margin-left: auto;
    font-size: 9px;
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(108, 99, 255, .15);
    color: #8b83ff;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 340px;
    scrollbar-width: thin;
    scrollbar-color: rgba(108,99,255,.3) transparent;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(108,99,255,.3); border-radius: 4px; }

.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: msgSlideIn .3s cubic-bezier(.4,0,.2,1);
}
@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg a { color: #8b83ff; text-decoration: underline; }
.chat-msg-user {
    align-self: flex-end;
    background: #6c63ff;
    color: #fff;
    border-bottom-right-radius: 4px;
    animation-name: msgSlideRight;
}
@keyframes msgSlideRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
.chat-msg-assistant {
    align-self: flex-start;
    background: #1e1e1e;
    color: rgba(255,255,255,.88);
    border-bottom-left-radius: 4px;
    animation-name: msgSlideLeft;
}
@keyframes msgSlideLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Typewriter cursor */
.chat-msg-assistant .typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: #6c63ff;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink .6s infinite;
}
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Typing indicator */
.chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 18px;
    background: #1e1e1e;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    gap: 5px;
    animation: msgSlideLeft .3s cubic-bezier(.4,0,.2,1);
}
.chat-typing.visible { display: flex; }
.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6c63ff;
    animation: chatDot 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatDot {
    0%, 60%, 100% { opacity: .3; transform: translateY(0) scale(1); }
    30% { opacity: 1; transform: translateY(-6px) scale(1.2); }
}

/* Quick actions */
.chat-quick-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 0 16px 8px;
    background: transparent;
}
.chat-quick-btn {
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid rgba(108, 99, 255, .3);
    background: transparent;
    color: #8b83ff;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.chat-quick-btn:hover {
    background: rgba(108, 99, 255, .15);
    border-color: #6c63ff;
}

/* Input */
.chat-input-area {
    padding: 12px 16px;
    background: #161616;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    gap: 8px;
}
.chat-input-area input {
    flex: 1;
    background: #222;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 8px;
    padding: 10px 14px;
    color: #fff;
    font-size: 13px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.chat-input-area input::placeholder { color: rgba(255,255,255,.3); }
.chat-input-area input:focus {
    border-color: #6c63ff;
    box-shadow: 0 0 0 3px rgba(108, 99, 255, .1);
}
.chat-input-area button {
    background: #6c63ff;
    border: none;
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, transform .15s;
}
.chat-input-area button:hover { background: #5a52e0; }
.chat-input-area button:active { transform: scale(.92); }
.chat-input-area button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.chat-input-area button svg { width: 18px; height: 18px; fill: #fff; }

/* ── Powered by ── */
.chat-powered {
    text-align: center;
    padding: 6px;
    font-size: 9px;
    color: rgba(255,255,255,.2);
    background: #161616;
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-sizing: border-box;
    }
    .chat-panel *,
    .chat-panel *::before,
    .chat-panel *::after { box-sizing: border-box; }
    .chat-input-area {
        padding: 12px;
        width: 100%;
        max-width: 100%;
    }
    .chat-input-area input {
        min-width: 0;
        padding: 10px 12px;
        font-size: 16px;
    }
    .chat-input-area button {
        flex-shrink: 0;
        width: 44px;
        min-width: 44px;
        padding: 0;
    }
    .chat-messages { max-height: calc(100dvh - 220px); }
    .chat-toggle { bottom: 80px; right: 16px; }
    .chat-toggle.open {
        bottom: auto;
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
        background: rgba(108, 99, 255, .8);
        box-shadow: none;
        z-index: 10000;
    }
    .chat-toggle.open svg { width: 20px; height: 20px; }
}
