:root {
    --bg-color: #0f172a;
    --surface-color: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --accent-color: #8b5cf6;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --font-family: 'Inter', sans-serif;
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Dynamic Background Mesh */
.background-mesh {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    background-image:
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

h1 span {
    background: linear-gradient(to right, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.text-highlight {
    color: var(--accent-color);
    font-weight: 700;
}

hr {
    border: none;
    border-top: 1px solid var(--surface-border);
    margin: 1.5rem 0;
}

/* Layout */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
    flex: 1;
    width: 100%;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid transparent;
    position: sticky;
    top: 0;
    z-index: 10;
    background: transparent;
    transition: all 0.3s ease;
}

.main-header.scrolled {
    padding: 0.75rem 2rem;
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--surface-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.main-header h1 {
    margin-bottom: 0;
    transition: font-size 0.3s ease;
}

.main-header.scrolled h1 {
    font-size: 1.25rem;
}

/* Glassmorphism */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card {
    padding: 2rem;
    margin-bottom: 2rem;
    animation: slideUp 0.5s ease backwards;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

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

input, textarea, select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-family);
    transition: var(--transition);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

select option {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

small {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-family);
    font-size: 0.95rem;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

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

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-secondary.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--primary-color);
    color: #93c5fd;
}

.btn-success {
    background: var(--success-color);
    color: white;
}
.btn-success:hover { background: #059669; box-shadow: 0 0 15px rgba(16, 185, 129, 0.4); }

.btn-danger {
    background: var(--danger-color);
    color: white;
}
.btn-danger:hover { background: #dc2626; box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }

.btn-warning {
    background: var(--warning-color);
    color: #1e293b;
}
.btn-warning:hover { background: #d97706; box-shadow: 0 0 15px rgba(245, 158, 11, 0.4); }

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

.btn-icon:hover {
    color: var(--text-primary);
    border-color: var(--surface-border);
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
}

/* Progress Bar */
.progress-bar-container {
    margin-bottom: 2rem;
}

.progress-phases {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.phase-item {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: var(--transition);
}

.phase-item.active {
    color: var(--primary-color);
    background: rgba(59, 130, 246, 0.2);
}

.phase-item.done {
    color: var(--success-color);
    background: rgba(16, 185, 129, 0.2);
}

.progress-track {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary-color), var(--accent-color));
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}

/* Status Indicator */
.tracker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    margin-bottom: 2rem;
}

.status-indicator h3 {
    margin: 0;
    font-size: 1.1rem;
    word-break: break-word;
    overflow-wrap: break-word;
}

.status-indicator.waiting {
    border-left-color: var(--warning-color);
}

.status-indicator.done {
    border-left-color: var(--success-color);
}

.status-indicator.error {
    border-left-color: var(--danger-color);
}

/* Status Badge */
.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    margin-left: auto;
    white-space: nowrap;
}

.status-badge.processing {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.status-badge.waiting {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.status-badge.done {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--surface-border);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(0, 0, 0, 0.1);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.05);
}

.dropzone p {
    color: var(--text-secondary);
    margin: 0;
}

.dropzone .dropzone-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Upload Progress */
.upload-progress {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.upload-progress .progress-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Colab Info Box */
.colab-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.colab-info h4 {
    color: #93c5fd;
    margin-bottom: 0.75rem;
}

.colab-info a {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
}

.colab-info a:hover {
    text-decoration: underline;
}

/* Approval Section */
.approval-section {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--surface-border);
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
}

.approval-section h4 {
    margin-bottom: 1rem;
}

.approval-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Copyable text */
.copyable {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.copyable:hover {
    background: rgba(0, 0, 0, 0.5);
}

.copyable::after {
    content: '📋';
    font-size: 0.8rem;
}

/* PDF Upload List */
.pdf-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.pdf-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid var(--surface-border);
}

.pdf-item .cite-key {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.pdf-item .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: var(--transition);
}

.modal-content {
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    transform: scale(1);
    transition: var(--transition);
}

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

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Markdown rendered content */
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    margin-top: 1rem;
}

.markdown-content p {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.markdown-content ul, .markdown-content ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.markdown-content li {
    margin-bottom: 0.5rem;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--surface-border);
}

th {
    background-color: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--primary-color);
}

tr:last-child td {
    border-bottom: none;
}

tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

/* Loading Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

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

.toast {
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-left: 4px solid var(--primary-color);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideInRight 0.3s ease forwards;
}

.toast.error { border-left-color: var(--danger-color); }
.toast.success { border-left-color: var(--success-color); }

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

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

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

/* Modal hiding animation */
.modal-overlay.hiding {
    opacity: 0;
}
.modal-overlay.hiding .modal-content {
    transform: scale(0.95);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .main-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 15px;
    }
    .main-header h1 {
        font-size: 1.5rem;
    }
    .progress-phases {
        font-size: 0.65rem;
    }
    .approval-actions {
        flex-direction: column;
    }
}
