/**
 * userpanel.css — User management panel (tabs) rendered in the primary area.
 * Covers: tab bar, user tables, group chips, row actions, forms.
 */

/* ===== User Panel Layer ===== */
#user-layer {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  background: var(--color-surface);
  overflow: hidden;
}

/* ===== Panel Header ===== */
.up-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.up-header h1 {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.up-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--color-text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.up-close:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* ===== Tab Bar ===== */
.up-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 16px 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
  overflow-x: auto;
}

.up-tab {
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.up-tab:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.up-tab.active {
  color: var(--color-primary);
  background: var(--color-surface-2);
  border-color: var(--color-border);
}

/* ===== Tab Content ===== */
.up-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.up-section {
  max-width: 900px;
}

/* ===== Toolbar row (title + action button) ===== */
.up-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.up-toolbar h2 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
}

/* ===== User Table ===== */
.user-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.user-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.user-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.88rem;
  vertical-align: middle;
}

.user-table tbody tr:last-child td {
  border-bottom: none;
}

.user-table tbody tr:hover {
  background: var(--color-bg);
}

/* ===== Avatar cell ===== */
.up-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.up-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}

.up-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.up-user-main {
  min-width: 0;
}

.up-user-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.up-user-sub {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Status badges ===== */
.up-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  background: var(--color-surface);
  white-space: nowrap;
}

.up-badge.active {
  color: var(--color-success);
  border-color: var(--color-success);
  background: rgba(90, 122, 90, 0.1);
}

.up-badge.suspended {
  color: var(--color-danger);
  border-color: var(--color-danger);
  background: rgba(139, 74, 74, 0.1);
}

.up-badge.pending {
  color: var(--color-warning);
  border-color: var(--color-warning);
  background: rgba(138, 112, 64, 0.1);
}

/* ===== Group chips ===== */
.up-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  max-width: 280px;
}

.up-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  font-size: 0.74rem;
  color: var(--color-text);
  white-space: nowrap;
}

.up-chip .up-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 0 2px;
  line-height: 1;
  border-radius: 50%;
}

.up-chip .up-chip-remove:hover {
  color: var(--color-danger);
  background: var(--color-border);
}

.up-chip-add {
  padding: 2px 6px 2px 2px;
}

.up-chip-none {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ===== Row actions ===== */
.up-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}

.up-actions .btn {
  padding: 3px 8px;
  font-size: 0.75rem;
}

/* ===== Forms ===== */
.up-form {
  max-width: 460px;
}

.up-form-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  max-width: 900px;
}

.up-form-card h3 {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

.up-form .input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 5px;
  align-items: center;
}

@media (max-width: 700px) {
  .up-form .input-row {
    grid-template-columns: 1fr;
  }
}

.up-avatar-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.up-avatar-preview .up-avatar {
  width: 64px;
  height: 64px;
  font-size: 1.4rem;
}

/* ===== Invite result / pending ===== */
.up-invite-result {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  font-size: 0.85rem;
  word-break: break-all;
}

/* ===== API access keys ===== */
.up-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

