:root {
  color-scheme: light dark;
  --background: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #5f6b7a;
  --border: #d7dce2;
  --accent: #1f6feb;
  --accent-strong: #1858bd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #14171c;
    --surface: #1d222a;
    --text: #e6e9ef;
    --muted: #9aa5b4;
    --border: #333b46;
    --accent: #6ea8ff;
    --accent-strong: #9cc2ff;
  }
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.125rem;
  text-decoration: none;
  color: var(--text);
}

.header-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  min-width: 0;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.breadcrumbs a {
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

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

.breadcrumbs [aria-current="page"] {
  color: var(--text);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.user-email,
.meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.inline-form {
  margin: 0;
}

.tag-rename-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tag-rename-form input {
  flex: 0 1 16rem;
  width: auto;
  margin: 0;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

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

.link-button.danger {
  background: none;
  color: #c94040;
}

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0 0 0.25rem;
}

.page-header-split {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.auth-card {
  max-width: 24rem;
  margin: 2rem auto;
}

.card h1,
.card h2 {
  margin-top: 0;
}

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

.inventory-list li {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.inventory-link {
  font-size: 1.1rem;
  font-weight: 600;
  text-decoration: none;
}

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

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

form p {
  margin: 0 0 1rem;
}

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--background);
  color: var(--text);
  font: inherit;
}

input[type="radio"],
input[type="checkbox"] {
  width: auto;
  margin: 0 0.35rem 0 0;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

select,
textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--background);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

button[type="submit"] {
  padding: 0.55rem 1.1rem;
  border: 0;
  border-radius: 0.35rem;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button[type="submit"]:hover {
  background: var(--accent-strong);
}

.errorlist {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
  color: #c94040;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.search-form {
  flex: 1 1 18rem;
}

.search-form input {
  margin: 0;
}

.filter-form {
  flex: 1 1 100%;
}

.filter-form input[type="search"] {
  margin: 0 0 0.5rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.filter-row select {
  flex: 1 1 10rem;
  width: auto;
  min-width: 9rem;
  max-width: 18rem;
  margin: 0;
}

.form-card {
  margin-bottom: 1.5rem;
}

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

.form-header h2 {
  margin: 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.input-with-action {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.input-with-action input {
  flex: 1;
  min-width: 0;
}

.input-with-action .link-button {
  flex: none;
}

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

.regenerate-status.error {
  color: #c94040;
}

button.danger {
  background: #c94040;
}

button.danger:hover {
  background: #a83232;
}

.button-link {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 0.35rem;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
}

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

.button-link.danger {
  background: #c94040;
}

.button-link.danger:hover {
  background: #a83232;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

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

.item-picker {
  max-height: 22rem;
  overflow-y: auto;
}

.code-block {
  overflow-x: auto;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bulk-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.bulk-form label {
  margin: 0;
  font-weight: 600;
}

.bulk-form select,
.bulk-form input {
  width: auto;
}

.bulk-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bulk-option[hidden] {
  display: none;
}

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

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

th {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  white-space: nowrap;
  text-align: right;
}

.form-table {
  width: 100%;
  border-collapse: collapse;
}

.form-table > tbody > tr > th,
.form-table > tbody > tr > td {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.form-table > tbody > tr > th {
  width: 13rem;
  padding-right: 1.25rem;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
}

.form-table > tbody > tr > th label {
  margin: 0;
  cursor: pointer;
}

.form-table > tbody > tr:last-child > th,
.form-table > tbody > tr:last-child > td {
  border-bottom: 0;
}

.form-table > tbody > tr > td > .helptext {
  margin-top: 0.15rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
}

.checkbox-row .helptext {
  margin: 0;
}

#id_value_type {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}

.tag {
  display: inline-block;
  margin: 0 0.25rem 0.25rem 0;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  font-size: 0.8rem;
}

.tag-input {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.5rem;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--background);
}

.tag-input:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tag-input .tag {
  margin: 0;
}

.tag-input-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.tag-input-remove {
  padding: 0 0.1rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.tag-input-remove:hover {
  color: var(--text);
}

.tag-input-text {
  flex: 1 1 8rem;
  width: auto;
  min-width: 6rem;
  padding: 0.2rem;
  border: 0;
  background: transparent;
}

.tag-input-text:focus {
  outline: none;
}

.tag-input-dropdown {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.2rem);
  right: 0;
  left: 0;
  max-height: 14rem;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--background);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  list-style: none;
}

.tag-input-option {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.tag-input-option:hover,
.tag-input-option[aria-selected="true"] {
  background: var(--surface);
}

.tag-input-count {
  color: var(--muted);
  font-size: 0.8rem;
}

.suggest-input {
  position: relative;
}

.suggest-input input[readonly] {
  cursor: pointer;
}

.suggest-dropdown {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.2rem);
  right: 0;
  left: 0;
  max-height: 14rem;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--background);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  list-style: none;
}

.suggest-option {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}

.suggest-option .meta {
  margin-left: auto;
  white-space: nowrap;
}

.suggest-option:hover,
.suggest-option[aria-selected="true"] {
  background: var(--surface);
}

.suggest-empty {
  padding: 0.35rem 0.6rem;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(8rem, 12rem) 1fr;
  gap: 0.6rem 1rem;
  margin: 0;
}

.detail-grid dt {
  color: var(--muted);
  font-weight: 600;
}

.detail-grid dd {
  margin: 0;
}


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

.message {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--surface);
}

.message.error {
  border-color: #c94040;
  color: #8a2626;
}

.message.success {
  border-color: #2f7d4f;
  color: #24603c;
}

.button-link.secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
}

.inline-add-form,
.rename-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.choice-table {
  margin: 0.5rem 0 0.75rem;
}

.choice-row.dragging {
  opacity: 0.5;
}

.choice-handle {
  width: 1%;
  white-space: nowrap;
}

.choice-row .errorlist {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
}

button.secondary {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.secondary:hover {
  background: var(--border);
}

.rename-form {
  display: inline-flex;
  gap: 0.5rem;
}

.rename-form input {
  max-width: 12rem;
}

.row-actions form + form {
  margin-left: 0.75rem;
}

.choice-map {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.choice-map-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.choice-map-choice {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 12rem;
}

.choice-map-row input[type="text"] {
  max-width: 10rem;
}

.helptext {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.field-row.dragging {
  opacity: 0.5;
}

.field-handle {
  width: 1%;
  white-space: nowrap;
}

.drag-handle {
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1.1;
  cursor: grab;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.row-actions form {
  display: inline;
}

.rename-form .template-input {
  max-width: 18rem;
}

.tree,
.tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-children {
  margin-left: 1.25rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
}

.tree-node {
  margin: 0.35rem 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tree-toggle {
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--surface);
  color: var(--text);
}

span.tree-toggle {
  border: 0;
  background: transparent;
}

.tree-empty {
  padding: 0.5rem 0;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tree-children[hidden] {
  display: none;
}
