/* AI Chat Widget Styles for Appify Labs */

.ai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999; /* Increased z-index to ensure it's above everything */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Ensure the chat widget works with existing mobile nav */
@media (max-width: 768px) {
    .ai-chat-container {
        bottom: 90px; /* Account for mobile bottom navigation on all mobile devices */
    }
}

/* Chat Toggle Button */
.chat-toggle {
    width: 68px;
    height: 68px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 32px rgba(102, 126, 234, 0.25),
        0 4px 16px rgba(118, 75, 162, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
    outline: none;
    backdrop-filter: blur(10px);
    animation: gentlePulse 3s ease-in-out infinite;
}

.chat-toggle::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c);
    border-radius: 50%;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.4s ease;
    animation: rotate 4s linear infinite;
}

.chat-toggle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.3s ease;
}

.chat-toggle:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 
        0 12px 40px rgba(102, 126, 234, 0.35),
        0 8px 24px rgba(118, 75, 162, 0.2),
        inset 0 2px 0 rgba(255, 255, 255, 0.4);
    animation: none;
}

.chat-toggle:hover::before {
    opacity: 1;
}

.chat-toggle:hover::after {
    transform: translate(-50%, -50%) scale(1);
}

.chat-toggle:active {
    transform: scale(1.02) translateY(0px);
    transition: all 0.1s ease;
}

.chat-toggle.open {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 50%, #d63384 100%);
    transform: rotate(180deg) scale(1.05);
    box-shadow: 
        0 10px 35px rgba(255, 107, 107, 0.3),
        0 6px 20px rgba(214, 51, 132, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: none;
}

.chat-toggle.open::before {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f, #d63384, #f093fb);
}

/* Pulse animation for attention */
@keyframes gentlePulse {
    0%, 100% {
        box-shadow: 
            0 8px 32px rgba(102, 126, 234, 0.25),
            0 4px 16px rgba(118, 75, 162, 0.15),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 
            0 10px 36px rgba(102, 126, 234, 0.35),
            0 6px 18px rgba(118, 75, 162, 0.25),
            inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
}

/* Rotating border animation */
@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.chat-icon {
    width: 28px;
    height: 28px;
    color: white;
    position: relative;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.chat-icon-svg,
.close-icon-svg {
    width: 100%;
    height: 100%;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.close-icon-svg {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    transform: rotate(-180deg) scale(0.8);
}

.chat-toggle.open .chat-icon-svg {
    opacity: 0;
    transform: rotate(180deg) scale(0.8);
}

.chat-toggle.open .close-icon-svg {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chat-toggle:hover .chat-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.3));
}

/* Chat Notification */
.chat-notification {
    position: absolute;
    right: 78px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 14px 18px;
    border-radius: 28px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 4px 16px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    opacity: 0;
    animation: slideInNotification 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards 2s;
    border: 1px solid rgba(255, 255, 255, 0.5);
    position: relative;
    overflow: hidden;
}

.chat-notification::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05), rgba(118, 75, 162, 0.05));
    border-radius: 28px;
    z-index: -1;
}

.chat-notification::after {
    content: '';
    position: absolute;
    right: -9px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid rgba(255, 255, 255, 0.95);
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    filter: drop-shadow(2px 0 4px rgba(0,0,0,0.1));
}

.notification-text {
    font-size: 14px;
    color: #1f2937;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

@keyframes slideInNotification {
    0% {
        opacity: 0;
        transform: translateY(-50%) translateX(20px) scale(0.8);
        filter: blur(4px);
    }
    60% {
        opacity: 0.8;
        transform: translateY(-50%) translateX(-5px) scale(1.05);
        filter: blur(0px);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) translateX(0) scale(1);
        filter: blur(0px);
    }
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    border: 1px solid #E5E7EB;
}

.chat-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.agent-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 18px;
}

.agent-avatar::before {
    content: '🤖';
    font-size: 20px;
}

.agent-status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #10B981;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

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

.agent-details h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.agent-status-text {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
}

