/**
 * AI Chatbot - Frontend Styles
 * Modern, beautiful chat widget
 */

/* CSS Variables */
.ai-chatbot-widget {
    --ai-chatbot-primary: #6366f1;
    --ai-chatbot-secondary: #8b5cf6;
    --ai-chatbot-bg: #ffffff;
    --ai-chatbot-bg-secondary: #f8fafc;
    --ai-chatbot-text: #1e293b;
    --ai-chatbot-text-secondary: #64748b;
    --ai-chatbot-text-muted: #94a3b8;
    --ai-chatbot-border: #e2e8f0;
    --ai-chatbot-user-bg: var(--ai-chatbot-primary);
    --ai-chatbot-user-text: #ffffff;
    --ai-chatbot-bot-bg: #f1f5f9;
    --ai-chatbot-bot-text: #334155;
    --ai-chatbot-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --ai-chatbot-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --ai-chatbot-radius: 20px;
    --ai-chatbot-radius-sm: 12px;
    --ai-chatbot-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --ai-chatbot-button-size: 60px;
    
    font-family: var(--ai-chatbot-font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Button Size Variants */
.ai-chatbot-widget[data-size="small"] {
    --ai-chatbot-button-size: 50px;
}

.ai-chatbot-widget[data-size="large"] {
    --ai-chatbot-button-size: 70px;
}

/* Widget Container */
.ai-chatbot-widget {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
}

.ai-chatbot-bottom-right {
    right: 24px;
}

.ai-chatbot-bottom-left {
    left: 24px;
}

/* Toggle Button */
.ai-chatbot-toggle {
    width: var(--ai-chatbot-button-size);
    height: var(--ai-chatbot-button-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-secondary));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ai-chatbot-shadow-sm), 0 0 0 0 rgba(99, 102, 241, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    position: relative;
    overflow: hidden;
}

.ai-chatbot-toggle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
    border-radius: 50%;
}

.ai-chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: var(--ai-chatbot-shadow), 0 0 0 8px rgba(99, 102, 241, 0.15);
}

.ai-chatbot-toggle:active {
    transform: scale(0.95);
}

.ai-chatbot-toggle svg {
    transition: all 0.3s ease;
}

.ai-chatbot-toggle .ai-chatbot-icon-close {
    display: none;
    transform: rotate(-90deg);
}

.ai-chatbot-widget.ai-chatbot-open .ai-chatbot-toggle .ai-chatbot-icon-chat {
    display: none;
}

.ai-chatbot-widget.ai-chatbot-open .ai-chatbot-toggle .ai-chatbot-icon-close {
    display: block;
    transform: rotate(0deg);
}

/* Pulse Animation for Toggle */
.ai-chatbot-toggle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    animation: ai-chatbot-pulse 2s infinite;
    z-index: -1;
}

@keyframes ai-chatbot-pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.ai-chatbot-widget.ai-chatbot-open .ai-chatbot-toggle::after {
    animation: none;
}

/* Chat Window */
.ai-chatbot-window {
    position: absolute;
    bottom: calc(var(--ai-chatbot-button-size) + 16px);
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--ai-chatbot-bg);
    border-radius: var(--ai-chatbot-radius);
    box-shadow: var(--ai-chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-bottom-right .ai-chatbot-window {
    right: 0;
    transform-origin: bottom right;
}

.ai-chatbot-bottom-left .ai-chatbot-window {
    left: 0;
    transform-origin: bottom left;
}

.ai-chatbot-widget.ai-chatbot-open .ai-chatbot-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chatbot-header {
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-secondary));
    color: white;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.ai-chatbot-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
}

.ai-chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.ai-chatbot-avatar {
    width: 46px;
    height: 46px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.ai-chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-chatbot-avatar svg {
    width: 26px;
    height: 26px;
    opacity: 0.9;
}

.ai-chatbot-header-text h4 {
    margin: 0 0 2px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.ai-chatbot-status-text {
    font-size: 13px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chatbot-status-text::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.ai-chatbot-minimize {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

.ai-chatbot-minimize:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* Messages Container */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--ai-chatbot-bg-secondary);
    scroll-behavior: smooth;
}

/* Message Bubbles */
.ai-chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: ai-chatbot-message-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes ai-chatbot-message-in {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-chatbot-message-user {
    align-self: flex-end;
}

.ai-chatbot-message-bot {
    align-self: flex-start;
}

.ai-chatbot-message-content {
    padding: 14px 18px;
    border-radius: 20px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
}

.ai-chatbot-message-user .ai-chatbot-message-content {
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-secondary));
    color: var(--ai-chatbot-user-text);
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.ai-chatbot-message-bot .ai-chatbot-message-content {
    background: var(--ai-chatbot-bg);
    color: var(--ai-chatbot-bot-text);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-message-time {
    font-size: 11px;
    color: var(--ai-chatbot-text-muted);
    margin-top: 6px;
    padding: 0 4px;
}

.ai-chatbot-message-user .ai-chatbot-message-time {
    text-align: right;
}

/* Typing Indicator */
.ai-chatbot-typing {
    padding: 0 24px 16px;
}

.ai-chatbot-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 14px 20px;
    background: var(--ai-chatbot-bg);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--ai-chatbot-primary);
    border-radius: 50%;
    animation: ai-chatbot-typing 1.4s infinite ease-in-out both;
}

.ai-chatbot-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-chatbot-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes ai-chatbot-typing {
    0%, 80%, 100% {
        transform: scale(0.5);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.ai-chatbot-input-container {
    padding: 20px 24px;
    background: var(--ai-chatbot-bg);
    border-top: 1px solid var(--ai-chatbot-border);
    flex-shrink: 0;
}

.ai-chatbot-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--ai-chatbot-bg-secondary);
    border: 1px solid var(--ai-chatbot-border);
    border-radius: 16px;
    padding: 6px 6px 6px 18px;
    transition: all 0.2s;
}

.ai-chatbot-form:focus-within {
    border-color: var(--ai-chatbot-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.ai-chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    color: var(--ai-chatbot-text);
}

.ai-chatbot-input::placeholder {
    color: var(--ai-chatbot-text-muted);
}

.ai-chatbot-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ai-chatbot-primary), var(--ai-chatbot-secondary));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chatbot-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.ai-chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

