/* =========================================================
   Chat widget — bottom-right FAB + panel (purple/red)
   ========================================================= */

.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--accent, #a855f7);
    color: #000000;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(168, 85, 247, .5);
    z-index: 1000;
    transition: transform .15s ease, background .2s ease;
}
.chat-fab:hover {
    background: var(--accent-soft, #c084fc);
    transform: translateY(-1px);
}
.chat-fab:focus-visible {
    outline: 3px solid rgba(168, 85, 247, .5);
    outline-offset: 2px;
}

.chat-fab__icon { display: block; }
.chat-fab__icon--close { display: none; }
.chat-fab[aria-expanded="true"] .chat-fab__icon--open { display: none; }
.chat-fab[aria-expanded="true"] .chat-fab__icon--close { display: block; }

.chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: min(380px, calc(100vw - 32px));
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--bg-card, #181818);
    color: var(--text, #f5f5f5);
    border: 1px solid var(--border, #262626);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transform-origin: bottom right;
    animation: chat-pop .18s ease-out;
}
/* Respect the HTML `hidden` attribute — JS removes it on click. */
.chat-panel[hidden] {
    display: none;
}
@keyframes chat-pop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-panel__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--border, #262626);
    background: linear-gradient(180deg, rgba(168,85,247,.18), transparent);
}
.chat-panel__eyebrow {
    margin: 0;
    font-family: var(--font-mono, monospace);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--accent-soft, #c084fc);
}
.chat-panel__title {
    margin: .15rem 0 0;
    font-size: 1.05rem;
}
.chat-panel__close {
    background: transparent;
    border: 1px solid var(--border, #262626);
    color: var(--text-dim, #a3a3a3);
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: color .15s ease, border-color .15s ease;
}
.chat-panel__close:hover {
    color: var(--text, #f5f5f5);
    border-color: var(--red, #ef4444);
}

.chat-panel__log {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    scroll-behavior: smooth;
}

.bubble {
    max-width: 85%;
    padding: .65rem .85rem;
    border-radius: 12px;
    line-height: 1.45;
    font-size: .92rem;
    word-wrap: break-word;
    animation: chat-bubble .18s ease-out;
}
@keyframes chat-bubble {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.bubble p { margin: 0; color: inherit; }
.bubble p + p { margin-top: .35rem; }

.bubble--user {
    align-self: flex-end;
    background: var(--accent, #a855f7);
    color: #f5f5f5;
    border-bottom-right-radius: 4px;
}
.bubble--bot {
    align-self: flex-start;
    background: var(--bg-soft, #141414);
    color: var(--text, #f5f5f5);
    border: 1px solid var(--border, #262626);
    border-bottom-left-radius: 4px;
}

.bubble--typing {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
}
.bubble--typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-mute, #6b6b6b);
    animation: chat-typing 1s infinite ease-in-out;
}
.bubble--typing span:nth-child(2) { animation-delay: .15s; }
.bubble--typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing {
    0%, 60%, 100% { opacity: .35; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

.chat-panel__form {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .75rem 1rem;
    border-top: 1px solid var(--border, #262626);
}
.chat-panel__input {
    flex: 1;
    resize: none;
    min-height: 38px;
    max-height: 120px;
    padding: .55rem .75rem;
    border: 1px solid var(--border, #262626);
    background: var(--bg, #0a0a0a);
    color: var(--text, #f5f5f5);
    border-radius: 10px;
    font-family: inherit;
    font-size: .92rem;
    line-height: 1.4;
}
.chat-panel__input:focus {
    outline: none;
    border-color: var(--accent, #a855f7);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, .2);
}
.chat-panel__send {
    flex: 0 0 38px;
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--red, #ef4444);
    color: #000000;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .15s ease, transform .15s ease;
}
.chat-panel__send:hover { background: var(--red-soft, #f87171); transform: translateY(-1px); }
.chat-panel__send:disabled {
    background: var(--border, #262626);
    color: var(--text-mute, #6b6b6b);
    cursor: not-allowed;
    transform: none;
}

.chat-panel__hint {
    margin: 0;
    padding: .5rem 1.1rem .85rem;
    font-size: .75rem;
    color: var(--text-mute, #6b6b6b);
    border-top: 1px dashed var(--border, #262626);
    text-align: center;
}
.chat-panel__hint a { color: var(--accent-soft, #c084fc); }

/* ---------- mobile ---------- */

@media (max-width: 480px) {
    .chat-fab {
        bottom: 16px;
        right: 16px;
    }
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 60vh;
        max-height: 100vh;
        border-radius: 14px 14px 0 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
    }
}