/* Insert modern font import at the very top */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');

/* Root Variables */
:root {
    --background-color: #f7f7f7; /* Updated: near-white light background */
    --primary-text-color: #333333; /* Dark grey for readability */
    --header-footer-bg: #283593; /* Bold deep blue for header and footer */
    --border-color: #cfd8dc; /* Subtle blue-grey border */
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --subtle-shadow: 0 2px 6px rgba(0, 0, 0, 0.08); /* Added subtle shadow */

    /* Updated Accent Colors */
    --accent-pink: #d81b60;
    --accent-blue: #1e88e5;
    --accent-green: #43a047;
    --accent-purple: #8e24aa;
    --hover-effect: rgba(0, 0, 0, 0.1);

    /* Message Backgrounds */
    --user-message-bg: #e0f2fe; /* Light Blue */
    --assistant-message-bg: #f3f4f6; /* Light Gray */

    --font-family: 'Inter', sans-serif;
    --font-size: 16px;
    --line-height: 1.6;

    --input-gradient: linear-gradient(90deg, #ffffff, #f9f9f9);
}

/* Reset and Body Styles */
body {
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--primary-text-color);
    font-family: var(--font-family);
    font-size: var(--font-size);
    line-height: var(--line-height);
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px; /* Responsive width for content */
    margin: 0 auto;
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Header Styles */
header {
    background: linear-gradient(135deg, var(--header-footer-bg), var(--accent-blue));
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: inset 0 -1px 0 var(--border-color);
}

header h1 {
    margin: 0;
    font-size: 1.8rem; /* Larger and easily readable */
    color: white; /* Ensure good contrast */
    text-transform: uppercase;
    letter-spacing: 1px;
}

header .model-info {
    font-size: 0.9rem;
    color: #c0c0c0; /* Softer grey for secondary info */
}

/* Main Chat Area */
main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--background-color);
}

/* Message Styles */
.message {
    max-width: 95%;
    margin-bottom: 1rem;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--subtle-shadow);
    transition: box-shadow 0.2s ease;
    animation: fadeIn 0.3s ease-out;
}

.user-message {
    margin-left: 0;
    margin-right: auto;
    background-color: var(--user-message-bg);
    border-top-left-radius: 4px;
    /* Adjusted for narrower column */
    padding: 0.6rem 0.8rem; 
    font-size: 0.95rem;
}

/* Make user message headers more compact */
#userMessagesColumn .message .flex.items-center {
    margin-bottom: 0.5rem;
}

#userMessagesColumn .w-8 {
    width: 1.75rem; /* Make avatar slightly smaller */
    height: 1.75rem;
}

#userMessagesColumn .text-sm {
    font-size: 0.8rem;
}

#userMessagesColumn .text-xs {
    font-size: 0.7rem;
}

.assistant-message {
    margin-left: auto;
    margin-right: 0;
    background-color: var(--assistant-message-bg);
    border-top-right-radius: 4px;
}

/* For consecutive messages, add a smaller top margin */
.message + .message {
    margin-top: 0.4rem;
}

.message .timestamp {
    font-size: 0.7rem; /* Slightly smaller */
    color: rgba(153, 153, 153, 0.8); /* More subtle with some transparency */
    text-align: right;
    margin-top: 0.4rem;
}

/* Column Scrollbars */
#userMessagesColumn::-webkit-scrollbar,
#assistantMessagesColumn::-webkit-scrollbar {
    width: 6px;
}

#userMessagesColumn::-webkit-scrollbar-track,
#assistantMessagesColumn::-webkit-scrollbar-track {
    background: transparent;
}

#userMessagesColumn::-webkit-scrollbar-thumb,
#assistantMessagesColumn::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
}

html.dark #userMessagesColumn::-webkit-scrollbar-thumb,
html.dark #assistantMessagesColumn::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
}
 
/* Generated Image Styles */
.image-container {
    width: 100%;
    margin: 1rem 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.generated-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
    display: block;
}

.generated-image:hover {
    transform: scale(1.02);
}

/* Error Message Styling */
.alert-message.error {
    background: rgba(220, 53, 69, 0.9);
    color: white;
    padding: 1rem 2rem;
    border-radius: 30px;
}

/* Loading Spinner */
#loadingIndicator .spinner-border {
    border-width: 4px;
    width: 48px;
    height: 48px;
    border-color: var(--accent-blue) transparent transparent transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Custom Alert Message */
.alert-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 1rem 2rem;
    border-radius: 30px;
    z-index: 1000;
    animation: fadeInOut 3s ease-in-out;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -20px); }
    15% { opacity: 1; transform: translate(-50%, 0); }
    85% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -20px); }
}

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

