/*
 * QA #458 (G10 batch): the permission set editor (Settings › Users & Teams › Permission sets).
 * The design has no such editor, so these are our own rules. They are scoped to its dialog
 * (`PermissionSetEditor.tsx`, `FieldAccessGrid.tsx`). Before this, none of its classes had any
 * CSS. Its tables (min-width 760px, settings.css) overflowed the 520px drawer. Field names, API
 * names and notes ran together on one line.
 */

/* A wider drawer: four columns of record access and a field list need the room. */
dialog.set-modal.set-modal--drawer.ps-editor {
  width: min(760px, 100vw);
}

dialog.set-modal--drawer.ps-editor .set-modal__body {
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}

.ps-editor__heading {
  margin: var(--sp-2) 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* Record access and field access tables fit the drawer instead of scrolling sideways. */
.ps-editor .ps-editor__table {
  min-height: max-content;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ps-editor .ps-editor__table .set-table {
  min-width: 0;
  table-layout: auto;
}

.ps-editor .ps-editor__table .set-table td,
.ps-editor .ps-editor__table .set-table th {
  padding: 10px 12px;
  vertical-align: middle;
}

/* Record access now fits: don't clip its View / Edit pickers' menus (settings.css scrolls cards). */
.ps-editor .ps-editor__table:not(.ps-fields__table) {
  overflow: visible;
}

/* Record access: the object, then View and Edit pickers, then Delete. */
.ps-editor .ps-editor__table .set-table td:nth-child(n + 2) {
  white-space: normal;
}

.ps-editor .ps-editor__table .set-table td:last-child,
.ps-editor .ps-editor__table .set-table th:last-child {
  width: 1%;
  text-align: center;
}

/* P2a: Record access now ends with the Delete and Merge pickers, not a checkbox column, so its
   last column takes the room a picker needs (the field access table keeps the rule above). */
.ps-editor .ps-editor__table:not(.ps-fields__table) .set-table td:last-child,
.ps-editor .ps-editor__table:not(.ps-fields__table) .set-table th:last-child {
  width: auto;
  text-align: left;
}

/* App permissions: two columns of checkboxes. */
.ps-editor__apps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2) var(--sp-4);
}

/* Field access: object and search, then the list. */
.ps-fields {
  display: grid;
  gap: var(--sp-3);
  min-width: 0;
}

.ps-fields__bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
}

.ps-fields__object {
  flex: 0 1 240px;
  min-width: 0;
}

.ps-fields__object .input {
  width: 100%;
}

.ps-fields__search {
  flex: 1 1 200px;
  min-width: 0;
}

.ps-fields__table {
  max-height: 420px;
  overflow-y: auto;
}

/* A field's label, then its API name and any note, each on its own line. */
.ps-fields__name,
.ps-fields__note {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.ps-fields__note {
  font-style: italic;
}

.ps-fields__table .set-table td:last-child,
.ps-fields__table .set-table th:last-child {
  width: 180px;
  text-align: left;
}

.ps-fields__table .set-table td:last-child .input {
  width: 100%;
}

@media (max-width: 575.98px) {
  .ps-editor__apps {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Permission set editor tabs: Access, Review, Users (design settings-users.php). */
.ps-editor__tabs {
  margin: 0 0 16px;
}
.ps-editor__review > .input {
  margin-bottom: 12px;
}
.ps-editor__review-list {
  margin: 0 0 12px;
}
.ps-editor__review-list > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ps-editor__review-list dt {
  font-weight: 500;
}
.ps-editor__review-list dd {
  margin: 0;
  color: var(--text-muted);
}
.ps-editor__user-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.ps-editor__user-list li {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ps-editor__user-list span {
  color: var(--text-muted);
  font-size: 12px;
}
.ps-editor__users {
  margin-top: 4px;
}

/* HUB-743: Segments as the design's permission item (settings-users.css .ut-perm-item). Its
   Critical badge and sub-row lines use fixed light colours there; tokens here, for dark mode. */
.ps-editor .ut-critical-badge {
  background: var(--danger-bg);
  color: var(--danger);
}
.ps-editor .ut-perm-subrow {
  border-bottom-color: var(--border);
}
.ps-editor .ut-perm-item .switch {
  align-items: center;
}
