/* ============================================================================
   ucx.css — User Control: the Username page (.ucx), the Department & Role
   page (.acx), and the pieces they share (sheet, menu, toast, fields).

   Built on tokens.css only. Every control a finger touches is at least 44px
   high; every focus is visible; on a phone a dialog is a full-screen sheet
   with its buttons pinned where the thumb is.
   ============================================================================ */

.ucx, .acx {
  --ucx-row-h: 64px;
  --ucx-ring: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  display: grid;
  gap: 16px;
  min-width: 0;
}

.ucx :focus-visible, .acx :focus-visible, .ucx-sheet :focus-visible, .ucx-menu :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- header ---------------------------------------------------------------- */
.ucx-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
}
.ucx-head-text { display: grid; gap: 2px; min-width: 0; }
.ucx-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.25;
  color: var(--ink);
}
.ucx-sub, .ucx-count { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.ucx-head-actions { display: flex; gap: 8px; align-items: center; }
.ucx-add { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }

/* --- toolbar: search + filters -------------------------------------------- */
.ucx-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.ucx-search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.ucx-search > svg {
  position: absolute;
  left: 12px;
  color: var(--ink-faint);
  pointer-events: none;
}
.ucx-search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.ucx-search-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ucx-ring); }
.ucx-filter-toggle { display: none; align-items: center; gap: 6px; min-height: 44px; }
.ucx-filter-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ucx-select, .ucx-input {
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  max-width: 100%;
}
.ucx-select { padding-right: 32px; }
.ucx-filter-panel .ucx-select { flex: 0 1 200px; min-width: 150px; }
.ucx-input { width: 100%; }
.ucx-select:focus, .ucx-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ucx-ring); }
.ucx-input:disabled { background: var(--surface-alt); color: var(--ink-soft); }
.ucx-input[aria-invalid="true"] { border-color: var(--danger); }
.ucx-result-count { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* --- notices --------------------------------------------------------------- */
.ucx-notices:empty { display: none; }
.ucx-notices { display: grid; gap: 8px; }
.ucx-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.55;
  background: var(--surface-alt);
  color: var(--ink);
}
.ucx-notice > svg { flex: none; margin-top: 2px; }
.ucx-notice.is-warn { background: var(--warning-soft); color: var(--warning); }
.ucx-notice.is-ok { background: var(--success-soft); color: var(--accent-deep); }
.ucx-notice.is-info { background: var(--accent-soft); color: var(--accent-deep); }
.ucx-notice .btn { margin-left: auto; flex: none; }

/* --- the user table ---------------------------------------------------------- */
.ucx-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.ucx-tr {
  display: grid;
  grid-template-columns: minmax(200px, 2.2fr) minmax(110px, 1fr) minmax(110px, 1fr) minmax(140px, 1.4fr) auto;
  gap: 12px;
  align-items: center;
  min-height: var(--ucx-row-h);
  padding: 10px 16px;
  border-top: 1px solid var(--pt-line-soft, var(--border));
}
.ucx-tr:first-child { border-top: 0; }
.ucx-tr:not(.ucx-th):not(.ucx-skel):hover { background: color-mix(in srgb, var(--surface-alt) 55%, transparent); }
.ucx-th {
  min-height: 42px;
  background: var(--surface-alt);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}
