/**
 * Strategic AI Chat Assistant Styling
 */

/* Main container - FIXED: Proper pointer events handling */
#ai-mentor-container {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 1060 !important;
    display: flex !important;
    flex-direction: column;
    align-items: flex-end;
    transition: all 0.3s ease;
    pointer-events: none; /* Container doesn't capture events */
    visibility: visible !important;
    opacity: 1 !important;
    
    /* Ensure container never blocks other elements */
    width: auto;
    height: auto;
    max-width: 400px;
    max-height: 600px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    #ai-mentor-container {
        bottom: 15px;
        right: 15px;
    }
}

/* The chat icon */
#ai-mentor-icon {
    width: 68px !important;
    height: 68px !important;
    border-radius: 50%;
    background: linear-gradient(135deg, #0073b1 0%, #005885 100%) !important;
    box-shadow: 0 4px 20px rgba(0, 115, 177, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.2) !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative !important;
    z-index: 1061 !important;
    color: white;
    pointer-events: auto !important; /* Only the icon itself should capture clicks */
    touch-action: manipulation; /* Improve mobile touch handling */
    -webkit-tap-highlight-color: rgba(0, 115, 177, 0.2);
    visibility: visible !important;
    opacity: 1 !important;
}

/* Mobile touch improvements */
@media (max-width: 768px) {
    #ai-mentor-icon {
        width: 60px;
        height: 60px;
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Chat interface pointer events fix */
.strategic-chat-interface {
    pointer-events: auto !important;
}

.strategic-chat-interface * {
    pointer-events: auto !important;
}

/* Mobile button fixes */
@media (max-width: 768px) {
    .report-type-card,
    .past-report-card,
    .card,
    .btn,
    button,
    a {
        -webkit-tap-highlight-color: rgba(255, 107, 53, 0.1);
        touch-action: manipulation;
    }
}

#ai-mentor-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(227, 114, 0, 0.4);
}

#ai-mentor-icon i {
    font-size: 24px;
}

/* Credit badge */
.chat-credits-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Welcome popup tooltip */
.chat-welcome-popup {
    position: absolute;
    bottom: 70px;
    right: -10px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 12px 16px;
    max-width: 280px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(227, 114, 0, 0.2);
    z-index: 1001;
    display: none;
    pointer-events: auto;
}

.chat-welcome-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 30px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

.chat-welcome-popup.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    display: block;
}

.chat-welcome-popup .popup-content {
    font-size: 13px;
    color: #333;
    line-height: 1.4;
}

.chat-welcome-popup .popup-title {
    font-weight: 600;
    color: #E37200;
    margin-bottom: 4px;
}

.chat-welcome-popup .popup-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    line-height: 1;
}

/* The chat interface - Professional messaging style */
#ai-mentor-tip {
    background: linear-gradient(145deg, #ffffff, #f8f9ff);
    pointer-events: auto;
    border-radius: 24px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.08),
        0 8px 32px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    padding: 0;
    width: 500px;
    height: 650px;
    margin-bottom: 20px;
    position: relative;
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: none;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

/* Mobile responsive chat */
@media (max-width: 768px) {
    #ai-mentor-tip {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        position: fixed;
        top: 50px;
        left: 10px;
        right: 10px;
        bottom: auto;
        z-index: 9999;
        margin-bottom: 0;
    }
    
    #ai-mentor-container {
        bottom: 20px !important;
        right: 20px !important;
    }
    
    #ai-mentor-icon {
        width: 55px !important;
        height: 55px !important;
    }
}

/* Desktop responsive adjustments */
@media (min-width: 769px) {
    #ai-mentor-tip {
        position: absolute;
        bottom: 80px;
        right: 0;
        width: 500px;
        height: 650px;
    }
}

#ai-mentor-tip.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    display: block;
}

/* Chat header - Professional gradient */
.chat-header {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    padding: 20px 24px;
    border-radius: 24px 24px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.2);
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    flex-grow: 1;
}

