/* ── Chat launcher (fixed bottom-right) ── */
#chat-launcher {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 60;
    width: 3.75rem;
    height: 3.75rem;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0ea5e9 0%, #7dd3fc 50%, #38bdf8 100%);
    color: #fff;
    box-shadow:
        0 4px 20px -4px rgba(56, 189, 248, 0.55),
        0 0 32px -4px rgba(125, 211, 252, 0.45);
    animation: chatNeonPulse 3.5s ease-in-out infinite;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

#chat-launcher:hover {
    transform: scale(1.08);
}

#chat-launcher:focus-visible {
    outline: 2px solid #bae6fd;
    outline-offset: 3px;
}

#chat-launcher svg {
    width: 1.65rem;
    height: 1.65rem;
}

#chat-launcher[data-open="true"] {
    animation: none;
    box-shadow: 0 4px 16px -4px rgba(56, 189, 248, 0.4);
}

@keyframes chatNeonPulse {
    0%, 100% {
        box-shadow:
            0 4px 20px -4px rgba(56, 189, 248, 0.5),
            0 0 24px 0 rgba(125, 211, 252, 0.35),
            0 0 48px -8px rgba(56, 189, 248, 0.25);
    }
    50% {
        box-shadow:
            0 4px 28px -2px rgba(56, 189, 248, 0.75),
            0 0 40px 4px rgba(125, 211, 252, 0.55),
            0 0 72px -4px rgba(14, 165, 233, 0.45);
    }
}

/* ── Chat panel ── */
#chat-panel {
    position: fixed;
    bottom: 5.75rem;
    right: 1.5rem;
    z-index: 60;
    width: min(400px, calc(100vw - 2rem));
    height: min(520px, calc(100vh - 8rem));
    display: flex;
    flex-direction: column;
    border-radius: 1.25rem;
    overflow: hidden;
    background: linear-gradient(165deg, rgba(24, 32, 52, 0.95) 0%, rgba(17, 24, 39, 0.98) 100%);
    backdrop-filter: blur(22px) saturate(140%);
    -webkit-backdrop-filter: blur(22px) saturate(140%);
    border: 1px solid rgba(56, 189, 248, 0.35);
    box-shadow:
        0 24px 60px -18px rgba(0, 0, 0, 0.65),
        0 0 48px -12px rgba(56, 189, 248, 0.25);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.96);
    transition:
        opacity 0.3s ease,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0.3s;
    pointer-events: none;
}

#chat-panel[data-open="true"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.125rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(56, 189, 248, 0.08);
}

.chat-header-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #f8fafc;
}

.chat-header-sub {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 0.125rem;
}

.chat-close-btn {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.06);
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.125rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

.chat-msg {
    max-width: 88%;
    padding: 0.625rem 0.875rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg--bot {
    align-self: flex-start;
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
    border-bottom-left-radius: 0.25rem;
}

.chat-msg--bot a.chat-link,
.chat-msg--bot a.chat-link:visited {
    color: #38bdf8;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.chat-msg--bot a.chat-link:hover {
    color: #7dd3fc;
}

.chat-msg--user {
    align-self: flex-end;
    background: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

.chat-msg--typing {
    align-self: flex-start;
    display: flex;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
}

.chat-msg--typing span {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 9999px;
    background: #7dd3fc;
    animation: chatTypingDot 1.2s ease-in-out infinite;
}

.chat-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-msg--typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingDot {
    0%, 80%, 100% { opacity: 0.35; transform: scale(0.85); }
    40% { opacity: 1; transform: scale(1); }
}

.chat-footer {
    flex-shrink: 0;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    min-height: 2.75rem;
    max-height: 6rem;
    padding: 0.625rem 0.875rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(17, 24, 39, 0.9);
    color: #f1f5f9;
    font-size: 0.875rem;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input::placeholder {
    color: #64748b;
}

.chat-input:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.chat-send-btn {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, #0284c7 0%, #7dd3fc 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-disclaimer {
    margin-top: 0.5rem;
    font-size: 0.6875rem;
    color: #64748b;
    text-align: center;
}

@media (max-width: 480px) {
    #chat-panel {
        right: 1rem;
        bottom: 5.25rem;
        width: calc(100vw - 2rem);
    }
    #chat-launcher {
        right: 1rem;
        bottom: 1.25rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #chat-launcher {
        animation: none;
    }
    #chat-panel {
        transition: opacity 0.15s ease, visibility 0.15s;
        transform: none;
    }
    #chat-panel[data-open="true"] {
        transform: none;
    }
}
