/* =================================
   CHAT PANEL WIDTH AND POSITION FIXES
   ================================= */

/* Fix AI advisor section positioning and width */
#ai-advisor-section {
    /* Ensure proper positioning below navbar */
    position: relative;
    z-index: 1;
    margin-top: 0;
    padding-top: 0;
}

/* Fix chat container width and positioning */
#ai-advisor-section .card {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
}

/* Responsive chat messages container */
.chat-messages-container {
    height: 400px; /* Reduced from 500px */
    max-height: 60vh; /* Responsive height */
    overflow-y: auto;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 0;
    position: relative;
    scroll-behavior: smooth;
}

/* Ensure navbar appears above chat panel */
.navbar {
    position: sticky;
    top: 0;
    z-index: 1020; /* Higher z-index than chat panel */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Fix main content positioning */
main.container {
    position: relative;
    z-index: 1;
}

/* Move AI advisor to proper location when displayed as main section */
.ai-advisor-main-section {
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 15px;
}

.ai-advisor-main-section .container {
    max-width: none;
    padding: 0;
}

.ai-advisor-main-section .card {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Control buttons for chat panel */
#minimize-chat-btn,
#close-chat-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

#minimize-chat-btn:hover {
    background-color: #f8f9fa;
    border-color: #6c757d;
}

#close-chat-btn:hover {
    background-color: #dc3545;
    border-color: #dc3545;
    color: white;
}

/* Minimized state */
.ai-advisor-main-section.minimized .card-body {
    display: none;
}

.ai-advisor-main-section.minimized .card {
    margin-bottom: 10px;
}

/* Responsive adjustments for chat panel */
@media (max-width: 1200px) {
    .chat-messages-container {
        height: 350px;
        max-height: 50vh;
    }
    
    #ai-advisor-section .card {
        margin: 0 10px;
    }
    
    .ai-advisor-main-section {
        margin: 15px auto;
        padding: 0 10px;
    }
}

@media (max-width: 768px) {
    .chat-messages-container {
        height: 300px;
        max-height: 40vh;
    }
    
    /* Stack chat on mobile more efficiently */
    #ai-advisor-section {
        margin: 10px 0;
    }
    
    #ai-advisor-section .card {
        margin: 0 5px;
        border-radius: 10px;
    }
    
    .ai-advisor-main-section {
        margin: 15px auto;
        padding: 0 10px;
    }
    
    .ai-advisor-main-section h2 {
        font-size: 1.1rem;
    }
    
    #minimize-chat-btn,
    #close-chat-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .chat-input-area {
        padding: 10px;
    }
    
    #chat-input {
        font-size: 14px;
        padding: 8px 12px;
    }
    
    #send-chat-btn {
        padding: 8px 12px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .chat-messages-container {
        height: 250px;
        max-height: 35vh;
    }
    
    .ai-advisor-main-section {
        margin: 10px auto;
        padding: 0 5px;
    }
    
    .ai-advisor-main-section h2 {
        font-size: 1rem;
    }
    
    .ai-advisor-main-section .d-flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .ai-advisor-main-section .d-flex .d-flex {
        flex-direction: row;
        align-items: center;
    }
    
    /* Further mobile optimizations */
    .message-content {
        font-size: 14px;
        padding: 8px 12px;
    }
    
    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
    
    .chat-input-area {
        padding: 8px;
    }
}

/* Fix z-index layering issues */
.profile-header {
    position: relative;
    z-index: 999;
}

/* Ensure proper container flow */
.container {
    max-width: 100%;
    padding-left: 15px;
    padding-right: 15px;
}

/* Fix overflow issues on smaller screens */
#ai-advisor-section .card-body {
    padding: 0;
    overflow: hidden;
}

/* Improve chat panel visual hierarchy */
#ai-advisor-section h2 {
    font-size: 1.25rem;
    margin-bottom: 15px;
}

/* Dark mode adjustments for better visibility */
[data-theme="dark"] .chat-messages-container {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] #ai-advisor-section .card {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .ai-advisor-main-section .card {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
}

/* Ensure chat doesn't interfere with other sections */
#ai-advisor-section.section-hidden {
    display: none !important;
}

/* Better spacing between elements */
#ai-advisor-section {
    margin-bottom: 20px;
}

/* Fix potential width overflow on very small screens */
@media (max-width: 320px) {
    #ai-advisor-section {
        margin: 5px 0;
    }
    
    #ai-advisor-section .card {
        margin: 0 2px;
        border-radius: 8px;
    }
    
    .ai-advisor-main-section {
        margin: 5px auto;
        padding: 0 2px;
    }
    
    .chat-messages-container {
        height: 200px;
        max-height: 30vh;
    }
    
    .message-content {
        max-width: 95%;
        font-size: 13px;
        padding: 6px 10px;
    }
}
