* { box-sizing: border-box; }
body {
  font-family: system-ui, sans-serif;
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
  color: #1a1a1a;
  background: #fafafa;
}
h1 { font-size: 1.4rem; }
nav { margin-bottom: 1.5rem; display: flex; gap: 1rem; align-items: center; }
nav a { color: #7c3aed; text-decoration: none; font-weight: 600; }
button {
  background: #7c3aed;
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
button.secondary { background: #e5e5e5; color: #1a1a1a; }
button.danger { background: #dc2626; }
input, textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: inherit;
  margin-bottom: 0.75rem;
}
.card {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #ede9fe;
  color: #6d28d9;
}
.badge.error { background: #fee2e2; color: #b91c1c; }
.badge.ready { background: #dcfce7; color: #15803d; }
.muted { color: #666; font-size: 0.85rem; }
.error { color: #b91c1c; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.site-picker { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; }
.site-picker select {
  padding: 0.3rem 0.5rem; border: 1px solid #ddd; border-radius: 6px;
  background: #fff; font-size: 0.85rem; max-width: 12rem;
}
.site-picker a { text-decoration: none; font-size: 1rem; }
nav { flex-wrap: wrap; }

.topics-page { max-width: 1100px; }
.topics-heading, .topics-list-heading {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.topics-heading h1, .topics-list-heading h2, .topic-create h2 { margin-top: 0; }
.topic-explanation {
  margin: 1rem 0; padding: 1rem; border: 1px solid #ddd6fe; border-radius: 10px;
  background: #f5f3ff; color: #4c1d95; font-size: 0.9rem; line-height: 1.5;
}
.topic-create { margin: 1.5rem 0 2rem; }
.topic-field { display: block; font-size: 0.85rem; font-weight: 650; }
.topic-field span { display: block; margin-bottom: 0.35rem; }
.topic-field input { margin-bottom: 0; }
.topic-id-preview { margin: 0.45rem 0 1.2rem; color: #666; font-size: 0.8rem; }
.topic-id-preview code, .topic-code {
  display: inline-block; padding: 0.12rem 0.4rem; border-radius: 4px; background: #f0f0f0;
  color: #444; font-family: ui-monospace, monospace; font-size: 0.78rem;
}
.topic-choice-group { min-width: 0; margin: 1rem 0; padding: 0; border: 0; }
.topic-choice-group legend { font-size: 0.88rem; font-weight: 700; }
.topic-choice-group .muted { margin: 0.25rem 0 0.6rem; }
.topic-choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.45rem; }
.topic-choice {
  display: flex; align-items: flex-start; gap: 0.55rem; min-width: 0; padding: 0.55rem 0.65rem;
  border: 1px solid #e5e5e5; border-radius: 7px; background: #fafafa; font-size: 0.84rem;
}
.topic-choice:has(input:checked) { border-color: #a78bfa; background: #f5f3ff; }
.topic-choice input { width: auto; flex: 0 0 auto; margin: 0.15rem 0 0; accent-color: #7c3aed; }
.topic-choice span { min-width: 0; overflow-wrap: anywhere; }
.topic-form-actions { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; margin-top: 1rem; }
.topic-form-actions p { flex: 1 1 220px; margin: 0; }
.topic-filters { display: flex; align-items: flex-end; gap: 0.65rem; flex-wrap: wrap; }
.topic-filters label { color: #555; font-size: 0.78rem; font-weight: 650; }
.topic-filters select {
  display: block; min-width: 170px; margin-top: 0.25rem; padding: 0.5rem;
  border: 1px solid #ddd; border-radius: 6px; background: #fff; font: inherit;
}
.topic-card { margin-top: 0.75rem; }
.topic-card.is-archived { border-color: #e5e7eb; background: #f9fafb; }
.topic-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.topic-card-header h3 { margin: 0 0 0.25rem; font-size: 1.05rem; overflow-wrap: anywhere; }
.badge.topic-archived { background: #e5e7eb; color: #4b5563; }
.topic-usage { margin: 0.8rem 0 1rem; font-size: 0.84rem; font-weight: 650; color: #5b21b6; }
.topic-edit-form > fieldset { min-width: 0; padding: 0; border: 0; }
.topic-edit-form > fieldset:disabled { opacity: 0.65; }
button.topic-restore { background: #15803d; }
.topics-page button:disabled { cursor: wait; opacity: 0.6; }
.topic-empty { padding: 1.2rem; }

@media (max-width: 640px) {
  body { margin-top: 1rem; }
  nav { gap: 0.65rem 0.9rem; }
  nav strong { flex-basis: 100%; }
  .topics-heading > button { width: 100%; }
  .topic-filters, .topic-filters label, .topic-filters select { width: 100%; }
  .topic-choice-grid { grid-template-columns: 1fr; }
  .topic-form-actions button { flex: 1 1 120px; }
}
