* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    grid-template-areas: 
        "header header"
        "main sidebar";
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 50px rgba(0,0,0,0.1);
}

.header {
    grid-area: header;
    background: white;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e1e5e9;
    text-align: center;
}

.header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.header p {
    color: #7f8c8d;
    margin-bottom: 1rem;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.status-indicator {
    font-size: 0.8rem;
    color: #e74c3c;
}

.status-indicator.connected {
    color: #27ae60;
}

.main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    animation: fadeIn 0.3s ease-in;
}

.message.user-message {
    align-self: flex-end;
}

.message.bot-message {
    align-self: flex-start;
}

.message-content {
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    line-height: 1.5;
}

.user-message .message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 0.3rem;
}

.bot-message .message-content {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 0.3rem;
}

.message-images {
    margin: 1rem 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.message-image-item {
    border: 1px solid #e1e5e9;
    border-radius: 0.5rem;
    overflow: hidden;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-image-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.message-main-image,
.message-content-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    cursor: pointer;
}

.message-content-image {
    height: 150px;
}

.image-caption {
    padding: 0.75rem;
    font-size: 0.85rem;
    color: #2c3e50;
    background: #f8f9fa;
    border-top: 1px solid #e1e5e9;
}

.image-caption strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #2c3e50;
}

.image-source-type {
    color: #6c757d;
    font-size: 0.8rem;
    font-weight: normal;
    text-transform: capitalize;
}

.content-image .image-caption {
    background: #f1f3f4;
}

.image-dedup-info {
    font-size: 0.75rem;
    color: #6c757d;
    font-style: italic;
    margin-top: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: #f8f9fa;
    border-radius: 0.25rem;
    border-left: 3px solid #dee2e6;
}

/* Dynamic image layouts based on count */
.message-images:has(.message-image-item:only-child) {
    grid-template-columns: 1fr;
    max-width: 400px;
}

.message-images:has(.message-image-item:nth-child(2):last-child) {
    grid-template-columns: 1fr 1fr;
}

.message-images:has(.message-image-item:nth-child(3):last-child) {
    grid-template-columns: repeat(3, 1fr);
}

.message-images:has(.message-image-item:nth-child(4):last-child) {
    grid-template-columns: repeat(2, 1fr);
}

/* Limit maximum images shown */
.message-images .message-image-item:nth-child(n+5) {
    display: none;
}

/* Mobile responsive images */
@media (max-width: 768px) {
    .message-images {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .message-main-image,
    .message-content-image {
        height: 180px;
    }

    .message-content-image {
        height: 140px;
    }

    .image-caption {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
}

.message-sources {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #6c757d;
}

.source-link {
    color: #667eea;
    text-decoration: none;
    margin-right: 1rem;
}

.source-link:hover {
    text-decoration: underline;
}

.input-container {
    padding: 1rem 2rem 2rem;
    background: white;
    border-top: 1px solid #e1e5e9;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#messageInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e1e5e9;
    border-radius: 0.5rem;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: #667eea;
}

#languageSelect {
    padding: 0.75rem;
    border: 2px solid #e1e5e9;
    border-radius: 0.5rem;
    background: white;
    font-size: 1rem;
    outline: none;
}

#newConversationButton {
    padding: 0.5rem 0.75rem;
    background: #f39c12;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 0.5rem;
}

#newConversationButton:hover:not(:disabled) {
    background: #e67e22;
}

#newConversationButton:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

#sendButton {
    padding: 0.75rem 1.5rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    min-width: 80px;
}

#sendButton:hover:not(:disabled) {
    background: #5a6fd8;
}

#sendButton:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.spinner {
    animation: spin 1s linear infinite;
}

.sidebar {
    grid-area: sidebar;
    background: #f8f9fa;
    border-left: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6c757d;
    display: none;
}

.sources-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.source-item {
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.source-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Content type specific styling */
.source-artist {
    border-left: 4px solid #e74c3c;
}

.source-artwork {
    border-left: 4px solid #9b59b6;
}

.source-book {
    border-left: 4px solid #3498db;
}

.source-journal {
    border-left: 4px solid #f39c12;
}

.source-page {
    border-left: 4px solid #95a5a6;
}

.source-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.source-icon {
    font-size: 1.1rem;
}

.source-meta {
    color: #6c757d;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.source-type {
    background: #ecf0f1;
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-weight: 500;
    text-transform: capitalize;
}

.source-url {
    color: #667eea;
    text-decoration: none;
    font-size: 0.8rem;
    word-break: break-all;
}

.source-url:hover {
    text-decoration: underline;
}

.no-sources {
    color: #6c757d;
    text-align: center;
    font-style: italic;
}

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

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

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "header"
            "main";
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        right: -100%;
        width: 100%;
        height: 100vh;
        z-index: 1000;
        transition: right 0.3s ease;
    }
    
    .sidebar.open {
        right: 0;
    }
    
    .close-btn {
        display: block;
    }
    
    .message {
        max-width: 95%;
    }
    
    .input-group {
        flex-wrap: wrap;
    }
    
    #languageSelect {
        order: 3;
        flex: 1;
        min-width: 120px;
    }
}
