/**
 * Wiki Chat Bubble - Floating Global Chat Widget
 * Minimizable/maximizable chat interface with @wiki toggle
 */

/* ============================================
   FLOATING CHAT BUBBLE (Collapsed State)
   ============================================ */
.wiki-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1050;
    box-shadow: var(--shadow-xl), 0 0 20px rgba(67, 97, 238, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
        box-shadow 0.3s ease;
    border: none;
    outline: none;
}

.wiki-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl), 0 0 30px rgba(67, 97, 238, 0.6);
}

.wiki-chat-bubble:active {
    transform: scale(0.95);
}

.wiki-chat-bubble-icon {
    font-size: 1.5rem;
    color: white;
    transition: transform 0.3s ease;
}

.wiki-chat-bubble.open .wiki-chat-bubble-icon {
    transform: rotate(90deg);
}

/* Pulse animation for bubble */
.wiki-chat-bubble::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--gradient-primary);
    animation: pulse-ring 2s infinite;
    z-index: -1;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* ============================================
   CHAT WIDGET (Expanded State)
   ============================================ */
.wiki-chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    z-index: 1049;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wiki-chat-widget.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ============================================
   CHAT HEADER
   ============================================ */
.wiki-chat-header {
    padding: var(--space-3) var(--space-4);
    background: var(--gradient-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.wiki-chat-header-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--font-bold);
    font-size: var(--text-base);
}

.wiki-chat-header-title .icon {
    font-size: 1.25rem;
}

.wiki-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    font-size: var(--text-lg);
}

.wiki-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   WIKI MODE TOGGLE
   ============================================ */
.wiki-mode-bar {
    padding: var(--space-2) var(--space-4);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.wiki-mode-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    user-select: none;
}

.wiki-mode-toggle input[type="checkbox"] {
    display: none;
}

.wiki-mode-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border-dark);
    border-radius: var(--radius-full);
    transition: background 0.3s ease;
}

.wiki-mode-slider::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.wiki-mode-toggle input:checked+.wiki-mode-slider {
    background: var(--accent-primary);
}

.wiki-mode-toggle input:checked+.wiki-mode-slider::before {
    transform: translateX(20px);
}

.wiki-mode-label {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.wiki-mode-label .badge {
    font-size: var(--text-xs);
    padding: 2px 6px;
    background: var(--accent-soft);
    color: var(--accent-primary);
    border-radius: var(--radius-sm);
    font-weight: var(--font-semibold);
}

.wiki-mode-toggle input:checked~.wiki-mode-label .badge {
    background: var(--success-soft);
    color: var(--success);
}

/* ============================================
   CHAT BODY
   ============================================ */
.wiki-chat-body {
    flex: 1;
    padding: var(--space-3);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    background: var(--bg-primary);
}

.wiki-chat-message {
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    max-width: 85%;
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    animation: message-in 0.3s ease;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wiki-chat-message.user {
    align-self: flex-end;
    background: var(--accent-primary);
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.wiki-chat-message.bot {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: var(--radius-sm);
}

.wiki-chat-message.bot.wiki-context {
    border-left: 3px solid var(--success);
}

/* Summary style */
.wiki-chat-summary {
    font-weight: var(--font-bold);
    color: var(--accent-primary);
    margin-bottom: var(--space-2);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wiki-chat-message .typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-1) 0;
}

.wiki-chat-message .typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.wiki-chat-message .typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.wiki-chat-message .typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-5px);
    }
}

/* ============================================
   CHAT FOOTER
   ============================================ */
.wiki-chat-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border-medium);
    background: var(--bg-elevated);
    flex-shrink: 0;
}

.wiki-chat-input-wrapper {
    display: flex;
    gap: var(--space-2);
    align-items: flex-end;
}

.wiki-chat-input {
    flex: 1;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    font-size: var(--text-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    min-height: 80px;
    max-height: 200px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wiki-chat-input::placeholder {
    color: var(--text-muted);
}

.wiki-chat-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.wiki-chat-send {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.wiki-chat-send:hover {
    background: var(--accent-primary-hover);
}

.wiki-chat-send:active {
    transform: scale(0.95);
}

.wiki-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wiki-chat-send svg {
    width: 20px;
    height: 20px;
}

/* Model selector */
.wiki-chat-model-select {
    width: 100%;
    margin-top: var(--space-2);
    padding: var(--space-2);
    font-size: var(--text-xs);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    .wiki-chat-widget {
        width: calc(100vw - 48px);
        height: 70vh;
        bottom: 90px;
        right: 24px;
    }

    .wiki-chat-bubble {
        width: 54px;
        height: 54px;
    }
}