.chat-credits {
    background: rgba(255,255,255,0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 10px;
}

/* Chat body */
.chat-body {
    height: 400px;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: #E37200 transparent;
}

/* COMPREHENSIVE MOBILE CHAT FIX - Professional UX/UI Standards */
@media (max-width: 768px) {
    #ai-mentor-container {
        bottom: 20px;
        right: 15px;
    }
    
    #ai-mentor-icon {
        width: 56px;
        height: 56px;
        background: linear-gradient(135deg, #ff6b35, #ff8c65) !important;
        border: 2px solid rgba(255, 255, 255, 0.9);
    }
    
    #ai-mentor-tip {
        background: #ffffff !important;
        color: #2c3e50 !important;
        border: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
        width: calc(100vw - 30px) !important;
        max-width: 380px !important;
        height: calc(100vh - 120px) !important;
        max-height: 500px !important;
        bottom: 75px !important;
        right: 0 !important;
        border-radius: 16px !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    
    .chat-header {
        background: linear-gradient(135deg, #ff6b35, #ff8c65) !important;
        color: white !important;
        padding: 12px 16px !important;
        border-radius: 16px 16px 0 0 !important;
        flex-shrink: 0 !important;
        min-height: 50px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    .chat-header h4 {
        color: white !important;
        font-size: 14px !important;
        font-weight: 600 !important;
        margin: 0 !important;
        flex: 1 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .chat-credits {
        background: rgba(255,255,255,0.2) !important;
        padding: 2px 6px !important;
        border-radius: 8px !important;
        font-size: 11px !important;
        margin-left: 8px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }
    
    .chat-body {
        background: #f8f9fb !important;
        background-image: linear-gradient(180deg, #ffffff 0%, #f8f9fb 100%) !important;
        color: #2c3e50 !important;
        padding: 12px !important;
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .chat-message {
        background: transparent !important;
        color: #2c3e50 !important;
        margin-bottom: 12px !important;
    }
    
    .message-bubble, .message-ai {
        background: #ffffff !important;
        color: #2c3e50 !important;
        border: 1px solid #e9ecef !important;
        padding: 16px !important;
        border-radius: 16px !important;
        border-bottom-left-radius: 4px !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
        font-size: 14px !important;
        line-height: 1.6 !important;
        position: relative !important;
    }
    
    .message-bubble h6 {
        color: #ff6b35 !important;
        margin: 12px 0 8px 0 !important;
        font-weight: 600 !important;
        font-size: 13px !important;
    }
    
    .message-bubble ul {
        margin: 8px 0 !important;
        padding-left: 20px !important;
    }
    
    .message-bubble li {
        margin: 4px 0 !important;
        line-height: 1.5 !important;
    }
    
    .message-bubble p {
        margin: 8px 0 !important;
        line-height: 1.6 !important;
    }
    
    .message-bubble strong {
        color: #ff6b35 !important;
        font-weight: 600 !important;
    }
    
    .message-bubble em {
        font-style: italic !important;
        color: #2c3e50 !important;
    }
    
    .message-user, .chat-message.user .message-bubble {
        background: linear-gradient(135deg, #007bff, #0056b3) !important;
        color: white !important;
        border: none !important;
        border-bottom-right-radius: 4px !important;
        border-bottom-left-radius: 16px !important;
        box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2) !important;
    }
    
    .chat-input-container {
        background: #ffffff !important;
        border-top: 1px solid #f0f0f0 !important;
        padding: 12px !important;
        border-radius: 0 0 16px 16px !important;
        flex-shrink: 0 !important;
        min-height: 60px !important;
    }
    
    .chat-input-group {
        background: #f8f9fa !important;
        border-radius: 24px !important;
        padding: 4px !important;
        border: 1px solid #e9ecef !important;
        display: flex !important;
        align-items: center !important;
    }
    
    #chat-input, .chat-input {
        background: transparent !important;
        color: #2c3e50 !important;
        border: none !important;
        padding: 12px 16px !important;
        flex: 1 !important;
        font-size: 14px !important;
        border-radius: 20px !important;
    }
    
    #chat-input::placeholder, .chat-input::placeholder {
        color: #6c757d !important;
    }
    
    #chat-send-btn {
        background: linear-gradient(135deg, #ff6b35, #ff8c65) !important;
        border: none !important;
        color: white !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 14px !important;
    }
    
    /* Ensure all text elements are visible with proper contrast */
    .strategic-chat-interface,
    .strategic-chat-interface * {
        color: inherit !important;
    }
    
    /* Typing indicator */
    .typing-indicator {
        background: #ffffff !important;
        color: #6c757d !important;
        border: 1px solid #e9ecef !important;
        padding: 8px 16px !important;
        border-radius: 16px !important;
        border-bottom-left-radius: 4px !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        font-size: 13px !important;
    }
    
    .typing-dot {
        background: #6c757d !important;
        width: 4px !important;
        height: 4px !important;
    }
}

/* Desktop optimizations for chat */
@media (min-width: 769px) {
    #ai-mentor-container {
        bottom: 30px;
        right: 30px;
    }
    
    #ai-mentor-icon {
        width: 60px;
        height: 60px;
    }
    
    #ai-mentor-tip {
        width: 400px !important;
        height: 550px !important;
        bottom: 90px !important;
        right: 0 !important;
    }
    
    .chat-header {
        padding: 20px 24px !important;
    }
    
    .chat-body {
        padding: 20px !important;
        min-height: 400px !important;
    }
    
    .chat-input-container {
        padding: 20px 24px !important;
    }
    
    .message-bubble {
        font-size: 15px !important;
        padding: 14px 18px !important;
    }
}
    