/* Typing indicator animation for when the assistant is typing */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.2rem;
    background-color: var(--assistant-message-bg);
    border-radius: 12px;
    margin-bottom: 0;
    box-shadow: var(--subtle-shadow);
    min-width: 80px;
    justify-content: center;
    border-top-right-radius: 4px;
    max-width: 180px; /* Limit width for better appearance in wide column */
    margin-left: auto; /* Position towards the right in the column */
    margin-right: 0; /* Align to the right edge like assistant messages */
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    margin: 0 3px;
    background-color: #888;
    border-radius: 50%;
    display: block;
    opacity: 0.4;
    will-change: transform, opacity; /* Performance optimization */
}

.typing-indicator span:nth-child(1) {
    animation: pulse 1.2s infinite 0.1s;
}

.typing-indicator span:nth-child(2) {
    animation: pulse 1.2s infinite 0.3s;
}

.typing-indicator span:nth-child(3) {
    animation: pulse 1.2s infinite 0.5s;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Responsive Design */
@media (max-width: 600px) {
    #app {
        max-width: 100%;
        height: 100%;
        margin: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    header {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .header-buttons {
        display: flex;
        gap: 0.5rem;
    }

    .header-buttons button {
        padding: 0.5rem;
        font-size: 1.1rem;
    }

    main {
        padding: 0.75rem;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    .message {
        max-width: 90%; /* Slightly wider on mobile */
    }

    footer {
        padding: 0.5rem;
        position: sticky;
        bottom: 0;
        background-color: var(--background-color);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    footer > div {
        padding: 0.25rem 0.75rem; /* Smaller padding on mobile */
    }

    #question {
        font-size: 1rem;
        min-height: 36px;
        max-height: 80px;
        overflow-y: auto;
    }

    footer button {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    footer #submit {
        width: 40px;
        height: 40px;
    }

    /* Prevent zoom on input focus for iOS */
    @supports (-webkit-touch-callout: none) {
        #question {
            font-size: 16px;
        }
    }

    /* Improve touch targets */
    .header-buttons button,
    footer button {
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Adjust message spacing for better readability */
    .message-content {
        line-height: 1.4;
    }

    /* Ensure code blocks don't overflow */
    .message pre {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    /* Improve image display on mobile */
    .image-container {
        margin: 0.5rem 0;
        width: 100%;
    }

    .generated-image {
        border-radius: 4px;
        width: 100%;
        height: auto;
    }

    /* Remove the #generateImage specific styling since we've standardized the buttons */
    #generateImage {
        /* Remove overrides */
    }

    .alert-message {
        width: 80%;
        font-size: 0.9rem;
        text-align: center;
    }

    /* Ensure avatars are properly sized on small screens */
    .w-10 {
        width: 2rem !important; /* Override Tailwind if needed */
    }
    
    .h-10 {
        height: 2rem !important; /* Override Tailwind if needed */
    }
}

/* Keyboard Height Adjustment for Mobile */
@media (max-width: 600px) and (max-height: 400px) {
    #app {
        height: calc(100% - var(--keyboard-height, 0px));
    }
    
    footer {
        position: sticky;
        bottom: 0;
    }
}

/* Prevent Content Shift on Mobile */
@media (max-width: 600px) {
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    main {
        height: calc(100% - 120px); /* Adjust based on header/footer height */
        overflow-y: auto;
    }
}

/* Improve Mobile Dark Mode */
@media (prefers-color-scheme: dark) {
    html.dark {
        --background-color: #1f2937; /* Dark Gray */
        --primary-text-color: #f9fafb; /* Near White */
        --header-footer-bg: #111827; /* Very Dark Gray */
        --border-color: #4b5563; /* Medium Gray */
        --subtle-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        
        /* Dark Mode Message Backgrounds */
        --user-message-bg: #374151; /* Darker Gray-Blue */
        --assistant-message-bg: #4b5563; /* Medium Gray */
    }

    .message pre {
        background: rgba(0, 0, 0, 0.3);
    }
}

/* Extra Responsive Enhancements for Tablets and Desktops */
@media (min-width: 768px) and (max-width: 1199px) {
    #app {
        max-width: 750px;
    }
}

@media (min-width: 1200px) {
    #app {
        max-width: 1000px;
        margin: 2rem auto;
    }
    header h1 {
        font-size: 2rem;
    }
    main {
        padding: 2rem;
    }
}

/* Touch Device Adjustments */
@media (hover: none) {
    .header-buttons button,
    footer button {
        transition: none;
    }
}

/* End of Extra Responsive Enhancements */

/* Insert smooth scrolling for a modern feel */
html {
    scroll-behavior: smooth;
}

/* Code Block Styling */
.message pre {
    position: relative; /* Needed for absolute positioning of button */
    background-color: #f0f0f0; /* Light background for code */
    border-radius: 8px;
    padding: 1rem;
    padding-top: 2.5rem; /* Add space for the button */
    margin-top: 0.5rem;
    overflow-x: auto;
    font-size: 0.9rem;
}

