/* --- Users (modules/users/views/list.php): one box filling the page, its 32px bar "Users" and its toolbar from the
   partner Overview (.overview__bar, .overview__toolbar, pages/dashboard.css), then the list straight in the box, its
   lines running edge to edge, its rows with initials (pages/clients.css). Phones to 1199px: the role and status under
   the name, an arrow at the right. From 1200px: a table, Name | Role | Belongs to | Status. --- */

.users {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr; /* the box takes the whole screen, and grows with its content */
}

.users .box__toolbar {
  flex-wrap: nowrap;
  padding-block: var(--sp-3); /* 12px above and below the 32px buttons, plus its 1px line: 57px, so the buttons sit on whole pixels */
  padding-inline: var(--sp-4); /* the buttons line up with the list under it (as Partners' search) */
}

/* The bar: the title on the type scale, the number of people on the right in small capitals. */
.users .overview__bar .box__title {
  font-size: var(--fs-small);
}

.users__count {
  font-size: var(--fs-xxs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--c-on-dark-muted);
}

/* Add a user and Search on the left, the order and Sort & filter on the right. */
.users__tools--start {
  flex: 1;
  min-width: 0;
  margin-left: 0;
}

.users__add,
.users__find-toggle {
  flex: none; /* never squeezed by the open field */
}

/* Search: its field slides out to the right of its button (site.js data-toggle: aria-expanded), joined to it with no
   gap, the button's right corners and the field's left corners square. The open button is light grey like the field's
   border, so the border runs round both as one piece; while the field has the cursor, that whole border goes dark (no
   outline or ring: the field's ring clipped against the button). The field is 32px like the buttons; its text stays 16px
   (inputs never below 16px, so phones do not zoom). Shut, nothing shows and it takes no room. Its margin is the same
   shut and open, so it stays against the button while it slides in and out, and the button's corners round only once it
   has slid shut. */
.users__find {
  flex: 0 1 var(--calendar-panel-w);
  max-width: 0;
  margin-left: calc(-1 * var(--sp-2)); /* cancels the toolbar's gap: the field is always against the button */
  overflow: hidden;
  visibility: hidden;
  transition: max-width var(--duration-slow) var(--ease), visibility var(--duration-slow);
}

.users__find-toggle {
  transition:
    background-color var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease),
    box-shadow var(--duration-fast) var(--ease),
    border-radius 0s linear var(--duration-slow); /* the corners round after the field has slid shut */
}

.users__find-toggle[aria-expanded="true"] {
  color: var(--c-text);
  background: var(--c-line);
  border-color: var(--c-line);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  transition:
    background-color var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease),
    box-shadow var(--duration-fast) var(--ease); /* the corners square at once */
}

.users__find-toggle[aria-expanded="true"] + .users__find {
  max-width: var(--calendar-panel-w);
  visibility: visible;
  transition: max-width var(--duration-slow) var(--ease); /* it shows at once, so the cursor can go in as it opens */
}

.users__find-input {
  display: block;
  width: 100%;
  height: var(--button-h-sm);
  padding: 0 var(--sp-2);
  font: inherit;
  font-size: var(--fs-body);
  color: var(--c-text);
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-left: 0;
  border-radius: 0 var(--radius-1) var(--radius-1) 0;
}

.users__find-input::placeholder {
  color: var(--c-text-muted);
}

/* With the cursor in the field: the border round button and field goes dark, and no ring (the global transparent
   outline stays for Windows high-contrast mode). */
.users__find-input:focus-visible {
  border-color: var(--c-anthracite);
  box-shadow: none;
}

.users__tools--start:has(.users__find-input:focus-visible) .users__find-toggle[aria-expanded="true"] {
  border-color: var(--c-anthracite);
}

@media (min-width: 576px) {
  .users__find-toggle[aria-expanded="true"] + .users__find {
    max-width: var(--calendar-menu-w);
  }
}

@media (prefers-reduced-motion: reduce) {
  .users__find,
  .users__find-toggle {
    transition: none;
  }
}

/* Phones: no room at a fixed height for the order's words (the panel shows it), and while Search is open Sort & filter
   steps aside so the field gets the room. Add a user stays, so the search button does not jump. */
@media (max-width: 575.98px) {
  .users .overview__toolbar-text {
    display: none;
  }

  .users .box__toolbar:has(.users__find-toggle[aria-expanded="true"]) .users__tools--end {
    display: none;
  }
}

/* The list straight in the box: the text size and spacing it had in its tile (.dashboard__tile), and no side padding
   of its own, so each row's line runs edge to edge; the rows and the column names carry the padding instead. */
.users .box__body {
  gap: 0; /* the first row meets the line above it (the toolbar's, or the column names'), so its hover has no gap on top */
  padding-block-start: 0;
  padding-inline: 0;
  font-size: var(--fs-small);
}

.users__row,
.users__cols,
.users__none {
  padding-inline: var(--sp-4);
}

.users__none {
  padding-block: var(--sp-4);
}

.users__rows {
  border-bottom: var(--border-1) solid var(--c-line);
}

@media (min-width: 768px) {
  .users .box__toolbar,
  .users__row,
  .users__cols,
  .users__none {
    padding-inline: var(--sp-6);
  }
}

/* Sort & filter: a square button in the toolbar; under it a white panel with a dark bar (as Change dose,
   32px like the box's bar) and an × that closes it (site.js data-drop-close; a click outside or Escape too). From
   768px the panel opens leftwards from its button; below, it hangs from the toolbar, as wide as it less a small margin,
   so it never leaves the screen. */
