/********************************************
  Chat Container
********************************************/
.aip-chat-container {
    max-width: 700px; /* Increased from 600px to make it wider */
    margin: 20px auto;
    background: #fff;
    border-radius: 10px; /* Reduced from 16px for less rounded corners */
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e0e5ec;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/********************************************
  Chat Messages Area
********************************************/
.aip-chat-messages {
    padding: 20px;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    display: flex;
    flex-direction: column;
    background: #f7f9fc;
    min-height: 450px; /* Increased from 350px to make it taller */
    max-height: 600px; /* Increased from 500px to make it taller */
    overflow-y: auto;
    overflow-x: hidden;
    gap: 16px; /* Consistent spacing between messages */
    scroll-behavior: smooth;
}

/********************************************
  Speech Bubbles (User & AI)
********************************************/
/* Shared bubble styles */
.user-message, .aip-message {
    position: relative;
    padding: 14px 18px;
    border-radius: 18px;
    max-width: 80%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    word-wrap: break-word;
    line-height: 1.4;
    animation: fadeIn 0.3s ease-out;
}

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

/* AI message bubble */
.aip-message {
    background: #e9f2ff; /* Light blue color */
    color: #333;
    align-self: flex-start;
    text-align: left;
    border-bottom-left-radius: 6px;
    line-height: 1.5;
    padding-left: 52px; /* Increased from 46px for larger avatar */
    margin-left: 15px; /* Increased from 10px for avatar positioning */
    position: relative;
}

/* User message bubble */
.user-message {
    background-color: #0078ff;
    color: #fff;
    align-self: flex-end;
    text-align: left;
    border-bottom-right-radius: 6px;
    margin-right: 10px;
}

/********************************************
  AI Message Avatar Styling
********************************************/
.aip-message-avatar {
    width: 42px; /* Increased from 36px */
    height: 42px; /* Increased from 36px */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent; /* Changed from white to transparent for your brand image */
    border: none; /* Removed border */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: absolute;
    left: -12px; /* Changed from -5px to position further left */
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    overflow: hidden; /* Ensure the image stays within the circular boundary */
}

.aip-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.aip-message-avatar i {
    font-size: 20px; /* Increased from 18px */
    color: #0078ff;
}

/* Position adjustments for message bubbles */
.aip-message::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: #e9f2ff; /* Match the bubble color */
    border-radius: 2px;
    z-index: 1;
}

.user-message::after {
    content: "";
    position: absolute;
    right: -6px;
    bottom: 8px;
    width: 12px;
    height: 12px;
    background: #0078ff;
    transform: rotate(45deg);
    border-radius: 2px;
    z-index: 1;
}

/********************************************
  Enhanced AI Message Formatting
********************************************/
/* HTML Formatting */
.aip-message p {
    margin: 0 0 12px 0;
}

.aip-message p:last-child {
    margin-bottom: 0;
}

.aip-message strong {
    color: #0056b3;
    font-weight: 600;
}

/* Fix for numbered lists */
.aip-message ol {
    margin: 12px 0;
    padding-left: 24px;
    counter-reset: item;
}

.aip-message ol li {
    display: block;
    position: relative;
    margin-bottom: 8px;
    padding-left: 8px;
}

.aip-message ol li::before {
    content: counter(item) ".";
    counter-increment: item;
    position: absolute;
    left: -18px;
    font-weight: bold;
    color: #0056b3;
}

.aip-message ul {
    margin: 12px 0;
    padding-left: 24px;
}

.aip-message li {
    margin-bottom: 8px;
}

.aip-message li:last-child {
    margin-bottom: 0;
}

/* Links in messages - made bold and darker */
.aip-message a {
    color: #0056b3; /* Darker blue than before */
    text-decoration: none;
    font-weight: bold;
    border-bottom: 1px solid rgba(0, 86, 179, 0.3);
}

.aip-message a:hover {
    border-bottom-color: #0056b3;
    background-color: rgba(0, 86, 179, 0.05);
}

/********************************************
  "AI is typing..." Indicator
********************************************/
.typing-indicator {
    font-style: italic;
    color: #777;
    align-self: flex-start;
    margin-left: 45px; /* Adjusted to align with avatar */
    padding: 8px 14px;
    background: rgba(240, 242, 245, 0.7);
    border-radius: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: pulse 1.5s infinite ease-in-out;
}

.typing-indicator img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

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

/********************************************
  Quick-Start Buttons
********************************************/
.chat-starter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0 12px 45px; /* Adjusted to align with avatar */
}

