:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --card: #111827;
  --text: #f8fafc;
  --muted: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page-center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.container {
  max-width: 900px;
  margin: 1rem auto 2rem;
  padding: 0 1rem;
  display: grid;
  gap: 1rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid #334155;
}

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

.card {
  background: var(--card);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1rem;
}

.card-sm {
  width: min(420px, 100%);
}

.form {
  display: grid;
  gap: 0.5rem;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
}

input,
textarea,
select,
button {
  border-radius: 8px;
  border: 1px solid #475569;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
}

textarea {
  resize: vertical;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.link-btn {
  color: white;
  text-decoration: none;
  background: #334155;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
}

.muted {
  color: var(--muted);
}

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

.ok {
  color: var(--ok);
}

.mt {
  margin-top: 0.8rem;
}

.hidden {
  display: none;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #334155;
  padding-bottom: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
}

.tab-btn:hover {
  background: transparent;
  color: var(--text);
}

.tab-btn.active {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

/* List header with count badge */
.list-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.list-header h2 {
  margin: 0;
}

.badge {
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 1.5rem;
  text-align: center;
}

.loan-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}

.loan-list-item {
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: #0b1220;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  transition: border-color 0.15s;
}

.loan-list-item:has(.loan-link):hover {
  border-color: var(--accent);
}

.loan-link {
  color: var(--text);
  text-decoration: none;
  display: block;
}

.loan-link:hover {
  color: #93c5fd;
}

/* Detail page */
.container.wide {
  max-width: 1400px;
}

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

.accent {
  color: #93c5fd;
}

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

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

.next-btn:hover:not(.disabled) {
  background: var(--accent-hover);
}

.next-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.loan-status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.loan-status-badge.tagged {
  background: #14532d;
  color: #4ade80;
  border: 1px solid #16a34a;
}

.loan-status-badge.untagged {
  background: #422006;
  color: #fbbf24;
  border: 1px solid #d97706;
}

/* Loan metadata card */
.loan-meta {
  margin-bottom: 0.25rem;
}

.loan-meta-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.45rem 1.5rem;
  font-size: 0.9rem;
}

.meta-json {
  margin: 0;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Items grid */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.item-card {
  background: var(--card);
  border: 1px solid #334155;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  transition: border-color 0.2s;
}

.item-card:hover {
  border-color: #475569;
}

/* Color the card border based on current class */
.item-card[data-class="authentic"] { border-color: #16a34a; }
.item-card[data-class="spurious"]  { border-color: #dc2626; }

.item-index {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.75rem 0;
}

.item-img-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0b1220;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.item-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.img-loader,
.img-error {
  font-size: 0.82rem;
  padding: 0.5rem;
  text-align: center;
}

.item-meta {
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.4rem 0.75rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-select-wrap {
  padding: 0.6rem 0.75rem 0.75rem;
  display: grid;
  gap: 0.35rem;
}

.item-select-label {
  font-size: 0.8rem;
}

.item-select {
  width: 100%;
  background: #0b1220;
  color: var(--text);
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}

.item-save-btn {
  width: 100%;
  padding: 0.45rem;
  font-size: 0.9rem;
  border-radius: 6px;
}

.item-save-status {
  font-size: 0.8rem;
  min-height: 1.1em;
  text-align: center;
}

.item-save-status.saving { color: var(--muted); }
.item-save-status.ok     { color: var(--ok); }
.item-save-status.error  { color: var(--danger); }

/* Bulk footer */
.bulk-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1rem 2.5rem;
}

.bulk-unknown-btn {
  background: #1e293b;
  color: #fbbf24;
  border: 1px solid #d97706;
  border-radius: 8px;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

.bulk-unknown-btn:hover:not(:disabled) {
  background: #2d3f58;
}

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

.bulk-progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.bulk-progress.hidden {
  display: none;
}

.bulk-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #475569;
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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