* {
    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%);
    height: 100vh;
    overflow: hidden;
}

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

/* Header */
.chat-header {
    grid-column: 1 / -1;
    background: white;
    border-bottom: 1px solid #e1e5e9;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chat-header h1 {
    color: #2d3748;
    font-size: 1.5rem;
    font-weight: 600;
}

.workspace-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.workspace-selector label {
    font-weight: 500;
    color: #4a5568;
    font-size: 0.9rem;
}

.workspace-selector select {
    padding: 0.5rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    color: #2d3748;
    cursor: pointer;
    transition: all 0.2s ease;
}

.workspace-selector select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #f8fafc;
    min-height: 0; /* allow inner scroll areas to work in flex/grid */
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    min-height: 0; /* critical for overflow scroll within flex/grid */
}

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

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

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

.message.system {
    align-self: center;
    max-width: 60%;
}

.message-content {
    padding: 1rem 1.5rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant .message-content {
    background: white;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.message.system .message-content {
    background: #edf2f7;
    color: #4a5568;
    text-align: center;
    font-style: italic;
    border-radius: 12px;
}

.message-time {
    font-size: 0.75rem;
    color: #a0aec0;
    margin-top: 0.25rem;
    align-self: flex-end;
}

.message.user .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Input Container */
.chat-input-container {
    padding: 1.5rem;
    background: white;
    border-top: 1px solid #e1e5e9;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    padding: 0.5rem;
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.95rem;
    line-height: 1.4;
    max-height: 120px;
    padding: 0.5rem 0;
    font-family: inherit;
}

#messageInput:disabled {
    background: transparent;
    color: #a0aec0;
    cursor: not-allowed;
}

#sendButton {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#sendButton:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#sendButton:disabled {
    background: #e2e8f0;
    color: #a0aec0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Sidebar */
.chat-sidebar {
    background: white;
    border-left: 1px solid #e1e5e9;
    padding: 1.5rem;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section h3 {
    color: #2d3748;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.info-item strong {
    color: #4a5568;
}

.info-item span {
    color: #2d3748;
    font-weight: 500;
}

.sources-list {
    max-height: 200px;
    overflow-y: auto;
}

.sources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.sources-count {
    font-size: 0.85rem;
    color: #4a5568;
    font-weight: 500;
}

.view-sources-btn {
    padding: 0.25rem 0.75rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-sources-btn:hover:not(:disabled) {
    background: #5a67d8;
    transform: translateY(-1px);
}

.view-sources-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.source-item {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.source-item:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.source-item .source-title {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.25rem;
    word-break: break-all;
}

.source-item .source-score {
    color: #667eea;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.source-item .source-preview {
    color: #4a5568;
    font-size: 0.8rem;
    line-height: 1.4;
    max-height: 3.2em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.no-sources {
    color: #a0aec0;
    font-style: italic;
    text-align: center;
    font-size: 0.9rem;
}

.clear-button {
    width: 100%;
    padding: 0.75rem;
    background: #fed7d7;
    color: #c53030;
    border: 1px solid #feb2b2;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-button:hover {
    background: #feb2b2;
    border-color: #fc8181;
}

/* Loading Animation */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 1rem 1.5rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    max-width: 80px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #a0aec0;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .chat-sidebar {
        grid-row: 3;
        border-left: none;
        border-top: 1px solid #e1e5e9;
        max-height: 200px;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .workspace-selector {
        justify-content: center;
    }
    
    .message {
        max-width: 90%;
    }
}

/* Document Viewer Modal Styles */
.document-modal {
    max-width: 800px;
    max-height: 90vh;
}

.document-info {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.info-row strong {
    color: #4a5568;
    min-width: 80px;
}

.info-row span {
    color: #2d3748;
    font-weight: 500;
    text-align: right;
}

.document-content h4 {
    color: #2d3748;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.document-text {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #2d3748;
    white-space: pre-wrap;
    word-wrap: break-word;
} 