.test-category-section + .test-category-section {
  margin-top: 18px;
}

.test-category-manager {
  margin: 12px 0 14px;
  padding: 16px;
  border: 1px solid #dde3ec;
  border-radius: 8px;
  background: #f8fafc;
}

.test-category-manager-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.test-category-manager-head > div {
  min-width: 0;
}

.test-category-manager-head span,
.test-category-dialog > span {
  color: #2969e8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.test-category-manager-head h3,
.test-category-dialog h3 {
  margin: 4px 0 5px;
  color: #111827;
  font-size: 17px;
  line-height: 1.25;
}

.test-category-manager-head p {
  margin: 0;
  color: #687386;
  font-size: 12px;
  line-height: 1.45;
}

.test-category-create {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: #111318;
  color: #fff;
  font-weight: 800;
}

.test-category-toolbar {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.test-category-all {
  min-height: 68px;
  border: 1px solid #d8dee8;
  border-radius: 7px;
  background: #fff;
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

.test-category-all strong {
  display: block;
  margin-top: 4px;
  color: #2969e8;
}

.test-category-filter.active,
.test-category-card:has(.test-category-filter.active) {
  border-color: #2969e8;
  box-shadow: inset 0 0 0 1px #2969e8;
}

.test-category-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  min-width: 0;
}

.test-category-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 68px;
  padding: 7px;
  border: 1px solid #d8dee8;
  border-radius: 7px;
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.test-category-card.dragging {
  opacity: 0.45;
}

.test-category-card.drag-over {
  border-color: #2969e8;
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(41, 105, 232, 0.13);
}

.test-category-card > .test-category-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px;
  border: 0;
  background: transparent;
  color: #111827;
  text-align: left;
}

.test-category-drag {
  flex: 0 0 auto;
  color: #9aa5b5;
  font-size: 18px;
  cursor: grab;
}

.test-category-card .test-category-filter > span:last-child {
  min-width: 0;
}

.test-category-card strong,
.test-category-card small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-category-card strong {
  font-size: 13px;
}

.test-category-card small {
  margin-top: 3px;
  color: #7b8797;
  font-size: 11px;
}

.test-category-card-actions {
  display: flex;
  gap: 4px;
}

.test-category-card-actions button {
  min-height: 31px;
  padding: 0 8px;
  border: 1px solid #d8dee8;
  border-radius: 5px;
  background: #fff;
  color: #48566a;
  font-size: 11px;
  font-weight: 700;
}

.test-category-card-actions .test-category-delete:not(:disabled) {
  color: #d9363e;
}

.test-category-card-actions button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.test-category-notice {
  min-height: 18px;
  margin: 10px 2px 0;
  color: #687386;
  font-size: 11px;
}

.test-category-notice[data-type="success"] {
  color: #147b52;
}

.test-category-notice[data-type="error"] {
  color: #ce2f3a;
}

/*
 * The category manager always lives in the narrow admin list panel.
 * Its layout must follow the panel width rather than the viewport width.
 */
.admin-list-panel .test-category-manager {
  overflow: hidden;
  padding: 14px;
}

.admin-list-panel .test-category-manager-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.admin-list-panel .test-category-manager-head > div {
  width: 100%;
}

.admin-list-panel .test-category-manager-head h3 {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-list-panel .test-category-manager-head p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.admin-list-panel .test-category-create {
  width: 100%;
  min-height: 40px;
}

.admin-list-panel .test-category-toolbar {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.admin-list-panel .test-category-all {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 4px;
}

.admin-list-panel .test-category-all strong {
  display: inline;
  margin-top: 0;
}

.admin-list-panel .test-category-cards {
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
}

.admin-list-panel .test-category-card {
  width: 100%;
  min-height: 62px;
  box-sizing: border-box;
}

.admin-list-panel .test-category-card-actions {
  flex: 0 0 auto;
}

.admin-list-panel .test-category-card-actions button {
  min-width: 40px;
  padding-inline: 7px;
}

.admin-list-panel .admin-row-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto !important;
  align-items: end;
  gap: 8px;
  padding: 9px;
}

.admin-list-panel .admin-row-item > button:not(.admin-danger-button) {
  grid-column: 1 / -1;
  grid-row: 1;
  min-width: 0;
  min-height: 58px;
  padding: 0;
}

.admin-list-panel .admin-row-item > button:not(.admin-danger-button) > * {
  min-width: 0;
}

.admin-list-panel .admin-row-item > button:not(.admin-danger-button) strong,
.admin-list-panel .admin-row-item > button:not(.admin-danger-button) em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-list-panel .admin-row-item .test-row-category-control {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  min-width: 0;
  flex: none;
}

.admin-list-panel .admin-row-item > .admin-danger-button {
  display: inline-flex;
  grid-column: 2;
  grid-row: 2;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 56px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid #efb7bc;
  border-radius: 6px;
  background: #fff;
  color: #ce2f3a;
}

.admin-row-item .test-row-category-control {
  position: relative;
  display: grid;
  gap: 3px;
  flex: 0 0 190px;
  min-width: 0;
}

.test-row-category-control > span {
  color: #7b8797;
  font-size: 10px;
  font-weight: 700;
}

.test-category-membership-trigger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  background: #fff;
  color: #172033;
  text-align: left;
}

.test-category-membership-trigger strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-category-membership-trigger em {
  min-width: 25px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #edf3ff;
  color: #2969e8;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  text-align: center;
}

.test-category-membership-trigger em:empty {
  display: none;
}

.test-category-membership-trigger[aria-expanded="true"] {
  border-color: #2969e8;
  box-shadow: 0 0 0 3px rgba(41, 105, 232, 0.12);
}

.test-category-membership-popover {
  position: absolute;
  z-index: 80;
  top: calc(100% + 6px);
  left: 0;
  width: min(280px, calc(100vw - 44px));
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid #d8dee8;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
}

.test-category-membership-popover[hidden] {
  display: none;
}

.test-category-membership-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 5px 8px;
  border-radius: 5px;
  color: #172033;
  cursor: pointer;
}

