/**
 * LX AI - Floating Chat Widget Styles
 * All styles are scoped to .lx-ai-widget to prevent conflicts
 */

/* Widget Container - scoped variables */
.lx-ai-widget {
    --lx-primary: #3b82f6;
    --lx-primary-dark: #2563eb;
    --lx-primary-light: #60a5fa;
    --lx-bg-light: #ffffff;
    --lx-bg-dark: #1f2937;
    --lx-text-light: #1f2937;
    --lx-text-dark: #f9fafb;
    --lx-border-light: #e5e7eb;
    --lx-border-dark: #374151;
    --lx-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --lx-radius: 16px;
    --lx-widget-width: 380px;
    --lx-widget-height: 600px;
    
    position: fixed !important;
    z-index: 2147483647 !important; /* Maximum z-index */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif !important;
    box-sizing: border-box !important;
    line-height: 1.5 !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Reset box-sizing for all widget elements */
.lx-ai-widget *,
.lx-ai-widget *::before,
.lx-ai-widget *::after {
    box-sizing: border-box !important;
}

.lx-ai-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.lx-ai-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

.lx-ai-widget-top-right {
    top: 20px;
    right: 20px;
}

.lx-ai-widget-top-left {
    top: 20px;
    left: 20px;
}

/* Toggle Button */
.lx-ai-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--lx-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.lx-ai-toggle:hover {
    transform: scale(1.05);
    background: var(--lx-primary-dark);
}

.lx-ai-toggle:active {
    transform: scale(0.95);
}

.lx-ai-toggle-icon {
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.lx-ai-toggle-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: 600;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lx-pulse 2s infinite;
}

@keyframes lx-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Panel */
.lx-ai-panel {
    position: absolute;
    width: var(--lx-widget-width);
    height: var(--lx-widget-height);
    max-height: calc(100vh - 100px);
    border-radius: var(--lx-radius);
    box-shadow: var(--lx-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: lx-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.lx-ai-widget-bottom-right .lx-ai-panel,
.lx-ai-widget-bottom-left .lx-ai-panel {
    bottom: 80px;
}

.lx-ai-widget-bottom-right .lx-ai-panel {
    right: 0;
}

.lx-ai-widget-bottom-left .lx-ai-panel {
    left: 0;
}

.lx-ai-widget-top-right .lx-ai-panel,
.lx-ai-widget-top-left .lx-ai-panel {
    top: 80px;
}

.lx-ai-widget-top-right .lx-ai-panel {
    right: 0;
}

.lx-ai-widget-top-left .lx-ai-panel {
    left: 0;
}

@keyframes lx-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Light Theme */
.lx-ai-theme-light .lx-ai-panel {
    background: var(--lx-bg-light);
    color: var(--lx-text-light);
}

.lx-ai-theme-light .lx-ai-header {
    background: var(--lx-primary);
    color: white;
}

.lx-ai-theme-light .lx-ai-messages {
    background: #f9fafb;
}

.lx-ai-theme-light .lx-ai-input-area {
    background: var(--lx-bg-light);
    border-top: 1px solid var(--lx-border-light);
}

/* Dark Theme */
.lx-ai-theme-dark .lx-ai-panel {
    background: var(--lx-bg-dark);
    color: var(--lx-text-dark);
}

.lx-ai-theme-dark .lx-ai-header {
    background: #111827;
    color: white;
}

.lx-ai-theme-dark .lx-ai-messages {
    background: #111827;
}

.lx-ai-theme-dark .lx-ai-input-area {
    background: var(--lx-bg-dark);
    border-top: 1px solid var(--lx-border-dark);
}

.lx-ai-theme-dark .lx-ai-input {
    background: #374151;
    color: white;
    border-color: #4b5563;
}

.lx-ai-theme-dark .lx-ai-message-user {
    background: var(--lx-primary);
}

.lx-ai-theme-dark .lx-ai-message-assistant .lx-ai-message-content {
    background: #374151;
    color: #f9fafb;
}

/* Header */
.lx-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    min-height: 70px;
}

.lx-ai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lx-ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.lx-ai-header-title {
    font-size: 16px;
    font-weight: 600;
}

.lx-ai-header-subtitle {
    font-size: 13px;
    opacity: 0.8;
}

.lx-ai-header-actions {
    display: flex;
    gap: 8px;
}

.lx-ai-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    transition: all 0.2s ease;
}

.lx-ai-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

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

.lx-ai-message {
    display: flex;
    max-width: 85%;
    animation: lx-message-in 0.3s ease;
}

@keyframes lx-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lx-ai-message-user {
    margin-left: auto;
    justify-content: flex-end;
}

.lx-ai-message-assistant {
    margin-right: auto;
    justify-content: flex-start;
}

.lx-ai-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.lx-ai-message-user .lx-ai-message-content {
    background: var(--lx-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.lx-ai-message-assistant .lx-ai-message-content {
    background: white;
    color: var(--lx-text-light);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Typing Indicator */
.lx-ai-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 10px;
}

.lx-ai-typing-dots {
    display: flex;
    gap: 4px;
}

.lx-ai-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--lx-primary);
    animation: lx-typing-dot 1.4s infinite ease-in-out both;
}

.lx-ai-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.lx-ai-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.lx-ai-typing-dots span:nth-child(3) { animation-delay: 0; }

@keyframes lx-typing-dot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.lx-ai-typing-text {
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
}

/* Input Area */
.lx-ai-input-area {
    padding: 16px 20px;
}

.lx-ai-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #f3f4f6;
    border-radius: 24px;
    padding: 8px 8px 8px 20px;
    transition: all 0.2s ease;
}

