/* ==============================
   CHAT WIDGET — Terminal Style
   ============================== */

/* Chat Bubble */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-bg-alt);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                background 0.3s ease, border-color 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.chat-bubble.visible {
    opacity: 1;
    transform: scale(1);
}

.chat-bubble:hover {
    background: #3a3a40;
    border-color: rgba(255, 255, 255, 0.18);
}

.chat-bubble-icon {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 16px;
    color: var(--color-text);
    font-weight: 500;
    line-height: 1;
    pointer-events: none;
}

/* Bubble tooltip */
.chat-bubble::after {
    content: 'Ask me anything';
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%) translateX(6px);
    white-space: nowrap;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    font-weight: 400;
    color: var(--color-text-secondary);
    background: var(--color-bg-alt);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease 0.3s, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.3s;
}

.chat-bubble.visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.chat-bubble.tooltip-hidden::after {
    opacity: 0 !important;
    transition-delay: 0s;
}

/* Subtle pulse */
@keyframes chatPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 0 0 6px rgba(255, 255, 255, 0.04); }
}

.chat-bubble.pulse {
    animation: chatPulse 3s ease-in-out infinite;
}

/* Chat Panel */
.chat-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 10000;
    width: 380px;
    height: 500px;
    background: var(--color-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

.chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Title Bar */
.chat-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.chat-title {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    color: var(--color-text-secondary);
    font-weight: 400;
}

.chat-close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 16px;
    transition: color 0.2s ease, background 0.2s ease;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.chat-close:hover {
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.06);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

/* Messages */
.chat-msg {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    opacity: 0;
    transform: translateY(8px);
    animation: msgIn 0.35s ease forwards;
}

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

.chat-msg-bot {
    color: var(--color-text-secondary);
}

.chat-msg-user {
    color: var(--color-text);
}

.chat-msg-prefix {
    color: var(--color-text-tertiary);
    margin-right: 6px;
    user-select: none;
}

.chat-msg-user .chat-msg-prefix {
    color: var(--color-text-secondary);
}

/* Streaming words */
.chat-word {
    opacity: 0;
    animation: wordFadeIn 0.3s ease forwards;
}

@keyframes wordFadeIn {
    from {
        opacity: 0;
        filter: blur(4px);
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* Typing indicator */
.chat-typing {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    color: var(--color-text-tertiary);
    padding: 0;
}

.chat-typing-dots {
    display: inline-block;
}

.chat-typing-dots span {
    animation: blink 1.4s infinite;
    opacity: 0.2;
}

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

@keyframes blink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

/* Suggested Prompts */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}

.chat-suggestion {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    color: var(--color-text-secondary);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.chat-suggestion:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
    color: var(--color-text);
}

/* Input Area */
.chat-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    gap: 8px;
    flex-shrink: 0;
}

.chat-input-prefix {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    color: var(--color-text-tertiary);
    flex-shrink: 0;
    user-select: none;
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    color: var(--color-text);
    caret-color: var(--color-text);
}

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

.chat-send {
    background: none;
    border: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    padding: 4px;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    color: var(--color-text);
}

/* Error message */
.chat-msg-error {
    color: #e07a5f;
}

/* ==============================
   RESPONSIVE
   ============================== */
@media (max-width: 768px) {
    .chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 46px;
        height: 46px;
    }

    .chat-bubble-icon {
        font-size: 14px;
    }

    .chat-bubble::after {
        display: none;
    }

    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: 14px 14px 0 0;
        transform: translateY(100%);
    }

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