/**
 * MAI Smart Assistant - Modern Premium Chatbot UI (2025)
 *
 * Inspired by: ChatGPT, Intercom, Drift
 * Design Trends: Glassmorphism, Neumorphism, Fluid Animations
 *
 * @package MAI_SMART_ASSISTANT
 * @since 1.0.1
 */

/* ========================================
   CSS Variables - Modern Theme
   ======================================== */
.mai-smart-assistant-chatbot {
    /* Primary Colors */
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.3);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-message: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);

    /* Neutral Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-glow: 0 0 20px var(--primary-glow);

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    --backdrop-blur: blur(20px);

    /* Transitions */
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
}

/* Dark Mode Support (Coming Soon)
.mai-smart-assistant-chatbot[data-theme="dark"] {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #0f172a;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border-color: #374151;
    --border-light: #1f2937;
    --glass-bg: rgba(31, 41, 55, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}
*/

/* ========================================
   Main Container - Modern Layout
   ======================================== */
.mai-smart-assistant-chatbot {
    position: fixed !important;
    z-index: 999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Reset inheritance */
    text-align: left;
    direction: ltr;
}

/* CSS Reset for Chatbot */
.mai-smart-assistant-chatbot *,
.mai-smart-assistant-chatbot *::before,
.mai-smart-assistant-chatbot *::after {
    box-sizing: border-box !important;
}

.mai-smart-assistant-chatbot p,
.mai-smart-assistant-chatbot h1,
.mai-smart-assistant-chatbot h2,
.mai-smart-assistant-chatbot h3,
.mai-smart-assistant-chatbot h4,
.mai-smart-assistant-chatbot h5,
.mai-smart-assistant-chatbot h6,
.mai-smart-assistant-chatbot ul,
.mai-smart-assistant-chatbot li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.mai-smart-assistant-chatbot img,
.mai-smart-assistant-chatbot svg {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

.mai-smart-assistant-chatbot[data-position="bottom-right"] {
    bottom: 24px !important;
    right: 24px !important;
}

.mai-smart-assistant-chatbot[data-position="bottom-left"] {
    bottom: 24px !important;
    left: 24px !important;
}

/* ========================================
   Floating Action Button - Modern Design
   ======================================== */
.mai-smart-assistant-chatbot-button {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-bounce);
    position: relative;
    overflow: hidden;
}

.mai-smart-assistant-chatbot-button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.3), transparent 70%);
    opacity: 0;
    transition: var(--transition-base);
}

.mai-smart-assistant-chatbot-button:hover {
    transform: scale(1.15) rotate(5deg);
    box-shadow: var(--shadow-2xl), 0 0 40px var(--primary-glow);
}

.mai-smart-assistant-chatbot-button:hover::before {
    opacity: 1;
}

.mai-smart-assistant-chatbot-button:active {
    transform: scale(0.95);
}

/* Icon Animations */
.mai-smart-assistant-chatbot-button svg {
    position: absolute;
    color: #ffffff;
    transition: var(--transition-base);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.mai-smart-assistant-chatbot-button .chatbot-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.mai-smart-assistant-chatbot-button .close-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
}

.chatbot-open .mai-smart-assistant-chatbot-button .chatbot-icon {
    opacity: 0;
    transform: rotate(180deg) scale(0);
}

.chatbot-open .mai-smart-assistant-chatbot-button .close-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Pulse Animation for Attention */
.mai-smart-assistant-chatbot-button::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: var(--radius-full);
    border: 2px solid var(--primary-color);
    opacity: 0;
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

/* ========================================
   Chatbot Window - Glassmorphism Design
   ======================================== */
.mai-smart-assistant-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 420px;
    max-width: calc(100vw - 48px);
    height: 650px;
    max-height: calc(100vh - 120px);
    background: var(--glass-bg);
    backdrop-filter: var(--backdrop-blur);
    -webkit-backdrop-filter: var(--backdrop-blur);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--transition-slow);
    overflow: hidden;
}

.mai-smart-assistant-chatbot[data-position="bottom-left"] .mai-smart-assistant-chatbot-window {
    right: auto;
    left: 0;
}

.chatbot-open .mai-smart-assistant-chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ========================================
   Header - Premium Design
   ======================================== */
.chatbot-header {
    background: var(--gradient-primary);
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.chatbot-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(255, 255, 255, 0.2), transparent 60%);
    pointer-events: none;
}

.chatbot-header-info {
    position: relative;
    z-index: 1;
}

.chatbot-header-info h3 {
    margin: 0 0 6px 0;
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
}