.test-category-membership-option:hover {
  background: #f2f6ff;
}

.test-category-membership-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #2969e8;
}

.test-category-membership-option span {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-row-category-control.saving {
  pointer-events: none;
  opacity: 0.62;
}

.test-category-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.54);
  backdrop-filter: blur(5px);
}

.test-category-dialog {
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.test-category-dialog label {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.test-category-dialog input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid #cad2df;
  border-radius: 6px;
  color: #111827;
  font: inherit;
}

.test-category-dialog input:focus {
  border-color: #2969e8;
  outline: 3px solid rgba(41, 105, 232, 0.13);
}

.test-category-dialog-error {
  min-height: 18px;
  margin: 7px 0 0;
  color: #ce2f3a;
  font-size: 11px;
}

.test-category-dialog > div {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.test-category-dialog > div button {
  min-width: 84px;
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: #111318;
  color: #fff;
  font-weight: 800;
}

.test-category-dialog > div .dialog-cancel {
  background: #eef1f5;
  color: #3e4a5d;
}

.test-category-dialog.saving {
  pointer-events: none;
  opacity: 0.7;
}

@media (max-width: 900px) {
  .test-category-manager {
    padding: 13px;
  }

  .test-category-manager-head,
  .test-category-toolbar {
    grid-template-columns: 1fr;
  }

  .test-category-manager-head {
    display: grid;
  }

  .test-category-create {
    width: 100%;
  }

  .test-category-cards {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }

  .test-category-card {
    flex: 0 0 252px;
    scroll-snap-align: start;
  }

  .admin-row-item .test-row-category-control {
    flex-basis: 150px;
  }
}

/* Keep the category picker readable inside the broad .admin-preview button theme. */
.admin-preview .test-category-membership-trigger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-content: stretch;
  gap: 8px;
  width: 100%;
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  background: #fff;
  color: #172033;
  box-shadow: none;
  text-align: left;
}

.admin-preview .test-category-membership-trigger strong {
  color: #172033;
}

.admin-preview .test-category-membership-trigger[aria-expanded="true"] {
  border-color: #2969e8;
  box-shadow: 0 0 0 3px rgba(41, 105, 232, 0.12);
}

.legacy-test-category-field {
  display: none !important;
}

.test-category-assignment {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #fff;
}

.test-category-assignment-empty {
  display: grid;
  place-items: center;
  min-height: 128px;
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 7px;
  background: #f8fafc;
  color: #64748b;
  text-align: center;
}

.test-category-assignment-empty span,
.test-category-assignment-head > div > span {
  color: #2969e8;
  font-size: 10px;
  font-weight: 900;
}

.test-category-assignment-empty strong {
  margin-top: 6px;
  color: #172033;
  font-size: 15px;
}

.test-category-assignment-empty p {
  margin: 4px 0 0;
  font-size: 12px;
}

.test-category-assignment-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.test-category-assignment-head h4 {
  margin: 4px 0 3px;
  color: #111827;
  font-size: 18px;
}

.test-category-assignment-head p {
  margin: 0;
  color: #667085;
  font-size: 12px;
  line-height: 1.55;
}

.test-category-assignment-count {
  display: grid;
  place-items: center;
  min-width: 76px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 6px;
  background: #eef4ff;
  color: #245cc7;
  font-size: 13px;
}

.test-category-assignment-search {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  background: #fff;
  color: #64748b;
}

.test-category-assignment-search:focus-within {
  border-color: #2969e8;
  box-shadow: 0 0 0 3px rgba(41, 105, 232, 0.11);
}

.test-category-assignment-search input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #172033;
  font: inherit;
  font-size: 13px;
}

