* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--primary);
}

.status-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 20px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    padding: 4px 0;
}

.status-label {
    color: var(--text-secondary);
}

.status-value {
    font-weight: 500;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 20px;
}

.nav-btn {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.nav-btn:hover {
    background: var(--bg-tertiary);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
}

.new-chat-btn {
    margin-top: auto;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
    color: var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-content {
    display: none;
    height: 100%;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Chat Tab */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
}

.message-sources-title {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    color: var(--text-secondary);
}

.source-score {
    font-size: 0.75rem;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--secondary);
    border-radius: 50%;
    animation: typing 1s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { opacity: 0.3; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-4px); }
}

/* Chat input */
.chat-input-container {
    padding: 16px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input-container textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}

.chat-input-container textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--secondary);
    cursor: not-allowed;
    transform: none;
}

/* Documents Tab */
.documents-container {
    padding: 24px;
    overflow-y: auto;
    height: 100%;
}

.documents-container h2 {
    margin-bottom: 20px;
}

.upload-section {
    margin-bottom: 30px;
}

.category-select {
    margin-bottom: 16px;
}

.category-select label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

.category-select select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    min-width: 200px;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.drop-zone-content svg {
    color: var(--secondary);
    margin-bottom: 12px;
}

.drop-zone-content p {
    color: var(--text-secondary);
}

.drop-zone-content .hint {
    font-size: 0.85rem;
    margin-top: 6px;
}

/* Documents list */
.documents-list-section {
    margin-top: 30px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h3 {
    font-size: 1rem;
}

.documents-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.document-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    color: var(--primary);
}

.document-info {
    flex: 1;
}

.document-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.document-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
}

.document-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.document-status.indexed {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.document-status.processing {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.document-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.document-actions {
    display: flex;
    gap: 8px;
}

/* Settings Tab */
.settings-container {
    padding: 24px;
    max-width: 600px;
}

.settings-container h2 {
    margin-bottom: 24px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-weight: 500;
}

.form-group select,
.form-group input[type="number"] {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}

.form-group input[type="range"] {
    width: 100%;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 12px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }

    .sidebar-header {
        width: 100%;
    }

    .sidebar-header h2 {
        margin-bottom: 0;
    }

    .status-card {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        flex: 1;
        margin-bottom: 0;
    }

    .new-chat-btn {
        margin-top: 0;
    }

    .message {
        max-width: 90%;
    }

    .documents-container,
    .settings-container {
        padding: 16px;
    }
}
