html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #333;
    background-color: #f5f7f9;
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

.container {
    display: flex;
    flex-direction: column;
    height: 100%; /* Fill the iframe's height */
    width: 100%; /* Ensure full width of iframe is used */
    max-width: 1200px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
    background-color: #fff;
    min-height: 0;
    /* Ensure these styles to maintain fixed layout */
    position: relative;
    overflow: hidden;
    box-sizing: border-box; /* Include padding in width/height calculation */
}

#chat_display {
    flex: 1;
    overflow-y: auto;
    white-space: pre-wrap;
    padding: 20px;
    background-color: #f5f7f9;
    border-bottom: 1px solid #e5e8ec;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flexbox to control height */
    max-height: calc(100% - 70px); /* Reserve space for input box */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 70px; /* Fixed height for input section */
}

.form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border-top: 1px solid #e5e8ec;
    width: 100%;
    padding: 5px 10px;
    /* Make sure form stays at the bottom */
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px; /* Fixed height */
    box-sizing: border-box; /* Include padding in the height calculation */
}

.form-top-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: flex-end; /* Change to flex-end to push elements to the right */
    margin-bottom: 5px;
    padding: 0 15px;
    box-sizing: border-box;
    flex-wrap: nowrap;
}

#message_form {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0 15px;
    background-color: #fff;
    border-radius: 0 0 10px 10px;
    box-sizing: border-box; /* Include padding in width calculation */
}

#message_label {
    margin-right: 10px;
    font-size: 14px;
    color: #666;
}

#message_input {
    flex: 1;
    padding: 12px 16px;
    margin-right: 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 15px;
    resize: none;
    transition: border-color 0.3s, box-shadow 0.3s;
    height: 40px; /* Increased initial height for better usability */
    max-height: 80px; /* Increased max height */
    outline: none;
    overflow-y: auto;
    box-sizing: border-box; /* Include padding in the height calculation */
}

#message_input:focus {
    border-color: #2c88d9;
    box-shadow: 0 0 0 2px rgba(44, 136, 217, 0.1);
}

#submit_button {
    padding: 10px 16px;
    background-color: #2c88d9;
    color: #fff;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    transition: background-color 0.2s, transform 0.1s;
}

#submit_button:hover {
    background-color: #1a74c4;
}

#submit_button:active {
    transform: scale(0.98);
}

#submit_button:disabled {
    background-color: #b3cce6;
    cursor: not-allowed;
}

#submit_button.sending {
    background-color: #1a74c4;
    position: relative;
}

#submit_button.sending::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.delimiter {
    display: none; /* Hide delimiters for cleaner interface */
}

/* Modern chat bubble styling */
.user_message, .assistant_message {
    position: relative;
    padding: 10px 14px; /* Slightly smaller padding */
    margin: 8px 0; /* Smaller margins */
    max-width: 85%; /* A bit wider for better use of space */
    border-radius: 16px; /* Slightly smaller rounding */
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-sizing: border-box; /* Include padding in width calculation */
}

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

.user_message {
    align-self: flex-end;
    background-color: #2c88d9;
    color: white;
    margin-left: 15%; /* Reduced margin for better space utilization */
    border-bottom-right-radius: 5px;
}

.assistant_message {
    align-self: flex-start;
    background-color: #ebeef1;
    color: #333;
    margin-right: 15%; /* Reduced margin for better space utilization */
    border-bottom-left-radius: 5px;
}

/* Code block styling within assistant messages */
.assistant_message pre {
    background-color: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px;
    margin: 8px 0;
    overflow-x: auto;
}

.assistant_message code {
    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 0.9em;
}

/* Style links in assistant messages */
.assistant_message a {
    color: #2c88d9;
    text-decoration: none;
    border-bottom: 1px solid rgba(44, 136, 217, 0.3);
    transition: border-bottom-color 0.2s ease;
}

.assistant_message a:hover {
    border-bottom-color: #2c88d9;
}

#limit_info {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    background-color: #f0f7ff;
    color: #426899;
    font-size: 11px; /* Slightly smaller font size */
    border-radius: 4px;
    margin: 0;
    flex-grow: 0;
    white-space: nowrap;
    min-width: fit-content;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease;
}

#limit_info:hover {
    transform: scale(1.05);
}

#limit_info:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -30px;
    left: -5px; /* Position to the left */
    transform: translateX(-90%); /* Shift it further left */
    background-color: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
}

#limit_info:hover::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 8px; /* Position the arrow to align with the left side */
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 10;
    pointer-events: none;
}

#search_tool_indicator {
    display: none;
    margin-left: 6px; /* Slightly reduced spacing */
    color: #2c88d9;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease, color 0.3s ease; /* Add color transition */
    flex-shrink: 0;
    line-height: 1; /* Ensure vertical alignment */
}

#search_tool_indicator:hover {
    transform: scale(1.1);
}

#search_tool_indicator svg {
    width: 16px;
    height: 16px;
    display: block;
}

#search_tool_indicator:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -30px;
    left: -5px; /* Position to the left */
    transform: translateX(-90%); /* Shift it further left */
    background-color: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
}

#search_tool_indicator:hover::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 8px; /* Position the arrow to align with the left side */
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 10;
    pointer-events: none;
}

.error_message {
    color: #e74c3c;
    background-color: #fef5f5;
    border-left: 3px solid #e74c3c;
    padding: 10px 15px;
    margin: 10px 0;
    border-radius: 3px;
    font-size: 14px;
}

.thinking_dots {
    align-self: flex-start;
    background-color: #ebeef1;
    color: #666;
    padding: 15px 20px;
    border-radius: 20px;
    border-bottom-left-radius: 5px;
    margin: 10px 0;
    margin-right: 20%;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

.search_indicator {
    align-self: flex-start;
    display: flex;
    align-items: center;
    background-color: #f0f7ff;
    color: #426899;
    padding: 10px 15px;
    border-radius: 20px;
    border-bottom-left-radius: 5px;
    margin: 10px 0;
    margin-right: 20%;
    font-style: italic;
}

.search_indicator svg {
    margin-right: 8px;
    animation: pulse 1.5s infinite;
}

/* Tools notification removed - replaced with icon */

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

/* Return to bottom button */
#return_to_bottom {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background-color: #2c88d9;
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: all 0.3s ease;
}

#return_to_bottom:hover {
    background-color: #1a74c4;
    transform: scale(1.05);
}

#return_to_bottom svg {
    width: 24px;
    height: 24px;
}

/* Media queries for better iframe responsiveness */
@media (max-width: 800px) {
    .form-top-row {
        padding: 0 10px;
    }
    
    #message_form {
        padding: 0 10px;
    }
    
    #limit_info {
        padding: 2px 4px;
        font-size: 10px;
    }
    
    #search_tool_indicator svg {
        width: 14px;
        height: 14px;
    }
}