/* Reset default margins and paddings, set height to full viewport */
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 */
}

/* Custom scrollbar styling for webkit browsers */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.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 */
    /* Ensure proper iframe behavior */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Ensure the main container fills the body completely when dual mode is hidden */
body > .container {
    height: 100vh;
    min-height: 100vh;
}

#chat_display {
    flex: 1;
    overflow-y: auto;
    white-space: pre-wrap;
    padding: 20px;
    padding-bottom: 10px; /* Reduce bottom padding to eliminate gap */
    background-color: #f5f7f9;
    border-bottom: none; /* Remove border that might cause visual gap */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flexbox to control height */
    max-height: calc(100% - 85px); /* Reserve space for input box + form-top-row */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 85px; /* Adjusted to account for form-top-row + form height */
    /* Improved scrolling behavior */
    scroll-behavior: auto; /* Remove smooth scrolling for better performance */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border-top: 1px solid #e5e8ec;
    width: 100%;
    padding: 0 10px; /* Remove top/bottom padding completely */
    /* Make sure form stays at the bottom */
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 85px; /* Increased to accommodate form-top-row */
    box-sizing: border-box; /* Include padding in the height calculation */
    margin: 0; /* Ensure no margin */
}

/* Force the form-top-row to take minimal space - simplified */
.form-top-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 5px;
    padding: 0 15px;
    box-sizing: border-box;
    flex: 0 0 auto;
    height: 25px;
}

#message_form {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px 15px;
    background-color: #fff;
    border-radius: 0 0 10px 10px;
    box-sizing: border-box;
    flex: 1;
    min-height: 55px;
    max-width: 1200px;
    margin: 0 auto;
}       

/* Styles for the dual-mode form container */
#message_form_dual {
    display: flex;
    flex-direction: row;
    width: 100%;
    padding: 0;
    margin: 0;
    background-color: transparent;
    align-items: center;
    gap: 15px;
}

/* The inner container for the dual-mode input elements */
#message_form_dual .message_form {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    flex: 1;
    gap: 10px;
}

/* Top row with icons - simplified to take minimal space */
.form-top-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 5px;
    padding: 0 15px;
    box-sizing: border-box;
    flex: 0 0 auto;
    height: 25px;
}

/* Override for dual mode - put icons on left, minimal width */
.dual_mode .form-top-row {
    width: auto;
    justify-content: flex-start;
    margin-bottom: 0;
    padding: 0;
    height: auto;
}

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

#message_label_dual {
    display: block;
    text-align: center; /* Centers the label horizontally */
    width: 100%; /* Makes the label as wide as its container */
    margin-bottom: 10px; /* Adds some spacing below the label */
    font-size: 1.2em; /* Adjusts font size for better visibility */
}

#message_input, #message_input_dual {
    flex: 1;
    padding: 12px 16px;
    margin: 0 8px; /* Reduce margins for more space */
    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 */
    width: 100%; /* Make it take full available width */
    min-width: 300px; /* Ensure minimum width for placeholder text */
    /* Remove max-width restriction to allow full width */
}

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

#submit_button, #submit_button_dual {
    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, #submit_button_dual:hover {
    background-color: #1a74c4;
}

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

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

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

#submit_button.sending::after, #submit_button_dual.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 {
    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;
}

/* Styles for dual chat displays */
.chat_display {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    height: 100%; /* Take full height of parent */
    max-height: 100%; /* Ensure it doesn't overflow */
    display: flex;
    flex-direction: column;
    /* Improved scrolling behavior */
    scroll-behavior: auto; /* Remove smooth scrolling for better performance */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Add borders to differentiate chat displays in dual mode */
#chat_display_left, #chat_display_right {
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    background-color: #ffffff;
    height: 100%; /* Fill the container */
    max-height: 100%; /* Ensure it doesn't overflow its parent */
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box; /* Include padding in height calculation */
    display: flex;
    flex-direction: column;
    /* Improved scrolling behavior */
    scroll-behavior: auto; /* Remove smooth scrolling for better performance */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.chat-containers {
    display: flex;
    width: 100%;
    gap: 20px;
    flex: 1;
    flex-direction: row;
    height: calc(100vh - 90px); /* Adjusted height to account for form and padding */
    max-height: calc(100vh - 90px); /* Set max-height to prevent overflow */
    background-color: #f5f7f9; /* Match body background color */
    padding: 0;
    box-sizing: border-box;
    overflow: hidden; /* Prevent container from scrolling */
}

#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;
    }
    
    /* Keep the chat containers side by side even on smaller screens */
    .chat-containers {
        flex-direction: row;
    }
}

.dual_mode {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    box-sizing: border-box;
    padding: 15px;
    background-color: #f5f7f9;
    overflow: hidden;
    position: relative;
}

.dual_mode form {
    margin-bottom: 15px;
    background-color: #ffffff;
    border-radius: 8px;
    flex-shrink: 0;
    padding: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

.dual_mode form {
    margin-bottom: 15px;
    background-color: #ffffff;
    border-radius: 8px;
    flex-shrink: 0;
    padding: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

/* Make the dual mode form layout horizontal */
.dual_mode #message_form_dual {
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

/* Put top row icons on the left - override for dual mode */
.dual_mode #message_form_dual .form-top-row {
    flex: 0 0 auto;
    height: auto;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0;
    width: auto;
    justify-content: flex-start;
}

/* Message form takes remaining space (90%) */
.dual_mode #message_form_dual .message_form {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.dual_mode #message_input_dual {
    flex: 1;
    margin: 0;
}

/* Hide the label in dual mode since it's not needed in horizontal layout */
.dual_mode #message_label_dual {
    display: none;
}

/* Style the dual chat containers */
.dual-chat-container {
    flex: 1;
    min-width: 0;
    background-color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Hide main container when dual mode is active */
body:has(.dual_mode[style*="display: flex"]) .container:not(.dual_mode .container) {
    display: none !important;
}

/* Fallback for browsers without :has() support */
.hidden-in-dual-mode {
    display: none !important;
}