html.dark .message pre {
    background-color: #374151; /* Darker background for code in dark mode */
    color: #f3f4f6;
}

.message code {
    display: block;
    white-space: pre-wrap; /* Wrap long lines */
    word-wrap: break-word;
}

/* Copy Code Button Styling */
.copy-code-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: rgba(0, 0, 0, 0.1);
    color: #333;
    border: none;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    display: flex; /* Align icon and text */
    align-items: center;
    gap: 0.3rem; /* Space between icon and text */
}

.copy-code-button:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.2);
}

.copy-code-button:active {
    background-color: rgba(0, 0, 0, 0.3);
}

.copy-code-button:disabled {
    opacity: 0.8;
    cursor: default;
    background-color: var(--accent-green); /* Indicate success */
    color: white;
}

html.dark .copy-code-button {
    background-color: rgba(255, 255, 255, 0.15);
    color: #f3f4f6;
}

html.dark .copy-code-button:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

html.dark .copy-code-button:active {
    background-color: rgba(255, 255, 255, 0.35);
}

html.dark .copy-code-button:disabled {
    background-color: var(--accent-green);
    color: white;
}

/* Markdown Formatting within Messages */
.message-content ul {
    list-style-type: disc;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.message-content ol {
    list-style-type: decimal;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-content blockquote {
    border-left: 3px solid var(--accent-blue);
    padding-left: 1rem;
    margin: 0.5rem 0;
    color: rgba(0, 0, 0, 0.7);
    font-style: italic;
}

html.dark .message-content blockquote {
    color: rgba(255, 255, 255, 0.7);
}

.message-content table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    width: 100%;
}

.message-content table th,
.message-content table td {
    border: 1px solid #ddd;
    padding: 0.5rem;
    text-align: left;
}

html.dark .message-content table th,
html.dark .message-content table td {
    border-color: #444;
}

.message-content table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

html.dark .message-content table th {
    background-color: #333;
}

.message-content p {
    margin-bottom: 0.75rem;
}

.message-content em {
    font-style: italic;
}

.message-content strong {
    font-weight: bold;
}

/* Ensure proper code block formatting in narrower column */
#userMessagesColumn .message-content pre {
    max-width: 100%;
    overflow-x: auto;
}

#userMessagesColumn .message-content pre code {
    white-space: pre;
    font-size: 0.8rem;
}

/* Settings Panel Styles */
#settingsPanel {
    transition: all 0.3s ease;
    z-index: 100;
}

#settingsPanel input[type="range"] {
    -webkit-appearance: none;
    height: 8px;
    border-radius: 5px;
    background: #d7d7d7;
    outline: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.dark #settingsPanel input[type="range"] {
    background: #4a5568;
}

#settingsPanel input[type="range"]:hover {
    opacity: 1;
}

#settingsPanel input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: none;
}

#settingsPanel input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: none;
}

/* Token display styles */
.token-indicator {
    font-size: 0.8rem;
    color: #718096;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.05);
    display: inline-block;
    margin-top: 0.5rem;
}

.dark .token-indicator {
    color: #cbd5e0;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Responsive design for the settings panel */
@media (max-width: 640px) {
    #settingsPanel {
        width: calc(100% - 2rem);
        right: 1rem;
    }
}

/* Web Search Indicator Styling */
.search-indicator {
    background-color: #f3f4f6;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    max-width: 300px;
    margin-left: auto;
    margin-right: 0;
}

html.dark .search-indicator {
    background-color: #4b5563;
}

.search-progress-bar {
    height: 4px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

html.dark .search-progress-bar {
    background-color: rgba(255, 255, 255, 0.1);
}

.search-progress-inner {
    height: 100%;
    width: 30%;
    background-color: var(--accent-blue);
    border-radius: 2px;
    animation: search-progress 1.5s infinite ease-in-out;
}

@keyframes search-progress {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(400%);
    }
}

/* Reasoning Indicator Styling */
.reasoning-feature {
    transition: all 0.3s ease;
}

/* Add subtle pulse animation to the reasoning icon */
.reasoning-feature i {
    animation: reasoning-pulse 2s infinite ease-in-out;
}

@keyframes reasoning-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Image Input Modal Styling */
.image-input-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.image-input-container {
    background-color: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

html.dark .image-input-container {
    background-color: #1f2937;
    color: #f9fafb;
    border: 1px solid #374151;
}

.image-input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.image-input-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.close-modal {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 9999px;
    transition: background-color 0.2s;
}

.close-modal:hover {
    background-color: #f3f4f6;
    color: #111827;
}

html.dark .close-modal:hover {
    background-color: #374151;
    color: #f9fafb;
}

.image-input-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 1.5rem;
}