.ucx-th .is-end { text-align: right; }
.ucx-td { min-width: 0; font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.ucx-tr.is-flash { animation: ucx-flash 2.2s ease-out; }
@keyframes ucx-flash { 0%, 30% { background: var(--accent-soft); } 100% { background: transparent; } }

.ucx-who { display: flex; align-items: center; gap: 12px; }
.ucx-name-btn {
  display: grid;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.ucx-name-btn:hover .ucx-name { color: var(--accent); text-decoration: underline; }
.ucx-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0; font-weight: 700; font-size: 15px; }
.ucx-name-sub { margin: 0; color: var(--ink-soft); font-size: 13px; }
.ucx-who .ucx-name-sub { display: none; }
.ucx-role {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 13px;
  font-weight: 600;
}
.ucx-role.is-admin { background: var(--ink); color: #fff; }
.ucx-muted { color: var(--ink-faint); }
.ucx-branch { display: block; }
.ucx-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.ucx-chips:empty { display: none; }
.ucx-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.ucx-badge.is-shop { background: var(--accent-soft); color: var(--accent-deep); }
.ucx-badge.is-saleman { background: #E4ECFB; color: #1D3F8A; }
.ucx-hint.is-warn { color: var(--warning); font-weight: 600; }
.ucx-badge.is-self { background: var(--brand-color); color: var(--ink); }
.ucx-badge.is-new { background: var(--accent-soft); color: var(--accent-deep); margin-left: 8px; }
.ucx-badge.is-muted { background: var(--warning-soft); color: var(--warning); margin-left: 6px; }
.ucx-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.ucx-edit { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.ucx-more-rows { justify-self: center; min-height: 44px; }

/* avatar */
.ucx-avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .02em;
}
.ucx-avatar--lg { width: 48px; height: 48px; font-size: 16px; }
.ucx-tone-0 { background: #E2F1EB; color: #0A4C3B; }
.ucx-tone-1 { background: #E4ECFB; color: #1D3F8A; }
.ucx-tone-2 { background: #FBE9DD; color: #8A3B0E; }
.ucx-tone-3 { background: #EFE6FA; color: #56308F; }
.ucx-tone-4 { background: #FFF3D4; color: #6B4B00; }
.ucx-tone-5 { background: #E3F2F6; color: #0E5566; }

/* loading rows */
.ucx-skel { grid-template-columns: 38px 1fr 120px; }
.ucx-skel-dot, .ucx-skel-line {
  display: block;
  background: linear-gradient(90deg, var(--surface-alt), var(--bg), var(--surface-alt));
  background-size: 200% 100%;
  animation: ucx-shimmer 1.2s linear infinite;
}
.ucx-skel-dot { width: 38px; height: 38px; border-radius: 50%; }
.ucx-skel-line { height: 12px; border-radius: 6px; }
.ucx-skel-line.is-short { width: 70%; }
@keyframes ucx-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* empty / error */
.ucx-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 40px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: center;
}
.ucx-state-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--ink-soft);
}
.ucx-state-title { margin: 0; font-weight: 700; font-size: 16px; color: var(--ink); }
.ucx-state-sub { margin: 0; color: var(--ink-soft); font-size: 14px; max-width: 42ch; }
.ucx-state .btn { margin-top: 6px; min-height: 44px; }

/* floating add button: phones only */
.ucx-fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--action);
  color: var(--action-ink);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  place-items: center;
}

/* --- icon buttons, menu, toast -------------------------------------------- */
.ucx-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.ucx-icon-btn:hover { background: var(--surface-alt); color: var(--ink); }
.ucx-menu-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.ucx-menu-btn > svg:last-child { transform: rotate(90deg); opacity: .7; }
.ucx-more[aria-expanded="true"] { background: var(--surface-alt); color: var(--ink); }

.ucx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: grid;
}
.ucx-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.ucx-menu-item:hover:not(:disabled), .ucx-menu-item:focus-visible { background: var(--surface-alt); }
.ucx-menu-item.is-danger { color: var(--danger); }
.ucx-menu-item.is-danger:hover:not(:disabled) { background: var(--danger-soft); }
.ucx-menu-item:disabled { color: var(--ink-faint); cursor: not-allowed; }

.ucx-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 1100;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  animation: ucx-toast-in .2s ease-out;
  transition: opacity .3s, transform .3s;
}
.ucx-toast > svg { flex: none; margin-top: 2px; }
.ucx-toast.is-warn { background: #5A3E00; }
.ucx-toast.is-out { opacity: 0; transform: translate(-50%, 8px); }
@keyframes ucx-toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* --- the sheet (dialog) ------------------------------------------------------ */
.ucx-sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: min(88vh, 860px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.ucx-sheet[open] { display: flex; flex-direction: column; }
.ucx-sheet.is-wide { width: min(820px, calc(100vw - 32px)); }
.ucx-sheet::backdrop { background: rgba(16, 32, 58, .45); }
.ucx-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px 22px;
  border-bottom: 1px solid var(--border);
}
.ucx-sheet-titles { min-width: 0; display: grid; gap: 4px; padding-top: 6px; }
.ucx-sheet-title { margin: 0; font-family: var(--font-display); font-size: 19px; line-height: 1.3; overflow-wrap: anywhere; }
.ucx-sheet-sub { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.ucx-sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 22px; overscroll-behavior: contain; }
.ucx-sheet-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 22px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ucx-sheet-foot .btn { min-height: 44px; }

/* --- forms ---------------------------------------------------------------- */
.ucx-form { display: grid; gap: 18px; }
.ucx-section { margin: 0; padding: 0; border: 0; display: grid; gap: 14px; min-width: 0; }
.ucx-section + .ucx-section { margin-top: 6px; }
.ucx-section-title {
  width: 100%;
  padding: 0 0 6px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.ucx-field { display: grid; gap: 6px; min-width: 0; }
.ucx-label { font-size: 14px; font-weight: 700; color: var(--ink); }
.ucx-req { color: var(--danger); }
.ucx-opt { color: var(--ink-faint); font-weight: 400; font-size: 13px; }
.ucx-hint { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.ucx-field-error, .ucx-form-error { margin: 0; color: var(--danger); font-size: 13px; font-weight: 600; line-height: 1.5; }
.ucx-form-error { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); }
.ucx-pw { position: relative; display: block; }
.ucx-pw .ucx-input { padding-right: 50px; }
.ucx-pw .ucx-in-field { position: absolute; right: 0; top: 0; }
.ucx-field > .btn--ghost { justify-self: start; }
.ucx-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  cursor: pointer;
}
.ucx-check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.ucx-dept-note { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-alt); }
.ucx-inline-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ucx-secret, .ucx-code {
  display: inline-block;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-family: var(--font-mono);
  font-size: 16px;
  overflow-wrap: anywhere;
  user-select: all;
}
.ucx-code { font-size: 13px; padding: 4px 8px; }
.ucx-secret.is-big { font-size: 22px; letter-spacing: .04em; }

/* steps (reset, import) */
.ucx-steps { margin: 0; padding: 0; list-style: none; counter-reset: ucx-step; display: grid; gap: 16px; }
.ucx-steps > li {
  counter-increment: ucx-step;
  position: relative;
  padding-left: 40px;
  display: grid;
  gap: 8px;
  justify-items: start;
}
.ucx-steps > li::before {
  content: counter(ucx-step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 800;
  font-size: 14px;
}
.ucx-steps p { margin: 0; line-height: 1.55; }
.ucx-steps > li > .ucx-field { justify-self: stretch; }
.ucx-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 88px;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--ink-soft);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.ucx-drop:hover, #ucx-import-file:focus-visible + .ucx-drop { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-soft); }
.ucx-hint-list { margin: 0; padding-left: 18px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; display: grid; gap: 4px; }
.ucx-file { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.ucx-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ucx-stat {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  font-size: 13px;
  color: var(--ink-soft);
}
.ucx-stat-n { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.1; }
.ucx-stat.is-ok { background: var(--success-soft); }
.ucx-stat.is-info { background: var(--accent-soft); }
.ucx-stat.is-bad { background: var(--danger-soft); }
.ucx-stat.is-bad .ucx-stat-n { color: var(--danger); }
.ucx-issues { display: grid; gap: 8px; }
.ucx-issues-title { margin: 0; font-weight: 700; }
.ucx-issues-scroll { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.ucx-issues table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ucx-issues th, .ucx-issues td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.ucx-issues th { position: sticky; top: 0; background: var(--surface-alt); }
.ucx-issues .is-num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* delete */
.ucx-danger-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--danger-soft);
}
.ucx-consequences { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; line-height: 1.55; }

/* save state line */
.ucx-save-state { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.ucx-save-state.is-dirty { color: var(--warning); }
.ucx-save-state.is-saving { color: var(--ink-soft); }
.ucx-save-state.is-saved { color: var(--accent); }
.ucx-save-state.is-failed { color: var(--danger); }

/* ============================================================================
   Department & Role
   ============================================================================ */
.acx-switch {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-alt);
}
.acx-switch-btn {
  min-height: 40px;
  padding: 6px 18px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.acx-switch-btn.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.acx-split {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.acx-pane {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  min-width: 0;
}
.acx-pane--list { padding: 12px; display: grid; gap: 10px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.acx-pane--detail { padding: 18px 20px 0; }
.acx-pane-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.acx-pane-head .btn { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; }
.acx-list-hint { padding: 2px 4px; }
.acx-items { display: grid; gap: 2px; }
.acx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.acx-item:hover { background: var(--surface-alt); }
.acx-item.is-on { background: var(--accent-soft); }
.acx-item.is-on .acx-item-name { color: var(--accent-deep); }
.acx-item.is-locked { cursor: default; opacity: .85; }
.acx-item.is-locked:hover { background: none; }
.acx-item > svg:last-child { color: var(--ink-faint); flex: none; }
.acx-item-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--ink-soft);
}
.acx-item-icon.is-big { width: 44px; height: 44px; background: var(--accent-soft); color: var(--accent-deep); }
.acx-item.is-on .acx-item-icon { background: var(--surface); color: var(--accent-deep); }
.acx-item-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.acx-item-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; flex-wrap: wrap; overflow-wrap: anywhere; }
.acx-item-sub { font-size: 12.5px; color: var(--ink-soft); }
.acx-empty { padding: 16px 8px; text-align: center; }

.acx-placeholder { border: 0; margin-bottom: 18px; }
.acx-detail { display: grid; gap: 16px; }
.acx-detail-head { display: flex; align-items: center; gap: 12px; }
.acx-back { display: none; }
.acx-detail-title { flex: 1; min-width: 0; }
.acx-detail-title h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
}
.acx-dept-row { display: grid; gap: 6px; max-width: 420px; }

.acx-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.acx-sum {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: none;
}
.acx-sum.is-on { border-color: transparent; background: var(--accent-soft); color: var(--accent-deep); }
.acx-sum-n { font-weight: 800; font-variant-numeric: tabular-nums; }
.acx-cap-search { max-width: 420px; }

.acx-groups { display: grid; gap: 14px; }
.acx-group {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  scroll-margin-top: 12px;
}
.acx-group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.acx-group-head h4 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.acx-group-n {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--ink-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.acx-group-actions { display: flex; gap: 4px; }
.acx-group-actions .btn { min-height: 36px; }
.acx-page + .acx-page { margin-top: 6px; }
.acx-page-name { margin: 6px 0 2px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }

.acx-cap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.acx-cap:hover { background: var(--surface-alt); }
.acx-cap.is-changed { background: color-mix(in srgb, var(--warning-soft) 70%, transparent); }
.acx-cap-text { font-size: 14px; line-height: 1.45; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
.acx-changed {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12px;
  font-weight: 800;
}
/* the switch: a real checkbox, drawn over */
.acx-switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.acx-toggle {
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #C3CAD6;
  transition: background .15s;
}
.acx-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform .15s;
}
.acx-switch-input:checked + .acx-toggle { background: var(--accent); }
.acx-switch-input:checked + .acx-toggle::after { transform: translateX(18px); }
.acx-switch-input:focus-visible + .acx-toggle { outline: 2px solid var(--accent); outline-offset: 2px; }

.acx-role-list { margin: 0; padding: 0; list-style: none; display: grid; }
.acx-role-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  border-top: 1px solid var(--border);
}
.acx-role-list li:first-child { border-top: 0; }
.acx-group > .ucx-select { margin-top: 8px; max-width: 320px; }

.acx-savebar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 -20px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: var(--surface);
}
.acx-savebar .ucx-save-state[hidden] + .acx-savebar-actions { margin-left: auto; }
.acx-savebar-actions { display: flex; gap: 8px; margin-left: auto; }
.acx-savebar-actions .btn { min-height: 44px; }

