/* AI Support Chat System */
.ai-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(79, 70, 229, 0.6);
}

.ai-chat-button.active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Chat Container */
.ai-chat-container {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: rgba(26, 26, 46, 0.98);
    backdrop-filter: blur(10px);
    border-left: 1px solid rgba(42, 46, 57, 0.5);
    transition: right 0.3s ease;
    z-index: 999;
    display: flex;
    flex-direction: column;
}

.ai-chat-container.open {
    right: 0;
}

/* Chat Header */
.ai-chat-header {
    padding: 20px;
    border-bottom: 1px solid rgba(42, 46, 57, 0.5);
    background: rgba(79, 70, 229, 0.1);
}

.ai-chat-header h3 {
    color: #ffffff;
    margin: 0 0 5px 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-header p {
    color: #8b9dc3;
    margin: 0;
    font-size: 14px;
}

.ai-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #10b981;
}

.ai-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Chat Messages */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.ai-chat-messages::-webkit-scrollbar-track {
    background: rgba(42, 46, 57, 0.3);
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.5);
    border-radius: 3px;
}

.chat-message {
    display: flex;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

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

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

.message-avatar.ai {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
}

.message-avatar.user {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.message-content {
    max-width: 280px;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
}

.message-content.ai {
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.2);
    color: #ffffff;
}

.message-content.user {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #ffffff;
}

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

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 18px;
    max-width: 280px;
}

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

.typing-dot {
    width: 6px;
    height: 6px;
    background: #4f46e5;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

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

/* Chat Input */
.ai-chat-input {
    padding: 20px;
    border-top: 1px solid rgba(42, 46, 57, 0.5);
    background: rgba(16, 16, 36, 0.8);
}

.chat-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    background: rgba(42, 46, 57, 0.5);
    border: 1px solid rgba(79, 70, 229, 0.3);
    border-radius: 20px;
    padding: 12px 16px;
    color: #ffffff;
    font-size: 14px;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: #4f46e5;
}

.chat-input::placeholder {
    color: #6b7280;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    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;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

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

.quick-action {
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.3);
    color: #4f46e5;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-action:hover {
    background: rgba(79, 70, 229, 0.2);
    border-color: #4f46e5;
}

/* Mobile Responsive - CONSOLIDATED RULES */
@media (max-width: 768px) {
    .ai-chat-container {
        width: 100vw;
        right: -100vw;
        top: 0;
        height: 100vh;
        z-index: 1010; /* Higher z-index */
        background: rgba(26, 26, 46, 0.98);
        backdrop-filter: blur(10px);
        transform: none; /* Remove conflicting transforms */
        transition: right 0.3s ease;
    }
    
    .ai-chat-container.open {
        right: 0;
    }
    
    .ai-chat-button {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 20px;
        z-index: 1011; /* Higher than container */
        position: fixed !important;
        display: flex !important;
        visibility: visible !important;
    }
    
    .ai-chat-header {
        padding: 20px;
        padding-top: 60px; /* Space for mobile status bar */
        border-bottom: 1px solid rgba(42, 46, 57, 0.5);
        background: rgba(79, 70, 229, 0.1);
    }
    
    .message-content {
        max-width: 240px;
    }
    
    /* Page-specific adjustments */
    .funding-page .ai-chat-container {
        top: 0;
        height: 100vh;
        z-index: 1012; /* Even higher for funding page */
    }
    
    .funding-page .ai-chat-button {
        z-index: 1013;
        bottom: 20px;
        right: 20px;
    }
    
    .dashboard-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    .platform-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    .admin-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    .landing-page .ai-chat-container {
        top: 60px;
        height: calc(100vh - 60px);
    }
    
    .auth-page .ai-chat-container {
        top: 50px;
        height: calc(100vh - 50px);
    }
}

/* Additional mobile fixes */
@media (max-width: 480px) {
    .ai-chat-container {
        z-index: 1014;
    }
    
    .ai-chat-button {
        z-index: 1015;
    }
    
    .funding-page .ai-chat-container {
        z-index: 1016;
    }
    
    .funding-page .ai-chat-button {
        z-index: 1017;
    }
}

/* Force visibility on touch devices */
@media (hover: none) and (pointer: coarse) {
    .ai-chat-button {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    
    .ai-chat-container {
        display: flex !important;
        visibility: visible !important;
    }
    
    .ai-chat-container.open {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Specific page adjustments */
@media (max-width: 768px) {
    /* Dashboard page - 70px header */
    .dashboard-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    /* Platform page - 70px header */
    .platform-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    /* Admin page - standard header */
    .admin-page .ai-chat-container {
        top: 70px;
        height: calc(100vh - 70px);
    }
    
    /* Landing page - smaller header */
    .landing-page .ai-chat-container {
        top: 60px;
        height: calc(100vh - 60px);
    }
    
    /* Auth pages - minimal header */
    .auth-page .ai-chat-container {
        top: 50px;
        height: calc(100vh - 50px);
    }
    
    /* Funding page - standard header */
    .funding-page .ai-chat-container {
        top: 0;
        height: 100vh;
    }
    
    .funding-page .ai-chat-button {
        bottom: 20px;
        right: 20px;
        z-index: 1003;
    }
}

/* Close Button */
.chat-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: #8b9dc3;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.chat-close-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.admin-label {
    font-size: 12px;
    font-weight: 600;
    color: #2196f3;
    margin-bottom: 4px;
}

.chat-message.admin .message-content {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-left: 3px solid #2196f3;
}

.chat-message.admin .message-avatar {
    background: #2196f3;
}