html.dark .image-input-tabs {
    border-bottom-color: #374151;
}

.tab-button {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #6b7280;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-button.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.tab-button:hover:not(.active) {
    color: #4b5563;
    background-color: #f9fafb;
}

html.dark .tab-button {
    color: #9ca3af;
}

html.dark .tab-button.active {
    color: var(--accent-blue);
}

html.dark .tab-button:hover:not(.active) {
    color: #d1d5db;
    background-color: #374151;
}

.tab-content {
    display: none;
    padding: 1rem 0;
}

.tab-content.active {
    display: block;
}

.tab-content p {
    margin-top: 0;
    margin-bottom: 1rem;
    color: #4b5563;
}

html.dark .tab-content p {
    color: #d1d5db;
}

.image-preview {
    margin-top: 1rem;
    max-height: 300px;
    overflow: hidden;
    border-radius: 8px;
    background-color: #f3f4f6;
    display: flex;
    justify-content: center;
    align-items: center;
}

html.dark .image-preview {
    background-color: #374151;
}

.preview-image {
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
}

#image-upload {
    width: 100%;
    padding: 0.75rem;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #111827;
}

html.dark #image-upload {
    background-color: #111827;
    border-color: #4b5563;
    color: #f9fafb;
}

#image-url {
    width: 100%;
    padding: 0.75rem;
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #111827;
    margin-bottom: 0.75rem;
}

html.dark #image-url {
    background-color: #111827;
    border-color: #4b5563;
    color: #f9fafb;
}

#preview-url-btn {
    padding: 0.5rem 1rem;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #111827;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

#preview-url-btn:hover {
    background-color: #e5e7eb;
}

html.dark #preview-url-btn {
    background-color: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

html.dark #preview-url-btn:hover {
    background-color: #4b5563;
}

.image-input-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

#add-image-btn {
    padding: 0.75rem 1.5rem;
    background-color: var(--accent-blue);
    border: none;
    border-radius: 6px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

#add-image-btn:hover:not(:disabled) {
    background-color: #1e6dba;
}

#add-image-btn:disabled {
    background-color: #93c5fd;
    cursor: not-allowed;
}

html.dark #add-image-btn:disabled {
    background-color: #1f2937;
}

.error {
    color: #dc2626;
    font-size: 0.875rem;
}

/* Message with Image Styling */
.message-with-image {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message-image-container {
    max-width: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.message-image {
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
}

/* Input Image Preview */
.input-image-preview {
    position: relative;
    margin-right: 10px;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.8;
}

.remove-image-btn:hover {
    opacity: 1;
}

/* Ensure images maintain proper aspect ratio and don't cause layout shifts */
.generated-image {
    aspect-ratio: 1; /* Default 1:1 for DALL-E images */
    object-fit: contain;
    width: 100%;
    height: auto;
    max-height: 70vh; /* Limit maximum height */
}

/* Add smooth scrolling for the whole document and chat columns */
html {
    scroll-behavior: smooth;
}

/* Improve column scrolling behavior */
#userMessagesColumn,
#assistantMessagesColumn {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    overscroll-behavior: contain; /* Prevent scroll chaining */
    overflow-y: auto;
    will-change: transform; /* Performance optimization */
    transition: transform 0.2s ease;
}

/* Prevent scroll bounce in iOS Safari */
main {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Reduce animation for better performance on mobile */
@media (max-width: 768px) {
    .message {
        animation: fadeInFast 0.15s ease-out; /* Faster animation on mobile */
    }

    @keyframes fadeInFast {
        from { opacity: 0.5; transform: translateY(5px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    /* Optimize scrolling on mobile */
    #userMessagesColumn,
    #assistantMessagesColumn {
        scroll-padding: 16px; /* Adds padding at the bottom of scroll areas */
    }
}

/* Image Placeholder and Loading Spinner */
.image-placeholder {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 200px;
    max-height: 400px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--accent-blue);
    border-radius: 50%;
    animation: spinner 1s linear infinite;
}

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

.image-error {
    padding: 1rem;
    background-color: rgba(255, 0, 0, 0.1);
    color: #d32f2f;
    border-radius: 8px;
    text-align: center;
    margin: 0.5rem 0;
}

/* Web Search Citation Styling */
.web-search-citation {
    color: #2563eb;
    text-decoration: underline;
    font-weight: 500;
    transition: color 0.2s ease;
}

.web-search-citation:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.dark .web-search-citation {
    color: #3b82f6;
}

.dark .web-search-citation:hover {
    color: #60a5fa;
}

.file-citation {
    background-color: rgba(96, 165, 250, 0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 500;
}

/* Make sure link styling is preserved in messages */
.message-content a {
    color: #2563eb;
    text-decoration: underline;
}

.dark .message-content a {
    color: #3b82f6;
}