/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-color: #f9fafb;
    --surface-color: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    background: var(--surface-color);
    border-radius: 0.75rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background-color: #f0f7ff;
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background-color: #eff6ff;
    transform: scale(1.02);
}

.upload-icon {
    width: 4rem;
    height: 4rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.upload-text {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Upload Progress */
.upload-progress {
    margin-top: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 0.5rem;
    background-color: var(--border-color);
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
    border-radius: 9999px;
}

.progress-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Upload Status */
.upload-status {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.upload-status.success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.upload-status.error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.status-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    opacity: 0.6;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.status-close:hover {
    opacity: 1;
}

/* Documents List */
.documents-list {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.documents-list h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.document-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-color);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
}

.document-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--primary-color);
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.document-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.document-name {
    font-weight: 500;
    color: var(--text-primary);
}

.document-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.document-status {
    font-size: 0.85rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-weight: 500;
    margin-right: 0.5rem;
}

.status-ready {
    background-color: #d1fae5;
    color: #065f46;
}

.status-processing {
    background-color: #fef3c7;
    color: #92400e;
}

.status-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.delete-button {
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-button:hover {
    background-color: #fee2e2;
    color: var(--error-color);
}

.delete-button svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Chat Section */
.chat-section {
    background: var(--surface-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    background-color: var(--bg-color);
}

.new-conversation-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.new-conversation-button:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.new-conversation-button svg {
    width: 1.25rem;
    height: 1.25rem;
}

.chat-container {
    height: 500px;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.welcome-message {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* Message Styles */
.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-content {
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 1rem;
}

.message-user .message-content {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message-assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-assistant .message-content {
    background-color: var(--bg-color);
    border-bottom-left-radius: 0.25rem;
    max-width: 100%;
}

.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Sources Section */
.sources {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.sources-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.source-item {
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.source-header:hover {
    background-color: var(--bg-color);
}

.source-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.source-chevron {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.source-header.expanded .source-chevron {
    transform: rotate(180deg);
}

.source-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.source-content.expanded {
    max-height: 500px;
}

.source-text {
    padding: 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

.source-scores {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

.score-item {
    display: flex;
    flex-direction: column;
}

.score-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.score-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Loading Indicator */
.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Larger spinner for document loading */
.spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-right-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Input Container */
.input-container {
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: white;
}

.query-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    transition: border-color 0.2s;
}

.query-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.query-input:disabled {
    background-color: var(--bg-color);
    cursor: not-allowed;
}

.send-button {
    padding: 0.75rem 1.25rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.send-button:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
}

.send-button svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem 0.5rem;
    }

    .header h1 {
        font-size: 2rem;
    }

    .upload-section,
    .chat-section {
        padding: 1rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .message-content {
        max-width: 85%;
    }

    .chat-container {
        height: 400px;
    }
}
