/* With many columns on, the middle scrolls sideways while Name and Actions stay in view. */
.users-table th,
.users-table td {
  white-space: nowrap;
}

.users-table td[data-col] {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.users-table th:first-child,
.users-table td:first-child,
.users-table th:last-child,
.users-table td:last-child {
  position: sticky;
  background: hsl(var(--background));
}

.users-table th:first-child,
.users-table th:last-child {
  background: color-mix(in srgb, hsl(var(--muted)) 50%, hsl(var(--background)));
}

.users-table th:first-child,
.users-table td:first-child {
  left: 0;
  box-shadow: 1px 0 0 hsl(var(--border));
}

.users-table th:last-child,
.users-table td:last-child {
  right: 0;
  box-shadow: -1px 0 0 hsl(var(--border));
}

.users-table tr:hover td:first-child,
.users-table tr:hover td:last-child {
  background: color-mix(in srgb, hsl(var(--muted)) 50%, hsl(var(--background)));
}

/* a shaded edge and an always-visible bar say there are more columns that way */
.users-more-left .users-table th:first-child::after,
.users-more-left .users-table td:first-child::after,
.users-more-right .users-table th:last-child::before,
.users-more-right .users-table td:last-child::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  pointer-events: none;
}

.users-more-left .users-table th:first-child::after,
.users-more-left .users-table td:first-child::after {
  left: 100%;
  background: linear-gradient(to right, rgba(29, 41, 57, 0.16), transparent);
}

.users-more-right .users-table th:last-child::before,
.users-more-right .users-table td:last-child::before {
  right: 100%;
  background: linear-gradient(to left, rgba(29, 41, 57, 0.16), transparent);
}

div:has(> .users-table) {
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--border)) transparent;
}

div:has(> .users-table)::-webkit-scrollbar {
  height: 10px;
}

div:has(> .users-table)::-webkit-scrollbar-thumb {
  border: 2px solid hsl(var(--background));
  border-radius: 999px;
  background: hsl(var(--muted-foreground) / 0.45);
}

/* a pinned cell is its own layer, so the row whose menu is open has to sit above the rows below it */
.users-table td:last-child:has([aria-expanded="true"]) {
  z-index: 5;
}

.users-popover {
  position: relative;
}

.users-popover-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 6px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(29, 41, 57, 0.14);
}

.users-filter-panel {
  left: 0;
  right: auto;
  width: 320px;
  max-height: min(460px, calc(100vh - 250px));
  padding: 8px 10px;
}

/* on a phone the panels open as a sheet from the bottom, so they can never hang off an edge */
@media (max-width: 639px) {
  .users-popover-panel,
  .users-filter-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    max-height: 70vh;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    z-index: 60;
  }
}

.users-popover-group {
  padding: 8px 10px 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}

.users-popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 400;
  color: hsl(var(--foreground));
  cursor: pointer;
}

.users-popover-item:hover {
  background: hsl(var(--muted));
}

.users-popover-item input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: hsl(var(--primary));
}

.users-popover-foot {
  margin: 6px -6px 0;
  padding: 8px 16px 4px;
  border-top: 1px solid hsl(var(--border));
}

.users-popover-foot button {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--primary));
  cursor: pointer;
}

.users-filter-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 2px dashed hsl(var(--input));
  border-radius: 10px;
  background: hsl(var(--background));
  font-size: 0.875rem;
  font-weight: 500;
  color: inherit;
  cursor: pointer;
}

.users-filter-button:hover,
.users-filter-button[aria-expanded="true"] {
  border-color: hsl(var(--primary));
}

.users-filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px 10px;
  font-size: 0.875rem;
  font-weight: 400;
  color: hsl(var(--foreground));
}

.users-filter-row span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.users-filter-row select {
  flex: 0 0 170px;
  width: 170px;
  height: 34px;
  padding: 0 30px 0 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  appearance: none;
  background: hsl(var(--background)) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236a7181' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  font-size: 0.8125rem;
  line-height: 32px;
  color: hsl(var(--foreground));
  text-overflow: ellipsis;
}

.users-chips-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.users-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.users-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 6px 0 12px;
  border: 1px solid hsl(var(--primary));
  border-radius: 999px;
  background: hsl(var(--primary) / 0.06);
  font-size: 0.8125rem;
  color: hsl(var(--foreground));
}

.users-chip a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: hsl(var(--muted-foreground));
}

.users-chip a:hover {
  background: hsl(var(--muted));
}

.users-chips-clear,
.users-chips-count {
  display: inline-flex;
  align-items: center;
  height: 30px;
  font-size: 0.8125rem;
  line-height: 1;
}

.users-chips-clear {
  font-weight: 500;
  color: hsl(var(--primary));
}

.users-chips-count {
  color: hsl(var(--muted-foreground));
}
