/* Keep account actions in the available panel. This works with both the
   deployed nine-column table and the additional MFA column in the source. */
[data-table='users'].tscroll {
  container: crm-users-table / inline-size;
  min-width: 0;
  max-width: 100%;
}
[data-table='users'].tscroll > .tb {
  width: 100%;
  min-width: 0;
  table-layout: auto;
}
[data-table='users'].tscroll > .tb > thead > tr > th,
[data-table='users'].tscroll > .tb > tbody > .row > td {
  width: auto !important;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  padding: 8px clamp(4px, .65cqi, 9px);
}
[data-table='users'].tscroll > .tb > thead > tr > th:last-child {
  width: 22% !important;
}
[data-table='users'].tscroll > .tb > tbody > .row > td > .flex {
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}
[data-table='users'].tscroll > .tb > tbody > .row > td > .flex > * {
  min-width: 0;
  max-width: 100%;
}
[data-table='users'].tscroll > .tb > tbody > .row .tag {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
[data-table='users'].tscroll > .tb > tbody > .row > td:last-child > .flex {
  justify-content: flex-start;
  gap: 6px;
}
[data-table='users'].tscroll > .tb > tbody > .row > td:last-child .btn {
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
}

/* Nine (or ten) columns cannot keep useful widths in a small pane.
   Keep every field and action; sortable headers remain available above. */
@container crm-users-table (max-width: 860px) {
  [data-table='users'].tscroll > .tb,
  [data-table='users'].tscroll > .tb > :is(thead, tbody) {
    display: block;
    width: 100%;
  }
  [data-table='users'].tscroll > .tb > thead {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface);
    border-bottom: 1px solid var(--grid);
  }
  [data-table='users'].tscroll > .tb > thead > tr {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px;
  }
  [data-table='users'].tscroll > .tb > thead > tr::before {
    content: 'Сортировка:';
    color: var(--muted);
    padding: 5px 4px;
    font-size: 11px;
  }
  [data-table='users'].tscroll > .tb > thead > tr > th:nth-child(n) {
    display: block;
    position: static;
    width: auto !important;
    padding: 5px;
    border: 0;
    border-radius: 4px;
  }
  [data-table='users'].tscroll > .tb > thead > tr > th:last-child:empty {
    padding: 0;
  }
  [data-table='users'].tscroll > .tb > tbody > .row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    padding: 14px 10px;
    border-bottom: 1px solid var(--grid);
  }
  [data-table='users'].tscroll > .tb > tbody > .row > td {
    display: block;
    padding: 0;
    border: 0;
    text-align: left;
  }
  [data-table='users'].tscroll > .tb > tbody > .row > td::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
  }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-child(1)::before { content: 'Логин'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-child(2)::before { content: 'Имя'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-child(3)::before { content: 'Почта'; }
  [data-table='users'].tscroll > .tb > tbody > .row:has(> td:nth-child(10)) > td:nth-child(4)::before { content: 'Код входа'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-last-child(6)::before { content: 'Роль'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-last-child(5)::before { content: 'Точки'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-last-child(4)::before { content: 'Состояние'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-last-child(3)::before { content: 'Последний вход'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:nth-last-child(2)::before { content: 'Пароль до'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:last-child::before { content: 'Действия'; }
  [data-table='users'].tscroll > .tb > tbody > .row > td:last-child {
    grid-column: 1 / -1;
    margin-top: 2px;
    padding-top: 10px;
    border-top: 1px solid var(--grid);
  }
}
@container crm-users-table (max-width: 420px) {
  [data-table='users'].tscroll > .tb > tbody > .row {
    grid-template-columns: minmax(0, 1fr);
  }
}
