:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e8e8ea;
  --border-strong: #d9d9dc;
  --text: #18181b;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.04);
  --shadow: 0 1px 3px rgba(24, 24, 27, 0.05), 0 4px 16px rgba(24, 24, 27, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  max-width: 880px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 6rem;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

h1 {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0.25rem 0 1.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.back-link:hover {
  color: var(--text);
  text-decoration: none;
}

/* Index — entity picker */

.entity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.entity-card {
  display: block;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.entity-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  text-decoration: none;
}

.entity-card-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.entity-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
}

.entity-card-meta .done {
  color: var(--success);
  font-weight: 600;
}

.empty-note {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.9rem;
}

/* Progress bar */

.progress-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background: #f4f4f5;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* List page */

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

.list-stats {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.list-progress {
  margin-bottom: 1.5rem;
}

.record-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.record-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.record-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fcfcfd;
}

.record-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}

.record-table tr:last-child td {
  border-bottom: none;
}

.record-row {
  cursor: pointer;
  transition: background 0.1s ease;
}

.record-row:hover {
  background: #fafafa;
}

.record-row td a {
  color: var(--text);
  display: block;
}

.record-row td a:hover {
  text-decoration: none;
  color: var(--accent);
}

.record-id-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-pill.done {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.pending {
  background: #f4f4f5;
  color: var(--text-faint);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination a {
  font-weight: 500;
}

/* Detail page */

.detail-title {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 1.75rem;
}

.detail-title .entity-name {
  font-size: 1.4rem;
}

.record-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text-faint);
  font-weight: 400;
}

.field-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem 1.4rem;
  margin-bottom: 1.1rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.field-group-title {
  font-weight: 600;
  font-size: 0.95rem;
  text-transform: capitalize;
  margin-bottom: 1rem;
  color: var(--text);
}

.compound-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
  margin-bottom: 0.9rem;
  background: #fcfcfd;
}

.compound-item:last-child {
  margin-bottom: 0;
}

.compound-item-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.compound-subfield {
  margin-bottom: 1rem;
}

.compound-subfield:last-child {
  margin-bottom: 0;
}

.compound-subfield-name {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
}

.field-cols {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-bottom: 0.6rem;
}

.field-col label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 0.35rem;
}

.field-col.lang-de label {
  color: var(--accent);
}

.field-input {
  display: block;
  width: 100%;
  padding: 0.55rem 0.65rem;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fdfdfd;
  resize: vertical;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field-col.lang-de .field-input {
  border-color: #c7d2fe;
  background: var(--accent-soft);
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.wysiwyg-toolbar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
}

.wysiwyg-toolbar button {
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fdfdfd;
  color: var(--text-muted);
  transition: background 0.12s ease, color 0.12s ease;
}

.wysiwyg-toolbar button:hover {
  background: #f4f4f5;
  color: var(--text);
}

.wysiwyg-editor {
  min-height: 4.5rem;
  max-height: 18rem;
  overflow-y: auto;
  cursor: text;
}

.wysiwyg-editor p {
  margin: 0 0 0.6em;
}

.wysiwyg-editor :first-child {
  margin-top: 0;
}

.wysiwyg-editor :last-child {
  margin-bottom: 0;
}

.wysiwyg-editor a {
  color: var(--accent);
  text-decoration: underline;
}

.save-status {
  min-height: 1rem;
  font-size: 0.76rem;
  color: var(--success);
  margin-bottom: 0.7rem;
}

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

.variants {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.variant-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
  background: #fcfcfd;
}

.variant-source {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 0.35rem;
}

.variant-source .used-badge {
  color: var(--success);
  text-transform: none;
  letter-spacing: normal;
}

.variant-text {
  font-size: 0.82rem;
  color: var(--text);
  max-height: 5.5rem;
  overflow-y: auto;
  margin-bottom: 0.5rem;
  white-space: pre-wrap;
}

.apply-option-btn {
  padding: 0.28rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s ease;
}

.apply-option-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Sticky action bar */

.actions {
  position: sticky;
  bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.5rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.actions .spacer {
  flex: 1;
}

#mark-reviewed-btn {
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

#mark-reviewed-btn:hover {
  border-color: var(--success);
  color: var(--success);
}

#mark-reviewed-btn.is-reviewed {
  background: var(--success-soft);
  color: var(--success);
  border-color: #bbf7d0;
}