.chatbot-status {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    margin-right: 8px;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: status-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes status-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.4);
    }
}

/* Header Action Buttons - Modern Style */
.chatbot-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 1;
}

.chatbot-new-conversation,
.chatbot-close,
.chatbot-minimize {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-base);
}

.chatbot-new-conversation:hover,
.chatbot-close:hover,
.chatbot-minimize:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chatbot-new-conversation:active,
.chatbot-close:active,
.chatbot-minimize:active {
    transform: translateY(0) scale(0.95);
}

/* ========================================
   Messages Container - Premium Style
   ======================================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-secondary) !important;
    scroll-behavior: smooth;
    position: relative;
}

/* Custom Scrollbar - Modern Design */
.chatbot-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    transition: var(--transition-base);
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Typing Indicator - Modern Animation */
.chatbot-typing {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    max-width: 80px;
    box-shadow: var(--shadow-md);
    margin-bottom: 16px;
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* ========================================
   Messages - Premium Design
   ======================================== */
.chatbot-messages-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    flex-direction: column;
    animation: message-appear 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Bot Message - Modern Style with Avatar */
.bot-message {
    align-items: flex-start;
}

.bot-message .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    box-shadow: var(--shadow-md);
    font-size: 16px;
}

.bot-message .message-content {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    border-top-left-radius: 4px;
    max-width: 85%;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    position: relative;
}

.bot-message .message-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: -6px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 6px 6px 0;
    border-color: transparent var(--bg-primary) transparent transparent;
    filter: drop-shadow(-1px 0 0 var(--border-light));
}

/* User Message - Gradient Style */
.user-message {
    align-items: flex-end;
}

.user-message .message-content {
    background: var(--gradient-message);
    color: #ffffff;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    border-top-right-radius: 4px;
    max-width: 85%;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.user-message .message-content::before {
    content: '';
    position: absolute;
    top: 0;
    right: -6px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 6px 0 0;
    border-color: #8b5cf6 transparent transparent transparent;
}

/* Message Metadata - Enhanced */
.message-meta {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    font-weight: 500;
}

.user-message .message-meta {
    justify-content: flex-end;
}

.message-time {
    opacity: 0.8;
}

/* System Message - Premium Style */
.system-message {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}

.system-message .message-content {
    background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
    color: #1e40af;
    padding: 10px 16px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    max-width: 90%;
    text-align: center;
    border: 1px solid rgba(30, 64, 175, 0.1);
    box-shadow: var(--shadow-sm);
    animation: system-pulse 0.5s ease-out;
}

@keyframes system-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* ========================================
   Predefined Questions - Modern Cards
   ======================================== */
.chatbot-predefined-questions {
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.predefined-questions-title {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 600;
}

.predefined-questions-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.predefined-question {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: var(--transition-base);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.predefined-question::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-primary);
    opacity: 0;
    transition: var(--transition-base);
}

.predefined-question span {
    position: relative;
    z-index: 1;
    transition: var(--transition-base);
}

.predefined-question:hover {
    border-color: var(--primary-color);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.predefined-question:hover::before {
    opacity: 0.05;
}

.predefined-question:active {
    transform: translateX(2px) scale(0.98);
}

/* ========================================
   Input Area - Modern Design
   ======================================== */
.chatbot-input-area {
    padding: 20px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    position: relative;
}

.chatbot-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-secondary);
    resize: none;
    max-height: 120px;
    transition: var(--transition-base);
    line-height: 1.5;
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.chatbot-input::placeholder {
    color: var(--text-tertiary);
}

/* Send Button - Premium Design */
.chatbot-send-button {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--gradient-primary);
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.chatbot-send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.chatbot-send-button:active:not(:disabled) {
    transform: translateY(0) scale(0.95);
}

.chatbot-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}



/* ========================================
   Responsive Design - Mobile Optimized
   ======================================== */
@media (max-width: 480px) {
    .mai-smart-assistant-chatbot[data-position="bottom-right"],
    .mai-smart-assistant-chatbot[data-position="bottom-left"] {
        inset: 0;
        margin: 0;
    }

    .mai-smart-assistant-chatbot-window {
        width: 100%;
        height: 100vh;
        max-width: 100%;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
    }

    .mai-smart-assistant-chatbot-button {
        bottom: 20px;
        right: 20px;
    }

    .chatbot-open .mai-smart-assistant-chatbot-button {
        display: none;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .mai-smart-assistant-chatbot {
        display: none !important;
    }
}

/* ========================================
   Reduced Motion Support
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
