/* AI Chat Panel — styles for the embedded AI assistant widget */

/* ============================================
   1. PANEL CONTAINER
   ============================================ */

#ai-chat-panel {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: var(--z-modal);
    width: 380px;
    max-width: calc(100vw - 2rem);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: box-shadow var(--transition-normal);
    font-family: var(--font-family);
}

#ai-chat-panel:hover {
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 8px 10px -6px rgb(0 0 0 / 0.15);
}

/* ============================================
   2. HEADER
   ============================================ */

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    user-select: none;
    background: var(--color-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    font-weight: 600;
    font-size: 0.875rem;
    min-height: 2.5rem;
}

.ai-chat-collapsed .ai-chat-header {
    border-radius: var(--radius-lg);
}

.ai-chat-header:hover {
    background: var(--color-primary-hover);
}

.ai-chat-detach {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 var(--space-xs);
    opacity: 0.7;
    line-height: 1;
}

.ai-chat-detach:hover {
    opacity: 1;
}

/* ============================================
   3. BODY (messages + input)
   ============================================ */

.ai-chat-body {
    flex-direction: column;
    max-height: 400px;
    overflow: hidden;
}

#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm) var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-height: 120px;
    max-height: 320px;
    scroll-behavior: smooth;
}

/* ============================================
   4. INPUT ROW
   ============================================ */

.ai-chat-input-row {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.ai-chat-input-row input {
    flex: 1;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.8125rem;
    outline: none;
    min-width: 0;
}

.ai-chat-input-row input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--status-info-bg);
}

.ai-chat-input-row button {
    padding: var(--space-xs) var(--space-md);
    background: var(--color-primary);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.ai-chat-input-row button:hover {
    background: var(--color-primary-hover);
}

/* ============================================
   5. MESSAGES
   ============================================ */

.ai-msg {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    line-height: 1.5;
    max-width: 90%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.ai-msg.user {
    align-self: flex-end;
    background: var(--color-primary);
    color: var(--text-inverse);
    border-bottom-right-radius: var(--radius-sm);
}

.ai-msg.assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-sm);
}

.ai-msg.error {
    align-self: flex-start;
    background: var(--status-error-bg);
    color: var(--status-error);
    border: 1px solid var(--status-error);
    font-size: 0.75rem;
}

.ai-msg.ai-status {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
    text-align: center;
}

/* ============================================
   6. STREAMING CURSOR
   ============================================ */

.ai-msg.ai-streaming::after {
    content: '\25AE';
    animation: ai-blink 0.8s step-end infinite;
    margin-left: 1px;
    color: var(--color-primary);
}

@keyframes ai-blink {
    50% { opacity: 0; }
}

/* ============================================
   7. THINKING INDICATOR (bouncing dots)
   ============================================ */

.ai-thinking {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
}

.ai-thinking span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: ai-bounce 1.2s ease-in-out infinite;
}

.ai-thinking span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-thinking span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ai-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ============================================
   8. FLOATING / DETACHED STATE
   ============================================ */

.ai-chat-floating {
    position: absolute;
    bottom: auto;
    right: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 440px;
    max-height: 520px;
    resize: both;
    overflow: hidden;
}

.ai-chat-floating .ai-chat-body {
    max-height: 440px;
}

.ai-chat-floating #ai-chat-messages {
    max-height: 360px;
}

/* ============================================
   9. RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
    #ai-chat-panel {
        width: calc(100vw - 1rem);
        right: 0.5rem;
        bottom: 0.5rem;
    }

    .ai-chat-floating {
        width: calc(100vw - 1rem);
        left: 0.5rem;
        right: 0.5rem;
        transform: none;
    }
}

/* ============================================
   10. SCROLLBAR
   ============================================ */

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

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

#ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-strong);
}