.minimize-btn {
    background: none;
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.minimize-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Messages */
.chat-messages {
    height: 320px;
    overflow-y: auto;
    padding: 16px;
    background: #F9FAFB;
    scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 2px;
}

.message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
    gap: 10px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-avatar {
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    color: white;
}

.user-avatar {
    background: linear-gradient(135deg, #10B981, #34D399);
    color: white;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 50px);
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    text-align: right;
}

.message-text {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.user-message .message-text {
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    color: white;
}

.ai-message .message-text::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 12px;
    width: 0;
    height: 0;
    border-right: 6px solid white;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.user-message .message-text::before {
    content: '';
    position: absolute;
    right: -6px;
    top: 12px;
    width: 0;
    height: 0;
    border-left: 6px solid #3B82F6;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.message-time {
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 4px;
}

.user-message .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    background: rgba(59, 130, 246, 0.1);
    margin: 0 -16px 8px;
    border-radius: 8px;
}

.typing-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #3B82F6;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.typing-text {
    font-size: 12px;
    color: #6B7280;
}

/* Chat Input Area */
.chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #E5E7EB;
}

.chat-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

#chat-input {
    flex: 1;
    border: 1px solid #D1D5DB;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
    resize: none;
}

#chat-input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-action-btn {
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #374151;
}

.quick-action-btn:hover {
    background: #E5E7EB;
    transform: translateY(-1px);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 40px);
        height: 450px;
        bottom: 80px;
        right: 20px;
        left: 20px;
    }
    
    .chat-notification {
        right: 70px;
        left: 20px;
        white-space: normal;
        text-align: center;
    }
    
    .quick-actions {
        flex-direction: column;
    }
    
    .quick-action-btn {
        text-align: center;
    }
}

/* Safari Compatibility Fixes */
.ai-chat-container {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.chat-window {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1F2937;
        border-color: #374151;
    }
    
    .chat-messages {
        background: #111827;
    }
    
    .message-text {
        background: #374151;
        color: #F9FAFB;
    }
    
    .ai-message .message-text::before {
        border-right-color: #374151;
    }
    
    .chat-input-area {
        background: #1F2937;
        border-color: #374151;
    }
    
    #chat-input {
        background: #374151;
        border-color: #4B5563;
        color: #F9FAFB;
    }
    
    #chat-input::placeholder {
        color: #9CA3AF;
    }
    
    .quick-action-btn {
        background: #374151;
        border-color: #4B5563;
        color: #F9FAFB;
    }
    
    .quick-action-btn:hover {
        background: #4B5563;
    }
    
    .chat-notification {
        background: #1F2937;
        border-color: #374151;
    }
    
    .chat-notification::after {
        border-left-color: #1F2937;
    }
    
    .notification-text {
        color: #F9FAFB;
    }
}

/* Additional fixes for better integration */

/* Prevent conflicts with scroll-to-top buttons */
.floating-buttons #scroll-to-top {
    bottom: 100px !important; /* Push scroll-to-top button higher when chat exists */
}

/* Improve button accessibility */
.chat-toggle:focus {
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5), 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Better mobile positioning when keyboard is open */
@media (max-width: 480px) and (max-height: 600px) {
    .ai-chat-container {
        bottom: 60px;
    }
    
    .chat-window.open {
        height: calc(100vh - 120px);
    }
}

/* Ensure button stays above mobile navigation bars */
@media (max-width: 768px) {
    .ai-chat-container {
        bottom: 90px;
    }
    
    /* Specific positioning for pages with mobile nav */
    body:has(.mobile-nav-bottom) .ai-chat-container {
        bottom: 90px;
    }
}

/* Fix for potential theme conflicts */
[data-theme="dark"] .chat-window,
.dark-mode .chat-window {
    background: #1F2937;
    border-color: #374151;
}

[data-theme="dark"] .chat-header,
.dark-mode .chat-header {
    background: linear-gradient(135deg, #1F2937, #374151);
}

/* Pulse animation for new messages notification */
@keyframes chatPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.chat-toggle.has-notification {
    animation: chatPulse 2s infinite;
}

.chat-toggle.has-notification::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    background: #EF4444;
    border-radius: 50%;
    border: 2px solid white;
} 