/* Chatbot Bubble */
.chatbot-bubble {
    position: fixed;
    bottom: 3.5rem;
    right: 1.5rem;
    z-index: 101;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    line-height: 1;
    transition: all 0.2s ease;
    padding: 0;
    overflow: hidden;
}

.chatbot-bubble:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.chatbot-bubble.active {
    border-color: var(--accent);
    color: var(--accent);
}

.chatbot-avatar {
    width: 56px;
    height: 56px;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.18));
}

.chatbot-bubble .chatbot-cursor {
    display: inline-block;
    position: absolute;
    right: 9px;
    bottom: 9px;
    width: 2px;
    height: 10px;
    background: var(--accent);
    animation: chatbot-blink 1s step-end infinite;
}

.chatbot-bubble.active .chatbot-cursor {
    animation: none;
    opacity: 1;
}

@keyframes chatbot-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Chat Window */
.chatbot-window {
    position: fixed;
    bottom: calc(3.5rem + 64px + 10px);
    right: 1.5rem;
    z-index: 500;
    width: 380px;
    max-height: 480px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
}

/* Header — Section Marker Style */
.chatbot-header {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chatbot-header-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chatbot-header-title::after {
    content: '';
    display: inline-block;
    width: 40px;
    height: 1px;
    background: var(--border);
}

.chatbot-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chatbot-clear,
.chatbot-close {
    background: none;
    border: none;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.2rem;
    line-height: 1;
    transition: color 0.2s ease;
}

.chatbot-clear {
    font-size: 0.6rem;
}

.chatbot-close {
    font-size: 0.8rem;
}

.chatbot-clear:hover,
.chatbot-close:hover {
    color: var(--accent);
}

/* Message Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chatbot-messages:hover::-webkit-scrollbar-thumb {
    background: var(--accent);
}

/* Bot Messages — Editorial left-border style */
.chatbot-msg-bot {
    align-self: flex-start;
    max-width: 90%;
    border-left: 2px solid var(--accent);
    padding-left: 0.75rem;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text);
}

/* User Messages — Subtle bg-alt bubble */
.chatbot-msg-user {
    align-self: flex-end;
    max-width: 80%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text);
}

/* Typing Indicator — Single blinking cursor */
.chatbot-typing {
    align-self: flex-start;
    border-left: 2px solid var(--accent);
    padding-left: 0.75rem;
    height: 1.4em;
}

.chatbot-typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent);
    animation: chatbot-blink 1s step-end infinite;
    vertical-align: text-bottom;
}

/* Streaming — cursor at end of growing text */
.chatbot-msg-bot .chatbot-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 0.85em;
    background: var(--accent);
    margin-left: 2px;
    animation: chatbot-blink 1s step-end infinite;
    vertical-align: text-bottom;
}

/* System Messages — Footnote style */
.chatbot-msg-system {
    text-align: center;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0.4rem 0;
}

/* Load Model Button */
.chatbot-load-btn {
    display: block;
    margin: 0.6rem auto 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0.35rem 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chatbot-load-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chatbot-load-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progress — Typographic underline */
.chatbot-progress-wrap {
    text-align: center;
    margin: 0.6rem auto 0;
}

.chatbot-progress-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    display: inline-block;
    background: linear-gradient(var(--accent), var(--accent)) no-repeat left bottom;
    background-size: 0% 2px;
    padding-bottom: 3px;
    transition: background-size 0.3s ease;
}

.chatbot-progress-pct {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Input Area */
.chatbot-input-area {
    display: flex;
    align-items: center;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 0.88rem;
    color: var(--text);
    padding: 0.6rem 0.8rem;
    min-width: 0;
}

.chatbot-input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.chatbot-input:disabled {
    opacity: 0.5;
}

.chatbot-send {
    background: none;
    border: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.6rem 0.8rem;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send:hover:not(:disabled) {
    color: var(--accent);
}

.chatbot-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Mobile */
@media (max-width: 768px) {
    .chatbot-bubble {
        right: 1rem;
        bottom: 8.5rem;
    }

    .chatbot-window {
        left: 8px;
        right: 8px;
        bottom: calc(8.5rem + 64px + 8px);
        width: auto;
        max-height: 55vh;
    }
}
