/* AI Chat System - Modern UI Styles */

:root {
    --primary-color: #6366f1;
    --primary-hover: #5558e3;
    --secondary-color: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --thinking-bg: #312e81;
    --user-msg-bg: #3730a3;
    --ai-msg-bg: #1e293b;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.app-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    min-height: calc(100vh - 80px);
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .sidebar.active {
        display: block;
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 1000;
    }
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo svg {
    width: 32px;
    height: 32px;
}

/* Sidebar */
.sidebar {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

/* Knowledge Base List */
.kb-list {
    list-style: none;
}

.kb-item {
    padding: 12px 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.kb-item:hover {
    background: var(--surface-light);
}

.kb-item.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

.kb-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.kb-item.active .kb-item-icon {
    background: rgba(255, 255, 255, 0.2);
}

.kb-item-info {
    flex: 1;
    overflow: hidden;
}

.kb-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kb-item-stats {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.kb-item.active .kb-item-stats {
    color: rgba(255, 255, 255, 0.7);
}

/* Main Content */
.main-content {
    background: var(--surface);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Area */
.chat-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
}

.message.user {
    flex-direction: row-reverse;
    margin-left: auto;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--primary-color);
}

.message-content {
    background: var(--ai-msg-bg);
    border-radius: 16px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
}

.message.user .message-content {
    background: var(--user-msg-bg);
    border-color: var(--user-msg-bg);
}

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

.thinking-block {
    background: var(--thinking-bg);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-left: 3px solid var(--secondary-color);
}

.thinking-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.sources-block {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.sources-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.source-item {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.source-similarity {
    color: var(--success-color);
    font-size: 0.75rem;
}

/* Chat Input */
.chat-input-area {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    min-height: 48px;
    max-height: 150px;
    font-family: inherit;
}

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

.chat-input::placeholder {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-icon {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 12px;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 15px;
    color: var(--text-secondary);
}

.upload-text {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

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

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Form */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
}

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

/* Document List */
.doc-list {
    list-style: none;
}

.doc-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface-light);
    border-radius: 10px;
    margin-bottom: 8px;
}

.doc-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.doc-info {
    flex: 1;
    overflow: hidden;
}

.doc-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.doc-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.doc-status.completed {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success-color);
}

.doc-status.processing {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.doc-status.failed {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error-color);
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
}

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

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

/* Typing Animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 3px solid var(--success-color);
}

.toast.error {
    border-left: 3px solid var(--error-color);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.tab {
    padding: 12px 20px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Upload Progress Bar */
.upload-progress {
    margin-top: 15px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}

/* Delete Button */
.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

/* Confirm Modal */
.confirm-modal {
    text-align: center;
}

.confirm-modal p {
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Document Delete Icon */
.doc-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.doc-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.doc-delete:hover {
    color: var(--error-color);
    background: rgba(239, 68, 68, 0.1);
}

/* Knowledge Base Actions */
.kb-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.kb-item:hover .kb-actions {
    opacity: 1;
}

.kb-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.kb-action-btn:hover {
    color: var(--error-color);
    background: rgba(239, 68, 68, 0.1);
}

/* File Type Icons */
.file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-icon.pdf { color: #ef4444; }
.file-icon.doc, .file-icon.docx { color: #3b82f6; }
.file-icon.txt, .file-icon.md { color: #22c55e; }
.file-icon.csv { color: #f59e0b; }
.file-icon.json { color: #8b5cf6; }
.file-icon.html { color: #ec4899; }

/* Message Actions */
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.message-action:hover {
    color: var(--text-primary);
    background: var(--surface-light);
}

/* Markdown Rendering */
.message-text pre {
    background: var(--surface-light);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 10px 0;
}

.message-text code {
    background: var(--surface-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
}

.message-text pre code {
    background: none;
    padding: 0;
}

.message-text blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 15px;
    margin: 10px 0;
    color: var(--text-secondary);
}

.message-text ul, .message-text ol {
    padding-left: 20px;
    margin: 10px 0;
}

.message-text li {
    margin: 5px 0;
}

/* Mobile Improvements */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header {
        padding: 10px 15px;
    }
    
    .chat-input-area {
        padding: 10px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .modal {
        width: 95%;
        padding: 15px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .stat-card {
        padding: 10px;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
}