.ai-chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chatbot-send svg {
    width: 20px;
    height: 20px;
    transform: translateX(1px);
}

.ai-chatbot-powered {
    text-align: center;
    font-size: 11px;
    color: var(--ai-chatbot-text-muted);
    margin-top: 12px;
}

.ai-chatbot-powered[data-hidden="true"] {
    display: none;
}

/* Error Message */
.ai-chatbot-error {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    margin: 0 24px 12px;
    border: 1px solid #fecaca;
    animation: ai-chatbot-shake 0.4s ease-in-out;
}

@keyframes ai-chatbot-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Scrollbar */
.ai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--ai-chatbot-border);
    border-radius: 3px;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--ai-chatbot-text-muted);
}

/* Theme Variants */

/* Minimal Theme */
.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-header {
    background: var(--ai-chatbot-bg);
    color: var(--ai-chatbot-text);
    border-bottom: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-header::before {
    display: none;
}

.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-avatar {
    background: var(--ai-chatbot-bg-secondary);
    border-color: var(--ai-chatbot-border);
}

.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-avatar svg {
    color: var(--ai-chatbot-primary);
}

.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-status-text::before {
    background: var(--ai-chatbot-primary);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

.ai-chatbot-widget[data-theme="minimal"] .ai-chatbot-minimize {
    background: var(--ai-chatbot-bg-secondary);
    border-color: var(--ai-chatbot-border);
    color: var(--ai-chatbot-text-secondary);
}

/* Rounded Theme */
.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-window {
    border-radius: 28px;
}

.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-message-content {
    border-radius: 24px;
}

.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-message-user .ai-chatbot-message-content {
    border-bottom-right-radius: 8px;
}

.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-message-bot .ai-chatbot-message-content {
    border-bottom-left-radius: 8px;
}

.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-form {
    border-radius: 24px;
}

.ai-chatbot-widget[data-theme="rounded"] .ai-chatbot-send {
    border-radius: 50%;
}

/* Glassmorphism Theme */
.ai-chatbot-widget[data-theme="glassmorphism"] .ai-chatbot-window {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.ai-chatbot-widget[data-theme="glassmorphism"] .ai-chatbot-messages {
    background: transparent;
}

.ai-chatbot-widget[data-theme="glassmorphism"] .ai-chatbot-message-bot .ai-chatbot-message-content {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
}

.ai-chatbot-widget[data-theme="glassmorphism"] .ai-chatbot-input-container {
    background: rgba(255, 255, 255, 0.5);
}

.ai-chatbot-widget[data-theme="glassmorphism"] .ai-chatbot-form {
    background: rgba(255, 255, 255, 0.6);
}

/* Mobile Responsive */
@media screen and (max-width: 480px) {
    .ai-chatbot-widget {
        bottom: 16px;
    }
    
    .ai-chatbot-bottom-right {
        right: 16px;
    }
    
    .ai-chatbot-bottom-left {
        left: 16px;
    }
    
    .ai-chatbot-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
        bottom: calc(var(--ai-chatbot-button-size) + 12px);
        border-radius: 16px;
    }
    
    .ai-chatbot-header {
        padding: 16px 20px;
    }
    
    .ai-chatbot-avatar {
        width: 40px;
        height: 40px;
    }
    
    .ai-chatbot-messages {
        padding: 16px;
        gap: 16px;
    }
    
    .ai-chatbot-input-container {
        padding: 16px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .ai-chatbot-toggle,
    .ai-chatbot-window,
    .ai-chatbot-message,
    .ai-chatbot-send,
    .ai-chatbot-minimize {
        transition: none;
    }
    
    .ai-chatbot-toggle::after,
    .ai-chatbot-typing-indicator span {
        animation: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .ai-chatbot-widget[data-theme="auto"] {
        --ai-chatbot-bg: #1e293b;
        --ai-chatbot-bg-secondary: #0f172a;
        --ai-chatbot-text: #f1f5f9;
        --ai-chatbot-text-secondary: #94a3b8;
        --ai-chatbot-text-muted: #64748b;
        --ai-chatbot-border: #334155;
        --ai-chatbot-bot-bg: #334155;
        --ai-chatbot-bot-text: #f1f5f9;
    }
}

/* Print styles - hide chatbot */
@media print {
    .ai-chatbot-widget {
        display: none !important;
    }
}
