/**
 * FMAI Kapa-Style Modern Chatbot CSS
 * 
 * Replicates the professional Kapa.ai design with:
 * - Clean, minimal interface
 * - Smooth animations
 * - Source citation cards
 * - Progressive loading
 * - Mobile-responsive layout
 */

/* CSS Custom Properties for theming */
:root {
    --fmai-primary: #6366f1;
    --fmai-primary-hover: #5855eb;
    --fmai-secondary: #f8fafc;
    --fmai-text: #1e293b;
    --fmai-text-muted: #64748b;
    --fmai-border: #e2e8f0;
    --fmai-border-light: #f1f5f9;
    --fmai-white: #ffffff;
    --fmai-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 4px 10px -2px rgba(0, 0, 0, 0.05);
    --fmai-shadow-light: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --fmai-radius: 12px;
    --fmai-radius-sm: 8px;
    --fmai-radius-lg: 16px;
}

/* Reset and base styles */
.fmai-kapa-chatbot * {
    box-sizing: border-box;
}

.fmai-kapa-chatbot {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.5;
    color: var(--fmai-text);
    position: relative;
    z-index: 999999;
}

/* Floating toggle button */
.fmai-kapa-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: var(--fmai-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--fmai-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000000;
}

.fmai-kapa-toggle:hover {
    background: var(--fmai-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.fmai-kapa-toggle-icon {
    color: white;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main container */
.fmai-kapa-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 600px;
    background: var(--fmai-white);
    border-radius: var(--fmai-radius-lg);
    box-shadow: var(--fmai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000000;
    animation: fmai-slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fmai-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.fmai-kapa-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--fmai-border-light);
    background: var(--fmai-white);
    flex-shrink: 0;
}

.fmai-kapa-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.fmai-kapa-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.fmai-kapa-logo-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--fmai-radius-sm);
    background: var(--fmai-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.fmai-kapa-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--fmai-text);
}

.fmai-kapa-close {
    background: none;
    border: none;
    padding: 8px;
    border-radius: var(--fmai-radius-sm);
    cursor: pointer;
    color: var(--fmai-text-muted);
    transition: all 0.2s;
}

.fmai-kapa-close:hover {
    background: var(--fmai-secondary);
    color: var(--fmai-text);
}

/* Messages area */
.fmai-kapa-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px;
    margin: 20px 0;
}

.fmai-kapa-welcome {
    background: var(--fmai-secondary);
    padding: 16px;
    border-radius: var(--fmai-radius);
    margin-bottom: 20px;
    color: var(--fmai-text-muted);
    font-size: 14px;
    line-height: 1.5;
}

/* Message bubbles */
.fmai-kapa-message {
    margin-bottom: 20px;
    animation: fmai-fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fmai-fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fmai-kapa-message.user {
    text-align: right;
}

.fmai-kapa-message.user .fmai-message-bubble {
    background: var(--fmai-primary);
    color: white;
    display: inline-block;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--fmai-radius);
    border-bottom-right-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
}

.fmai-kapa-message.assistant {
    text-align: left;
}

.fmai-kapa-message.assistant .fmai-message-bubble {
    background: var(--fmai-white);
    border: 1px solid var(--fmai-border-light);
    display: inline-block;
    max-width: 90%;
    padding: 16px;
    border-radius: var(--fmai-radius);
    border-bottom-left-radius: 4px;
    font-size: 14px;
    line-height: 1.6;
    box-shadow: var(--fmai-shadow-light);
}

/* Progressive loading */
.fmai-kapa-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--fmai-secondary);
    border-radius: var(--fmai-radius);
    margin-bottom: 16px;
}

.fmai-kapa-loading-text {
    color: var(--fmai-text-muted);
    font-size: 14px;
}

.fmai-kapa-progress {
    width: 200px;
    height: 4px;
    background: var(--fmai-border);
    border-radius: 2px;
    overflow: hidden;
}

.fmai-kapa-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--fmai-primary) 0%, #8b5cf6 100%);
    border-radius: 2px;
    animation: fmai-progressLoad 2s ease-in-out infinite;
    width: 0%;
    transition: width 0.3s ease;
}

