:root {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #1a1a1a;
    --border-light: #e5e5e5;
    --accent-primary: #1a1a1a;
    --accent-secondary: #f5f5f5;
    --shadow: 4px 4px 0px #1a1a1a;
    --shadow-sm: 2px 2px 0px #1a1a1a;
    --radius: 8px;
    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
}

body {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    padding: 1.5rem 0;
    border-bottom: 2px solid var(--border-color);
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-decoration: none;
    color: var(--text-primary);
}

/* Navigation */
.nav {
    display: flex;
    gap: 0.25rem;
    background: var(--bg-primary);
    padding: 0.25rem;
    border-radius: var(--radius);
    border: 2px solid var(--border-color);
}

.nav-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: 6px;
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.nav-link.active {
    background: var(--accent-primary);
    color: white;
}

/* Main Content */
.main {
    padding: 2rem 0 4rem;
    flex: 1;
}

/* Card */
.card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    resize: vertical;
    transition: var(--transition);
    background: var(--bg-secondary);
}

.form-textarea:focus {
    outline: none;
    box-shadow: var(--shadow-sm);
}

.form-textarea::placeholder {
    color: var(--text-muted);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--accent-secondary);
}

.upload-area:hover {
    background: var(--bg-secondary);
    border-style: solid;
}

.upload-area.dragover {
    background: var(--bg-secondary);
    border-style: solid;
    box-shadow: var(--shadow-sm);
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
}

.upload-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.upload-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.upload-input {
    display: none;
}

/* File Display */
.file-display {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--accent-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    gap: 1rem;
}

.file-display.visible {
    display: flex;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.file-icon {
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon svg {
    width: 18px;
    height: 18px;
}

.file-name {
    font-weight: 500;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.6;
    transition: var(--transition);
}

.file-remove:hover {
    opacity: 1;
}

.file-remove svg {
    width: 20px;
    height: 20px;
}

/* Progress Bar */
.progress-container {
    display: none;
    margin-top: 0.75rem;
}

.progress-container.visible {
    display: block;
}

.progress-bar {
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary);
    width: 0%;
    transition: width 0.3s ease;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0px var(--border-color);
}

.btn-primary:active {
    transform: translate(0, 0);
    box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Upload Grid (for Compare) */
.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 640px) {
    .upload-grid {
        grid-template-columns: 1fr;
    }
}

.upload-box {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    background: var(--accent-secondary);
    transition: var(--transition);
}

.upload-box.has-file {
    border-style: solid;
    background: var(--bg-secondary);
}

.upload-box-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.upload-box-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Results */
.results-card {
    display: none;
}

.results-card.visible {
    display: block;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-light);
}

.results-title {
    font-size: 1.125rem;
    font-weight: 700;
}

.score-badge {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent-primary);
}

.results-content {
    font-size: 0.9375rem;
    line-height: 1.75;
}

.results-content h1,
.results-content h2,
.results-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.results-content h1:first-child,
.results-content h2:first-child,
.results-content h3:first-child {
    margin-top: 0;
}

.results-content p {
    margin-bottom: 0.75rem;
}

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

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

.results-content strong {
    font-weight: 600;
}

/* Chat */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--accent-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.chat-message {
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    max-width: 85%;
}

.chat-message.user {
    background: var(--accent-primary);
    color: white;
    margin-left: auto;
    border: 2px solid var(--border-color);
}

.chat-message.assistant {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.chat-message-content {
    font-size: 0.9375rem;
    line-height: 1.6;
}

.chat-input-container {
    display: flex;
    gap: 0.75rem;
}

.chat-input {
    flex: 1;
    padding: 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    transition: var(--transition);
}

.chat-input:focus {
    outline: none;
    box-shadow: var(--shadow-sm);
}

/* File List (for Rank) */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.file-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 6px;
}

.file-list-name {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Loading */
.loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
}

.loading.visible {
    display: flex;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-weight: 500;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    background: var(--accent-secondary);
    border: 2px solid var(--border-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state-icon svg {
    width: 28px;
    height: 28px;
    stroke: var(--text-muted);
}

/* Alert */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    display: none;
}

.alert.visible {
    display: block;
}

.alert-error {
    background: #fef2f2;
    border: 2px solid #dc2626;
    color: #dc2626;
}

.alert-success {
    background: #f0fdf4;
    border: 2px solid #16a34a;
    color: #16a34a;
}

/* Responsive */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

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

    .logo {
        text-align: center;
    }

    .nav {
        justify-content: center;
        flex-wrap: wrap;
    }

    .nav-link {
        flex: 1;
        text-align: center;
        min-width: auto;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .card {
        padding: 1.25rem;
    }

    .upload-area {
        padding: 1.5rem;
    }

    .chat-container {
        height: calc(100vh - 250px);
        min-height: 400px;
    }

    .chat-message {
        max-width: 95%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.75rem;
    }

    .main {
        padding: 1.5rem 0 3rem;
    }

    .card {
        padding: 1rem;
        box-shadow: var(--shadow-sm);
    }

    .btn {
        width: 100%;
    }

    .chat-input-container {
        flex-direction: column;
    }

    .chat-input-container .btn {
        width: 100%;
    }
}

/* Chat Setup Card */
.chat-setup {
    margin-bottom: 1.5rem;
}

.chat-setup.collapsed .chat-setup-content {
    display: none;
}

.chat-setup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.5rem 0;
}

.chat-setup-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
}

.chat-setup-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
}

.chat-setup.collapsed .chat-setup-toggle svg {
    transform: rotate(-90deg);
}

/* Markdown rendering in results */
.results-content code {
    background: var(--accent-secondary);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.875em;
}

.results-content pre {
    background: var(--accent-secondary);
    border: 2px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.results-content pre code {
    background: none;
    padding: 0;
}

.results-content blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
}

/* Visually hidden */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Footer */
.footer {
    padding: 2rem 0;
    border-top: 2px solid var(--border-color);
    background: var(--bg-secondary);
    margin-top: auto;
}

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

.footer-text a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.footer-text a:hover {
    text-decoration: underline;
}