.chat-starter-button {
    background-color: #f2f3f5;
    color: #1877f2;
    padding: 12px 18px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-starter-button:hover {
    background-color: #e4e6e9;
    transform: translateY(-2px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

.chat-starter-button:active {
    transform: translateY(0);
}

/********************************************
  Input Section
********************************************/
.aip-chat-input-area {
    display: flex;
    align-items: center;
    padding: 15px;
    border-top: 1px solid #e4e6eb;
    background: #fff;
    position: relative;
}

.aip-chat-input {
    flex-grow: 1;
    font-size: 16px;
    padding: 14px 50px 14px 18px;
    border-radius: 24px;
    border: 1px solid #e4e6eb;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) inset;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.aip-chat-input:focus {
    border-color: #0078ff;
    box-shadow: 0 0 0 2px rgba(0, 120, 255, 0.15);
}

.aip-chat-send {
    position: absolute;
    right: 25px;
    background: #0078ff;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.aip-chat-send:hover {
    background: #0069e0;
    transform: scale(1.05);
}

/* Explicit Font Awesome icon styles */
.aip-chat-send i.fas,
.aip-chat-send i.fa-paper-plane {
    font-size: 16px !important;
    display: inline-block !important;
    font-style: normal !important;
    font-variant: normal !important;
    text-rendering: auto !important;
    line-height: 1 !important;
    font-family: "Font Awesome 6 Free", "Font Awesome 6", FontAwesome !important;
    font-weight: 900 !important;
}

/* Fallback for send icon */
.aip-chat-send i.fa-paper-plane::before {
    content: "➤";
}

.aip-chat-send::after {
    content: attr(title);
    font-size: 0;
}

/* Fix for proper alignment of bot avatar in typing indicator */
.typing-indicator i.fa-face-smile {
    margin-right: 4px;
    color: #0078ff;
    font-size: 16px;
}

/********************************************
  Responsive Tweaks
********************************************/
@media (max-width: 768px) {
    .aip-chat-container {
        width: 95%;
        margin: 10px auto;
        border-radius: 8px; /* Reduced border radius for mobile */
    }

    .aip-chat-messages {
        font-size: 15px;
        min-height: 350px;
        padding: 16px;
    }

    .chat-starter-button {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .aip-message, .user-message {
        max-width: 85%;
    }
}

/********************************************
  Message Content Formatting
********************************************/
/* First message in conversation - welcome message */
.aip-message:first-child {
    margin-top: 8px;
    background-color: #e7f3ff;
}

.aip-message:first-child::before {
    background-color: #e7f3ff;
}

/* Scroll to bottom button (optional) */
.scroll-to-bottom {
    position: absolute;
    bottom: 85px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.scroll-to-bottom.visible {
    opacity: 1;
}

.scroll-to-bottom i {
    color: #0078ff;
}
/* Replace or update the button style in your CSS */

/* Clear history button - improved styling */
.aip-clear-history {
    display: inline-block;
    margin: 5px 10px;
    padding: 6px 12px;
    background-color: #f0f0f0;
    color: #555;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s ease;
    float: right;
    position: relative;
    top: 5px;
}

.aip-clear-history:hover {
    background-color: #e0e0e0;
    color: #333;
}

/* Add icon to button (optional) */
.aip-clear-history:before {
    content: "↺"; /* Refresh symbol */
    margin-right: 5px;
}

/* Ensure proper positioning */
.aip-chat-container {
    position: relative;
}

/* Add this if you want to move the button to the top right of the chat */
.aip-chat-header {
    display: flex;
    justify-content: flex-end;
    padding: 5px 10px;
    border-bottom: 1px solid #eee;
}

/* If you decide to place the button in a header, use this in your JS
   instead of inserting before the input area:
   
   const header = document.createElement('div');
   header.classList.add('aip-chat-header');
   header.appendChild(clearButton);
   chatContainer.insertBefore(header, chatMessages);
*//* Add these styles to your aip-chatbot.css file */

/* Chat header */
.aip-chat-header {
    display: flex;
    justify-content: flex-end;
    padding: 5px 10px;
    border-bottom: 1px solid #eee;
    background-color: #f9f9f9;
}

/* Clear history button - improved styling */
.aip-clear-history {
    display: inline-block;
    margin: 5px 0;
    padding: 6px 12px;
    background-color: #f0f0f0;
    color: #555;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s ease;
}

.aip-clear-history:hover {
    background-color: #e0e0e0;
    color: #333;
}

.aip-clear-history:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Add icon to button (optional) */
.aip-clear-history:before {
    content: "↺"; /* Refresh symbol */
    margin-right: 5px;
}

/* Debug button */
.aip-debug-button {
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 9999;
    padding: 3px 8px;
    font-size: 10px;
    background: #ff9800;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

/* Ensure proper padding for chat messages with the header */
.aip-chat-container {
    position: relative;
}

.aip-chat-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
}