@keyframes fmai-progressLoad {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

/* Action buttons */
.fmai-kapa-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.fmai-kapa-action {
    background: var(--fmai-white);
    border: 1px solid var(--fmai-border);
    padding: 6px 12px;
    border-radius: var(--fmai-radius-sm);
    font-size: 12px;
    color: var(--fmai-text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.fmai-kapa-action:hover {
    background: var(--fmai-secondary);
    border-color: var(--fmai-primary);
    color: var(--fmai-primary);
}

.fmai-kapa-action.good {
    color: #059669;
    border-color: #10b981;
}

.fmai-kapa-action.good:hover {
    background: #ecfdf5;
}

.fmai-kapa-action.bad {
    color: #dc2626;
    border-color: #ef4444;
}

.fmai-kapa-action.bad:hover {
    background: #fef2f2;
}

/* Source citations */
.fmai-kapa-sources {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--fmai-border-light);
}

.fmai-kapa-sources-title {
    font-size: 13px;
    color: var(--fmai-text-muted);
    margin-bottom: 12px;
    font-weight: 500;
}

.fmai-kapa-source-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.fmai-kapa-source-card {
    background: var(--fmai-white);
    border: 1px solid var(--fmai-border);
    border-radius: var(--fmai-radius-sm);
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.fmai-kapa-source-card:hover {
    border-color: var(--fmai-primary);
    box-shadow: var(--fmai-shadow-light);
    transform: translateY(-1px);
}

.fmai-kapa-source-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.fmai-kapa-source-favicon {
    width: 16px;
    height: 16px;
    border-radius: 2px;
}

.fmai-kapa-source-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--fmai-text);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.fmai-kapa-source-domain {
    font-size: 11px;
    color: var(--fmai-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Input area */
.fmai-kapa-input-area {
    padding: 20px 24px;
    border-top: 1px solid var(--fmai-border-light);
    background: var(--fmai-white);
    flex-shrink: 0;
}

.fmai-kapa-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--fmai-secondary);
    border-radius: var(--fmai-radius);
    padding: 12px;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.fmai-kapa-input-container:focus-within {
    border-color: var(--fmai-primary);
    background: var(--fmai-white);
    box-shadow: var(--fmai-shadow-light);
}

.fmai-kapa-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    color: var(--fmai-text);
    min-height: 20px;
    max-height: 120px;
    font-family: inherit;
}

.fmai-kapa-input::placeholder {
    color: var(--fmai-text-muted);
}

.fmai-kapa-send {
    background: var(--fmai-primary);
    border: none;
    border-radius: var(--fmai-radius-sm);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.fmai-kapa-send:hover:not(:disabled) {
    background: var(--fmai-primary-hover);
    transform: translateY(-1px);
}

.fmai-kapa-send:disabled {
    background: var(--fmai-border);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Features row */
.fmai-kapa-features {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.fmai-kapa-deep-thinking {
    background: var(--fmai-white);
    border: 1px solid var(--fmai-border);
    padding: 8px 12px;
    border-radius: var(--fmai-radius-sm);
    font-size: 13px;
    color: var(--fmai-text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.fmai-kapa-deep-thinking:hover {
    background: var(--fmai-secondary);
    border-color: var(--fmai-primary);
    color: var(--fmai-primary);
}

.fmai-kapa-deep-thinking.active {
    background: var(--fmai-primary);
    border-color: var(--fmai-primary);
    color: white;
}

/* Follow-up input */
.fmai-kapa-followup {
    background: var(--fmai-secondary);
    border: 1px solid var(--fmai-border-light);
    border-radius: var(--fmai-radius);
    padding: 16px;
    margin-top: 16px;
}

.fmai-kapa-followup-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-size: 14px;
    color: var(--fmai-text-muted);
    font-family: inherit;
}

.fmai-kapa-followup-input::placeholder {
    color: var(--fmai-text-muted);
}

/* Footer */
.fmai-kapa-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--fmai-border-light);
    background: var(--fmai-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.fmai-kapa-powered {
    font-size: 12px;
    color: var(--fmai-text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.fmai-kapa-powered strong {
    color: var(--fmai-text);
    font-weight: 600;
}

.fmai-kapa-protection {
    font-size: 11px;
    color: var(--fmai-text-muted);
}

/* Content highlighting */
.fmai-highlight {
    color: #dc2626;
    font-weight: 500;
}

/* Responsive design */
@media (max-width: 480px) {
    .fmai-kapa-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        animation: fmai-slideInMobile 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    @keyframes fmai-slideInMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .fmai-kapa-toggle {
        bottom: 20px;
        right: 20px;
    }
    
    .fmai-kapa-header {
        padding: 16px 20px;
    }
    
    .fmai-kapa-messages {
        padding: 0 20px;
    }
    
    .fmai-kapa-input-area {
        padding: 16px 20px;
    }
    
    .fmai-kapa-footer {
        padding: 12px 20px;
    }
    
    .fmai-kapa-source-cards {
        grid-template-columns: 1fr;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --fmai-white: #1e293b;
        --fmai-secondary: #334155;
        --fmai-text: #f8fafc;
        --fmai-text-muted: #cbd5e1;
        --fmai-border: #475569;
        --fmai-border-light: #374151;
    }
    
    .fmai-kapa-source-card {
        background: var(--fmai-secondary);
    }
    
    .fmai-kapa-action {
        background: var(--fmai-secondary);
    }
}