/* ============================================================================
   Tablet and phone
   ============================================================================ */
@media (max-width: 900px) {
  .ucx-tr { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) auto; }
  .ucx-col-role, .ucx-col-dept, .ucx-th > :nth-child(2), .ucx-th > :nth-child(3) { display: none; }
  .ucx-who .ucx-name-sub { display: block; }

  .acx-split { grid-template-columns: minmax(0, 1fr); }
  .acx-pane--list { position: static; max-height: none; }
  .acx-split:not(.is-detail) > .acx-pane--detail { display: none; }
  .acx-split.is-detail > .acx-pane--list { display: none; }
  .acx-back { display: inline-grid; margin-left: -8px; }
}

@media (max-width: 640px) {
  .ucx, .acx { gap: 12px; }
  .ucx-title { font-size: 19px; }
  .ucx-add { display: none; }
  .ucx-menu-btn { min-height: 40px; padding: 6px 12px; }
  .ucx-fab { display: grid; }
  .ucx-list-slot { padding-bottom: 72px; }

  .ucx-filter-toggle { display: inline-flex; }
  .ucx-filter-panel { display: none; }
  .ucx.filters-open .ucx-filter-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .ucx-filter-panel .ucx-select { min-width: 0; width: 100%; flex: none; }

  /* each user a card */
  .ucx-table { border: 0; background: none; display: grid; gap: 8px; overflow: visible; }
  .ucx-th { display: none; }
  .ucx-tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "who act" "branch branch";
    gap: 4px 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .ucx-tr:first-child { border-top: 1px solid var(--border); }
  .ucx-who { grid-area: who; }
  .ucx-actions { grid-area: act; }
  .ucx-col-branch { grid-area: branch; padding-left: 50px; font-size: 13px; color: var(--ink-soft); }
  .ucx-col-branch .ucx-branch { display: inline; }
  .ucx-col-branch .ucx-chips { display: inline-flex; margin: 0 0 0 6px; vertical-align: middle; }
  .ucx-edit span { display: none; }
  .ucx-edit { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .ucx-skel { grid-template-columns: 38px 1fr; grid-template-areas: none; }
  .ucx-skel .is-short { display: none; }

  /* the sheet fills the screen, its buttons under the thumb */
  .ucx-sheet, .ucx-sheet.is-wide {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  .ucx-sheet-head { padding: 10px 8px 10px 16px; }
  .ucx-sheet-body { padding: 16px; }
  .ucx-sheet-foot { padding-left: 16px; padding-right: 16px; }
  .ucx-sheet-foot .btn { flex: 1; }
  .ucx-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .ucx-stat { padding: 10px; }
  .ucx-stat-n { font-size: 22px; }

  .acx-switch { width: 100%; }
  .acx-switch-btn { flex: 1; min-height: 44px; }
  .acx-pane--detail { padding: 14px 14px 0; }
  .acx-savebar { margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
  .acx-savebar-actions { width: 100%; }
  .acx-savebar-actions .btn { flex: 1; }
  .acx-group { padding: 12px; }
  .acx-group-actions .btn { min-height: 44px; }
  .acx-cap { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .ucx-tr.is-flash, .ucx-skel-dot, .ucx-skel-line, .ucx-toast { animation: none; }
  .acx-toggle, .acx-toggle::after, .ucx-toast { transition: none; }
}

/* ============================================================================
   Role and Department as cards, each opening a box (access-tab.js, 2026-11)
   ========================================================================= */
.ucx-shell { display: grid; gap: 18px; min-width: 0; }
.ucx-tabs { margin: 0; }

.rx, .rx-page { display: grid; gap: 16px; min-width: 0; }
.rx-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.rx-search { flex: 1 1 260px; max-width: 440px; }
.rx-empty { padding: 24px 0; text-align: center; grid-column: 1 / -1; }

.rx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.rx-card {
  display: grid; align-content: start; gap: 10px; min-width: 0;
  padding: 16px; text-align: left; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform 0.18s var(--ease-out, ease), box-shadow 0.18s ease, border-color 0.18s ease;
}
.rx-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong, #CBD3DE); }
.rx-card:active { transform: translateY(0); }
.rx-card.is-locked { background: var(--surface-alt); box-shadow: none; cursor: default; transform: none; }
.rx-card.is-flash { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.14); }
.rx-card-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rx-card-icon {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent-deep);
}
.is-locked .rx-card-icon { background: var(--surface); color: var(--ink-faint); }
.rx-card-name {
  flex: 1; min-width: 0; font-family: var(--font-display); font-size: 16px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rx-card-ok {
  flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-deep); font-size: 12px; font-weight: 700;
}
.rx-dept-tag {
  justify-self: start; display: inline-flex; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-alt); color: var(--ink-soft); font-size: 12.5px; font-weight: 600;
}
.rx-dept-tag.is-none { background: none; border: 1px dashed var(--border-strong, #CBD3DE); color: var(--ink-faint); }
.rx-card-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; color: var(--ink-faint); font-size: 12.5px; }
.rx-card-meta > span { display: inline-flex; align-items: center; gap: 5px; }
.rx-card-mods { display: flex; flex-wrap: wrap; gap: 6px; }
.rx-mod-dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-alt); color: var(--ink-soft); }
.rx-mod-more { align-self: center; font-size: 12px; font-weight: 600; color: var(--ink-faint); }

