/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background-color: #f9fafb;
    --surface-color: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --sidebar-width: 280px;
    --header-height: 60px;
}

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

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

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

.page {
    min-height: 100vh;
}

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

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

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

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

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

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* Login Page */
#login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
}

.login-box h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-box .subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#login-form .btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

.error-message {
    color: var(--error-color);
    font-size: 14px;
    margin-top: 16px;
    min-height: 20px;
}

/* Dashboard Layout */
#dashboard-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    height: var(--header-height);
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.org-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.org-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.org-item:hover {
    background-color: var(--background-color);
}

.org-item.active {
    background-color: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

.org-item .org-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.org-item .org-stats {
    font-size: 12px;
    color: var(--text-secondary);
}

.org-item.active .org-stats {
    color: var(--primary-color);
    opacity: 0.7;
}

/* Content Area */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.content-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content-title h2 {
    font-size: 18px;
    font-weight: 600;
}

.chunk-count {
    background: var(--background-color);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.content-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-box input {
    width: 250px;
    padding: 10px 16px 10px 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
}

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

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.sort-select {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.sort-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Chunks Container */
.chunks-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.placeholder svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.placeholder p {
    font-size: 16px;
}

/* Chunk Cards */
.chunks-grid {
    display: grid;
    gap: 16px;
}

.chunk-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chunk-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

.chunk-id {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
    padding: 4px 10px;
    border-radius: 4px;
}

.chunk-doc-id {
    font-size: 12px;
    color: var(--text-secondary);
}

.chunk-text {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    max-height: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
}

.chunk-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.chunk-source {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--surface-color);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    line-height: 1;
}

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

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.detail-value {
    font-size: 14px;
    color: var(--text-primary);
    background: var(--background-color);
    padding: 12px 16px;
    border-radius: 8px;
    word-break: break-word;
}

.detail-value.text-content {
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.detail-value code {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

.loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

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

/* No Results */
.no-results {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .content-header {
        flex-direction: column;
        align-items: stretch;
    }

    .content-controls {
        flex-direction: column;
    }

    .search-box input {
        width: 100%;
    }

    .sort-select {
        width: 100%;
    }
}

/* Highlight for search matches */
.highlight {
    background-color: #fef08a;
    padding: 1px 2px;
    border-radius: 2px;
}

/* Load More Section */
.load-more-section {
    display: flex;
    justify-content: center;
    padding: 24px 0;
    margin-top: 16px;
}

.load-more-btn {
    min-width: 200px;
    padding: 12px 24px;
}

.load-more-btn:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.load-more-indicator {
    display: flex;
    justify-content: center;
    padding: 24px 0;
}

/* Pagination Info */
.pagination-info {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 8px 0;
}