.users__drop {
  position: relative;
}

.users__drop > summary {
  list-style: none; /* no triangle */
  cursor: pointer;
}

.users__drop > summary::-webkit-details-marker {
  display: none; /* Safari: its own triangle ignores list-style */
}

.users__drop[open] > summary {
  color: var(--c-page);
  background: var(--c-anthracite);
  border-color: var(--c-anthracite);
}

.users__panel {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  z-index: 3;
  display: grid;
  gap: var(--sp-3);
  width: max-content;
  min-width: 100%;
  padding: var(--sp-4);
  background-color: var(--c-page);
  border: var(--border-1) solid var(--c-line);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-1);
}

.users__panel .availability__bar {
  height: var(--sp-8);
  padding-block: 0;
  padding-inline: var(--sp-4) 0; /* the × reaches the right edge */
  font-size: var(--fs-xxs);
}

.users__close {
  width: var(--sp-8);
  height: var(--sp-8);
  padding: 0;
  font-size: var(--fs-small);
  background: none;
  border: 0;
  cursor: pointer;
}

.users__options {
  display: grid;
  gap: var(--sp-1);
}

.users__options .client__band {
  margin: 0;
}

.users__options .users__band {
  margin-top: var(--sp-2);
}

.users__options .client__menu-item {
  font-family: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.users__options .client__menu-item:hover {
  background-color: var(--c-surface);
}

.users__options .client__menu-item[aria-current="true"] {
  font-weight: 600;
  color: var(--c-accent-text);
  background-color: var(--c-chip);
}

@media (max-width: 767.98px) {
  .users .box__toolbar {
    position: relative;
  }

  .users__drop {
    position: static;
  }

  .users__panel {
    top: calc(100% - var(--sp-1));
    left: var(--sp-2);
    right: var(--sp-2);
    width: auto;
    min-width: 0;
  }
}

/* Add a user: the password's help line sits close under its field. */
.users__help {
  margin-top: calc(-1 * var(--sp-2));
}

/* A person: initials, name over email, the arrow; role (and status, when there is one) on the line under the name. */
.users__row {
  position: relative; /* holds its open button, which covers the whole row (.clients__open) */
  display: grid;
  grid-template-columns: var(--sp-8) minmax(0, 1fr) auto auto;
  grid-template-areas:
    "avatar who  who    chevron"
    "avatar role status chevron"
    "avatar org  org    chevron";
  align-items: center;
  gap: var(--sp-1) var(--sp-3);
  padding-block: var(--sp-2);
}

.users__row > .open {
  display: contents; /* its form takes no cell; the button inside covers the row */
}

.users__row + .users__row {
  border-top: var(--border-1) solid var(--c-line);
}

.users__row .clients__avatar { grid-area: avatar; }
.users__who { grid-area: who; }
.users__role { grid-area: role; justify-self: start; }
.users__status { grid-area: status; }
.users__chevron { grid-area: chevron; color: var(--c-text-muted); }

.users__org {
  grid-area: org;
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.users__org--none,
.users__row:not(.users__row--status) .users__status {
  display: none; /* phones to 1199px: no dash for a login without a partner or clinic; "Active" goes without saying */
}

/* Below 576px the status gets its own line under the role, so the two never run into each other. */
@media (max-width: 575.98px) {
  .users__row {
    grid-template-columns: var(--sp-8) minmax(0, 1fr) auto;
    grid-template-areas:
      "avatar who    chevron"
      "avatar role   chevron"
      "avatar status chevron"
      "avatar org    chevron";
  }

  .users__status {
    justify-self: start;
  }
}

/* Their role: a pale blue chip. */
.users__role {
  padding-inline: var(--sp-2);
  font-size: var(--fs-xs);
  line-height: var(--sp-5);
  color: var(--c-accent-text);
  white-space: nowrap;
  background-color: var(--c-chip);
  border: var(--border-1) solid var(--c-chip-border);
  border-radius: var(--radius-pill);
}

/* Switched off: red; Invited and Not confirmed use Clients' amber "To contact" (.dashboard__tag--contact). */
.users__tag--off {
  color: var(--c-error);
  background-color: var(--c-error-bg);
}

.users__active {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

.users__cols {
  display: none;
}

@media (hover: hover) {
  .users__row:has(.clients__open:hover) {
    background-color: var(--c-off-white);
  }
}

/* From 1200px: a table, with the column names in the band's small capitals above it. */
@media (min-width: 1200px) {
  .users .box__body {
    padding-block-start: var(--sp-4); /* room above the column names */
  }

  .users__row,
  .users__cols {
    grid-template-columns: var(--sp-8) minmax(0, 3fr) minmax(0, 1.4fr) minmax(0, 2.4fr) minmax(0, 1.2fr) var(--sp-4);
    grid-template-areas: "avatar who role org status chevron";
  }

  .users__org--none,
  .users__row:not(.users__row--status) .users__status {
    display: block;
  }

  .users__org {
    font-size: inherit;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--c-text-muted);
  }

  .users__cols {
    display: grid;
    column-gap: var(--sp-3);
    padding-block: 0 var(--sp-2);
    font-size: var(--fs-xxs);
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--c-anthracite);
    border-bottom: var(--border-1) solid var(--c-line);
  }

  .users__cols > :nth-child(2) { grid-column: 2; }
}