/* --- the box --------------------------------------------------------------- */
.rx-box { display: grid; gap: 24px; }
.rx-sec { display: grid; gap: 12px; min-width: 0; }
.rx-sec-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.rx-sec-title { display: flex; align-items: center; gap: 8px; margin: 0; font-family: var(--font-body); font-size: 14px; font-weight: 700; color: var(--ink); }
.rx-cap-search { flex: 0 1 260px; min-width: 180px; }

.rx-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.rx-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--ink-soft); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
.rx-pill:hover { border-color: var(--border-strong, #CBD3DE); color: var(--ink); }
.rx-pill.is-on { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }

.rx-areas { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.rx-areas::-webkit-scrollbar { display: none; }
.rx-area {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 5px 6px 5px 12px;
  border: 0; border-radius: 999px; background: var(--surface-alt); color: var(--ink-soft);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background-color 0.16s ease, color 0.16s ease;
}
.rx-area:hover { color: var(--ink); }
.rx-area-n { padding: 1px 8px; border-radius: 999px; background: var(--surface); font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); }
.rx-area.has-on .rx-area-n { color: var(--accent-deep); }
.rx-area.is-on { background: var(--ink); color: #fff; }
.rx-area.is-on .rx-area-n { background: rgba(255, 255, 255, 0.16); color: #fff; }

.rx-caps { display: grid; gap: 12px; }
.rx-group { display: grid; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.rx-group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rx-group-head h4 { display: flex; align-items: center; gap: 8px; margin: 0; font-family: var(--font-body); font-size: 14.5px; font-weight: 700; }
.rx-group-n { padding: 1px 8px; border-radius: 999px; background: var(--surface-alt); color: var(--ink-soft); font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; }
.rx-group-n.is-on { background: var(--accent-soft); color: var(--accent-deep); }
.rx-mini {
  flex: none; padding: 6px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--accent-deep); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.rx-mini:hover { background: var(--accent-soft); }
.rx-page-row { display: grid; gap: 8px; }
.rx-page-name { font-size: 12.5px; font-weight: 600; color: var(--ink-faint); }

.rx-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.rx-chip {
  position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 13px 7px 9px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 500; line-height: 1.35; text-align: left; cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.12s var(--ease-out, ease);
}
.rx-chip:hover { border-color: var(--border-strong, #CBD3DE); }
.rx-chip:active { transform: scale(0.97); }
.rx-chip-tick {
  flex: none; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 6px;
  border: 1.5px solid var(--border-strong, #CBD3DE); background: var(--surface); color: transparent;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
.rx-chip.is-on { background: var(--accent-soft); border-color: #A7E3CB; color: var(--accent-deep); font-weight: 600; }
.rx-chip.is-on .rx-chip-tick { background: var(--accent); border-color: var(--accent); color: #fff; }
.rx-chip.is-changed::after {
  content: ""; position: absolute; top: -4px; right: -4px; width: 10px; height: 10px; border-radius: 50%;
  background: #F59E0B; border: 2px solid var(--surface);
}
.rx-chip.is-mod { padding: 7px 9px 7px 12px; }
.rx-chip-icon { display: inline-flex; color: var(--ink-faint); }
.rx-chip.is-on .rx-chip-icon { color: var(--accent-deep); }
.rx-chips.is-roomy { gap: 10px; }

.rx-fold { border: 1px dashed var(--border-strong, #CBD3DE); border-radius: var(--radius-md); padding: 0 14px; }
.rx-fold[open] { padding-bottom: 14px; }
.rx-fold > summary {
  display: flex; align-items: center; gap: 8px; padding: 12px 0; cursor: pointer;
  color: var(--ink-soft); font-size: 14px; font-weight: 600; list-style: none;
}
.rx-fold > summary::-webkit-details-marker { display: none; }
.rx-fold > summary::before { content: "\203A"; font-size: 18px; line-height: 1; transition: transform 0.16s ease; }
.rx-fold[open] > summary::before { transform: rotate(90deg); }
.rx-fold > .rx-group + .rx-group { margin-top: 10px; }

.rx-role {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 5px 5px 13px; border-radius: 999px;
  background: var(--surface-alt); border: 1px solid var(--border); font-size: 13.5px; font-weight: 600;
}
.rx-role.is-changed { background: var(--accent-soft); border-color: #A7E3CB; color: var(--accent-deep); }
.rx-role-n { padding: 1px 7px; border-radius: 999px; background: var(--surface); color: var(--ink-faint); font-family: var(--font-mono); font-size: 11.5px; }
.rx-role-x {
  display: grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-faint); cursor: pointer;
}
.rx-role-x:hover { background: var(--danger-soft); color: var(--danger); }
.rx-add { display: flex; }
.rx-add-select { width: auto; max-width: 100%; min-width: 220px; }

.ucx-sheet-foot { align-items: center; flex-wrap: wrap; }
.ucx-sheet-foot .ucx-save-state { margin: 0; }
.rx-foot-gap { flex: 1; }

@media (max-width: 640px) {
  .rx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .rx-card { gap: 8px; padding: 12px; }
  .rx-card-icon { width: 30px; height: 30px; border-radius: 9px; }
  .rx-card-name { font-size: 14.5px; }
  .rx-card-meta { gap: 2px 10px; font-size: 12px; }
  .rx-card-mods { display: none; }
  .rx-card-top { flex-wrap: wrap; }
  .rx-card-top .ucx-badge, .rx-card-ok { white-space: normal; max-width: 100%; }
  .rx-remove span { display: none; }
  .ucx-sheet-foot .ucx-save-state { order: -1; flex-basis: 100%; }
  .ucx-sheet-foot .rx-foot-gap { display: none; }
  .ucx-sheet-foot .btn--outline, .ucx-sheet-foot .btn--primary { flex: 1; white-space: nowrap; }
  .rx-cap-search { flex: 1 1 100%; }
}

.ucx-tr.is-openable { cursor: pointer; transition: background-color 0.12s ease; }
.ucx-tr.is-openable:hover { background: #F8FAFC; }