.test-category-assignment-list {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow: auto;
  padding-right: 3px;
}

.test-category-assignment-item {
  display: grid;
  grid-template-columns: 18px 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 58px;
  padding: 7px 10px;
  border: 1px solid #e3e8ef;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, transform 140ms ease;
}

.test-category-assignment-item:hover {
  border-color: #aebddd;
  background: #f8faff;
  transform: translateY(-1px);
}

.test-category-assignment-item:has(input:checked) {
  border-color: #96b6f1;
  background: #f3f7ff;
}

.test-category-assignment-item > input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: #2969e8;
}

.test-category-assignment-thumb {
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 6px;
  background: linear-gradient(135deg, #eef2f7, #dfe7f1);
}

.test-category-assignment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.test-category-assignment-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.test-category-assignment-copy strong,
.test-category-assignment-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-category-assignment-copy strong {
  color: #172033;
  font-size: 13px;
}

.test-category-assignment-copy small {
  color: #7a8699;
  font-size: 10px;
}

.test-category-assignment-state {
  min-width: 54px;
  padding: 5px 7px;
  border-radius: 5px;
  background: #eef1f5;
  color: #667085;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  text-align: center;
}

.test-category-assignment-item:has(input:checked) .test-category-assignment-state {
  background: #dfeaff;
  color: #245cc7;
}

.test-category-assignment-item.saving {
  pointer-events: none;
  opacity: 0.58;
}

.test-category-assignment-no-results {
  margin: 0;
  padding: 22px 12px;
  border-radius: 6px;
  background: #f8fafc;
  color: #7a8699;
  font-size: 12px;
  text-align: center;
}

.test-category-assignment-no-results[hidden],
.test-category-assignment-item[hidden] {
  display: none;
}

@media (max-width: 900px) {
  .test-category-assignment {
    padding: 14px;
  }

  .test-category-assignment-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .test-category-assignment-list {
    max-height: 320px;
  }

  .test-category-assignment-item {
    grid-template-columns: 18px 38px minmax(0, 1fr);
  }

  .test-category-assignment-thumb {
    width: 38px;
    height: 38px;
  }

  .test-category-assignment-state {
    display: none;
  }
}
