:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8ba3c0;
  --accent: #3d9eff;
  --accent-dim: #2563a8;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --font: "SF Pro Text", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  background: linear-gradient(135deg, #1a2a44 0%, #0f1419 60%);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.auth-user {
  font-size: 0.8rem;
  color: var(--muted);
}

body.auth-pending > .header,
body.auth-pending > .main {
  visibility: hidden;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.auth-user {
  font-size: 0.8rem;
  color: var(--muted);
}

body.auth-pending > .header,
body.auth-pending > .main {
  visibility: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 8px rgba(61, 158, 255, 0.5));
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-badge {
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.status-badge.ok {
  border-color: var(--success);
  color: var(--success);
}

.status-badge.warn {
  border-color: var(--warn);
  color: var(--warn);
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}

.tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.pdf-status-line {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
}

.pdf-status-line.ok {
  color: var(--success);
  border-left: 3px solid var(--success);
}

.pdf-status-line.warn {
  color: var(--warn);
  border-left: 3px solid var(--warn);
}

.pdf-checkbox {
  justify-content: flex-end;
  padding-top: 1.4rem;
}

.pdf-queue-panel {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pdf-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.pdf-queue-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.pdf-queue-summary {
  font-size: 0.8rem;
  color: var(--muted);
}

.pdf-queue-current {
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  background: rgba(61, 158, 255, 0.1);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.85rem;
}

.pdf-queue-current-label {
  color: var(--accent);
  font-weight: 500;
  margin-right: 0.35rem;
}

.pdf-queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.pdf-queue-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.pdf-queue-item:last-child {
  border-bottom: none;
}

.pdf-queue-pos {
  flex-shrink: 0;
  width: 1.5rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pdf-queue-item-body {
  flex: 1;
  min-width: 0;
}

.pdf-queue-item-title {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-queue-item-doi {
  color: var(--muted);
  font-size: 0.75rem;
}

.pdf-queue-empty {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.25rem 0;
}

.pdf-knowledge-panel {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pdf-knowledge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.pdf-knowledge-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.pdf-knowledge-search input {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.pdf-rag-enable {
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}

.pdf-rag-hits {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}

.pdf-rag-hit {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.pdf-rag-hit:last-child {
  border-bottom: none;
}

.pdf-rag-hit-title {
  color: var(--accent);
  font-weight: 500;
}

.pdf-rag-hit-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.badge-extract_ok {
  background: rgba(52, 211, 153, 0.2);
  color: var(--success);
}

.badge-failed {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.badge-text_ok {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
}

.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.label-full {
  grid-column: 1 / -1;
}

.preset-desc {
  margin: 0 0 1rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  line-height: 1.45;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input,
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  cursor: pointer;
}

.journal-panel {
  margin-bottom: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.journal-panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.journal-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.journal-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn-xs {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
}

.journal-chips {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.journal-chip-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}

.journal-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.journal-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.78rem;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}

.journal-chip:hover {
  border-color: var(--accent);
}

.journal-chip.selected {
  border-color: var(--accent);
  background: rgba(61, 158, 255, 0.15);
  color: var(--text);
}

.journal-chip input {
  accent-color: var(--accent);
}

.journal-chip .chip-meta {
  color: var(--muted);
  font-size: 0.68rem;
}

.journal-hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

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

.btn-primary {
  background: var(--accent);
  color: #0a0f14;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

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

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.input-sm {
  width: 200px;
}

.meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

tr:hover td {
  background: rgba(61, 158, 255, 0.06);
}

.title-cell {
  max-width: 360px;
}

.title-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.title-link:hover {
  text-decoration: underline;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
}

.badge-pending {
  background: #374151;
  color: #d1d5db;
}

.badge-synced {
  background: #1e3a5f;
  color: #93c5fd;
}

.badge-pdf {
  background: #064e3b;
  color: var(--success);
}

.badge-manual {
  background: #451a03;
  color: var(--warn);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.library-filters {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.loading,
.error {
  padding: 1rem;
  text-align: center;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.loading {
  background: var(--surface);
  color: var(--muted);
}

.error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 960px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-inner {
  margin: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
  padding-right: 1rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 0.9rem;
}

.annotation-card {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.annotation-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.annotation-header h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.annotation-header p,
.annotation-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.annotation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.annotation-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.annotation-grid input,
.annotation-grid select,
.annotation-grid textarea {
  width: 100%;
}

.annotation-full {
  grid-column: 1 / -1;
}

.annotation-meta {
  margin-top: 0.75rem;
}

.modal-body dl {
  margin: 0;
}

.modal-body dt {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.75rem;
}

.modal-body dd {
  margin: 0.2rem 0 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 100;
  max-width: 360px;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at top, rgba(61, 158, 255, 0.18), transparent 55%),
    var(--bg);
}

.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

.login-brand {
  text-align: center;
  margin-bottom: 0.35rem;
}

.login-brand h1 {
  margin: 0.35rem 0 0.2rem;
  font-size: 1.2rem;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.login-submit {
  width: 100%;
  margin-top: 0.25rem;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

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

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

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .input-sm {
    width: 100%;
  }
}