/* Mobile responsive chat body */
@media (max-width: 768px) {
    .chat-body {
        height: calc(100vh - 240px);
        flex: 1;
    }
}

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

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

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

/* Chat messages */
.chat-message {
    margin-bottom: 10px;
    animation: fadeInUp 0.3s ease;
}

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

.chat-message.assistant {
    text-align: left;
}

.message-bubble {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 85%;
    word-wrap: break-word;
}

.chat-message.user .message-bubble {
    background: #E37200;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-bubble {
    background: #f1f3f4;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Chat input */
.chat-input-container {
    padding: 15px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

.chat-input-group {
    display: flex;
    gap: 8px;
}

#chat-input {
    flex: 1;
    border: 1px solid #e1e5e9;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 15px;
    line-height: 1.4;
    outline: none;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transition: all 0.2s ease;
}

#chat-input:focus {
    border-color: #E37200;
    box-shadow: 0 0 0 2px rgba(227, 114, 0, 0.2);
}

#chat-send-btn {
    background: #E37200;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(227, 114, 0, 0.3);
}

#chat-send-btn:hover:not(:disabled) {
    background: #c66200;
    transform: scale(1.05);
}

#chat-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Loading animation */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #f1f3f4;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.5s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0ms; }
.typing-dot:nth-child(2) { animation-delay: 200ms; }
.typing-dot:nth-child(3) { animation-delay: 400ms; }

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

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

/* Tip title */
#ai-mentor-tip .tip-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#ai-mentor-tip .tip-title h4 {
    margin: 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
}

#ai-mentor-tip .tip-title h4 i {
    color: #E37200;
    margin-right: 8px;
}

/* Tip content */
#ai-mentor-tip .tip-content {
    color: #555;
    font-size: 14px;
    line-height: 1.5;
}

#ai-mentor-tip .tip-content p {
    margin-bottom: 10px;
}

#ai-mentor-tip .tip-content p:last-child {
    margin-bottom: 0;
}

/* Tip action buttons */
#ai-mentor-tip .tip-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
}

#ai-mentor-tip .tip-actions button {
    background: none;
    border: none;
    color: #E37200;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

#ai-mentor-tip .tip-actions button:hover {
    background-color: rgba(227, 114, 0, 0.1);
}

/* Close button */
#ai-mentor-tip .tip-close {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    transition: color 0.2s ease;
}

#ai-mentor-tip .tip-close:hover {
    color: #555;
}

/* Indicator dot for new tips */
#ai-mentor-new-indicator {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background-color: #E37200;
    border-radius: 50%;
    border: 2px solid white;
}

/* Minimize state */
#ai-mentor-container.minimized #ai-mentor-icon {
    width: 40px;
    height: 40px;
    opacity: 0.7;
}

#ai-mentor-container.minimized #ai-mentor-icon img {
    width: 32px;
    height: 32px;
}

/* Mobile responsive adjustments */
@media (max-width: 767px) {
    #ai-mentor-container {
        bottom: 20px;
        right: 20px;
    }
    
    #ai-mentor-tip {
        width: calc(100vw - 40px);
        max-width: 380px;
        height: 480px;
    }
    
    .chat-body {
        height: 280px;
        padding: 16px;
    }
    
    #chat-input {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    #chat-send-btn {
        width: 44px;
        height: 44px;
    }
    
    .chat-welcome-popup {
        bottom: 75px;
        right: -5px;
        max-width: 250px;
        font-size: 12px;
        padding: 10px 14px;
    }
    
    .chat-header h4 {
        font-size: 15px;
    }
    
    .chat-credits {
        font-size: 11px;
        padding: 3px 6px;
    }
}

/* Animation for the icon */
@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

.ai-mentor-pulse {
    animation: pulse 2s infinite;
}