:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e1e4e8;
  --text: #1a1d21;
  --text-muted: #5b6470;
  --text-dim: #8a939f;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #dc2626;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);

  --c-0: #f87171;
  --c-1: #fbbf24;
  --c-2: #34d399;
  --c-3: #60a5fa;
  --c-4: #a78bfa;
  --c-5: #f472b6;
  --c-6: #22d3ee;
  --c-7: #94a3b8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ─── Top bar ───────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

.progress {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}

#progress-text {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  min-width: 140px;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reviewer-input {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.reviewer-input input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  width: 160px;
}

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

.topbar button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.topbar button:hover:not(:disabled) {
  background: #f8f9fa;
  border-color: #d0d7de;
}

.topbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover) !important;
  border-color: var(--primary-hover) !important;
}

.btn-export {
  background: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
}

.btn-export:hover {
  filter: brightness(0.95);
}

/* ─── Main layout ──────────────────────────────────────────────────────── */

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.article-meta {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.pmid-badge {
  background: var(--primary);
  color: white !important;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 12px;
  font-family: "SF Mono", Consolas, monospace;
}

.pmid-badge:hover {
  filter: brightness(0.9);
}

.meta-item {
  color: var(--text-muted);
  text-decoration: none;
}

.meta-item:hover {
  color: var(--primary);
}

#title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

/* ─── Content columns ───────────────────────────────────────────────────── */

.article-content {
  display: grid;
  grid-template-columns: 1fr 520px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 1200px) {
  .article-content { grid-template-columns: 1fr; }
  .col-right { position: static !important; }
}

.col-right {
  position: sticky;
  top: 70px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.muted { color: var(--text-muted); font-weight: normal; text-transform: none; letter-spacing: 0; }
.muted.small { font-size: 12px; }

.abstract-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  max-height: 340px;
  overflow-y: auto;
  padding-right: 8px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tags .tag {
  background: #eef2f7;
  color: var(--text);
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 12px;
  font-family: "SF Mono", Consolas, monospace;
}

.tags .tag.major {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
}

.pubtype-tags .tag {
  background: #e0e7ff;
  color: #3730a3;
}

/* ─── Auto-classifier suggestion ───────────────────────────────────────── */

.auto-panel {
  background: #fef9c3;
  border-color: #fde047;
}

.auto-panel h3 {
  color: #713f12;
}

.auto-suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 14px;
}

.auto-cluster-pill, .auto-subtopic-pill {
  padding: 6px 14px;
  border-radius: 6px;
  background: white;
  border: 1px solid #d4d4d8;
  font-weight: 500;
}

.arrow { color: var(--text-dim); }

/* ─── Labeling panel ───────────────────────────────────────────────────── */

.labeling-panel {
  border: 2px solid var(--primary);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.field {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.required {
  color: var(--danger);
  font-weight: bold;
}

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.cluster-button {
  text-align: left;
  border: 2px solid var(--border);
  background: var(--surface);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.1s ease;
  user-select: none;
}

.cluster-button:hover { border-color: #9ca3af; }

.cluster-button .kb-hint {
  font-size: 10px;
  color: var(--text-dim);
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: auto;
}

.cluster-button .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cluster-button.selected {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
}

.cluster-grid.secondary .cluster-button.selected {
  background: #dcfce7;
  border-color: var(--success);
  color: #047857;
}

select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}

select:focus { outline: none; border-color: var(--primary); }
select:disabled { background: #f8f9fa; color: var(--text-dim); cursor: not-allowed; }

.nature-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.nature-button {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.1s ease;
}

.nature-button:hover { border-color: #9ca3af; background: #f8f9fa; }

.nature-button.selected {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 500;
}

.nature-button code {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 6px;
}

.nature-button.selected code { color: var(--primary); }

.confidence-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.confidence-row input[type="range"] { flex: 1; }

#confidence-label {
  min-width: 70px;
  font-weight: 500;
  color: var(--primary);
}

#confidence-label.low {
  color: var(--danger);
  font-weight: 600;
}

.confidence-row.low input[type="range"] {
  accent-color: var(--danger);
}

/* ─── "Does not fit" escape hatch ────────────────────────────────────────── */

.fit-check {
  background: #fff8ec;
  border: 1px dashed #f59e0b;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.fit-check.active {
  background: #fef3c7;
  border-color: #d97706;
  border-style: solid;
}

.fit-check-label {
  display: flex !important;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 0 !important;
  cursor: pointer;
  font-weight: 600;
}

.fit-check-label input[type="checkbox"] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: #d97706;
  flex-shrink: 0;
  cursor: pointer;
}

.fit-check-label span u {
  text-decoration-color: #d97706;
  text-decoration-thickness: 2px;
}

#suggested-alternative:focus {
  outline: none;
  border-color: #d97706;
}

textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  color: var(--text);
}

textarea:focus { outline: none; border-color: var(--primary); }

.keybind-hint {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.8;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  font-family: "SF Mono", Consolas, monospace;
  background: #f3f4f6;
  border: 1px solid #d0d7de;
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--text);
}

/* ─── Completion banner ─────────────────────────────────────────────────── */

#completion-banner {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.completion-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  max-width: 500px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.completion-box h2 {
  margin: 0 0 16px 0;
  color: var(--success);
}

.completion-box p { margin: 8px 0; color: var(--text); }

/* ─── Scrollbar polish ──────────────────────────────────────────────────── */

.abstract-text::-webkit-scrollbar { width: 6px; }
.abstract-text::-webkit-scrollbar-track { background: transparent; }
.abstract-text::-webkit-scrollbar-thumb { background: #d0d7de; border-radius: 3px; }
.abstract-text::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