.up-card-header h3 {
  margin: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.up-muted {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.up-mono {
  font-family: var(--iosevka, monospace);
}

.up-keys-create {
  margin-bottom: 12px;
}

.up-keys-action {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.up-keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.up-keys-row {
  display: flex;
  align-items: center;
/*   justify-content: space-between; */
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
}

.up-keys-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.up-keys-name {
  font-weight: 600;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.up-keys-prefix {
  font-family: var(--iosevka, monospace);
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.up-keys-reveal {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-bg);
}

.up-keys-secret-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.up-keys-secret-row .input {
  flex: 1;
  min-width: 0;
}

.up-keys-copy {
  display: flex;
  align-items: stretch;
}

/* ===== API-keys help modal ===== */
.keys-help-modal {
  max-width: 640px;
  width: 92%;
}

.keys-help-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-y: auto;
}

.keys-help-body h4 {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--color-border);
}

.keys-help-code {
  margin: 0;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--iosevka, monospace);
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre;
  overflow-x: auto;
  color: var(--color-text);
}

.keys-help-route {
  display: grid;
  grid-template-columns: minmax(220px, auto) 1fr;
  gap: 12px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px dashed var(--color-border);
}

.keys-help-route:last-child {
  border-bottom: none;
}

.keys-help-endpoint {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.keys-help-method {
  font-family: var(--iosevka, monospace);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-primary);
}

.keys-help-path {
  font-family: var(--iosevka, monospace);
  font-size: 0.78rem;
}

.keys-help-desc {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

/** Explanatory text under the create form and inside the result box */
.up-invite-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin: 8px 0 0;
  word-break: normal;
}

/** A code, shown or masked. Monospace because it is read character by character. */
.up-invite-code {
  font-family: var(--iosevka);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/** The code of a brand-new invitation — nothing to hide, it was just handed over */
.up-invite-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 4px;
}

.up-invite-code-live {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

/** Copy code / Copy link / Revoke — grouped at the right of a row */
.up-invite-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.up-pending-list {
  margin-top: 8px;
}

.up-pending-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
}

/** The label + target + status column; takes the space the buttons do not */
.up-pending-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.up-pending-label {
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.up-pending-target {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.up-pending-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.up-pending-item:last-child {
  border-bottom: none;
}

/* ===== Invite e-mail composer ===== */
/* Wider than the other cards: a message body wraps badly in a 460px column. */
.up-mail-form {
  max-width: 100%;
}

.up-mail-body {
  font-family: var(--iosevka);
  font-size: 0.82rem;
  line-height: 1.55;
  resize: vertical;
  min-height: 220px;
  white-space: pre-wrap;
}

/* ===== Empty / loading ===== */
.up-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.up-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

/* ===== Groups tab ===== */
.up-create-form {
  margin-bottom: 16px;
}

.up-create-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.up-create-row .input {
  flex: 1;
  min-width: 0;
}

.up-create-row .btn {
  flex-shrink: 0;
}

.up-avatar.sm {
  width: 26px;
  height: 26px;
  font-size: 0.68rem;
}

.up-badge.member {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: rgba(107, 91, 78, 0.1);
}

.up-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
}

.up-member-row:last-child {
  border-bottom: none;
}

.up-member-row .up-user-main {
  flex: 1;
  min-width: 0;
}

.up-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ===== Notification settings ===== */

.ns-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.ns-card-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.ns-muted {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.ns-editor {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ns-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.ns-row:last-child {
  border-bottom: none;
}

.ns-row-text {
  min-width: 0;
}

.ns-row-title {
  font-size: 0.86rem;
  font-weight: 500;
}

.ns-row-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.ns-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.ns-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ns-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-surface-2);
}

.ns-group-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--color-text);
  padding: 0;
  text-align: left;
}

.ns-caret {
  display: inline-block;
  transition: transform var(--transition-fast);
  color: var(--color-text-muted);
}

.ns-type-list.expanded .ns-caret {
  transform: rotate(90deg);
}

.ns-type-list {
  padding: 2px 12px;
}

.ns-type-list.hidden {
  display: none;
}

.ns-type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.8rem;
}

.ns-type-row:last-child {
  border-bottom: none;
}

/* Toggle switch */
.ns-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 19px;
  flex-shrink: 0;
}

.ns-switch-input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ns-slider {
  position: absolute;
  inset: 0;
  background: var(--color-border-2);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.ns-slider::before {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--color-surface);
  transition: transform var(--transition-fast);
}

.ns-switch-input:checked + .ns-slider {
  background: var(--color-primary);
}

.ns-switch-input:checked + .ns-slider::before {
  transform: translateX(15px);
}

.ns-switch-input:disabled + .ns-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

.ns-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.ns-binder-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ns-effective-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.ns-eff-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 16px;
}

.ns-eff-group-label {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.ns-eff-type {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
}

.ns-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ns-dot.on {
  background: var(--color-success);
}

.ns-dot.off {
  background: var(--color-border-2);
}

.ns-eff-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--color-border);
}

.ns-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.ns-tag.on {
  color: var(--color-success);
  background: rgba(90, 122, 90, 0.12);
}

.ns-tag.off {
  color: var(--color-danger);
  background: rgba(139, 74, 74, 0.12);
}