:root {
    --bg: #f5f7fa;
    --surface: #fff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --danger: #dc2626;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --transition: 150ms ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Navbar */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}
.nav-brand { font-weight: 700; color: var(--primary); text-decoration: none; font-size: 1.1rem; }
.nav-links { display: flex; gap: 1rem; align-items: center; }
.nav-links a {
    color: var(--text);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: color var(--transition), background var(--transition);
}
.nav-links a:hover { color: var(--primary); background: var(--primary-light); }
.nav-user { color: var(--text-muted); font-size: 0.9rem; }

.container { max-width: 960px; margin: 2rem auto; padding: 0 1.5rem; }

h1 { margin-bottom: 0.25rem; }
h2 { margin-bottom: 1rem; margin-top: 0.5rem; }
h3 { margin-bottom: 0.75rem; }

.page-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }

/* Forms */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    max-width: 600px;
    margin: 0 auto;
}
.form-group { margin-bottom: 1.25rem; }
.form-group > label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.form-row { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.form-row label { min-width: 80px; font-weight: 600; }

input[type="text"], input[type="password"],
select, textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input[type="text"]:focus, input[type="password"]:focus,
select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-row input, .form-row select { margin-bottom: 0; }

textarea { font-family: monospace; resize: vertical; }

button, .btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
button:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.secondary:hover { background: var(--bg); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.85rem; }

.submit-btn-large {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.checkbox-label { display: flex; align-items: center; gap: 0.5rem; margin: 0.25rem 0; font-weight: normal; }
.checkbox-label input { width: auto; margin: 0; }

.model-options {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg);
}
.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
    border-style: solid;
}
.drop-zone.has-file {
    border-color: var(--primary);
    border-style: solid;
    background: var(--primary-light);
}
.drop-zone-icon {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    line-height: 1;
}
.drop-zone-text {
    color: var(--text-muted);
    font-size: 0.95rem;
}
.drop-zone-text strong {
    color: var(--primary);
}
.drop-zone-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.35rem;
}
.drop-zone-filename {
    display: none;
    margin-top: 0.75rem;
}
.drop-zone-filename .file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text);
}

/* Tables */
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th, td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
th { font-weight: 600; background: var(--bg); }
.clickable-row { cursor: pointer; transition: background var(--transition); }
.clickable-row:hover { background: var(--primary-light); }

.rec-table { font-size: 0.9rem; }
.rec-table td { padding: 0.4rem 0.5rem; }
.rec-table tbody tr { transition: background var(--transition); }
.rec-table tbody tr:nth-child(even) { background: var(--bg); }
.rec-table tbody tr:hover { background: var(--primary-light); }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: background var(--transition);
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-fail { background: #fecaca; color: #991b1b; }

.oa-badge {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 0.25rem;
    vertical-align: middle;
}
.oa-badge-green {
    background: #dcfce7;
    color: #166534;
}
.oa-badge-gold {
    background: #fef3c7;
    color: #92400e;
}

.status-badge {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.status-note { color: var(--text-muted); font-size: 0.92rem; }

/* Login */
.login-box {
    max-width: 360px;
    margin: 4rem auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; }

/* Admin */
.admin-section { background: var(--surface); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 1.5rem; }
details > summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-top: 0.75rem; }
details > form, details > div { margin-top: 0.75rem; }

.inline { display: inline; }
.aims-scope { font-size: 0.8rem; color: var(--text-muted); max-width: 300px; }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; max-width: 500px; width: 90%; box-shadow: var(--shadow-md); }
dialog::backdrop { background: rgba(0,0,0,0.3); }
.dialog-buttons { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Run cards */
.run-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition);
}
.run-card:hover { box-shadow: var(--shadow-md); }
.run-card h3 { margin-bottom: 0.5rem; }
.run-score { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.run-meta { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; margin-bottom: 0.75rem; }

/* Rating summary (journal match) */
.final-results { margin-top: 1rem; }
.progress-card {
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.08), rgba(255, 255, 255, 0.95));
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin: 1rem 0;
}
.progress-card-failed {
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.08), rgba(255, 255, 255, 0.96));
    border-color: rgba(220, 38, 38, 0.2);
}
.progress-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}
.progress-eyebrow {
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
}
.progress-copy { color: var(--text-muted); max-width: 42rem; }
.progress-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.progress-metric {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}
.progress-metric span {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 0.2rem;
}
.progress-metric strong {
    font-size: 1.1rem;
    line-height: 1.2;
}
.progress-steps {
    display: grid;
    gap: 0.75rem;
}
.progress-step {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}
.progress-step-marker {
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    border: 2px solid var(--border);
    flex: 0 0 auto;
    margin-top: 0.2rem;
}
.progress-step-title { font-weight: 600; margin-bottom: 0.1rem; }
.progress-step-meta { color: var(--text-muted); font-size: 0.86rem; }
.progress-step-done .progress-step-marker {
    background: var(--primary);
    border-color: var(--primary);
}
.progress-step-active .progress-step-marker {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}
.progress-step-todo {
    opacity: 0.78;
}
.rating-summary { margin: 1rem 0; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); }
.rating-summary.rating-ok { background: var(--surface); border-color: var(--primary); }
.rating-summary.rating-pending { background: var(--surface); }
.rating-summary.rating-failed { background: rgba(220, 53, 69, 0.08); border-color: var(--danger, #dc3545); }
.recommendation-banner { margin-top: 0.5rem; font-weight: 500; }
.batch-threshold { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.5rem; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    padding: 0.5rem 0;
}

/* Results section fade in */
.results-enter {
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.error { color: var(--danger); }
.warning { color: #92400e; }

small { color: var(--text-muted); }

/* File input (hidden when using drop zone) */
input[type="file"].hidden-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 640px) {
    .container { padding: 0 1rem; margin: 1rem auto; }
    .navbar { flex-direction: column; gap: 0.5rem; padding: 1rem; }
    .form-card, .admin-section, .login-box { padding: 1.25rem; }
    table { display: block; overflow-x: auto; }
    .dialog-buttons { flex-direction: column; }
    .form-row { flex-direction: column; align-items: stretch; }
    .form-row label { min-width: auto; }
    .progress-card-header { flex-direction: column; }
}
