:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2430;
  --muted: #667085;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --admin: #b45309;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #111827;
  color: #fff;
}
.topbar .brand { color: #fff; font-weight: 600; text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { color: #cbd5e1; text-decoration: none; }
.topbar nav a:hover { color: #fff; }

.user-badge {
  background: #374151;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}
.user-badge.admin { background: var(--admin); color: #fff; }
.user-badge.reviewer { background: #0891b2; color: #fff; }

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

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card.narrow { max-width: 400px; margin: 3rem auto; }

h1 { font-size: 1.25rem; margin-top: 0; }

label { display: block; margin-bottom: 0.9rem; font-size: 0.9rem; color: var(--muted); }
label.checkbox { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
label.checkbox input { width: auto; }

.backup-dataset-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.9rem;
}
.backup-dataset-list label.checkbox { margin-bottom: 0.4rem; }
.backup-dataset-list label.checkbox:last-child { margin-bottom: 0; }

input[type="text"], input[type="password"], input[type="file"], textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
input:disabled { background: #f1f2f4; color: var(--muted); }

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

button, .button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-dark); }
button.secondary, .button.secondary { background: #6b7280; }
button.secondary:hover, .button.secondary:hover { background: #4b5563; }
button.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }
.button.disabled { background: #d1d5db; color: #9ca3af; cursor: default; pointer-events: none; }

.button-row { display: flex; gap: 0.6rem; }

.flash-list { margin-bottom: 1rem; }
.flash { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.datasets-table { width: 100%; border-collapse: collapse; }
.datasets-table th, .datasets-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.label-header { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 0.5rem; }
.label-header h1 { margin: 0; }
.progress { color: var(--muted); font-size: 0.9rem; }

.label-nav { display: flex; justify-content: space-between; margin-bottom: 1rem; }

.label-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 800px) { .label-body { grid-template-columns: 1fr; } }

.images { display: flex; flex-direction: column; gap: 1rem; }
.image-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  text-align: center;
}
.image-box img {
  display: block;
  width: 100%;
  border-radius: 6px;
  object-fit: contain;
  background: var(--bg);
  margin: 0 auto;
}
/* Fixed heights so the box stays the same size from one image to the next,
   regardless of each photo's native resolution/aspect ratio. */
.image-box img.sign-image { height: 320px; }
.image-box img.context-image { height: 380px; }
.image-caption { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }

.form-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.review-badge {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.review-badge.approved { background: #dcfce7; color: #166534; }

.review-form { margin-top: 0.75rem; }

.meta { margin-top: 1rem; font-size: 0.8rem; color: var(--muted); }

select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
}
select:disabled { background: #f1f2f4; color: var(--muted); }

.code-hint-link { display: block; margin-bottom: 0.2rem; }
.code-field { display: flex; align-items: center; gap: 0.6rem; }
.code-field input { flex: 1; margin-top: 0; }
.picker-select {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
}
.code-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  flex-shrink: 0;
}

.mutcd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}
.mutcd-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  text-align: center;
}
.mutcd-tile img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}
.mutcd-code { font-size: 0.8rem; font-weight: 600; word-break: break-word; }

.role-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #e5e7eb;
  color: var(--text);
}
.role-badge.admin { background: var(--admin); color: #fff; }
.role-badge.reviewer { background: #0891b2; color: #fff; }

.datasets-table form { display: inline-block; margin: 0; }

.tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.2rem;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 0.95rem;
}
.tab-btn:hover { color: var(--text); background: none; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hidden { display: none !important; }

.source-toggle { display: flex; gap: 1.2rem; margin-bottom: 0.9rem; font-size: 0.9rem; }
.source-toggle label { display: flex; align-items: center; gap: 0.35rem; color: var(--text); margin-bottom: 0; }
.source-toggle input { width: auto; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { background: none; color: var(--accent-dark); }

.notes-cell { max-width: 220px; }
.notes-text { display: block; white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; }
.notes-form { margin-top: 0.3rem; }
.notes-form textarea { margin-top: 0; font-size: 0.85rem; }
.notes-form-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.35rem; }
.notes-form-actions .button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

.progress-wrap { margin-top: 1rem; }
.progress-bar {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.progress-fill.progress-fill-error { background: var(--danger); }
#import-progress-text { margin-top: 0.4rem; }

#recent-imports-wrap { margin-top: 1.25rem; }
.recent-imports-title { font-size: 0.9rem; margin: 0 0 0.5rem; color: var(--muted); }
.recent-imports-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.recent-import-item {
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: #f4f5f7;
  color: var(--text);
}
.recent-import-item.recent-import-running { background: #dbeafe; color: #1e3a8a; }
.recent-import-item.recent-import-done { background: #dcfce7; color: #166534; }
.recent-import-item.recent-import-error { background: #fee2e2; color: #991b1b; }

input[type="url"] {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
}