.lx-ai-input-wrapper:focus-within {
    box-shadow: 0 0 0 2px var(--lx-primary-light);
}

.lx-ai-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 0;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
}

.lx-ai-input::placeholder {
    color: #9ca3af;
}

.lx-ai-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--lx-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.lx-ai-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.lx-ai-send:not(:disabled):hover {
    background: var(--lx-primary-dark);
    transform: scale(1.05);
}

.lx-ai-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 8px;
}

.lx-ai-char-count {
    font-size: 11px;
    color: #9ca3af;
}

.lx-ai-powered {
    font-size: 11px;
    color: #9ca3af;
}

/* Scrollbar */
.lx-ai-messages::-webkit-scrollbar {
    width: 6px;
}

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

.lx-ai-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.lx-ai-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Mobile Responsive - only affects the widget, not the page */
@media screen and (max-width: 480px) {
    .lx-ai-widget.lx-ai-widget-bottom-right {
        bottom: 10px !important;
        right: 10px !important;
        left: auto !important;
    }

    .lx-ai-widget.lx-ai-widget-bottom-left {
        bottom: 10px !important;
        left: 10px !important;
        right: auto !important;
    }

    .lx-ai-widget.lx-ai-widget-top-right {
        top: 10px !important;
        right: 10px !important;
        left: auto !important;
    }

    .lx-ai-widget.lx-ai-widget-top-left {
        top: 10px !important;
        left: 10px !important;
        right: auto !important;
    }

    .lx-ai-widget .lx-ai-panel {
        width: calc(100vw - 20px) !important;
        height: calc(100vh - 100px) !important;
        max-height: none !important;
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        border-radius: 16px 16px 0 0 !important;
    }

    .lx-ai-widget.lx-ai-widget-bottom-right .lx-ai-panel,
    .lx-ai-widget.lx-ai-widget-bottom-left .lx-ai-panel {
        bottom: 70px !important;
        top: auto !important;
    }

    .lx-ai-widget.lx-ai-widget-top-right .lx-ai-panel,
    .lx-ai-widget.lx-ai-widget-top-left .lx-ai-panel {
        top: 70px !important;
        bottom: auto !important;
    }

    .lx-ai-widget .lx-ai-toggle {
        width: 56px !important;
        height: 56px !important;
    }
}

/* Widget Open State */
.lx-ai-widget.lx-ai-open .lx-ai-toggle-chat {
    display: none;
}

.lx-ai-widget.lx-ai-open .lx-ai-toggle-close {
    display: flex !important;
}

/* Markdown in Messages */
.lx-ai-message-content pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.lx-ai-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.lx-ai-message-content pre code {
    background: none;
    padding: 0;
}

.lx-ai-message-content ul,
.lx-ai-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.lx-ai-message-content p {
    margin: 0 0 8px 0;
}

.lx-ai-message-content p:last-child {
    margin-bottom: 0;
}

/* Error State */
.lx-ai-message-error .lx-ai-message-content {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Loading State */
.lx-ai-loading .lx-ai-message-content {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: lx-shimmer 1.5s infinite;
}

@keyframes lx-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Streaming cursor */
.lx-ai-streaming::after {
    content: '▋';
    animation: lx-cursor 0.8s infinite;
    margin-left: 2px;
}

@keyframes lx-cursor {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

