/* Using CSS variables makes it easy to change the theme later */
:root {
    --aic-primary-color: #0073aa;
    --aic-light-gray: #f0f0f0;
    --aic-user-message-bg: #0073aa;
    --aic-ai-message-bg: #e5e5ea;
    --aic-text-color-light: #ffffff;
    --aic-text-color-dark: #333333;
}

/* --- No changes to the container, open button, or window styles --- */
#aic-chat-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; }
#aic-chat-open-button { width: 60px; height: 60px; background-color: var(--aic-primary-color); border-radius: 50%; color: var(--aic-text-color-light); display: flex; justify-content: center; align-items: center; cursor: pointer; box-shadow: 0 4px 8px rgba(0,0,0,0.2); transition: transform 0.2s ease; }
#aic-chat-open-button:hover { transform: scale(1.1); }
#aic-chat-window { width: 350px; max-width: 90vw; height: 500px; max-height: 80vh; background-color: #fff; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); display: flex; flex-direction: column; overflow: hidden; transition: opacity 0.3s ease, transform 0.3s ease; transform-origin: bottom right; }
.aic-hidden { display: none !important; opacity: 0; transform: scale(0.5); }
#aic-chat-header { background-color: var(--aic-primary-color); color: var(--aic-text-color-light); padding: 15px; display: flex; justify-content: space-between; align-items: center; }
#aic-chat-header h3 { margin: 0; font-size: 1.1em; }
#aic-chat-close-button { background: none; border: none; color: var(--aic-text-color-light); font-size: 24px; cursor: pointer; line-height: 1; }
#aic-chat-messages { flex-grow: 1; padding: 15px; overflow-y: auto; background-color: var(--aic-light-gray); }

/* --- START NEW/MODIFIED STYLES --- */
.aic-message {
    display: flex;
    align-items: flex-end;
    margin-bottom: 15px;
    max-width: 90%;
    clear: both; /* This is the critical fix */
}

.aic-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #ccc;
    margin-right: 10px;
    flex-shrink: 0;
    /* Basic SVG for a user icon */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E");
    background-size: 20px;
    background-position: center;
    background-repeat: no-repeat;
}

.aic-message-content {
    display: flex;
    flex-direction: column;
}

.aic-sender-name {
    font-size: 0.8em;
    color: #555;
    margin-bottom: 4px;
}

.aic-message-content p {
    margin: 0;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
}

/* AI/Agent messages appear on the left */
.aic-message-ai {
    float: left;
}
.aic-message-ai .aic-sender-name {
    margin-left: 5px;
}
.aic-message-ai .aic-message-content p {
    background-color: var(--aic-ai-message-bg);
    color: var(--aic-text-color-dark);
    border-bottom-left-radius: 4px;
}
/* A simple bot icon */
.aic-message-ai .aic-message-avatar {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6zm2 5h2v2H6v-2zm4 0h8v2h-8v-2z'/%3E%3C/svg%3E");
    background-color: var(--aic-primary-color);
}


/* User messages appear on the right */
.aic-message-user {
    float: right;
    flex-direction: row-reverse; /* Reverses the order of avatar and content */
}
.aic-message-user .aic-message-avatar {
    margin-right: 0;
    margin-left: 10px;
}
.aic-message-user .aic-sender-name {
    text-align: right;
    margin-right: 5px;
}
.aic-message-user .aic-message-content p {
    background-color: var(--aic-user-message-bg);
    color: var(--aic-text-color-light);
    border-bottom-right-radius: 4px;
}
/* --- END NEW/MODIFIED STYLES --- */


/* --- No changes to the footer or typing indicator --- */
#aic-chat-footer { padding: 10px; border-top: 1px solid #ddd; }
#aic-chat-form { display: flex; align-items: center; }
#aic-chat-input { flex-grow: 1; border: 1px solid #ccc; border-radius: 20px; padding: 10px 15px; font-size: 1em; }
#aic-send-button { background: none; border: none; cursor: pointer; padding: 8px; margin-left: 8px; color: var(--aic-primary-color); }
#aic-send-button:hover { opacity: 0.7; }
#aic-typing-indicator { padding: 0 15px 10px 15px; background-color: var(--aic-light-gray); }
#aic-typing-indicator span { height: 8px; width: 8px; background-color: #999; border-radius: 50%; display: inline-block; animation: aic-typing-bounce 1.3s infinite; }
#aic-typing-indicator span:nth-of-type(2) { animation-delay: 0.15s; }
#aic-typing-indicator span:nth-of-type(3) { animation-delay: 0.3s; }
@keyframes aic-typing-bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }