/* AI Chat Widget */
.chat-widget-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #d946ef);
    color: white;
    box-shadow: 0 8px 32px rgba(139, 92, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    z-index: 900;
    transition: transform 0.2s, box-shadow 0.2s;
    border: none;
}

.chat-widget-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(139, 92, 246, 0.6);
}

.chat-window {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    height: 100vh;
    max-height: 100vh;
    background: rgba(15, 23, 42, 0.95);
    /* Detailed backdrop */
    backdrop-filter: blur(16px);
    border-left: 1px solid var(--border-subtle);
    border-radius: 0;
    /* No radius for sidebar */
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transform-origin: right center;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    opacity: 0;
    transform: translateX(100%);
    /* Slide from right */
    pointer-events: none;
    overflow: hidden;
    min-width: 300px;
    max-width: 800px;
}

.chat-window.visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

/* Resize Handle */
.chat-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: ew-resize;
    z-index: 1001;
    transition: background 0.2s;
}

.chat-resize-handle:hover,
.chat-resize-handle.resizing {
    background: var(--accent-purple);
}

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

/* Header */
.chat-header {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(217, 70, 239, 0.05));
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-title {
    font-weight: 700;
    font-size: 16px;
    background: linear-gradient(135deg, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.chat-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.ai {
    align-self: flex-start;
    background: var(--bg-card-alt);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 4px;
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    border: none;
    font-style: italic;
    padding: 4px 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-card-alt);
    border-radius: 12px;
    align-self: flex-start;
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

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

    40% {
        transform: scale(1);
    }
}

/* Input Area */
.chat-input-area {
    padding: 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    background: var(--bg-card-alt);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-purple);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    padding: 4px;
    resize: none;
    max-height: 100px;
    min-height: 20px;
    outline: none;
}

.chat-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent-purple);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Context Sources */
.chat-sources {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.source-chip {
    font-size: 10px;
    padding: 2px 8px;
    background: rgba(139, 92, 246, 0.1);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.source-chip:hover {
    background: rgba(139, 92, 246, 0.2);
}

/* Markdown Styles in Chat */
.chat-message p {
    margin-bottom: 8px;
}

.chat-message p:last-child {
    margin-bottom: 0;
}

.chat-message strong {
    font-weight: 600;
    color: #a78bfa;
}

.chat-message ul {
    margin: 4px 0 8px 16px;
    list-style-type: disc;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 80vh;
        /* Bottom sheet style */
        border-radius: 20px 20px 0 0;
        border-bottom: none;
    }
}