/* ── AI Chat Widget ─────────────────────── */

/* Floating bubble */
.chat-bubble {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    z-index: 9998;
    box-shadow: 0 4px 20px rgba(79, 142, 255, 0.35);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(79, 142, 255, 0.5);
}

.chat-bubble .chat-icon,
.chat-bubble .chat-close-icon {
    position: absolute;
    transition: all 0.3s ease;
}

.chat-bubble.open .chat-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.chat-bubble .chat-close-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.chat-bubble.open .chat-close-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse ring */
.chat-bubble::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--accent-gradient);
    opacity: 0;
    animation: chatPulse 3s ease-in-out infinite;
    z-index: -1;
}

.chat-bubble.open::after {
    animation: none;
}

@keyframes chatPulse {

    0%,
    100% {
        opacity: 0;
        transform: scale(1);
    }

    50% {
        opacity: 0.3;
        transform: scale(1.5);
    }
}

/* Chat panel */
.chat-panel {
    position: fixed;
    bottom: 6rem;
    right: 2rem;
    width: 380px;
    max-height: 520px;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat header */
.chat-header {
    padding: 1rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-avatar svg {
    color: #fff;
}

.chat-header-info h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 2px;
}

.chat-header-info span {
    font-size: 0.7rem;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header-info .online-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 200px;
    max-height: 320px;
}

.chat-message {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    animation: msgFadeIn 0.3s ease;
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg-avatar svg {
    width: 12px;
    height: 12px;
    color: #fff;
}

.chat-message.user .chat-msg-avatar {
    background: var(--border-hover);
}

.chat-msg-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.chat-message.bot .chat-msg-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-top-left-radius: 4px;
}

.chat-message.user .chat-msg-bubble {
    background: var(--accent-blue);
    color: #fff;
    border-top-right-radius: 4px;
}

.chat-msg-bubble a {
    color: var(--accent-blue);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-message.user .chat-msg-bubble a {
    color: #fff;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1.25rem 0.5rem;
}

.chat-typing-dots {
    display: flex;
    gap: 3px;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

@keyframes msgFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Quick reply chips */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem 1.25rem;
}

.chat-quick-reply {
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-hover);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.chat-quick-reply:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(79, 142, 255, 0.06);
}

/* Input area */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.chat-input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--accent-blue);
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.chat-send-btn:hover {
    transform: scale(1.08);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

/* Rate limit warning */
.chat-rate-warning {
    padding: 0.4rem 1.25rem;
    font-size: 0.7rem;
    color: #f59e0b;
    text-align: center;
    animation: msgFadeIn 0.3s ease;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-panel {
        width: calc(100vw - 2rem);
        right: 1rem;
        bottom: 5rem;
        max-height: 70vh;
    }

    .chat-bubble {
        bottom: 1rem;
        right: 1rem;
        width: 48px;
        height: 48px;
    }
}