/* --- Panel open state --- */
.chat-panel.is-open {
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0);
}

.chat-fab,
.telegram-fab {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-fab-stack {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#chat-voice-button.is-recording {
    border-color: rgb(252 165 165);
    background-color: rgb(254 226 226);
    color: rgb(220 38 38);
    animation: chatMicPulse 1.2s ease-in-out infinite;
}

.chat-recording-dot {
    animation: chatMicPulse 1.2s ease-in-out infinite;
}

@keyframes chatMicPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.55;
        transform: scale(0.88);
    }
}

/* Mobile: anchor between sticky header and FAB — prevents top clipping */
@media (max-width: 639px) {
    .chat-panel {
        inset-inline: 0.75rem;
        top: calc(env(safe-area-inset-top, 0px) + 4.25rem);
        bottom: calc(env(safe-area-inset-bottom, 0px) + 9.5rem);
        width: auto;
        max-height: none;
    }

    .chat-panel.is-open {
        transform: translateY(0);
    }

    .chat-fab.is-panel-open {
        opacity: 0;
        pointer-events: none;
        transform: scale(0.85);
    }

    body.chat-panel-open {
        overflow: hidden;
    }
}

/* Desktop: floating card above FAB */
@media (min-width: 640px) {
    .chat-panel {
        bottom: 10.5rem;
        left: 1.5rem;
        width: min(100vw - 2rem, 24rem);
        max-height: min(92dvh, 40rem);
    }
}

.chat-messages {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.chat-bubble {
    animation: chatBubbleIn 0.25s ease-out;
}

.chat-action-card {
    max-width: 100%;
}

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

#chat-typing-indicator {
    display: none;
}

#chat-typing-indicator.htmx-request {
    display: block;
}

.chat-typing-dots span {
    display: inline-block;
    width: 0.35rem;
    height: 0.35rem;
    border-radius: 9999px;
    background: #10b981;
    animation: chatDotPulse 1.2s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatDotPulse {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-bubble,
    .chat-panel,
    .chat-typing-dots span,
    .chat-fab,
    .telegram-fab {
        animation: none !important;
        transition: none !important;
    }
}
